diff --git a/src/pages/Authorized.js b/src/pages/Authorized.js index 676ef4486943655d38880e423eadeb94de5c12bc..b9d18f2fd66346a717508f34a93e17e9cd73d0c1 100644 --- a/src/pages/Authorized.js +++ b/src/pages/Authorized.js @@ -1,21 +1,22 @@ import React from 'react'; import RenderAuthorized from '@/components/Authorized'; import Exception from '@/components/Exception'; +import { getAuthority } from '@/utils/authority'; import { matchRoutes } from 'react-router-config'; -import uniq from 'lodash/uniq'; +import intersection from 'lodash/intersection'; import { formatMessage } from 'umi/locale'; import Link from 'umi/link'; -const Authorized = RenderAuthorized(['admin', 'user']); +const Authorized = RenderAuthorized(getAuthority()); export default ({ children, route, location }) => { const routes = matchRoutes(route.routes, location.pathname); let authorities = []; routes.forEach(item => { - if (Array.isArray(item.route.authority)) { - authorities = authorities.concat(item.route.authority); - } else if (typeof item.route.authority === 'string') { + if (Array.isArray(item.route.authority) && item.route.authority.length) { authorities.push(item.route.authority); + } else if (typeof item.route.authority === 'string' && item.route.authority) { + authorities.push([item.route.authority]); } }); const noMatch = ( @@ -28,7 +29,7 @@ export default ({ children, route, location }) => { ); return ( {children} diff --git a/src/utils/authority.js b/src/utils/authority.js index 7c2fc013268f64231f26ef168962a1a5c8a5f7ca..76bd0f7ccde4e07566a4ef0b989f117f95307917 100644 --- a/src/utils/authority.js +++ b/src/utils/authority.js @@ -6,7 +6,7 @@ export function getAuthority() { if (authority.includes('[')) { authority = JSON.parse(authority); } else { - authority = [authority]; + authority = [JSON.parse(authority)]; } } else { authority = ['admin'];