提交 | 用户 | 时间
|
fd2207
|
1 |
import store from '@/store' |
懒 |
2 |
|
|
3 |
/** |
|
4 |
* 字符权限校验 |
|
5 |
* @param {Array} value 校验值 |
|
6 |
* @returns {Boolean} |
|
7 |
*/ |
|
8 |
export function checkPermi(value) { |
|
9 |
if (value && value instanceof Array && value.length > 0) { |
|
10 |
const permissions = store.getters && store.getters.permissions |
|
11 |
const permissionDatas = value |
|
12 |
const all_permission = "*:*:*"; |
|
13 |
|
|
14 |
const hasPermission = permissions.some(permission => { |
|
15 |
return all_permission === permission || permissionDatas.includes(permission) |
|
16 |
}) |
|
17 |
|
|
18 |
return hasPermission; |
|
19 |
|
|
20 |
} else { |
|
21 |
console.error(`need roles! Like checkPermi="['system:user:add','system:user:edit']"`) |
|
22 |
return false |
|
23 |
} |
|
24 |
} |
|
25 |
|
|
26 |
/** |
|
27 |
* 角色权限校验 |
|
28 |
* @param {Array} value 校验值 |
|
29 |
* @returns {Boolean} |
|
30 |
*/ |
|
31 |
export function checkRole(value) { |
|
32 |
if (value && value instanceof Array && value.length > 0) { |
|
33 |
const roles = store.getters && store.getters.roles |
|
34 |
const permissionRoles = value |
|
35 |
const super_admin = "admin"; |
|
36 |
|
|
37 |
const hasRole = roles.some(role => { |
|
38 |
return super_admin === role || permissionRoles.includes(role) |
|
39 |
}) |
|
40 |
|
|
41 |
return hasRole; |
|
42 |
|
|
43 |
} else { |
|
44 |
console.error(`need roles! Like checkRole="['admin','editor']"`) |
|
45 |
return false |
|
46 |
} |
|
47 |
} |