FlowPacs/ruoyi-ui/src/utils/permission.js

49 lines
1.2 KiB
JavaScript
Raw Normal View History

2019-10-08 09:14:38 +08:00
import store from '@/store'
/**
2020-02-24 09:28:16 +08:00
* 字符权限校验
* @param {Array} value 校验值
2019-10-08 09:14:38 +08:00
* @returns {Boolean}
*/
2020-02-24 09:28:16 +08:00
export function checkPermi(value) {
if (value && value instanceof Array && value.length > 0) {
const permissions = store.getters && store.getters.permissions
const permissionDatas = value
const hasPermission = permissions.some(permission => {
return permissionDatas.includes(permission)
})
if (!hasPermission) {
return false
}
return true
} else {
console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`)
return false
}
}
/**
* 角色权限校验
* @param {Array} value 校验值
* @returns {Boolean}
*/
export function checkRole(value) {
2019-10-08 09:14:38 +08:00
if (value && value instanceof Array && value.length > 0) {
const roles = store.getters && store.getters.roles
const permissionRoles = value
2020-02-24 09:28:16 +08:00
const hasRole = roles.some(role => {
2019-10-08 09:14:38 +08:00
return permissionRoles.includes(role)
})
2020-02-24 09:28:16 +08:00
if (!hasRole) {
2019-10-08 09:14:38 +08:00
return false
}
return true
} else {
2020-02-24 09:28:16 +08:00
console.error(`need roles! Like checkRole="['admin','editor']"`)
2019-10-08 09:14:38 +08:00
return false
}
2020-02-24 09:28:16 +08:00
}