🐛 fix(模块): 修复了一些 bug
This commit is contained in:
parent
6ed190d92e
commit
5689ff04eb
@ -114,7 +114,7 @@ const userApi = {
|
|||||||
handleCommonRes({
|
handleCommonRes({
|
||||||
authority: [
|
authority: [
|
||||||
'/',
|
'/',
|
||||||
'/about/u/1',
|
'/about/u/index',
|
||||||
'/about/u/2',
|
'/about/u/2',
|
||||||
'/about/m',
|
'/about/m',
|
||||||
'/about/um',
|
'/about/um',
|
||||||
|
|||||||
@ -41,13 +41,15 @@ const handleGetOpenKeys = (currentLocation: API.MenuItem[] | []): string[] => {
|
|||||||
res.push(`${currentLocation[i].key}`);
|
res.push(`${currentLocation[i].key}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log('res', res);
|
||||||
|
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
};
|
};
|
||||||
|
|
||||||
//自定义的layout页面, 顶部导航通栏+侧边栏(菜单)布局, 可根据需要做调整
|
//自定义的layout页面, 顶部导航通栏+侧边栏(菜单)布局, 可根据需要做调整
|
||||||
const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatch: any, location: any }> = (props) => {
|
const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatch: any, location: any }> = (props) => {
|
||||||
const [collapsed, setCollapsed] = useState(false);
|
const [collapsed, setCollapsed] = useState(false);
|
||||||
const [openKeys, setOpenKeys] = useState(['']);
|
|
||||||
const { pathname } = useLocation();
|
const { pathname } = useLocation();
|
||||||
|
|
||||||
|
|
||||||
@ -63,23 +65,12 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
|
|||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
console.log('props', props);
|
console.log('props', props);
|
||||||
const [activeKey, setActiveKey] = useState<string>('/')
|
console.log('pathname', pathname);
|
||||||
|
|
||||||
|
|
||||||
const validMenuItem = indexValidMenuItemByPath[pathname];
|
const validMenuItem = indexValidMenuItemByPath[pathname];
|
||||||
const selectedKeys = validMenuItem?.key;
|
// const selectedKeys = validMenuItem?.key;
|
||||||
|
const [activeKey, setActiveKey] = useState<string>(validMenuItem?.key || '/')
|
||||||
|
|
||||||
useEffect(
|
|
||||||
() => {
|
|
||||||
//每次页面重新渲染都要设置openKeys
|
|
||||||
setOpenKeys(
|
|
||||||
handleGetOpenKeys(
|
|
||||||
handleGetCurrentLocation(indexValidMenuItemByPath[pathname], indexAllMenuItemById),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
[pathname, indexAllMenuItemById, indexValidMenuItemByPath],
|
|
||||||
);
|
|
||||||
|
|
||||||
//Menu中的selectedKeys和openKeys不是一回事:
|
//Menu中的selectedKeys和openKeys不是一回事:
|
||||||
//openKeys:
|
//openKeys:
|
||||||
@ -139,9 +130,7 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
|
|||||||
// ],
|
// ],
|
||||||
// },
|
// },
|
||||||
// ];
|
// ];
|
||||||
console.log('consumableMenu', consumableMenu);
|
|
||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
console.log('location', location);
|
|
||||||
|
|
||||||
|
|
||||||
// 改变panes
|
// 改变panes
|
||||||
@ -297,16 +286,14 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
|
|||||||
}}
|
}}
|
||||||
actionsRender={() => <nav />}
|
actionsRender={() => <nav />}
|
||||||
onPageChange={(location) => {
|
onPageChange={(location) => {
|
||||||
console.log('location', location);
|
console.log('location------', location);
|
||||||
if (location?.pathname && location?.pathname !== '/') {
|
if (location?.pathname && location?.pathname !== '/') {
|
||||||
console.log('oneFloorList', oneFloorList);
|
console.log('oneFloorList', oneFloorList);
|
||||||
|
|
||||||
// const nextModule = oneFloorList.find(n => location?.pathname && n?.path && location?.pathname.match(n?.path))
|
|
||||||
const nextModule: any = oneFloorList.filter(n => location?.pathname === n?.path)
|
const nextModule: any = oneFloorList.filter(n => location?.pathname === n?.path)
|
||||||
console.log('nextModule', nextModule);
|
console.log('nextModule', nextModule);
|
||||||
let title = ''
|
let title = ''
|
||||||
if (nextModule && nextModule.length > 0) {
|
if (nextModule && nextModule.length > 0) {
|
||||||
// `${formatMessage({ id: `menu${title.substring(0, title?.indexOf('.detail'))}` })}详情`
|
|
||||||
title = nextModule[0].name
|
title = nextModule[0].name
|
||||||
}
|
}
|
||||||
handleTabsPanes({ path: location?.pathname, key: location?.pathname, title: title })
|
handleTabsPanes({ path: location?.pathname, key: location?.pathname, title: title })
|
||||||
@ -314,25 +301,6 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
|
|||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
||||||
{/* menuExtraRender={() =>
|
|
||||||
<Layout>
|
|
||||||
<Menu
|
|
||||||
mode="inline"
|
|
||||||
openKeys={openKeys}
|
|
||||||
items={consumableMenu}
|
|
||||||
onOpenChange={(e: any, dom: any) => {
|
|
||||||
onOpenChange(e)
|
|
||||||
}}
|
|
||||||
onSelect={(item: any, key: any) => {
|
|
||||||
console.log('item', item);
|
|
||||||
console.log('key', key);
|
|
||||||
}}
|
|
||||||
selectedKeys={[selectedKeys]}
|
|
||||||
/>
|
|
||||||
</Layout>
|
|
||||||
} */}
|
|
||||||
|
|
||||||
<Layout>
|
<Layout>
|
||||||
<Header style={{ background: '#fff', height: '48px', padding: '0 16px' }}>
|
<Header style={{ background: '#fff', height: '48px', padding: '0 16px' }}>
|
||||||
<Nav />
|
<Nav />
|
||||||
@ -413,53 +381,6 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
|
|||||||
</Layout>
|
</Layout>
|
||||||
</ProLayout>
|
</ProLayout>
|
||||||
</LayoutWrapper >
|
</LayoutWrapper >
|
||||||
|
|
||||||
// <LayoutWrapper>
|
|
||||||
// <Layout style={{ minHeight: '100vh' }}>
|
|
||||||
// <Header
|
|
||||||
// style={{
|
|
||||||
// padding: '0',
|
|
||||||
// height: 'auto',
|
|
||||||
// }}
|
|
||||||
// >
|
|
||||||
// <Nav />
|
|
||||||
// </Header>
|
|
||||||
// <Layout>
|
|
||||||
// <Sider
|
|
||||||
// collapsible
|
|
||||||
// theme="light"
|
|
||||||
// collapsed={collapsed}
|
|
||||||
// onCollapse={(value) => setCollapsed(value)}
|
|
||||||
// >
|
|
||||||
// <Menu
|
|
||||||
// mode="inline"
|
|
||||||
// openKeys={openKeys}
|
|
||||||
// items={consumableMenu}
|
|
||||||
// onOpenChange={onOpenChange}
|
|
||||||
// selectedKeys={[selectedKeys]}
|
|
||||||
// />
|
|
||||||
// </Sider>
|
|
||||||
// <Layout>
|
|
||||||
// <Content style={{ margin: '0 16px' }}>
|
|
||||||
// {
|
|
||||||
// //统一对所有有效路由做页面鉴权的处理
|
|
||||||
// validMenuItem
|
|
||||||
// ? (
|
|
||||||
// <PageAccess>
|
|
||||||
// <Outlet />
|
|
||||||
// </PageAccess>
|
|
||||||
// )
|
|
||||||
// //这里不再使用<Outlet />是因为当一条路由在菜单接口中没有返回, 但实际项目中创建了,
|
|
||||||
// //此时访问应该显示404页面; 菜单中没有, 实际项目中有表示这条路由/页面当前登录用户无法访问,
|
|
||||||
// //而如果继续使用<Outlet />则那条路由/页面依旧会被渲染, 因为对于umi来说这条路由/页面是有效的,
|
|
||||||
// //是存在的, 而对于本项目来说则不是
|
|
||||||
// : <Page404 />
|
|
||||||
// }
|
|
||||||
// </Content>
|
|
||||||
// </Layout>
|
|
||||||
// </Layout>
|
|
||||||
// </Layout>
|
|
||||||
// </LayoutWrapper>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -468,4 +389,4 @@ export default connect(
|
|||||||
user,
|
user,
|
||||||
global
|
global
|
||||||
}),
|
}),
|
||||||
)(BasicLayout);
|
)(BasicLayout);
|
||||||
|
|||||||
@ -172,6 +172,8 @@ const GlobalModel: GlobalModelType = {
|
|||||||
|
|
||||||
const tabsRoutes: tabsRoute[] = yield select((state: ConnectState) => {
|
const tabsRoutes: tabsRoute[] = yield select((state: ConnectState) => {
|
||||||
const { data } = payload
|
const { data } = payload
|
||||||
|
console.log('data', data);
|
||||||
|
console.log('payload', payload);
|
||||||
|
|
||||||
if (payload.action === 'add') {
|
if (payload.action === 'add') {
|
||||||
const index = state.global.tabsRoutes.findIndex(n => n.path === data.path)
|
const index = state.global.tabsRoutes.findIndex(n => n.path === data.path)
|
||||||
|
|||||||
@ -193,6 +193,9 @@ const UserModel: UserModelType = {
|
|||||||
const indexAllMenuItemByPath = handleGetEachDatumFromNestedDataByKey(menuRes.data, 'path');
|
const indexAllMenuItemByPath = handleGetEachDatumFromNestedDataByKey(menuRes.data, 'path');
|
||||||
const indexValidMenuItemByPath = handleGetIndexValidMenuItemByPath(menuRes.data);
|
const indexValidMenuItemByPath = handleGetIndexValidMenuItemByPath(menuRes.data);
|
||||||
|
|
||||||
|
console.log('indexValidMenuItemByPath', indexValidMenuItemByPath);
|
||||||
|
|
||||||
|
|
||||||
//在登录完获取菜单数据之后做是否需要重定向的操作
|
//在登录完获取菜单数据之后做是否需要重定向的操作
|
||||||
yield call(
|
yield call(
|
||||||
handleRedirect,
|
handleRedirect,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user