Commit 608d5998 authored by ι™ˆεΈ…'s avatar ι™ˆεΈ…

fix #2291 Increase authority judgment

parent 9fff7f84
...@@ -16,6 +16,7 @@ import logo from '../assets/logo.svg'; ...@@ -16,6 +16,7 @@ import logo from '../assets/logo.svg';
import Footer from './Footer'; import Footer from './Footer';
import Header from './Header'; import Header from './Header';
import Context from './MenuContext'; import Context from './MenuContext';
import Exception403 from '../pages/Exception/403';
const { Content } = Layout; const { Content } = Layout;
...@@ -76,6 +77,7 @@ class BasicLayout extends React.PureComponent { ...@@ -76,6 +77,7 @@ class BasicLayout extends React.PureComponent {
this.getPageTitle = memoizeOne(this.getPageTitle); this.getPageTitle = memoizeOne(this.getPageTitle);
this.getBreadcrumbNameMap = memoizeOne(this.getBreadcrumbNameMap, isEqual); this.getBreadcrumbNameMap = memoizeOne(this.getBreadcrumbNameMap, isEqual);
this.breadcrumbNameMap = this.getBreadcrumbNameMap(); this.breadcrumbNameMap = this.getBreadcrumbNameMap();
this.matchParamsPath = memoizeOne(this.matchParamsPath, isEqual);
} }
state = { state = {
...@@ -156,14 +158,16 @@ class BasicLayout extends React.PureComponent { ...@@ -156,14 +158,16 @@ class BasicLayout extends React.PureComponent {
return routerMap; return routerMap;
} }
matchParamsPath = pathname => {
const pathKey = Object.keys(this.breadcrumbNameMap).find(key =>
pathToRegexp(key).test(pathname)
);
return this.breadcrumbNameMap[pathKey];
};
getPageTitle = pathname => { getPageTitle = pathname => {
let currRouterData = null; const currRouterData = this.matchParamsPath(pathname);
// match params path
Object.keys(this.breadcrumbNameMap).forEach(key => {
if (pathToRegexp(key).test(pathname)) {
currRouterData = this.breadcrumbNameMap[key];
}
});
if (!currRouterData) { if (!currRouterData) {
return 'Ant Design Pro'; return 'Ant Design Pro';
} }
...@@ -221,6 +225,7 @@ class BasicLayout extends React.PureComponent { ...@@ -221,6 +225,7 @@ class BasicLayout extends React.PureComponent {
const { isMobile } = this.state; const { isMobile } = this.state;
const isTop = PropsLayout === 'topmenu'; const isTop = PropsLayout === 'topmenu';
const menuData = this.getMenuData(); const menuData = this.getMenuData();
const routerConfig = this.matchParamsPath(pathname);
const layout = ( const layout = (
<Layout> <Layout>
{isTop && !isMobile ? null : ( {isTop && !isMobile ? null : (
...@@ -247,12 +252,15 @@ class BasicLayout extends React.PureComponent { ...@@ -247,12 +252,15 @@ class BasicLayout extends React.PureComponent {
isMobile={isMobile} isMobile={isMobile}
{...this.props} {...this.props}
/> />
<Content style={this.getContentStyle()}>{children}</Content> <Content style={this.getContentStyle()}>
<Authorized authority={routerConfig.authority} noMatch={<Exception403 />}>
{children}
</Authorized>
</Content>
<Footer /> <Footer />
</Layout> </Layout>
</Layout> </Layout>
); );
return ( return (
<React.Fragment> <React.Fragment>
<DocumentTitle title={this.getPageTitle(pathname)}> <DocumentTitle title={this.getPageTitle(pathname)}>
......
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