🐛 fix(模块): 修复了一些 bug

This commit is contained in:
cclu 2025-02-28 15:16:21 +08:00
parent 6ed190d92e
commit 5689ff04eb
4 changed files with 15 additions and 89 deletions

View File

@ -114,7 +114,7 @@ const userApi = {
handleCommonRes({
authority: [
'/',
'/about/u/1',
'/about/u/index',
'/about/u/2',
'/about/m',
'/about/um',

View File

@ -41,13 +41,15 @@ const handleGetOpenKeys = (currentLocation: API.MenuItem[] | []): string[] => {
res.push(`${currentLocation[i].key}`);
}
console.log('res', res);
return res;
};
//自定义的layout页面, 顶部导航通栏+侧边栏(菜单)布局, 可根据需要做调整
const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatch: any, location: any }> = (props) => {
const [collapsed, setCollapsed] = useState(false);
const [openKeys, setOpenKeys] = useState(['']);
const { pathname } = useLocation();
@ -63,23 +65,12 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
} = props;
console.log('props', props);
const [activeKey, setActiveKey] = useState<string>('/')
console.log('pathname', 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不是一回事:
//openKeys:
@ -139,9 +130,7 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
// ],
// },
// ];
console.log('consumableMenu', consumableMenu);
const location = useLocation();
console.log('location', location);
// 改变panes
@ -297,16 +286,14 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
}}
actionsRender={() => <nav />}
onPageChange={(location) => {
console.log('location', location);
console.log('location------', location);
if (location?.pathname && location?.pathname !== '/') {
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)
console.log('nextModule', nextModule);
let title = ''
if (nextModule && nextModule.length > 0) {
// `${formatMessage({ id: `menu${title.substring(0, title?.indexOf('.detail'))}` })}详情`
title = nextModule[0].name
}
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>
<Header style={{ background: '#fff', height: '48px', padding: '0 16px' }}>
<Nav />
@ -413,53 +381,6 @@ const BasicLayout: FC<{ user: UserModelState, global: ProfileModelState, dispatc
</Layout>
</ProLayout>
</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>
);
};

View File

@ -172,6 +172,8 @@ const GlobalModel: GlobalModelType = {
const tabsRoutes: tabsRoute[] = yield select((state: ConnectState) => {
const { data } = payload
console.log('data', data);
console.log('payload', payload);
if (payload.action === 'add') {
const index = state.global.tabsRoutes.findIndex(n => n.path === data.path)

View File

@ -193,6 +193,9 @@ const UserModel: UserModelType = {
const indexAllMenuItemByPath = handleGetEachDatumFromNestedDataByKey(menuRes.data, 'path');
const indexValidMenuItemByPath = handleGetIndexValidMenuItemByPath(menuRes.data);
console.log('indexValidMenuItemByPath', indexValidMenuItemByPath);
//在登录完获取菜单数据之后做是否需要重定向的操作
yield call(
handleRedirect,