You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RuoYi-Vue-cloud/ruoyi-ui/src/utils/permission.js

49 lines
1.2 KiB

5 years ago
import store from '@/store'
/**
5 years ago
* 字符权限校验
* @param {Array} value 校验值
5 years ago
* @returns {Boolean}
*/
5 years ago
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) {
5 years ago
if (value && value instanceof Array && value.length > 0) {
const roles = store.getters && store.getters.roles
const permissionRoles = value
5 years ago
const hasRole = roles.some(role => {
5 years ago
return permissionRoles.includes(role)
})
5 years ago
if (!hasRole) {
5 years ago
return false
}
return true
} else {
5 years ago
console.error(`need roles! Like checkRole="['admin','editor']"`)
5 years ago
return false
}
5 years ago
}