// eslint-disable-next-line
import * as loginService from '@/api/upms/login'
// eslint-disable-next-line
import { UserLayout, BasicLayout, BlankLayout, RouteView, PageView } from '@/layouts'
import { GlobalConstant } from '@/constant'
import BaseTool from '../utils/tool'
// 前端路由表
const constantRouterComponents = {
  // 基础页面 layout 必须引入
  'UserLayout': UserLayout,
  'BasicLayout': BasicLayout,
  'BlankLayout': BlankLayout,
  'RouteView': RouteView,
  'PageView': PageView,
  '403': () => import(/* webpackChunkName: "error" */ '@/views/exception/403'),
  '404': () => import(/* webpackChunkName: "error" */ '@/views/exception/404'),
  '500': () => import(/* webpackChunkName: "error" */ '@/views/exception/500'),
  'IndexView': () => import(/* webpackChunkName: "error" */ '@/views/index/Index'),

  // form
  'BasicForm': () => import('@/views/form/BasicForm'),
  'StepForm': () => import('@/views/form/stepForm/StepForm'),
  'AdvanceForm': () => import('@/views/form/advancedForm/AdvancedForm'),

  // list
  'TableList': () => import('@/views/list/TableList'),
  'StandardList': () => import('@/views/list/StandardList'),
  'CardList': () => import('@/views/list/CardList'),
  'SearchLayout': () => import('@/views/list/search/SearchLayout'),
  'SearchArticles': () => import('@/views/list/search/Article'),
  'SearchProjects': () => import('@/views/list/search/Projects'),
  'SearchApplications': () => import('@/views/list/search/Applications'),
  'ProfileBasic': () => import('@/views/profile/basic/Index'),
  'ProfileAdvanced': () => import('@/views/profile/advanced/Advanced'),

  // upms
  'Dept': () => import('@/views/upms/dept/Dept'),
  'User': () => import('@/views/upms/user/User'),
  'Role': () => import('@/views/upms/role/Role'),
  'Menu': () => import('@/views/upms/menu/Menu'),
  'Dict': () => import('@/views/upms/dict/Dict'),
  'Notice': () => import('@/views/upms/notice/SysNotice'),
  'Log': () => import('@/views/upms/log/Log'),
  'Task': () => import('@/views/upms/task/Task'),
  'Config': () => import('@/views/upms/config/Config'),
  'SysTeam': () => import('@/views/upms/team/SysTeam'),

  // result
  'ResultSuccess': () => import(/* webpackChunkName: "result" */ '@/views/result/Success'),
  'ResultFail': () => import(/* webpackChunkName: "result" */ '@/views/result/Error'),

  // exception
  'Exception403': () => import(/* webpackChunkName: "fail" */ '@/views/exception/403'),
  'Exception404': () => import(/* webpackChunkName: "fail" */ '@/views/exception/404'),
  'Exception500': () => import(/* webpackChunkName: "fail" */ '@/views/exception/500'),

  // account
  'AccountCenter': () => import('@/views/account/center/Index'),
  'AccountSettings': () => import('@/views/account/settings/Index'),

  // 其他组件
  'IconSelectorView': () => import('@/views/other/IconSelectorView'),
  'TreeList': () => import('@/views/other/TreeList'),
  'TableInnerEditList': () => import('@/views/other/TableInnerEditList'),
  'UserList': () => import('@/views/other/UserList'),
  'RoleList': () => import('@/views/other/RoleList'),
  'SystemRoleList': () => import('@/views/role/RoleList'),
  'PermissionList': () => import('@/views/other/PermissionList'),
  // 设备类型
  'SbType': () => import('@/views/sb/type/SbType'),
  // 设备位置
  'SbPosition': () => import('@/views/sb/position/SbPosition'),
  // 设别规格
  'SbGuige': () => import('@/views/sb/guige/SbGuige'),
  // 设别基础信息
  'SbInfo': () => import('@/views/sb/info/SbInfo'),
  // 测量设备基础信息
  'MeasureSbInfo': () => import('@/views/sb/info/MeasureSbInfo'),
  // 测量设备预警台账
  'MeasureSbInfoWarn': () => import('@/views/sb/info/MeasureSbInfoWarn'),
  // 特种设备基础信息
  'SpecialSbInfo': () => import('@/views/sb/info/SpecialSbInfo'),
  // 父子设备树
  'ParentSbInfo': () => import('@/views/sb/info/ParentSbInfo'),
  // 设别型号库
  'SbModel': () => import('@/views/sb/model/SbModel'),
  // 设备bom
  'SbModelBom': () => import('@/views/sb/modelbom/SbModelBom'),
  // 设备型号筛选对应的备件bom
  'SbModelSpareListBom': () => import('@/views/sb/modelbom/SbModelSpareListBom'),
  // 设备树
  'SbInfoTree': () => import('@/views/sb/info/SbInfoTree'),
  // 部件类别
  'PartType': () => import('@/views/part/type/PartType'),
  // 部件信息
  'PartInfo': () => import('@/views/part/info/PartInfo'),
  // 部件信息
  'SbInfoForPartInfo': () => import('@/views/sb/info/SbInfoForPartInfo'),
  // 备件类别
  'SpareType': () => import('@/views/sqarepartmanage/sparetype/SpareType'),
  // 备件基础信息
  'SparePartInfo': () => import('@/views/sqarepartmanage/sparepartinfo/SparePartInfo'),
  'SparePartInfoPrint': () => import('@/views/sqarepartmanage/sparepartinfo/SparePartInfoPrint'),
  // 备件使用信息
  'SparePartUsed': () => import('@/views/sqarepartmanage/sparepartused/SparePartUsed'),
  // 点检
  'SpotCheckStandard': () => import('@/views/check/checkstandard/SpotCheckStandard'),
  'SpotCheckProject': () => import('@/views/check/checkproject/SpotCheckProject'),
  'SpotCheckPlan': () => import('@/views/check/checkplan/SpotCheckPlan'),
  'SpotCheckJob': () => import('@/views/check/checkjob/SpotCheckJob'),
  // 保养
  'PollingCheckStandard': () => import('@/views/check/checkstandard/PollingCheckStandard'),
  'PollingCheckProject': () => import('@/views/check/checkproject/PollingCheckProject'),
  'PollingCheckPlan': () => import('@/views/check/checkplan/PollingCheckPlan'),
  'PollingCheckJob': () => import('@/views/check/checkjob/PollingCheckJob'),
  // 润滑
  'RunCheckStandard': () => import('@/views/check/checkstandard/RunCheckStandard'),
  'RunCheckProject': () => import('@/views/check/checkproject/RunCheckProject'),
  'RunCheckPlan': () => import('@/views/check/checkplan/RunCheckPlan'),
  'RunCheckJob': () => import('@/views/check/checkjob/RunCheckJob'),
  // 工器具校准
  'AdjustCheckStandard': () => import('@/views/check/checkstandard/AdjustCheckStandard'),
  'AdjustCheckProject': () => import('@/views/check/checkproject/AdjustCheckProject'),
  'AdjustCheckPlan': () => import('@/views/check/checkplan/AdjustCheckPlan'),
  'AdjustCheckJob': () => import('@/views/check/checkjob/AdjustCheckJob'),
  // 特种设备定期检验
  'SpecialCheckStandard': () => import('@/views/check/checkstandard/SpecialCheckStandard'),
  'SpecialCheckProject': () => import('@/views/check/checkproject/SpecialCheckProject'),
  'SpecialCheckPlan': () => import('@/views/check/checkplan/SpecialCheckPlan'),
  'SpecialCheckJob': () => import('@/views/check/checkjob/SpecialCheckJob'),
  // 仓库信息
  'Store': () => import('@/views/store/store/Store'),
  // 备件库存
  'SpareStore': () => import('@/views/store/sparestore/SpareStore'),
  // 备件库存汇总
  'SpareStoreTotal': () => import('@/views/store/sparestore/SpareStoreTotal'),
  // 备件二级库存
  'SpareStoreSecond': () => import('@/views/store/sparestoresecond/SpareStoreSecond'),
  // 入库登记单
  'InStoreForm': () => import('@/views/store/instoreform/InStoreForm'),
  // 出库登记单
  'OutStoreForm': () => import('@/views/store/outstoreform/OutStoreForm'),
  // 调拨登记单
  'TransferStoreForm': () => import('@/views/store/transferstoreform/TransferStoreForm'),

  // 备件领用详情
  'SparePickDetail': () => import('@/views/store/sparepickdetail/SparePickDetail'),
  // 备件领用登记单
  'SparePickForm': () => import('@/views/store/sparepickform/SparePickForm'),
  // 备件回收详情
  'SpareRecoveryDetail': () => import('@/views/store/sparerecoverydetail/SpareRecoveryDetail'),
  // 备件回收登记单
  'SpareRecoveryForm': () => import('@/views/store/sparerecoveryform/SpareRecoveryForm'),
  // 备件退库详情
  'SpareRestoreDetail': () => import('@/views/store/sparerestoredetail/SpareRestoreDetail'),
  // 备件退库登记单
  'SpareRestoreForm': () => import('@/views/store/sparerestoreform/SpareRestoreForm'),
  // 备件退货详情
  'SpareBackDetail': () => import('@/views/store/sparebackdetail/SpareBackDetail'),
  // 备件退货登记单
  'SpareBackForm': () => import('@/views/store/sparebackform/SpareBackForm'),
  // 入库详情
  'InStoreDetail': () => import('@/views/store/instoredetail/InStoreDetail'),
  // 出库详情
  'OutStoreDetail': () => import('@/views/store/outstoredetail/OutStoreDetail'),
  // 调拨详情
  'TransferStoreDetail': () => import('@/views/store/transferstoredetail/TransferStoreDetail'),
  // 报修单
  'RepairApplicationForm': () => import('@/views/repair/application-form/RepairApplicationForm'),
  'RepairOut': () => import('@/views/repair/application-form/RepairOut'),
  // 验收单
  'RepairCheckForm': () => import('@/views/repair/application-form/RepairCheckForm'),
  // 维修单
  'RepairForm': () => import('@/views/repair/application-form/RepairForm'),
  'MRepairForm': () => import('@/views/repair/application-form/MyRepairForm'),
  'MyRepairForm': () => import('@/views/repair/form/MyRepairForm'),
  // 验收单
  'RepairCheck': () => import('@/views/repair/check/RepairCheck'),
  // 故障类别
  'ErrorType': () => import('@/views/repair/errortype/ErrorType'),
  // 维修费用单
  'RepairFee': () => import('@/views/repair/fee/RepairFee'),
  // 维修项目
  'RepairProject': () => import('@/views/repair/repairproject/RepairProject'),
  'RepairReason': () => import('@/views/repair/repair-reason/RepairReason'),
  // 生产商
  'FirmProducer': () => import('@/views/firm/producer/FirmProducer'),
  // 报表管理
  'MonthlySbThreeRate': () => import('@/views/monthly/sb-three-rate/MonthlySbThreeRateView'),
  // 工作票管理
  'Ticket': () => import('@/views/ticket/ticket/Ticket'),
  'TicketSafe': () => import('@/views/ticket/ticketsafe/TicketSafe'),
  'TicketExecute': () => import('@/views/ticket/ticketexecute/TicketExecute'),
  'TicketSafeExecute': () => import('@/views/ticket/ticketsafeexecute/TicketSafeExecute'),
  // 日常管理
  'FillInfo': () => import('@/views/fill/info/FillInfo'),
  'FillGather': () => import('@/views/fill/gather/FillGather'),
  'SbInspectionFill': () => import('@/views/sb/inspection-fill/SbInspectionFill'),
  'MySbInspectionFill': () => import('@/views/sb/inspection-fill/MySbInspectionFill'),
  'ZGSbInspectionFill': () => import('@/views/sb/inspection-fill/ZGSbInspectionFill'),
  'AdminSbInspectionFill': () => import('@/views/sb/inspection-fill/AdminSbInspectionFill'),
  'SbRunFill': () => import('@/views/sb/run-fill/SbRunFill'),
  'ZGSbRunFill': () => import('@/views/sb/run-fill/ZGSbRunFill'),
  'MySbRunFill': () => import('@/views/sb/run-fill/MySbRunFill'),
  'AdminSbRunFill': () => import('@/views/sb/run-fill/AdminSbRunFill'),
  // 仓库月报表
  'StoreMonthReport': () => import('@/views/report/store/StoreMonthReport'),
  // 出入库明细+汇总
  'ReportInStoreDetail': () => import('@/views/report/instoredetail/InStoreDetail'),
  'MyReportInStoreDetail': () => import('@/views/report/instoredetail/MyInStoreDetail'),
  'ReportOutStoreDetail': () => import('@/views/report/outstoredetail/OutStoreDetail'),
  'MyReportOutStoreDetail': () => import('@/views/report/outstoredetail/MyOutStoreDetail'),
  'ReportInStoreCount': () => import('@/views/report/instorecount/InStoreCount'),
  'ReportOutStoreCount': () => import('@/views/report/outstorecount/OutStoreCount'),
  'ReportSparePartInfo': () => import('@/views/report/sparepartinfo/SparePartInfo'),
  'ReportSparePickDetail': () => import('@/views/report/sparepickdetail/SparePickDetail'),
  'MyReportSparePickDetail': () => import('@/views/report/sparepickdetail/MySparePickDetail'),
  'ReportSparePickCount': () => import('@/views/report/sparepickcount/SparePickCount'),
  'StatisticsRepairFormSb': () => import('@/views/statistics/repair/StatisticsRepairFormSb'),
  'StatisticsRepairFormMonth': () => import('@/views/statistics/repair/StatisticsRepairFormMonthView'),
  'StatisticsRepairFormErrorType': () => import('@/views/statistics/repair/StatisticsRepairFormErrorTypeView'),
  'StatisticsSparePartUsedSpare': () => import('@/views/statistics/spare/StatisticsSparePartUsedSpare'),
  'StatisticsRepairFormUser': () => import('@/views/statistics/repair/StatisticsRepairFormUserView'),
  'WorkplaceBacklog': () => import('@/views/workplace/backlog/WorkplaceBacklog'),
  'Supplier': () => import('@/views/purchase/supplier/Supplier'),
  'SupplierApply': () => import('@/views/purchase/supplier/SupplierApply'),
  'PurchaseDemandPlan': () => import('@/views/purchase/purchase-demand-plan/PurchaseDemandPlan'),
  'PurchasePlan': () => import('@/views/purchase/purchase-plan/PurchasePlan'),
  'PurchasePayment': () => import('@/views/purchase/purchase-payment/PurchasePaymentPage'),
  'PurchaseReimburse': () => import('@/views/purchase/purchase-reimburse/PurchaseReimbursePage'),
  'PurchaseOrder': () => import('@/views/purchase/purchase-order/PurchaseOrder'),
  'PurchaseApply': () => import('@/views/purchase/purchase-apply/PurchaseApply'),
  'PurchaseDispatchOrderPage': () => import('@/views/purchase/purchase-dispatch-order/PurchaseDispatchOrderPage'),

  'Model': () => import('@/views/activiti/model/Model'),
  'Flow': () => import('@/views/activiti/flow/Flow'),
  'MyTask': () => import('@/views/activiti/task/MyTask'),

  // 调拨申请
  'SbAllocateApply': () => import('@/views/sb/allocate-apply/ProjectSbAllocateApply'),
  'GroupToProjectSbAllocateApply': () => import('@/views/sb/allocate-apply/GroupToProjectSbAllocateApply'),
  'ProjectToProjectSbAllocateApply': () => import('@/views/sb/allocate-apply/ProjectToProjectSbAllocateApply'),
  'MySbAllocateApply': () => import('@/views/sb/allocate-apply/MySbAllocateApply'),
  'ZGSbAllocateApply': () => import('@/views/sb/allocate-apply/ZGSbAllocateApply'),
  'XmbZgSbAllocateApply': () => import('@/views/sb/allocate-apply/XmbZgSbAllocateApply'),
  'FgsZgSbAllocateApply': () => import('@/views/sb/allocate-apply/FgsZgSbAllocateApply'),
  // 调拨审批
  'SbAllocateTaskAudit': () => import('@/views/sb/allocate-task/SbAllocateTaskAudit'),
  'SbOilUser': () => import('@/views/sb/oil/SbOilUser'),
  'SbOilTask': () => import('@/views/sb/oil/SbOilTask'),
  'SbOilAudit': () => import('@/views/sb/oil/SbOilAudit'),
  'MySbOil': () => import('@/views/sb/oil/MySbOil'),
  'ZGSbOil': () => import('@/views/sb/oil/ZGSbOil'),
  'AdminSbOil': () => import('@/views/sb/oil/AdminSbOil'),
  // 我的功能
  'ProjectStore': () => import('@/views/store/store/ProjectStore'),
  'CompanyStore': () => import('@/views/store/store/CompanyStore'),
  'MyStore': () => import('@/views/store/store/MyStore'),
  'MyInStoreForm': () => import('@/views/store/instoreform/MyInStoreForm'),
  'MyOutStoreForm': () => import('@/views/store/outstoreform/MyOutStoreForm'),
  'MyTransferStoreForm': () => import('@/views/store/transferstoreform/MyTransferStoreForm'),
  'MySparePickForm': () => import('@/views/store/sparepickform/MySparePickForm'),
  'MySbInfo': () => import('@/views/sb/info/MySbInfo'),
  'ProjectSbInfo': () => import('@/views/sb/info/ProjectSbInfo'),
  'BanzuSbInfo': () => import('@/views/sb/info/BanzuSbInfo'),
  'CompanySbInfo': () => import('@/views/sb/info/CompanySbInfo'),
  'MySpareStore': () => import('@/views/store/sparestore/MySpareStore'),
  'MySpareStoreTotal': () => import('@/views/store/sparestore/MySpareStoreTotal'),
  'ProjectSpareStoreTotal': () => import('@/views/store/sparestore/ProjectSpareStoreTotal'),
  'CompanySpareStoreTotal': () => import('@/views/store/sparestore/CompanySpareStoreTotal'),
  'ProjectSpareStore': () => import('@/views/store/sparestore/ProjectSpareStore'),
  'CompanySpareStore': () => import('@/views/store/sparestore/CompanySpareStore'),
  'MyRunCheckJob': () => import('@/views/check/checkjob/MyRunCheckJob'),
  'MyPollingCheckJob': () => import('@/views/check/checkjob/MyPollingCheckJob'),
  'MySpotCheckJob': () => import('@/views/check/checkjob/MySpotCheckJob'),
  // 验收单
  'SbCheckForm': () => import('@/views/sb/sbcheckform/SbCheckForm'),
  'FillProjectQuantity': () => import('@/views/fill/project-quantity/FillProjectQuantity'),
  'SbCheckDetail': () => import('@/views/sb/sbcheckdetail/SbCheckDetail'),
  'Article': () => import('@/views/operate/article/Article'),
  'AnalysisSbInfo': () => import('@/views/dashboard/Analysis'),
  // 备件盘点
  'StoreCheckPlan': () => import('@/views/store/storecheckplan/StoreCheckPlan'),
  'StoreCheckJob': () => import('@/views/store/storecheckjob/StoreCheckJob'),

  // 设备盘点
  'SbStoreCheckPlan': () => import('@/views/sb/storecheckplan/StoreCheckPlan'),
  'SbStoreCheckJob': () => import('@/views/sb/storecheckjob/StoreCheckJob'),
  // 保养任务日程表
  'CheckJobCalendar': () => import('@/views/check/checkjob/CheckJobCalendar'),
  // 设备状态变更表
  'SbStatusLog': () => import('@/views/sb/status-log/SbStatusLog'),
  // 设备停机记录表
  'SbStopLog': () => import('@/views/sb/stop-logs/SbStopLog'),
}

