import {
  createRouter,
  createWebHistory,
  createWebHashHistory,
} from "vue-router";
import Home from "../pages/Home.vue";
const routes = [
  {
    path: "/",
    redirect: "/safe/realwaring",
    // redirect: '/firstPage',
  },
  {
    path: "/",
    name: "Home",
    redirect: "/safe/realwaring",
    // redirect: '/firstPage',
    component: Home,
    children: [
      //   {
      //     icon: "el-icon-s-home",
      //     path: "/firstPage",
      //     name: "shouye",
      //     meta: {
      //       title: "系统首页",
      //     },
      //     component: () => import("../pages/firstPage.vue"),
      //   },

      //   {
      //     icon: "el-icon-s-home",
      //     path: "/dashboard",
      //     name: "dashboard",
      //     meta: {
      //       title: "系统首页",
      //     },
      //     component: () =>
      //       import(
      //         /* webpackChunkName: "dashboard" */
      //         "../pages/Dashboard.vue"
      //       ),
      //   },

      {
        icon: "iconfont iconfengji",
        path: "/safe",
        name: "safe",
        redirect: "/safe/realwaring",
        meta: {
          title: "安全运行",
        },
        component: () => import("../pages/routerView.vue"),
        children: [
          {
            path: "/safe/realwaring",
            name: "saferealwaring",
            meta: {
              title: "实时报警",
              keepAlive: true, //需要被缓存的组件
            },
            component: () =>
              import(
                /* webpackChunkName: "form" */
                "../pages/safe/realwaring.vue"
              ),
          },
          {
            path: "/safe/historywaring",
            name: "safehistorywaring",
            meta: {
              title: "报警记录",
            },
            component: () =>
              import(
                /* webpackChunkName: "form" */
                "../pages/safe/historywaring.vue"
              ),
          },
          {
            path: "/safe/dataSearch",
            name: "safedataSearch",
            meta: {
              title: "数据查询",
            },
            component: () =>
              import(
                /* webpackChunkName: "form" */
                "../pages/safe/datasearch.vue"
              ),
          },
        ],
      },

      {
        icon: "iconfont iconguzhangzhenduan",
        path: "/faultDiagnosis",
        name: "faultDiagnosis",
        redirect: "/faultDiagnosis/warning",
        meta: {
          title: "状态检修",
          permission: true,
        },
        component: () =>
          import(
            /* webpackChunkName: "permission" */
            "../pages/routerView.vue"
          ),
        children: [
          // {
          //     icon: 'el-icon-s-home',
          //     path: '/faultDiagnosis/record',
          //     name: 'faultDiagnosissrecord',
          //     meta: {
          //         title: '预警记录',
          //     },
          //     component: () =>
          //         import (
          //             /* webpackChunkName: "form" */
          //             '../pages/faultDiagnosis/record.vue'
          //         ),
          // },
          {
            icon: "el-icon-s-home",
            path: "/faultDiagnosis/warning",
            name: "faultDiagnosiswarning",
            meta: {
              title: "预警分析",
            },
            component: () =>
              import(
                /* webpackChunkName: "form" */
                "../pages/faultDiagnosis/warning.vue"
              ),
          },
          {
            icon: "el-icon-s-home",
            path: "/faultDiagnosis/statistics",
            name: "faultDiagnosisstatistics",
            meta: {
              title: "预警统计",
            },
            component: () =>
              import(
                /* webpackChunkName: "form" */
                "../pages/faultDiagnosis/statistics.vue"
              ),
          },
          {
            icon: "el-icon-s-home",
            path: "/basedata/FanDataStatisticTable",
            name: "FanDataStatisticTable",
            meta: {
              title: "原始报警统计",
              keepAlive: true,
            },
            component: () =>
              import("../pages/baseData/FanDataStatisticTable.vue"),
          },
          //   {
          //     icon: "el-icon-s-home",
          //     path: "/faultDiagnosis/report",
          //     name: "faultDiagnosisreport",
          //     meta: {
          //       title: "隐患报告",
          //     },
          //     component: () => import("../pages/faultDiagnosis/report.vue"),
          //   },
          //   {
          //     icon: "el-icon-s-home",
          //     path: "/faultDiagnosis/dangerReportReview",
          //     name: "dangerReportReview",
          //     meta: {
          //       title: "报告评审",
          //     },
          //     component: () =>
          //       import("../pages/faultDiagnosis/dangerReportReview.vue"),
          //   },
          //   {
          //     icon: "el-icon-s-home",
          //     path: "/faultDiagnosis/patrolInspectionPlan",
          //     name: "patrolInspectionPlan",
          //     meta: {
          //       title: "巡检计划",
          //     },
          //     component: () =>
          //       import("../pages/faultDiagnosis/patrolInspectionPlan.vue"),
          //   },

          //   {
          //     icon: "el-icon-s-home",
          //     path: "/faultDiagnosis/Recommend",
          //     name: "faultDiagnosisRecommend",
          //     meta: {
          //       title: "诊断报告",
          //     },
          //     component: () =>
          //       import(
          //         /* webpackChunkName: "form" */
          //         "../pages/faultDiagnosis/Recommend.vue"
          //       ),
          //   },

          // {
          //     icon: 'el-icon-s-home',
          //     path: '/faultDiagnosis/fault',
          //     name: 'faultDiagnosisfault',
          //     meta: {
          //         title: '故障诊断',
          //     },
          //     component: () =>
          //         import (
          //             /* webpackChunkName: "form" */
          //             '../pages/faultDiagnosis/fault.vue'
          //         ),
          // },

          // {
          //     icon: 'el-icon-s-home',
          //     path: '/faultDiagnosis/cluster',
          //     name: 'faultDiagnosiscluster',
          //     meta: {
          //         title: '聚类分析',
          //     },
          //     component: () =>
          //         import (
          //             /* webpackChunkName: "form" */
          //             '../pages/faultDiagnosis/cluster.vue'
          //         ),
          // },
        ],
      },
      {
        icon: "iconfont iconbaojingpeizhi",
        path: "/alarmconfig",
        name: "alarmconfig",
        isshow: ["admin", "superuser"],
        redirect: "/alarmconfig/station",
        meta: {
          title: "预警配置",
        },
        component: () =>
          import(
            /* webpackChunkName: "tabs" */
            "../pages/routerView.vue"
          ),
        children: [
          {
            icon: "el-icon-s-home",
            path: "/alarmConfig/custom",
            name: "alarmConfigcustom",
            meta: {
              title: "自定义预警",
            },
            component: () =>
              import(
                /* webpackChunkName: "form" */
                "../pages/alarmConfig/bj_custom/custom.vue"
              ),
          },
          {
            icon: "el-icon-s-home",
            path: "/alarmConfig/fan",
            name: "alarmConfigfan",
            meta: {
              title: "风机报警",
            },
            component: () =>
              import(
                /* webpackChunkName: "form" */
                "../pages/alarmConfig/bj_windturbine/windturbine.vue"
              ),
          },

          // {
          //     icon: 'el-icon-s-home',
          //     path: '/alarmConfig/boostleg',
          //     name: 'alarmConfigboostleg',
          //     meta: {
          //         title: '升压站报警',
          //     },
          //     component: () =>
          //         import(
          //             /* webpackChunkName: "form" */
          //             '../pages/alarmConfig/bj_scada/scada.vue'
          //         ),
          // },

          {
            icon: "el-icon-s-home",
            path: "/alarmConfig/Logs",
            name: "alarmConfigLogs",
            meta: {
              title: "规则修改日志",
            },
            component: () =>
              import(
                /* webpackChunkName: "form" */
                "../pages/alarmConfig/Logs.vue"
              ),
          },
        ],
      },

      {
        icon: "iconfont iconjichushuju",
        path: "/basedata",
        name: "basedata",
        isshow: "admin",

        redirect: "/basedata/station",
        meta: {
          title: "基础数据",
        },
        component: () =>
          import(
            /* webpackChunkName: "home" */
            "../pages/routerView.vue"
          ),
        children: [
          {
            icon: "el-icon-s-home",
            path: "/basedata/device",
            name: "basedatadevice",
            meta: {
              title: "设备模型",
              keepAlive: true,
            },
            component: () =>
              import(
                /* webpackChunkName: "form" */
                "../pages/baseData/device.vue"
              ),
          },
          {
            icon: "el-icon-s-home",
            path: "/basedata/dictionary",
            name: "basedatadictionary",
            meta: {
              title: "字典维护",
              keepAlive: true,
            },
            component: () =>
              import(
                /* webpackChunkName: "form" */
                "../pages/baseData/dictionary.vue"
              ),
          },
        ],
      },
      //   {
      //     icon: "el-icon-user-solid",
      //     path: "/userManage",
      //     name: "userManage",
      //     isshow: "admin",
      //     meta: {
      //       title: "用户管理",
      //     },
      //     component: () => import("../pages/userManage/userManage.vue"),
      //   },
      //   {
      //     icon: "iconfont iconxitongcaidan",
      //     path: "/systemManage",
      //     isshow: "admin",
      //     name: "systemManage",
      //     meta: {
      //       title: "系统管理",
      //     },
      //     component: () => import("../pages/systemManage/systemManage.vue"),
      //   },
    ],
  },
  {
    icon: "iconfont iconxitongcaidan",
    path: "/check",
    isshow: "admin",
    name: "check",
    meta: {
      title: "单点登录",
    },
    component: () => import("../pages/check/check.vue"),
  },
  {
    path: "/login",
    name: "Login",
    meta: {
      title: "登录",
    },
    component: () =>
      import(
        /* webpackChunkName: "login" */
        "../pages/Login.vue"
      ),
  },
];

const router = createRouter({
  history: createWebHashHistory(""),
  routes,
});

router.beforeEach((to, from, next) => {
  document.title = `${to.meta.title} | 设备隐患感知系统`;
  const role = sessionStorage.getItem("ms_chinesename");
  if (to.path === "/check") {
    next();
  } else if (!role && to.path !== "/login") {
    next("/login");
  } else {
  }
  next();
});

export default router;
