新增 Web 浏览端(Go+Vue 报表系统)
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
48
web/frontend/src/router/index.ts
Normal file
48
web/frontend/src/router/index.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
import { createRouter, createWebHistory, type RouteRecordRaw } from 'vue-router'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
const routes: RouteRecordRaw[] = [
|
||||
{
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
component: () => import('@/views/LoginView.vue'),
|
||||
meta: { layout: 'blank', public: true },
|
||||
},
|
||||
{ path: '/', redirect: '/scores' },
|
||||
{
|
||||
path: '/scores',
|
||||
name: 'scores',
|
||||
component: () => import('@/views/ScoresView.vue'),
|
||||
},
|
||||
{
|
||||
path: '/chart',
|
||||
name: 'chart',
|
||||
component: () => import('@/views/ChartView.vue'),
|
||||
},
|
||||
{
|
||||
path: '/admin/users',
|
||||
name: 'admin-users',
|
||||
component: () => import('@/views/AdminUsersView.vue'),
|
||||
meta: { adminOnly: true },
|
||||
},
|
||||
{ path: '/:pathMatch(.*)*', redirect: '/scores' },
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes,
|
||||
})
|
||||
|
||||
router.beforeEach((to) => {
|
||||
const auth = useAuthStore()
|
||||
if (to.meta.public) return true
|
||||
if (!auth.token) {
|
||||
return { path: '/login', query: { redirect: to.fullPath } }
|
||||
}
|
||||
if (to.meta.adminOnly && !auth.isAdmin) {
|
||||
return { path: '/scores' }
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
export default router
|
||||
Reference in New Issue
Block a user