rk
4 天以前 568e38a95cb6fb20fe16b53d17f610aefc6f744f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
export default {
  inserted: function (el, binding, vnode) {
    // 获取用户信息
    const userInfo = vnode.context.$store.state.userInfo
    if (userInfo == null) {
      el.parentNode && el.parentNode.removeChild(el)
      return
    }
    // 获取配置权限
    const configPermissions = binding.value
    if (configPermissions == null) {
      return
    }
    if (!(configPermissions instanceof Array)) {
      throw new Error('v-permissions的值必须为一个数组')
    }
    // 验证权限
    if (configPermissions.findIndex(code => userInfo.permissions.findIndex(p => p === code) > -1) === -1) {
      el.parentNode && el.parentNode.removeChild(el)
    }
  }
}