123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import {state} from '@/store'
- /**
- * 字符权限校验
- * @param {Array} value 校验值
- * @returns {Boolean}
- */
- export function checkPermi(value:string[]):boolean {
- if (value && value instanceof Array && Array.isArray(value) && value.length > 0) {
- const permissions:string[] = state.permissions
- const permissionDatas:string[] = value
- const all_permission:string = "*:*:*"
- const hasPermission:boolean = permissions.some((permission:string) => {
- return (all_permission === permission || permissionDatas.includes(permission)) as boolean
- }) as boolean
- 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:string[]):boolean {
- if (value && value instanceof Array && Array.isArray(value) && value.length > 0) {
- const roles:string[] = state.roles
- const permissionRoles:string[] = value
- const super_admin:string = "admin"
- const hasRole = roles.some(role => {
- return (super_admin === role || permissionRoles.includes(role)) as boolean
- }) as boolean
- if (!hasRole) {
- return false
- }
- return true
- } else {
- console.error(`need roles! Like checkRole="['admin','editor']"`)
- return false
- }
- }
|