 /**
 * v-hasRole 角色权限处理
 * Copyright (c) 2026 platform
 */
 import {unifiedLoginSDK} from "oauth2-login-sdk";

export default {
  mounted(el: HTMLElement, binding: DirectiveBinding, vnode: any) {
    const { value } = binding
    const super_admin = "admin"
    const roles = unifiedLoginSDK.getUserInfo().roles

    if (value && value instanceof Array && value.length > 0) {
      const roleFlag = value

      const hasRole = roles?.some((role: string) => {
        return super_admin === role || roleFlag.includes(role)
      })

      if (!hasRole) {
        el.parentNode && el.parentNode.removeChild(el)
      }
    } else {
      throw new Error(`请设置角色权限标签值`)
    }
  }
}
