提交 | 用户 | 时间
|
fd2207
|
1 |
/** |
懒 |
2 |
* v-hasRole 角色权限处理 |
|
3 |
* Copyright (c) 2019 ruoyi |
|
4 |
*/ |
|
5 |
|
|
6 |
import store from '@/store' |
|
7 |
|
|
8 |
export default { |
|
9 |
inserted(el, binding, vnode) { |
|
10 |
const { value } = binding |
|
11 |
const super_admin = "admin"; |
|
12 |
const roles = store.getters && store.getters.roles |
|
13 |
|
|
14 |
if (value && value instanceof Array && value.length > 0) { |
|
15 |
const roleFlag = value |
|
16 |
|
|
17 |
const hasRole = roles.some(role => { |
|
18 |
return super_admin === role || roleFlag.includes(role) |
|
19 |
}) |
|
20 |
|
|
21 |
if (!hasRole) { |
|
22 |
el.parentNode && el.parentNode.removeChild(el) |
|
23 |
} |
|
24 |
} else { |
|
25 |
throw new Error(`请设置角色权限标签值"`) |
|
26 |
} |
|
27 |
} |
|
28 |
} |