项目初始化
This commit is contained in:
81
frontend/src/router/index.ts
Normal file
81
frontend/src/router/index.ts
Normal file
@@ -0,0 +1,81 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router'
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
redirect: '/player'
|
||||
},
|
||||
{
|
||||
path: '/player/login',
|
||||
name: 'PlayerLogin',
|
||||
component: () => import('@/views/player/Login.vue'),
|
||||
meta: { title: '玩家登录' }
|
||||
},
|
||||
{
|
||||
path: '/player',
|
||||
component: () => import('@/layouts/PlayerLayout.vue'),
|
||||
children: [
|
||||
{
|
||||
path: 'dashboard',
|
||||
name: 'PlayerDashboard',
|
||||
component: () => import('@/views/player/Dashboard.vue'),
|
||||
meta: { title: '玩家控制台', requiresAuth: true }
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
path: '/admin/login',
|
||||
name: 'AdminLogin',
|
||||
component: () => import('@/views/admin/Login.vue'),
|
||||
meta: { title: '管理员登录' }
|
||||
},
|
||||
{
|
||||
path: '/admin',
|
||||
component: () => import('@/layouts/AdminLayout.vue'),
|
||||
children: [
|
||||
{
|
||||
path: 'dashboard',
|
||||
name: 'AdminDashboard',
|
||||
component: () => import('@/views/admin/Dashboard.vue'),
|
||||
meta: { title: '管理控制台', requiresAdminAuth: true }
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes
|
||||
})
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
document.title = (to.meta.title as string) || '梦幻西游一站式运营管理平台'
|
||||
|
||||
if (to.path.startsWith('/player')) {
|
||||
if (to.path === '/player/login') {
|
||||
next()
|
||||
} else {
|
||||
const playerToken = sessionStorage.getItem('player_token')
|
||||
if (playerToken) {
|
||||
next()
|
||||
} else {
|
||||
next('/player/login')
|
||||
}
|
||||
}
|
||||
} else if (to.path.startsWith('/admin')) {
|
||||
if (to.path === '/admin/login') {
|
||||
next()
|
||||
} else {
|
||||
const adminToken = localStorage.getItem('admin_token')
|
||||
if (adminToken) {
|
||||
next()
|
||||
} else {
|
||||
next('/admin/login')
|
||||
}
|
||||
}
|
||||
} else {
|
||||
next()
|
||||
}
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user