import { createRouter, createWebHashHistory } from 'vue-router'
const routes = [
    {
        path: '/',
        redirect: '/login'
    },
    {
        path: '/login',
        name: 'login',
        meta: {
            title: '登录'
        },
        component: () => import('../view/Login.vue')
    },
    {
        path: '/home',
        name: '主页',
        meta: {
            title: '主页'
        },
        component: () => import('../view/Home.vue'),
        redirect: '/index',
        children: [
            {
                path: '/index',
                meta: {
                    title: '首页'
                },
                component: () => import('../view/case/index.vue')
            },
            {
                path: '/echart',
                meta: {
                    title: '运营概况',
                },
                component: () => import('../view/echart.vue')
            },
            {
                path: '/item/list',
                meta: {
                    title: '单元订单'
                },
                component: () => import('../view/item/Index.vue'),
            },
            {
                path: '/vip/list',
                meta: {
                    title: 'VIP会员订单'
                },
                component: () => import('../view/vip/Index.vue'),
            },
            {
                path: '/user/list',
                meta: {
                    title: '用户管理'
                },
                component: () => import('../view/user/Index.vue'),
            },
            {
                path: '/classifyManage/list',
                meta: {
                    title: '分类管理'
                },
                component: () => import('../view/classifyManage/Index.vue'),
            },
            {
                path: '/itemManage/list',
                meta: {
                    title: '单元管理'
                },
                component: () => import('../view/itemManage/Index.vue'),
            },
            {
                path: '/couponManage/list',
                meta: {
                    title: '优惠卷管理'
                },
                component: () => import('../view/couponManage/Index.vue'),
            },
            {
                path: '/accountManage/list',
                meta: {
                    title: '账户管理'
                },
                component: () => import('../view/accountManage/Index.vue'),
            },
            {
                path: '/settingManage/list',
                meta: {
                    title: '设置管理'
                },
                component: () => import('../view/settingManage/Index.vue'),
            },
            
        ]
    },
]
const router = createRouter({
    history: createWebHashHistory(),
    routes
})
// 挂载路由导航守卫：to表示将要访问的路径，from表示从哪里来，next是下一个要做的操作
router.beforeEach((to, from, next) => {
    // 修改页面 title
    if (to.meta.title) {
      document.title = '互动病例后台管理系统 - ' + to.meta.title
    }
    // 放行登录页面
    if (to.path === '/login') {
      return next()
    }
    // 获取token
    // const token= sessionStorage.getItem('token')
    // if (!token) {
    //   return next('/login')
    // } else {
    //   next()
    // }
    return next()
  })
  
// 导出路由
export default router