From cbf052c6dbd7892b91e917fef2c68fb607d9e75a Mon Sep 17 00:00:00 2001 From: Tan90Qian <1436811949@qq.com> Date: Wed, 5 Sep 2018 11:25:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D2.0=E6=9D=83=E9=99=90?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/pages/Authorized.js | 13 +++++++------ src/utils/authority.js | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/pages/Authorized.js b/src/pages/Authorized.js index 676ef448..b9d18f2f 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 7c2fc013..76bd0f7c 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']; -- GitLab