import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

// 引入路由
import supplierRoutes from './module/supplier'
import clubRoutes from './module/club'
import doctorRoutes from './module/doctor'
import feedbackRoutes from './module/feedback'
import helperRoutes from './module/helper'
import materialRoutes from './module/material'
import AuditRoutes from './module/audit'

// 需要权限访问的路由列表
export const asyncRoutes = [
  ...supplierRoutes,
  ...AuditRoutes,
  ...clubRoutes,
  ...doctorRoutes,
  ...materialRoutes,
  ...feedbackRoutes,
  ...helperRoutes,
  // 404页面 放在最后面
  { path: '*', redirect: '/404', hidden: true }
]

// 默认路由列表 全部用户都可以访问
export const constantRoutes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: () => import(/* webpackChunkName: "login" */ '@/views/login/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import(/* webpackChunkName: "error-page" */ '@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import(/* webpackChunkName: "error-page" */ '@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/proxy',
    component: () => import(/* webpackChunkName: "proxy" */ '@/views/proxy'),
    hidden: true
  }
]

// 创建路由对象
const createRouter = () =>
  new Router({
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// 重置路由
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
