提交 | 用户 | 时间
|
e57a89
|
1 |
import store from '@/store' |
懒 |
2 |
|
|
3 |
function authPermission(permission) { |
|
4 |
const all_permission = "*:*:*"; |
|
5 |
const permissions = store.getters && store.getters.permissions |
|
6 |
if (permission && permission.length > 0) { |
|
7 |
return permissions.some(v => { |
|
8 |
return all_permission === v || v === permission |
|
9 |
}) |
|
10 |
} else { |
|
11 |
return false |
|
12 |
} |
|
13 |
} |
|
14 |
|
|
15 |
function authRole(role) { |
|
16 |
const super_admin = "admin"; |
|
17 |
const roles = store.getters && store.getters.roles |
|
18 |
if (role && role.length > 0) { |
|
19 |
return roles.some(v => { |
|
20 |
return super_admin === v || v === role |
|
21 |
}) |
|
22 |
} else { |
|
23 |
return false |
|
24 |
} |
|
25 |
} |
|
26 |
|
|
27 |
export default { |
|
28 |
// 验证用户是否具备某权限 |
|
29 |
hasPermi(permission) { |
|
30 |
return authPermission(permission); |
|
31 |
}, |
|
32 |
// 验证用户是否含有指定权限,只需包含其中一个 |
|
33 |
hasPermiOr(permissions) { |
|
34 |
return permissions.some(item => { |
|
35 |
return authPermission(item) |
|
36 |
}) |
|
37 |
}, |
|
38 |
// 验证用户是否含有指定权限,必须全部拥有 |
|
39 |
hasPermiAnd(permissions) { |
|
40 |
return permissions.every(item => { |
|
41 |
return authPermission(item) |
|
42 |
}) |
|
43 |
}, |
|
44 |
// 验证用户是否具备某角色 |
|
45 |
hasRole(role) { |
|
46 |
return authRole(role); |
|
47 |
}, |
|
48 |
// 验证用户是否含有指定角色,只需包含其中一个 |
|
49 |
hasRoleOr(roles) { |
|
50 |
return roles.some(item => { |
|
51 |
return authRole(item) |
|
52 |
}) |
|
53 |
}, |
|
54 |
// 验证用户是否含有指定角色,必须全部拥有 |
|
55 |
hasRoleAnd(roles) { |
|
56 |
return roles.every(item => { |
|
57 |
return authRole(item) |
|
58 |
}) |
|
59 |
} |
|
60 |
} |