hasPermi.js 926 Bytes
Newer Older
张成 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14
 /**
 * v-hasPermi 操作权限处理
 * Copyright (c) 2019 ruoyi
 */
 
import store from '@/store'

export default {
  inserted(el, binding, vnode) {
    const { value } = binding
    const all_permission = "*:*:*";
    const permissions = store.getters && store.getters.permissions

    if (value && value instanceof Array && value.length > 0) {
lixiaomin committed
15
      const permissionFlag = value      
张成 committed
16 17 18
      const hasPermissions = permissions.some(permission => {
        return all_permission === permission || permissionFlag.includes(permission)
      })
lixiaomin committed
19 20 21
      //自定义权限按钮处理
      if(vnode.elm.attributes["myattr"] ){
        if (!hasPermissions) {
lixiaomin committed
22
          vnode.elm.innerHTML = vnode.elm.innerText          
lixiaomin committed
23 24 25
          return ;
        }
      }
张成 committed
26 27 28 29 30 31 32 33
      if (!hasPermissions) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error(`请设置操作权限标签值`)
    }
  }
}