From 69b514ee10ff2118dc0089bad560db1910fcd960 Mon Sep 17 00:00:00 2001 From: chenghongxing <1126263215@qq.com> Date: Thu, 3 Sep 2020 19:01:16 +0800 Subject: [PATCH] chore: optimize the code of routerUtil.js --- src/utils/routerUtil.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/utils/routerUtil.js b/src/utils/routerUtil.js index 34a8941..ce573c7 100644 --- a/src/utils/routerUtil.js +++ b/src/utils/routerUtil.js @@ -156,10 +156,11 @@ function formatRoutes(routes) { function formatAuthority(routes, pAuthorities = []) { routes.forEach(route => { const meta = route.meta + const defaultAuthority = pAuthorities[pAuthorities.length - 1] || {permission: '*'} if (meta) { let authority = {} if (!meta.authority) { - authority = pAuthorities.length > 0 ? pAuthorities[pAuthorities.length - 1] : {permission: '*'} + authority = defaultAuthority }else if (typeof meta.authority === 'string') { authority.permission = meta.authority } else if (typeof meta.authority === 'object') { @@ -169,14 +170,12 @@ function formatAuthority(routes, pAuthorities = []) { authority.role = [role] } if (!authority.permission && !authority.role) { - authority = pAuthorities.length > 0 ? pAuthorities[pAuthorities.length - 1] : {permission: '*'} + authority = defaultAuthority } - } else { - console.log(typeof meta.authority) } meta.authority = authority } else { - const authority = pAuthorities.length > 0 ? pAuthorities[pAuthorities.length - 1] : {permission: '*'} + const authority = defaultAuthority route.meta = {authority} } route.meta.pAuthorities = pAuthorities