import baseInfo from './baseInfo'
import userInfo from './userInfo'
import tool from './tool'

const permission = {

  /**
   * 获取权限
   * @returns {*}
   */
  getPermission(){
    // 自己的管理组
    let role = userInfo.baseData().roleId
    if(role === baseInfo.superAdminRoleId()){
      return 'all'
    } else {
      // 全部的管理员权限
      let allAdminRoles = baseInfo.adminRoles()
      // 自己的权限
      return allAdminRoles[role].PERMISSION
    }
  },
  /**
   * 是否拥有权限该路由的权限
   * @param route
   * @returns {boolean}
   */
  hasPermission(route) {
    let permissions = this.getPermission()
    if (permissions === 'all') return true
    return tool.isInArray(permissions, route)
  },
}

export default permission
