import {
  createRouter,
  createWebHistory,
  createWebHashHistory,
} from "vue-router";

import NProgress from "nprogress";
import "nprogress/nprogress.css";
import Layout from "@/layout/index.vue";
const router = createRouter({
  // history: createWebHashHistory("/campusMaintenance/repairManage"), // 线上地址
  history: createWebHashHistory("/testingServer/repairManage"), // 测试环境发布地址
  routes: [
    {
      path: "/login",
      component: () => import("@/views/login/index.vue"),
    },
    {
      path: "/",
      redirect: "/login",
    },
    {
      path: "/repairs",
      component: Layout,
      children: [
        {
          path: "news",
          component: () => import("@/views/news/news.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "home",
          component: () => import("@/views/home/home.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "workOrder",
          component: () => import("@/views/workOrder/workOrder.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "area",
          component: () => import("@/views/area/area.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "consumable",
          component: () => import("@/views/consumable/consumable.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "staff",
          component: () => import("@/views/staff/staff.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "account",
          component: () => import("@/views/account/account.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "goods",
          component: () => import("@/views/goods/goods.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "scheduling",
          component: () => import("@/views/scheduling/scheduling.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "paySuccess",
          component: () => import("@/views/paySuccess/paySuccess.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "evaluate",
          component: () => import("@/views/evaluate/evaluate.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "affiche",
          component: () => import("@/views/affiche/affiche.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
        {
          path: "waiting",
          component: () => import("@/views/waiting/waiting.vue"),
          meta: { title: "Dashboard", icon: "dashboard" },
        },
      ],
    },
  ],
});
router.beforeEach((to, from, next) => {
  NProgress.start(); // 进度条开始
  // 判断 如果cook是否存在，可以进去
  if (sessionStorage.getItem("token")) {
    next(); //放行
  } else {
    if (to.path == "/login") {
      next();
    } else {
      next(`/login`);
    }
  }
});

router.afterEach(() => {
  NProgress.done(); // 进度条结束
});
export default router;
// router.beforeEach(async (to, from, next) => {
//   // 判断 如果cook是否存在，可以进去
//   if (sessionStorage.getItem("token")) {
//     next(); //放行
//   } else {
//     if (to.path == "/login") {
//       next();
//     } else {
//       next(`/login`);
//     }
//   }
// });
