Commit e77a6044 authored by 前端-许佳敏's avatar 前端-许佳敏

优化菜单拉取

parent b8ee832c
......@@ -94,12 +94,6 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
let list = routes.filter((item: any) => pathname.indexOf(item.key) > -1)
return list[0]
}
const initOpendKeys = (routes: any) => {
if (routes) {
return routes.map((item: any) => item.key)
}
return []
}
const { formatMessage } = useIntl();
const basicInfo = getMenuData(props.route.routes, { locale: true }, formatMessage)
......@@ -107,6 +101,8 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
const menuRouter = getMenuRouter(menuData, location.pathname)
const currentRouter = basicInfo.breadcrumb[location.pathname];
useEffect(() => {
// if pathname can't match, use the nearest parent's key
const keys = getSelectedMenuKeys(
......@@ -125,13 +121,13 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
if (collapsed) {
setOpenKeys([])
} else {
setOpenKeys(initOpendKeys(menuRouter.children))
// 优化默认打开的菜单
setOpenKeys([...openKeys, currentRouter.key, ...currentRouter.pro_layout_parentKeys])
}
} else {
setOpenKeys([])
}
}, [location.pathname, collapsed])
}, [currentRouter, location.pathname, collapsed])
return (
<ProLayout
style={{ minHeight: '100vh' }}
......@@ -145,6 +141,7 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
)}
collapsed={collapsed}
onCollapse={handleMenuCollapse}
disableContentMargin={currentRouter.noMargin !== undefined}
breadcrumbRender={(routers = []) => [
]}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment