/**
 * v-hasRole 角色权限处理
 */
import { useUserStore } from '@/store/modules/user'

export default {
  mounted (el, binding, vnode) {
    const { value } = binding
    const roles = useUserStore().userInfo.userRoleInfoList
    if (value && value instanceof Array && value.length > 0) {
      const roleFlag = value
      const hasRole = roles.some(role => {
        return roleFlag.includes(role.name)
      })
      if (!hasRole) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error(`请设置角色权限标签值`)
    }
  }
}
