From 8bc421a7ad087267d1e076b5dcb4cb4563bda912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=B0=8F=E8=81=AA?= Date: Tue, 4 Dec 2018 17:33:31 +0800 Subject: [PATCH] :bug: fix route noAuthority nowork Close: 2998 (#3052) --- src/layouts/BasicLayout.js | 44 ++++++++++++++++---------------------- src/models/menu.js | 7 +----- 2 files changed, 20 insertions(+), 31 deletions(-) diff --git a/src/layouts/BasicLayout.js b/src/layouts/BasicLayout.js index 00e3429d..7cd5be5b 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 39c9b317..9cc54fb5 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); }; /** -- GitLab