feat: 功能优化
This commit is contained in:
@@ -35,7 +35,6 @@ const routes = [
|
||||
{ path: '', redirect: '/trends/heat' },
|
||||
{ path: 'heat', name: '热度分析', component: () => import('../views/trends/Heat.vue') },
|
||||
{ path: 'forecast', name: '热点预测', component: () => import('../views/trends/Forecast.vue') },
|
||||
{ path: 'copywriting', name: '趋势文案创作', component: () => import('../views/trends/Copywriting.vue') },
|
||||
]
|
||||
},
|
||||
{
|
||||
@@ -52,7 +51,7 @@ const routes = [
|
||||
name: '素材库',
|
||||
children: [
|
||||
{ path: '', redirect: '/material/list' },
|
||||
{ path: 'list', name: '素材列表', component: () => import('../views/material/MaterialList.vue') },
|
||||
{ path: 'list', name: '素材列表', component: () => import('../views/material/MaterialListNew.vue') },
|
||||
{ path: 'mix', name: '智能混剪', component: () => import('../views/material/Mix.vue') },
|
||||
{ path: 'mix-task', name: '混剪任务', component: () => import('../views/material/MixTaskList.vue') },
|
||||
{ path: 'group', name: '素材分组', component: () => import('../views/material/MaterialGroup.vue') },
|
||||
@@ -74,21 +73,12 @@ const routes = [
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
{ path: 'realtime-hot', name: '实时热点推送', component: () => import('../views/realtime/RealtimeHot.vue') },
|
||||
{ path: 'capcut-import', name: '剪映导入', component: () => import('../views/capcut/CapcutImport.vue') },
|
||||
{ path: 'help', name: '帮助', component: () => import('../views/misc/Help.vue') },
|
||||
{ path: 'download', name: '下载', component: () => import('../views/misc/Download.vue') },
|
||||
{ path: 'settings/theme', name: '主题设置', component: () => import('../views/misc/Theme.vue') },
|
||||
],
|
||||
meta: {
|
||||
requiresAuth: true
|
||||
}
|
||||
},
|
||||
// 向后兼容:重定向旧路径到新路径
|
||||
{
|
||||
path: '/material/mix-task',
|
||||
redirect: '/system/task-management/mix-task'
|
||||
}
|
||||
|
||||
]
|
||||
|
||||
const router = createRouter({
|
||||
@@ -99,18 +89,7 @@ const router = createRouter({
|
||||
// 路由守卫
|
||||
router.beforeEach(async (to, from, next) => {
|
||||
const userStore = useUserStore()
|
||||
|
||||
// 等待 Pinia store 恢复完成(最多等待 500ms)
|
||||
if (to.meta.requiresAuth) {
|
||||
let waitCount = 0
|
||||
while (!userStore.isHydrated && waitCount < 50) {
|
||||
await new Promise(resolve => setTimeout(resolve, 10))
|
||||
waitCount++
|
||||
}
|
||||
}
|
||||
|
||||
// 检查是否已登录(通过 token 是否有效)
|
||||
const authenToken = tokenManager.getToken()
|
||||
const authenToken = tokenManager.getAccessToken()
|
||||
|
||||
// 路由访问控制
|
||||
if (to.meta.requiresAuth && !authenToken) {
|
||||
@@ -128,12 +107,8 @@ router.beforeEach(async (to, from, next) => {
|
||||
return
|
||||
}
|
||||
|
||||
// 首次访问且已登录时,同步用户信息到 store
|
||||
if (authenToken) {
|
||||
userStore.isLoggedIn = true
|
||||
userStore.fetchUserInfo().catch(error => {
|
||||
console.error('初始化用户信息失败:', error)
|
||||
})
|
||||
if (authenToken && !userStore.isLoggedIn.value) {
|
||||
userStore.fetchUserInfo()
|
||||
}
|
||||
|
||||
next()
|
||||
|
||||
Reference in New Issue
Block a user