chore: optimize the code of routerUtil.js

master
chenghongxing 4 years ago
parent 4856f06f41
commit 69b514ee10
  1. 9
      src/utils/routerUtil.js

@ -156,10 +156,11 @@ function formatRoutes(routes) {
function formatAuthority(routes, pAuthorities = []) { function formatAuthority(routes, pAuthorities = []) {
routes.forEach(route => { routes.forEach(route => {
const meta = route.meta const meta = route.meta
const defaultAuthority = pAuthorities[pAuthorities.length - 1] || {permission: '*'}
if (meta) { if (meta) {
let authority = {} let authority = {}
if (!meta.authority) { if (!meta.authority) {
authority = pAuthorities.length > 0 ? pAuthorities[pAuthorities.length - 1] : {permission: '*'} authority = defaultAuthority
}else if (typeof meta.authority === 'string') { }else if (typeof meta.authority === 'string') {
authority.permission = meta.authority authority.permission = meta.authority
} else if (typeof meta.authority === 'object') { } else if (typeof meta.authority === 'object') {
@ -169,14 +170,12 @@ function formatAuthority(routes, pAuthorities = []) {
authority.role = [role] authority.role = [role]
} }
if (!authority.permission && !authority.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 meta.authority = authority
} else { } else {
const authority = pAuthorities.length > 0 ? pAuthorities[pAuthorities.length - 1] : {permission: '*'} const authority = defaultAuthority
route.meta = {authority} route.meta = {authority}
} }
route.meta.pAuthorities = pAuthorities route.meta.pAuthorities = pAuthorities

Loading…
Cancel
Save