import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);

/* Layout */
import Layout from "@/layout";

import dashRouter from "./modules/dash"; //首页
import purchasRouter from "./modules/purchas"; //采购管理
import applyRouter from "./modules/apply"; //申领管理
import storeroomRouter from "./modules/storeroom"; //库房管理
import approveRouter from "./modules/approve"; //审批中心
import supplierRouter from "./modules/supplier"; //供应商管理
import orderRouter from "./modules/order"; //订单管理

export const constantRoutes = [
  {
    path: "/redirect",
    component: Layout,
    hidden: true,
    children: [
      {
        path: "/redirect/:path(.*)",
        component: () => import("@/views/redirect/index")
      }
    ]
  },
  {
    path: "/login",
    component: () => import("@/views/login/index"),
    hidden: true
  },
  {
    path: "/firstLogin",
    component: () => import("@/views/firstLogin/index"),
    hidden: true
  },
  {
    path: "/404",
    component: () => import("@/views/error-page/404"),
    hidden: true
  },
  {
    path: "/401",
    component: () => import("@/views/error-page/401"),
    hidden: true
  },
  {
    path: "/",
    component: Layout,
    redirect: "/homePage/dashboard",
    children: [
      {
        // 公告详情
        path: "/noticeDetail/:id",
        component: () => import("@/views/page/system/notice/noticeDetail"),
        name: "NoticeDetail",
        meta: { title: "公告详情", icon: "dashboard" },
        hidden: true
      },
      {
        // 个人中心
        path: "/personalCenter",
        component: () => import("@/views/page/personalCenter/index"),
        name: "PersonalCenter",
        meta: { title: "个人中心", icon: "dashboard" },
        hidden: true
      }
    ]
  },
];


export const asyncRoutes = [
  dashRouter,
  purchasRouter,
  applyRouter,
  storeroomRouter,
  approveRouter,
  supplierRouter,
  orderRouter,
  { path: "*", redirect: "/404", hidden: true }
];

const createRouter = () =>
  new Router({
    //mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  });

const router = createRouter();

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
