/**
 * v-hasPermi 流程管理操作权限处理
 * Copyright (c) 2019
 */

import store from '@/store'

export default {
  inserted(el, binding, vnode) {
    const { value } = binding
    const permissions = store.getters && store.getters.processPermissions
    if (permissions && permissions.length > 0) {
      if (value && value instanceof Array && value.length > 0) {
        const permissionFlag = value
        const hasPermissions = permissions.some(permission => {
          return permissionFlag.includes(permission)
        })
        if (!hasPermissions) {
          el.parentNode && el.parentNode.removeChild(el)
        }
      } else {
        throw new Error(`请设置流程管理操作权限标签值`)
      }
    } else {
      console.log('获取的流程管理权限为空')
    }
  }
}
