diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 00e3429dec0cb0995418e092d03f5a87c5bb027d..7cd5be5b217442d4936de94920053f90e2a36773 100644 --- a/src/layouts/BasicLayout.js +++ b/src/layouts/BasicLayout.js @@ -91,31 +91,27 @@ class BasicLayout extends React.PureComponent { }; } - /** - * 获取面包屑映射 - * @param {Object} menuData 菜单配置 - */ - getBreadcrumbNameMap() { - const routerMap = {}; - const { menuData } = this.props; - const flattenMenuData = data => { - data.forEach(menuItem => { - if (menuItem.children) { - flattenMenuData(menuItem.children); - } - // Reduce memory usage - routerMap[menuItem.path] = menuItem; - }); - }; - flattenMenuData(menuData); - return routerMap; - } - matchParamsPath = (pathname, breadcrumbNameMap) => { const pathKey = Object.keys(breadcrumbNameMap).find(key => pathToRegexp(key).test(pathname)); return breadcrumbNameMap[pathKey]; }; + getRouterAuthority = (pathname, routeData) => { + let routeAuthority = ['noAuthority']; + const getAuthority = (key, routes) => { + routes.map(route => { + if (route.path === key) { + routeAuthority = route.authority; + } else if (route.routes) { + routeAuthority = getAuthority(key, route.routes); + } + return route; + }); + return routeAuthority; + }; + return getAuthority(pathname, routeData); + }; + getPageTitle = (pathname, breadcrumbNameMap) => { const currRouterData = this.matchParamsPath(pathname, breadcrumbNameMap); @@ -166,11 +162,12 @@ class BasicLayout extends React.PureComponent { isMobile, menuData, breadcrumbNameMap, + route: { routes }, fixedHeader, } = this.props; const isTop = PropsLayout === 'topmenu'; - const routerConfig = this.matchParamsPath(pathname, breadcrumbNameMap); + const routerConfig = this.getRouterAuthority(pathname, routes); const contentStyle = !fixedHeader ? { paddingTop: 0 } : {}; const layout = ( @@ -198,10 +195,7 @@ class BasicLayout extends React.PureComponent { {...this.props} /> - } - > + }> {children} diff --git a/src/models/menu.js b/src/models/menu.js index 39c9b317667e0c68701381cb5b0cf4ea71aa3071..9cc54fb5d0857d944176c86577b586a0a38b7737 100644 --- a/src/models/menu.js +++ b/src/models/menu.js @@ -62,12 +62,7 @@ const filterMenuData = menuData => { } return menuData .filter(item => item.name && !item.hideInMenu) - .map(item => { - // make dom - const ItemDom = getSubMenu(item); - const data = check(item.authority, ItemDom); - return data; - }) + .map(item => check(item.authority, getSubMenu(item))) .filter(item => item); }; /**