/**
 * v-hasPermiAnd 操作权限处理
 * Copyright (c) 2022 ded
 */

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) {
      let num = 0;
      for(let i=0;i<value.length;i++){
        if(permissions[0] == all_permission){
            num++
        }else{
          if(permissions.includes(value[i], 0)){
            num++
          }
        }
      }
      if(num == value.length){
        return true
      } else {
        el.parentNode && el.parentNode.removeChild(el)
        return false
      }
    } else {
      throw new Error(`请设置操作权限标签值`)
    }
  }
}