// 前端未找到页面路由（固定不用改）
const notFoundRouter = {
  path: '*', redirect: '/404', hidden: true
}

// 根级菜单
const rootRouter = {
  key: 'RootIndex',
  path: '/',
  url: '/',
  name: 'index',
  component: 'BasicLayout',
  meta: { title: '首页' },
  redirect: '/WorkplaceBacklog',
  type: 1,
  children: []
}

/**
 * 基础路由
 * @type { *[] }
 */
export const constantRouterMap = [
  {
    path: '/user',
    component: UserLayout,
    redirect: '/user/login',
    hidden: true,
    children: [
      {
        path: 'login',
        name: 'login',
        component: () => import(/* webpackChunkName: "user" */ '@/views/Login')
      },
      {
        path: '/work/scan',
        name: 'scan',
        component: () => import(/* webpackChunkName: "user" */ '@/views/Scan')
      },
      {
        path: 'register',
        name: 'register',
        component: () => import(/* webpackChunkName: "user" */ '@/views/Register')
      },
      {
        path: 'register-result',
        name: 'registerResult',
        component: () => import(/* webpackChunkName: "user" */ '@/views/RegisterResult')
      },
      {
        path: 'recover',
        name: 'recover',
        component: undefined
      }
    ]
  },

  {
    path: '/screen',
    component: BlankLayout,
    redirect: '/screen/leader',
    children: [
      {
        path: 'leader',
        name: 'LeaderScreen',
        component: () => import('@/views/big-screen/LeaderScreen')
      }
    ]
  },

  {
    path: '/404',
    component: () => import(/* webpackChunkName: "fail" */ '@/views/exception/404')
  },
  {
    path: '/single/login',
    name: 'SingleLogin',
    component: () => import('@/views/white-list/SingleLogin'),
    meta: {
      title: '单点登录',
      keepAlive: false,
      hiddenHeaderContent: true,
      target: null,
      permission: ''
    },
    hidden: true,
    hideChildrenInMenu: true
  },
  {
    path: '/result/success',
    name: 'ResultSuccess',
    component: () => import(/* webpackChunkName: "result" */ '@/views/result/Success'),
    meta: {
      title: '结果页',
      keepAlive: false,
      hiddenHeaderContent: true,
      target: null,
      permission: ''
    },
    hidden: true,
    hideChildrenInMenu: true

  }

]

