frontend layout and infrastructure

This commit is contained in:
2026-03-18 13:53:36 +08:00
parent 88df42fe52
commit 2b1a2f0c28
26 changed files with 986 additions and 460 deletions
+35 -1
View File
@@ -13,9 +13,43 @@ const router = createRouter({
routes,
})
const pinia = createPinia()
const app = createApp(App)
app.use(createPinia())
app.use(pinia)
app.use(router)
// 路由守卫
const authWhitelist = ['/login', '/register']
router.beforeEach(async (to) => {
const { useUserStore } = await import('./stores/user')
const userStore = useUserStore()
// 白名单页面(登录/注册)
if (authWhitelist.includes(to.path)) {
if (userStore.isLoggedIn) {
return '/'
}
return true
}
// 未登录跳转登录页
if (!userStore.isLoggedIn) {
return `/login?redirect=${to.fullPath}`
}
// 已登录但未获取用户信息
if (!userStore.user) {
try {
await userStore.fetchCurrentUser()
} catch {
userStore.logout()
return '/login'
}
}
return true
})
app.mount('#app')