import store from '@/store'

/**
 * @param {Array} value
 * @returns {Boolean}
 * @example see @/views/permission/directive.vue
 */
export default function checkPermisAction(value) {
  if (value && value instanceof Array && value.length > 0) {
    const all_permission = '*:*:*'
    const permissions = store.getters && store.getters.permisaction
    const permissionFlag = value

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

    return hasPermissions
  } else {
    throw new Error(`请设置操作权限标签值`)
  }
}
