feat: implement theme synchronization and loading skeletons across various components, enhancing user experience during content loading

This commit is contained in:
wizardchen
2026-04-11 15:03:20 +08:00
committed by lyingbug
parent 1a4b7b390d
commit 6d8b47e57c
15 changed files with 441 additions and 19 deletions
+46 -4
View File
@@ -1,7 +1,27 @@
import { createRouter, createWebHistory } from 'vue-router'
import { listKnowledgeBases } from '@/api/knowledge-base'
import type { RouteLocationNormalized } from 'vue-router'
import { useAuthStore } from '@/stores/auth'
import { validateToken, autoSetup } from '@/api/auth'
import { autoSetup } from '@/api/auth'
/** Lite /桌面 WebView 硬刷新时可能只打开 `/`,用 session 记住上次页面以便恢复 */
const LITE_LAST_PATH_KEY = 'weknora_lite_last_path'
function isLiteEdition(authStore: ReturnType<typeof useAuthStore>) {
return authStore.isLiteMode || localStorage.getItem('weknora_lite_mode') === 'true'
}
function isLiteSpaDefaultEntry(to: RouteLocationNormalized) {
return (
to.path === '/' ||
to.path === '/platform' ||
to.path === '/platform/knowledge-bases' ||
to.name === 'knowledgeBaseList'
)
}
function isSafeLiteRestoreTarget(path: string) {
return path.startsWith('/platform/') && !path.startsWith('/platform/organizations')
}
const router = createRouter({
history: createWebHistory(import.meta.env.BASE_URL),
@@ -134,11 +154,26 @@ function persistLoginResponse(authStore: ReturnType<typeof useAuthStore>, respon
}
let autoSetupAttempted = false
let liteDeepLinkRestoreDone = false
// 路由守卫:检查认证状态和系统初始化状态
router.beforeEach(async (to, from, next) => {
const authStore = useAuthStore()
// Lite:硬刷新后若落在默认首页,恢复本次会话中最后访问的 /platform 子路径
if (!liteDeepLinkRestoreDone) {
liteDeepLinkRestoreDone = true
if (isLiteEdition(authStore)) {
const saved = sessionStorage.getItem(LITE_LAST_PATH_KEY)
if (saved && isSafeLiteRestoreTarget(saved) && isLiteSpaDefaultEntry(to)) {
if (saved !== to.fullPath) {
next(saved)
return
}
}
}
}
// 如果访问的是登录页面或初始化页面,直接放行
if (to.meta.requiresAuth === false || to.meta.requiresInit === false) {
// 如果已登录用户访问登录页面,重定向到知识库列表页面
@@ -174,6 +209,13 @@ router.beforeEach(async (to, from, next) => {
}
next()
});
})
router.afterEach((to) => {
if (!isLiteEdition(useAuthStore())) return
if (to.path === '/login') return
if (!to.path.startsWith('/platform')) return
sessionStorage.setItem(LITE_LAST_PATH_KEY, to.fullPath)
})
export default router