Blame view

frontend/front/src/plugins/permissions.js 635 Bytes
8ea9c133   陈威   初始化提交
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import store from '@/store'

const permissions = {
  inserted(element, binding) {
    const { value } = binding
    const permissions = store.getters['user/permissions']
    if (value && value instanceof Array && value.length > 0) {
      const hasPermission = permissions.some((role) => value.includes(role))
      if (!hasPermission)
        element.parentNode && element.parentNode.removeChild(element)
    }
  },
}

const install = function (Vue) {
  Vue.directive('permissions', permissions)
}

if (window.Vue) {
  window['permissions'] = permissions
  Vue.use(install)
}

permissions.install = install
export default permissions