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

优化菜单拉取

parent b8ee832c
...@@ -94,12 +94,6 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => { ...@@ -94,12 +94,6 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
let list = routes.filter((item: any) => pathname.indexOf(item.key) > -1) let list = routes.filter((item: any) => pathname.indexOf(item.key) > -1)
return list[0] return list[0]
} }
const initOpendKeys = (routes: any) => {
if (routes) {
return routes.map((item: any) => item.key)
}
return []
}
const { formatMessage } = useIntl(); const { formatMessage } = useIntl();
const basicInfo = getMenuData(props.route.routes, { locale: true }, formatMessage) const basicInfo = getMenuData(props.route.routes, { locale: true }, formatMessage)
...@@ -107,6 +101,8 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => { ...@@ -107,6 +101,8 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
const menuRouter = getMenuRouter(menuData, location.pathname) const menuRouter = getMenuRouter(menuData, location.pathname)
const currentRouter = basicInfo.breadcrumb[location.pathname];
useEffect(() => { useEffect(() => {
// if pathname can't match, use the nearest parent's key // if pathname can't match, use the nearest parent's key
const keys = getSelectedMenuKeys( const keys = getSelectedMenuKeys(
...@@ -125,13 +121,13 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => { ...@@ -125,13 +121,13 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
if (collapsed) { if (collapsed) {
setOpenKeys([]) setOpenKeys([])
} else { } else {
setOpenKeys(initOpendKeys(menuRouter.children)) // 优化默认打开的菜单
setOpenKeys([...openKeys, currentRouter.key, ...currentRouter.pro_layout_parentKeys])
} }
} else { } else {
setOpenKeys([]) setOpenKeys([])
} }
}, [location.pathname, collapsed]) }, [currentRouter, location.pathname, collapsed])
return ( return (
<ProLayout <ProLayout
style={{ minHeight: '100vh' }} style={{ minHeight: '100vh' }}
...@@ -145,6 +141,7 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => { ...@@ -145,6 +141,7 @@ const BasicLayout: React.FC<BasicLayoutProps> = (props) => {
)} )}
collapsed={collapsed} collapsed={collapsed}
onCollapse={handleMenuCollapse} onCollapse={handleMenuCollapse}
disableContentMargin={currentRouter.noMargin !== undefined}
breadcrumbRender={(routers = []) => [ 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