/**
 * 默认菜单
 */
const defaultRouter = {
  key: 'RootDefault',
  path: '/default',
  url: '/default',
  name: 'default',
  component: BasicLayout,
  meta: { title: '默认' },
  redirect: '/account/settings',
  type: 1,
  children: [
    {
      path: '/account/center',
      name: 'center',
      component: constantRouterComponents['AccountCenter'],
      meta: {
        title: '个人中心',
        keepAlive: false,
        hiddenHeaderContent: false,
        target: null,
        permission: ''
      },
      hidden: true,
      hideChildrenInMenu: true
    },
    {
      path: '/account/settings',
      name: 'settings',
      component: constantRouterComponents['AccountSettings'],
      meta: {
        title: '个人设置',
        keepAlive: false,
        hiddenHeaderContent: true,
        target: null,
        permission: ''
      },
      hidden: true,
      hideChildrenInMenu: true
    }]
}

/**
 * 动态生成菜单
 * @param token
 * @returns {Promise<Router>}
 */
export const generatorDynamicRouter = (menus) => {
  return new Promise((resolve, reject) => {
    try {
      const menuNav = []
      //      后端数据, 根级树数组,  根级 PID,后端已转为树型 解构
      // listToTree(result, childrenNav, 0)
      rootRouter.children = menus
      menuNav.push(rootRouter)
      const routers = generator(menuNav)
      routers.push(notFoundRouter)
      routers.push(defaultRouter)
      resolve(routers)
    } catch (e) {
      reject(e)
    }
  })
}

