xyc
10 小时以前 b509d59af23c6afba086fa3fb4c2afb47ab0becb
traffic-audit-web/src/router/index.js
@@ -14,16 +14,22 @@
    { 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: '/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 = localStorage.getItem('token')
  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(token ? undefined : '/login')
    next()
  }
})