新增账号,超管体系
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
import Layout from '@/layout/index.vue'
|
||||
import { getToken, clearToken, isTokenExpired } from '@/utils/auth'
|
||||
import { getToken, clearAuth, isTokenExpired, isSuperAdmin } from '@/utils/auth'
|
||||
import { HOME_PATH } from '@/utils/tabs'
|
||||
|
||||
const routes = [
|
||||
{
|
||||
@@ -13,8 +14,14 @@ const routes = [
|
||||
path: '/',
|
||||
component: Layout,
|
||||
meta: { requiresAuth: true },
|
||||
redirect: '/brand',
|
||||
redirect: HOME_PATH,
|
||||
children: [
|
||||
{
|
||||
path: HOME_PATH,
|
||||
name: 'Home',
|
||||
component: () => import('@/views/home/index.vue'),
|
||||
meta: { title: '首页', icon: 'home' }
|
||||
},
|
||||
{
|
||||
path: '/brand',
|
||||
name: 'Brand',
|
||||
@@ -38,6 +45,12 @@ const routes = [
|
||||
name: 'ShareCodeLog',
|
||||
component: () => import('@/views/share-code/log.vue'),
|
||||
meta: { title: '分享日志', icon: 'document' }
|
||||
},
|
||||
{
|
||||
path: '/system/users',
|
||||
name: 'SystemUsers',
|
||||
component: () => import('@/views/system/users/index.vue'),
|
||||
meta: { title: '账号管理', icon: 'user', requiresSuperAdmin: true }
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -54,15 +67,20 @@ router.beforeEach((to, _from, next) => {
|
||||
|
||||
if (needAuth) {
|
||||
if (!token || isTokenExpired(token)) {
|
||||
if (token) clearToken()
|
||||
if (token) clearAuth()
|
||||
next({ path: '/login', query: { redirect: to.fullPath } })
|
||||
return
|
||||
}
|
||||
|
||||
const needSuperAdmin = to.matched.some((r) => r.meta && r.meta.requiresSuperAdmin === true)
|
||||
if (needSuperAdmin && !isSuperAdmin()) {
|
||||
next({ path: HOME_PATH })
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (to.path === '/login' && token && !isTokenExpired(token)) {
|
||||
const redirect = to.query.redirect
|
||||
next(typeof redirect === 'string' && redirect ? redirect : '/')
|
||||
next({ path: HOME_PATH })
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user