import Vue from 'vue'
import Router from 'vue-router'
import Layout from '@/layout'

Vue.use(Router)

//不管是超级管理员还是普通用户都可以看到的页面 
export const constantRoutes = [
    // 登录页
    {
        path: '/login',
        component: () => import('@/views/login/index'),
        hidden: true
    },
]

/**
 * 异步路由
 * asyncRoutes
 */
export const asyncRoutes = [
    {
        path: '/',
        name: 'Layout',
        redirect: '/login',
        alwaysShow: true,
        component: Layout,
        children: [
            {
                path: 'home',
                name: 'Home',
                component: () => import('@/views/home')
            },
            {
                path: 'order',
                name: 'Order',
                component: () => import('@/views/order')
            },
            {
                path: 'staff',
                name: 'Staff',
                component: () => import('@/views/staff')
            },
            {
                path: 'account',
                name: 'Account',
                component: () => import('@/views/account')
            },
            {
                path: 'stat',
                name: 'Stat',
                component: () => import('@/views/stat')
            },
            {
                path: 'system',
                name: 'System',
                component: () => import('@/views/system')
            },
            {
                path: 'inform',
                name: 'Inform',
                component: () => import('@/views/inform')
            }
        ]
    },
]


export const anyRoute = { path: '*', redirect: '/404', hidden: true }
const createRouter = () => new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: [...constantRoutes, ...asyncRoutes]
})

const router = createRouter()

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

export default router
