xyc
10 小时以前 b509d59af23c6afba086fa3fb4c2afb47ab0becb
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
import Vue from 'vue'
import Router from 'vue-router'
 
Vue.use(Router)
 
const router = new Router({
  routes: [
    { path: '/', redirect: '/login' },
    { path: '/login', name: 'Login', component: () => import('@/views/Login.vue') },
    { path: '/dashboard', name: 'Dashboard', component: () => import('@/views/Dashboard.vue') },
    { path: '/import', name: 'DataImport', component: () => import('@/views/DataImport.vue') },
    { path: '/data', name: 'DataView', component: () => import('@/views/DataView.vue') },
    { path: '/explain', name: 'ExplainReview', component: () => import('@/views/ExplainReview.vue') },
    { path: '/audit', name: 'AuditResult', component: () => import('@/views/AuditResult.vue') },
    { path: '/report', name: 'ReportExport', component: () => import('@/views/ReportExport.vue') },
    { path: '/rules', name: 'RuleManage', component: () => import('@/views/RuleManage.vue') },
    { path: '/users', name: 'UserManage', component: () => import('@/views/UserManage.vue') },
    { path: '/holiday-stat', name: 'HolidayStat', component: () => import('@/views/HolidayStat.vue') },
    { path: '/system-config', name: 'SystemConfig', component: () => import('@/views/SystemConfig.vue'), meta: { requireAdmin: true } }
  ]
})
 
router.beforeEach((to, from, next) => {
  const token = sessionStorage.getItem('token')
  if (to.path === '/login') {
    next(token ? '/dashboard' : undefined)
  } else if (!token) {
    next('/login')
  } else if (to.meta && to.meta.requireAdmin && sessionStorage.getItem('username') !== 'admin') {
    next('/dashboard')
  } else {
    next()
  }
})
 
export default router