功能优化

This commit is contained in:
2025-11-16 19:35:55 +08:00
parent c2bd94cfad
commit bdbe74cebb
53 changed files with 8235 additions and 107 deletions

View File

@@ -35,6 +35,16 @@ const routes = [
{ path: 'voice-copy', name: '人声克隆', component: () => import('../views/dh/VoiceCopy.vue') },
{ path: 'voice-generate', name: '生成配音', component: () => import('../views/dh/VoiceGenerate.vue') },
{ path: 'avatar', name: '生成数字人', component: () => import('../views/dh/Avatar.vue') },
{ path: 'video', name: '数字人视频', component: () => import('../views/dh/Video.vue') },
]
},
{
path: '/material',
name: '素材库',
children: [
{ path: '', redirect: '/material/list' },
{ path: 'list', name: '素材列表', component: () => import('../views/material/MaterialList.vue') },
{ path: 'group', name: '素材分组', component: () => import('../views/material/MaterialGroup.vue') },
]
},
{
@@ -62,10 +72,13 @@ const router = createRouter({
let userInfoInitialized = false
/**
* 路由导航守卫:初始化用户信息
* 路由导航守卫:初始化用户信息 + 登录验证
* 在首次路由跳转时,如果已登录(有 token则获取用户信息
* 如果未登录访问系统相关路由,则重定向到首页
*/
router.beforeEach(async (to, from, next) => {
const userStore = useUserStore()
// 只在首次路由跳转时初始化用户信息
if (!userInfoInitialized) {
userInfoInitialized = true
@@ -73,7 +86,6 @@ router.beforeEach(async (to, from, next) => {
const token = getToken()
if (token) {
try {
const userStore = useUserStore()
// 如果 store 中已标记为登录,则获取用户信息
if (userStore.isLoggedIn) {
userStore.fetchUserInfo()
@@ -90,6 +102,22 @@ router.beforeEach(async (to, from, next) => {
}
}
// 检查访问系统相关路由时是否已登录
if (to.path.startsWith('/system')) {
// 等待 store 从本地存储恢复完成最多等待500ms
let waitCount = 0
while (!userStore.isHydrated && waitCount < 50) {
await new Promise(resolve => setTimeout(resolve, 10))
waitCount++
}
// 如果未登录,重定向到首页
if (!userStore.isLoggedIn) {
next({ path: '/content-style/benchmark', replace: true })
return
}
}
// 继续路由跳转
next()
})