|
|
|
@ -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 = ( |
|
|
|
<Layout> |
|
|
|
@ -198,10 +195,7 @@ class BasicLayout extends React.PureComponent { |
|
|
|
{...this.props} |
|
|
|
/> |
|
|
|
<Content className={styles.content} style={contentStyle}> |
|
|
|
<Authorized |
|
|
|
authority={routerConfig && routerConfig.authority} |
|
|
|
noMatch={<Exception403 />} |
|
|
|
> |
|
|
|
<Authorized authority={routerConfig} noMatch={<Exception403 />}> |
|
|
|
{children} |
|
|
|
</Authorized> |
|
|
|
</Content> |
|
|
|
|