/**
 * hasPermiDom 方法 操作权限验证
 * Copyright (c) 2022 ded
 */

import store from '@/store'
import router from '@/router'
export default {
  hasPermiDom(binding) {
    let pageRoute = router.currentRoute.matched[router.currentRoute.matched.length-1].name
    const value  = binding;
    const all_permission = "*:*:*";
    const permissions = store.getters && store.getters.permissions
    if (permissions == all_permission) {
      return true
    }else if (value && value instanceof Array && value.length > 0) {
      const permissionFlag = value
      for(let i=0;i<permissions.length;i++){
        if(permissions[i].path == pageRoute){
          const hasPermissions = permissions[i].permissions.some(permission => {
            return all_permission === permission || permissionFlag.includes(permission)
          })
          return hasPermissions;
        }
      }
    } else {
      return false;
    }
  }
}
