import store from '@/store'

export default {
  inserted(el, binding) {
    const { value } = binding
    const roles = store.getters && store.getters.roles
    if (value && value instanceof Array) {
      if (value.length > 0) {
        const permissionRoles = value
        const hasPermission = roles.some(role => {
          return permissionRoles.includes(role)
        })
        if (!hasPermission) {
          el.parentNode && el.parentNode.removeChild(el)
        }
      }
    } else {
      //todo-sn 2021/10/20 15:00 Ash:不知道为啥这报错，注释掉错误就没了= =
      // throw new Error(`使用方式： v-permission="['admin','editor']"`)
    }
  }
}
