提交 8bc421a7 编写于 作者: 陈小聪 提交者: 陈帅

🐛 fix route noAuthority nowork Close: 2998 (#3052)

上级 29477bb4
......@@ -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>
......
......@@ -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);
};
/**
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册