import { createRouter, createWebHashHistory } from "vue-router"
import layout from "@/layout/index" //layout直接引用 其他使用路由懒加载
import store from "@/store"
import { systemRouterList } from "@/router/modules/systemManager.js"
import { businessRouteList } from "@/router/modules/businessCenter.js"
import { decisionRouteList } from "@/router/modules/decisionCenter.js"
import { integrationRouteList } from "@/router/modules/integrationMangerCenter.js"
import { safetyMonitoringRouteList } from "@/router/modules/safetyMonitoringCenter.js"
/**
 * 关于路由配置描述
 * 1.meta && meta.title && meta.icon  则在菜单栏显示
 * 2.如果存在children , 则以el-sub-menu子菜单显示
 * 否则不在menu菜单显示
 * 如果只展示单级别菜单  需要像developer这样配置
 */
/**
 * 私有路由表
 */
export const privateRoutes = [...businessRouteList, ...safetyMonitoringRouteList, ...integrationRouteList, ...decisionRouteList, ...systemRouterList]
/**
 * 公开路由表
 */
export const publicRoutes = [
  {
    path: "/",
    // 注意：带有路径“/”的记录中的组件“默认”是一个不返回 Promise 的函数
    component: layout,
    // redirect: "/profile",
    redirect: "/login",
    children: [
      {
        path: "/dutyBook/home/workbench",
        name: "dutyBook/home/workbench",
        component: () => import("@/views/dutyBook/home/workbench.vue"),
        meta: {
          title: "工作台",
          icon: "icon_ywyy",
          iconH: "gongzuotai"
        }
      },
      // {
      //   path: "/newsystem",
      //   component: () => import("@/views/newsystem/index.vue"),
      //   name: "/newsystem",
      //   meta: {
      //     title: "地图看板",
      //     icon: "shouye"
      //   }
      // },
      {
        path: "/editPassword",
        name: "editPassword",
        component: () => import("@/views/systemConfig/editPassword/index"),
        meta: {
          title: "个人中心",
          // icon: "gerenzhongxin"
        }
      },
      // {
      //   path: "/staging",
      //   name: "/staging",
      //   component: () => import("@/views/staging/index"),
      //   meta: {
      //     title: "工作台",
      //     icon: "tree"
      //   }
      // },
      {
        path: "/dict/detail",
        name: "dictDetail",
        component: () => import("@/views/systemConfig/dict/detail"),
        meta: {
          title: "字典数据"
        }
      },
      {
        path: "/user/allocationUser",
        name: "allocationUser",
        component: () => import("@/views/systemConfig/role-list/allocationUser"),
        meta: {
          title: "分配用户"
        }
      },
      //按钮打开的路由 不需要进入左侧路由表
      {
        path: "/jgryandzz/zrsstatistics",
        name: "zrsstatistics",
        component: () => import("@/views/dutyBook/jgryandzz/commponents/zrsstatistics"),
        meta: {
          title: "责任书签订统计"
        }
      },
      {
        path: "/yxkzgl/csbwgl/csgl",
        name: "yxkzgl/csbwgl/csgl",
        meta: {
          title: "场所管理"
        },
        component: () => import("@/views/yxkzgl/csbwgl/csgl")
      },
      {
        path: "/jgryandzz/zrsstatisticsList",
        name: "zrsstatisticsList",
        component: () => import("@/views/dutyBook/jgryandzz/commponents/zrsstatisticsList"),
        meta: {
          title: "责任书列表"
        }
      },
      {
        path: "/jgryandzz/Cnsqdqk",
        name: "Cnsqdqk",
        component: () => import("@/views/dutyBook/jgryandzz/Cnsqdqk.vue"),
        meta: {
          title: "承诺书列表"
        }
      },
      {
        path: "/dutyBook/index",
        name: "/dutyBook/index",
        component: () => import("@/views/dutyBook/index"),
        meta: {
          title: "责任书统计"
        }
      },
      // {
      //   path: "/aqfxfjgk/bshzqd",
      //   name: "bshzqd",
      //   component: () => import("@/views/fxgk/aqfxfjgk/bshzqd"),
      //   meta: {
      //     title: "个人风险辨识清单"
      //   }
      // },
      {
        path: "/fxgk/aqfxfjgk/bshz",
        name: "/fxgk/aqfxfjgk/bshz",
        meta: {
          title: "辨识汇总"
        },
        component: () => import("@/views/fxgk/aqfxfjgk/bshz")
      },
      {
        path: "/fxgk/aqfxfjgk/bsqd",
        name: "/fxgk/aqfxfjgk/bsqd",
        meta: {
          title: "辨识清单"
          // icon: "article"
        },
        component: () => import("@/views/fxgk/aqfxfjgk/bsqd")
      },
      {
        path: "/pxjhcoms/pxssxq",
        name: "pxssxq",
        component: () => import("@/views/safety/pxjygl/pxjhcoms/pxssxq"),
        meta: {
          title: "培训实施详情"
        }
      },
      // {
      //   path: "/pxjhcoms/Trainingreport",
      //   name: "Trainingreport",
      //   component: () => import("@/views/safety/pxjygl/pxjhcoms/Trainingreport"),
      //   meta: {
      //     title: "培训上报详情"
      //   }
      // },
      {
        path: "/jgryandzz/Readytotal",
        name: "Readytotal",
        component: () => import("@/views/dutyBook/jgryandzz/commponents/Readytotal"),
        meta: {
          title: "在线安全库学习统计"
        }
      },
      {
        path: "/pxjhcoms/profiledetails",
        name: "profiledetails",
        component: () => import("@/views/safety/pxjygl/pxjhcoms/profiledetails.vue"),
        meta: {
          title: "个人培训档案详情"
        }
      },
      {
        path: "/fxgk/jcss/yhtz",
        name: "/fxgk/jcss/yhtz",
        meta: {
          title: "隐患台账"
        },
        component: () => import("@/views/fxgk/jcss/yhtz")
      },
      {
        path: "/fxgk/aqfxfjgk/component/fxtjxq",
        name: "/fxgk/aqfxfjgk/component/fxtjxq",
        meta: {
          title: store?.state.user.routerName ? store?.state.user.routerName : "风险辨识详情"
        },
        component: () => import("@/views/fxgk/aqfxfjgk/component/fxtjxq")
      },
      {
        path: "/yxkzgl/jsygl/sgzsbxq",
        name: "/yxkzgl/jsygl/sgzsbxq",
        meta: {
          title: "消息任务处理"
        },
        component: () => import("@/views/yxkzgl/jsygl/Sgzsbxq.vue")
      },
      {
        path: "/fxgk/jcss/dxmfx",
        name: "/fxgk/jcss/dxmfx",
        meta: {
          title: store?.state.user.routerName ? store?.state.user.routerName : "点线面分析"
        },
        component: () => import("@/views/fxgk/jcss/dxmfx")
      },
      {
        path: "/fxgk/jcss/zhjczgqk",
        name: "/fxgk/jcss/zhjczgqk",
        meta: {
          title: "综合检查整改情况"
        },
        component: () => import("@/views/fxgk/jcss/zhjczgqk")
      },
      {
        path: "/fxgk/jcss/yhtjxq",
        name: "/fxgk/jcss/yhtjxq",
        meta: {
          title: store?.state.user.routerName ? store?.state.user.routerName : "隐患详情"
        },
        component: () => import("@/views/fxgk/jcss/yhtjxq")
      },
      {
        path: "/fxgk/jcss/yhtjckjd",
        name: "/fxgk/jcss/yhtjckjd",
        meta: {
          title: store?.state.user.routerName ? store?.state.user.routerName : "隐患进度"
        },
        component: () => import("@/views/fxgk/jcss/yhtjckjd")
      },
      // 首页-通知，公告
      {
        path: "/dutyBook/tzgg/show/:id/:row",
        name: "dutyBook/tzgg/show",
        component: () => import("@/views/dutyBook/tzgg/show.vue"),
        meta: {
          title: "通知公告展示"
        }
      },
      // 首页-安全动态展示
      {
        path: "/dutyBook/aqdt/show/:id/:row",
        name: "dutyBook/aqdt/show",
        component: () => import("@/views/dutyBook/aqdt/show.vue"),
        meta: {
          title: "安全动态展示"
        }
      },
      // 首页-安全动态列表展示
      {
        path: "/dutyBook/aqdt/showList/:level",
        name: "dutyBook/aqdt/showList",
        component: () => import("@/views/dutyBook/aqdt/showList.vue"),
        meta: {
          title: "安全动态列表"
        }
      },
      {
        path: "/integrationCenter/xfHome/config",
        name: "integrationCenter/xfHome/config",
        component: () => import("@/views/wljc/xf/config.vue"),
        meta: {
          title: "消防控制主机接入配置",
        }
      },
      {
        path: "/integrationCenter/spjk/config",
        name: "integrationCenter/spjk/config",
        component: () => import("@/views/wljc/spjk/config.vue"),
        meta: {
          title: "视频监控系统接入配置",
        }
      },
      {
        path: "/integrationCenter/dqhz/config",
        name: "integrationCenter/dqhz/config",
        component: () => import("@/views/wljc/dqhz/config.vue"),
        meta: {
          title: "电气火灾自动报警系统接入配置",
        }
      },
      {
        path: "/integrationCenter/tcc/config",
        name: "integrationCenter/tcc/config",
        component: () => import("@/views/wljc/tcc/config.vue"),
        meta: {
          title: "停车场管理系统接入配置",
        }
      },
      {
        path: "/integrationCenter/zhjt/config",
        name: "integrationCenter/zhjt/config",
        component: () => import("@/views/wljc/zhjt/config.vue"),
        meta: {
          title: "智慧交通管理系统接入配置",
        }
      },
      {
        path: "/404",
        name: "404",
        component: () => import("@/views/error-page/404")
      },
      {
        path: "/401",
        name: "401",
        component: () => import("@/views/error-page/401")
      }
      // {
      //   path: "/dutyBook/goalWay/yearZbkNew/targetCustom",
      //   name: "dutyBook/goalWay/yearZbkNew/targetCustom",
      //   meta: {
      //     title: "年度目标指定制定"
      //   },
      //   component: () =>
      //     import(
      //       "@/views/dutyBook/goalWay/compon/targetCustom.vue"
      //     )
      // }
    ]
  },
  {
    path: "/login",
    component: () => import("@/views/login/index") //系统登录
  },
  {
    path: "/mapdemo",
    component: () => import("@/views/mapDemo/index.vue"),
    name: "mapdemo",
    meta: {
      title: "地图demo"
    }
  },
  {
    path: "/:pathMatch(.*)*",
    component: () => import("@/views/error-page/404")
  }
]

const router = createRouter({
  history: createWebHashHistory(),
  routes: [...publicRoutes]
  // routes: publicRoutes1
})
router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.path == "/fxgk/jcss/yhtjxq") {
    to.meta.title = store?.state.user.routerName
  }
  if (to.path == "/fxgk/aqfxfjgk/component/fxtjxq") {
    to.meta.title = store?.state.user.routerName
  }
  if (to.path == "/fxgk/jcss/dxmfx") {
    to.meta.title = store?.state.user.routerName
  }
  next()
})
// const whiteList = [
//   "/login",
//   "/oatuh_login",
//   "/profile",
//   "/",
//   ,
//   "/instructCenter",
//   "/editPassword",
//   "/404",
//   "/401"
// ];
// 初始化路由表
export function resetRouter() {
  if (store.getters?.routeReady && store.getters?.userInfo?.permission?.menus) {
    const menus = store.getters.userInfo.permission.menus
    menus.forEach(menu => {
      router.removeRoute(menu)
    })
  }
  // const newArr = router.getRoutes().filter(item => {
  //   return !whiteList.includes(item.path)
  // })
  // newArr.forEach((menu) => {
  //   if (menu.name) {
  //     router.removeRoute(menu.name);
  //   }
  // });
}

export default router
