|
|
@@ -14,19 +14,35 @@ import React, { useEffect } from 'react';
|
|
|
import Link from 'umi/link';
|
|
|
import { Dispatch } from 'redux';
|
|
|
import { connect } from 'dva';
|
|
|
-import { Icon } from 'antd';
|
|
|
+import { Icon, Result, Button } from 'antd';
|
|
|
import { formatMessage } from 'umi-plugin-react/locale';
|
|
|
|
|
|
import Authorized from '@/utils/Authorized';
|
|
|
import RightContent from '@/components/GlobalHeader/RightContent';
|
|
|
import { ConnectState } from '@/models/connect';
|
|
|
-import { isAntDesignPro } from '@/utils/utils';
|
|
|
+import { isAntDesignPro, getAuthorityFromRouter } from '@/utils/utils';
|
|
|
import logo from '../assets/logo.svg';
|
|
|
|
|
|
+const noMatch = (
|
|
|
+ <Result
|
|
|
+ status="403"
|
|
|
+ title="403"
|
|
|
+ subTitle="Sorry, you are not authorized to access this page."
|
|
|
+ extra={
|
|
|
+ <Button type="primary">
|
|
|
+ <Link to="/user/login">Go Login</Link>
|
|
|
+ </Button>
|
|
|
+ }
|
|
|
+ />
|
|
|
+);
|
|
|
+
|
|
|
export interface BasicLayoutProps extends ProLayoutProps {
|
|
|
breadcrumbNameMap: {
|
|
|
[path: string]: MenuDataItem;
|
|
|
};
|
|
|
+ route: ProLayoutProps['route'] & {
|
|
|
+ authority: string[];
|
|
|
+ };
|
|
|
settings: Settings;
|
|
|
dispatch: Dispatch;
|
|
|
}
|
|
|
@@ -100,7 +116,7 @@ const footerRender: BasicLayoutProps['footerRender'] = () => {
|
|
|
};
|
|
|
|
|
|
const BasicLayout: React.FC<BasicLayoutProps> = props => {
|
|
|
- const { dispatch, children, settings } = props;
|
|
|
+ const { dispatch, children, settings, location = { pathname: '/' } } = props;
|
|
|
/**
|
|
|
* constructor
|
|
|
*/
|
|
|
@@ -115,7 +131,6 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => {
|
|
|
});
|
|
|
}
|
|
|
}, []);
|
|
|
-
|
|
|
/**
|
|
|
* init variables
|
|
|
*/
|
|
|
@@ -127,6 +142,10 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => {
|
|
|
});
|
|
|
}
|
|
|
};
|
|
|
+ // get children authority
|
|
|
+ const authorized = getAuthorityFromRouter(props.route.routes, location.pathname || '/') || {
|
|
|
+ authority: undefined,
|
|
|
+ };
|
|
|
|
|
|
return (
|
|
|
<ProLayout
|
|
|
@@ -163,7 +182,9 @@ const BasicLayout: React.FC<BasicLayoutProps> = props => {
|
|
|
{...props}
|
|
|
{...settings}
|
|
|
>
|
|
|
- {children}
|
|
|
+ <Authorized authority={authorized!.authority} noMatch={noMatch}>
|
|
|
+ {children}
|
|
|
+ </Authorized>
|
|
|
</ProLayout>
|
|
|
);
|
|
|
};
|