mirror of
https://github.com/iczer/vue-antd-admin
synced 2025-04-05 07:27:06 +08:00
fix: fixed the issue that the router permission configuration does not support arrays
; 🐛
修复:修复路由权限配置不支持数组的问题;
This commit is contained in:
parent
d7a530db46
commit
a4d4b28ce3
@ -8,10 +8,12 @@ function hasPermission(authority, permissions) {
|
||||
let required = '*'
|
||||
if (typeof authority === 'string') {
|
||||
required = authority
|
||||
} else if (Array.isArray(authority)) {
|
||||
required = authority
|
||||
} else if (typeof authority === 'object') {
|
||||
required = authority.permission
|
||||
}
|
||||
return required === '*' || (permissions && permissions.findIndex(item => item === required || item.id === required) !== -1)
|
||||
return required === '*' || hasAnyItem(required, permissions, (r, t) => !!(r === t || r === t.id))
|
||||
}
|
||||
|
||||
/**
|
||||
@ -24,25 +26,23 @@ function hasRole(authority, roles) {
|
||||
if (typeof authority === 'object') {
|
||||
required = authority.role
|
||||
}
|
||||
return authority === '*' || hasAnyRole(required, roles)
|
||||
return authority === '*' || hasAnyItem(required, roles, (r, t) => !!(r === t || r === t.id))
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否有需要的任意一个角色
|
||||
* @param required {String | Array[String]} 需要的角色,可以是单个角色或者一个角色数组
|
||||
* @param roles 拥有的角色
|
||||
* 判断目标数组是否有所需元素
|
||||
* @param {String | String[]}required 所需元素,数组或单个元素
|
||||
* @param {String[]|Object[]} source 目标数组
|
||||
* @param {Function} filter 匹配条件
|
||||
* (r: String, s: String|Object) => boolean
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function hasAnyRole(required, roles) {
|
||||
function hasAnyItem(required, source, filter) {
|
||||
if (!required) {
|
||||
return false
|
||||
} else if(Array.isArray(required)) {
|
||||
return roles.findIndex(role => {
|
||||
return required.findIndex(item => item === role || item === role.id) !== -1
|
||||
}) !== -1
|
||||
} else {
|
||||
return roles.findIndex(role => role === required || role.id === required) !== -1
|
||||
}
|
||||
let checkedList = Array.isArray(required) ? required : [required]
|
||||
return !!source.find(s => checkedList.find(r => filter(r, s)))
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -212,7 +212,7 @@ function formatAuthority(routes, pAuthorities = []) {
|
||||
let authority = {}
|
||||
if (!meta.authority) {
|
||||
authority = defaultAuthority
|
||||
}else if (typeof meta.authority === 'string') {
|
||||
}else if (typeof meta.authority === 'string' || Array.isArray(meta.authority)) {
|
||||
authority.permission = meta.authority
|
||||
} else if (typeof meta.authority === 'object') {
|
||||
authority = meta.authority
|
||||
|
Loading…
x
Reference in New Issue
Block a user