提交 83df4267 编写于 作者: A afc163 提交者: 偏右

fix authority

上级 ff08655f
......@@ -3,22 +3,35 @@ import RenderAuthorized from '@/components/Authorized';
import Exception from '@/components/Exception';
import { matchRoutes } from 'react-router-config';
import uniq from 'lodash/uniq';
import { formatMessage } from 'umi/locale';
import Link from 'umi/link';
const Authorized = RenderAuthorized(['admin', 'user']);
const noMatch = <Exception type="403" style={{ minHeight: 500, height: '80%' }} />;
export default ({ children, route, location }) => {
const routes = matchRoutes(route.routes, location.pathname);
let authorities = [];
routes.forEach(item => {
if (Array.isArray(item.authority)) {
authorities = authorities.concat(item.authority);
} else if (typeof item.authority === 'string') {
authorities.push(item.authority);
if (Array.isArray(item.route.authority)) {
authorities = authorities.concat(item.route.authority);
} else if (typeof item.route.authority === 'string') {
authorities.push(item.route.authority);
}
});
const noMatch = (
<Exception
type="403"
desc={formatMessage({ id: 'app.exception.description.403' }, {})}
style={{ minHeight: 500, height: '80%' }}
linkElement={Link}
backText={formatMessage({ id: 'app.exception.back' })}
/>
);
return (
<Authorized authority={uniq(authorities)} noMatch={noMatch}>
<Authorized
authority={authorities.length === 0 ? undefined : uniq(authorities)}
noMatch={noMatch}
>
{children}
</Authorized>
);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册