 /**
 * 操作权限处理
 * Copyright (c) 2019 ruoyi
 */
 
import store from '@/store'

export default {
  inserted(el, binding, vnode) {
    // console.log(111111, el, binding, vnode);
    const { value } = binding
    const all_permission = "*:*:*";
    // const permissions = store.getters && store.getters.permissions
    const permissions = store.getters && store.getters.btnPower
    if (value && value instanceof Array && value.length > 0) {
      const permissionFlag = value
      let hasPermissions = true
      if(permissions) {
        if(!permissionFlag.includes(all_permission)) {
          hasPermissions = permissions.some(permission => {
            return permissionFlag.includes(permission.perms)
          })
        }
      } else {
        hasPermissions = false
      }
      
      if (!hasPermissions) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error(`请设置操作权限标签值`)
    }
  }
}
