/*
 * @Company: 沈阳信诚科技
 * @Email: html_venustar@163.com
 * @Author: Liuqiming
 * @Description: 
 * @LastEditors: Liuqiming
 * @LastEditTime: 2024-03-29 14:49:31
 * @Date: 2024-03-29 14:44:41
 */
 /**
 * v-hasPermi 操作权限处理
 */
 
import useUserStore from '@/store/modules/user'

export default {
  mounted(el, binding, vnode) {
    const { value } = binding
    let newVal = []
    if (!(value instanceof Array)) {
      newVal = value ? [value] : []
    } else {
      newVal = value[0] ? value : []
    }
    const all_permission = "*:*:*";
    const permissions = useUserStore().permissions

    if (newVal && newVal instanceof Array && newVal.length > 0) {
      const permissionFlag = newVal

      const hasPermissions = permissions.some(permission => {
        return all_permission === permission || permissionFlag.includes(permission)
      })

      if (!hasPermissions) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      // throw new Error(`请设置操作权限标签值`)
      return
    }
  }
}
