Blame view

store-pc/src/router/index.js 1.64 KB
58083915   “wangming”   对门店PC进行设计
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
  import Vue from 'vue'
  import VueRouter from 'vue-router'
  
  Vue.use(VueRouter)
  
  const routes = [
    {
      path: '/login',
      name: 'Login',
      component: () => import('@/views/login/index.vue'),
      meta: { title: '登录', noLayout: true }
    },
    {
      path: '/',
      component: () => import('@/layout/index.vue'),
      redirect: '/dashboard',
      children: [
        {
          path: 'dashboard',
          name: 'Dashboard',
          component: () => import('@/views/dashboard/index.vue'),
          meta: { title: '工作台', icon: 'el-icon-s-home' }
        },
        {
          path: 'booking',
          name: 'Booking',
          component: () => import('@/views/booking/index.vue'),
          meta: { title: '新建预约', icon: 'el-icon-date' }
        },
        {
          path: 'orders',
          name: 'Orders',
          component: () => import('@/views/orders/index.vue'),
          meta: { title: '开单记录', icon: 'el-icon-document' }
        },
        {
          path: 'members',
          name: 'Members',
          component: () => import('@/views/members/index.vue'),
          meta: { title: '会员管理', icon: 'el-icon-user' }
        }
      ]
    }
  ]
  
  const router = new VueRouter({
    mode: 'hash',
    base: process.env.BASE_URL,
    routes
  })
  
  const whiteList = ['/login']
  
  router.beforeEach((to, from, next) => {
    document.title = to.meta.title ? `${to.meta.title} - 绿纤门店` : '绿纤门店'
    const token = localStorage.getItem('store_token')
    if (token) {
      if (to.path === '/login') {
        next({ path: '/' })
      } else {
        next()
      }
    } else {
      if (whiteList.includes(to.path)) {
        next()
      } else {
        next('/login')
      }
    }
  })
  
  export default router