/**
 * 格式化树形结构数据 生成 vue-router 层级路由表
 *
 * @param routerMap
 * @param parent
 * @returns {*}
 */
export const generator = (routerMap, parent) => {
  return routerMap.map(itemTree => {
    let item = itemTree.item
    if (BaseTool.Object.isBlank(item)) {
      item = itemTree
    }
    item.children = itemTree.children
    // 如果不是菜单则跳过
    if (GlobalConstant.MenuTypeMenu === item.type) {
      return null
    }
    // path: '/dashboard',
    //         name: 'dashboard',
    //         redirect: '/dashboard/workplace', // 可以做父路由到子路由的跳转
    //         component: RouteView,
    //         meta: { title: '仪表盘', keepAlive: true, icon: bxAnaalyse, permission: [ 'dashboard' ] },
    const { title, visible, hideChildren, hiddenHeaderContent, target, icon } = item || {}
    const myComponent = constantRouterComponents[item.component || item.name]
    const currentRouter = {
      // 如果路由设置了 path，则作为默认 path，否则 路由地址 动态拼接生成如 /dashboard/workplace
      path: item.url || `${parent && parent.url || ''}/${item.name}`,
      // 路由名称，建议唯一
      name: item.name,
      // 该路由对应页面的 组件 :方案1
      component: myComponent,
      // 该路由对应页面的 组件 :方案2 (动态加载)
      // component: constantRouterComponents[item.component || item.key] || () => import(`@/views/${item.component}`),

      // meta: 页面标题, 菜单图标, 页面权限(供指令权限用，可去掉)
      meta: { title: title, icon: icon || undefined, keepAlive: false, hiddenHeaderContent: hiddenHeaderContent || false, target: target, permission: item.permission }
    }
    // 是否设置了隐藏菜单
    if (visible === false) {
      currentRouter.hidden = true
    }
    // 是否设置了隐藏子菜单
    if (hideChildren || visible === false) {
      currentRouter.hideChildrenInMenu = true
    }
    // 为了防止出现后端返回结果不规范，处理有可能出现拼接出两个 反斜杠
    if (!currentRouter.path.startsWith('http')) {
      currentRouter.path = currentRouter.path.replace('//', '/')
    }
    // 重定向
    item.redirect && (currentRouter.redirect = item.redirect)
    // 是否有子菜单，并递归处理
    if (item.children && item.children.length > 0) {
      // Recursion
      currentRouter.children = generator(item.children, currentRouter)
    }
    return currentRouter
  })
}

/**
 * 数组转树形结构
 * @param list 源数组
 * @param tree 树
 * @param parentId 父ID
 */
// const listToTree = (list, tree, parentId) => {
//   list.forEach(item => {
//     // 判断是否为父级菜单
//     if (item.parentId === parentId) {
//       const child = {
//         ...item,
//         key: item.key || item.name,
//         children: []
//       }
//       // 迭代 list， 找到当前菜单相符合的所有子菜单
//       listToTree(list, child.children, item.id)
//       // 删掉不存在 children 值的属性
//       if (child.children.length <= 0) {
//         delete child.children
//       }
//       // 加入到树中
//       tree.push(child)
//     }
//   })
// }
