This commit is contained in:
2026-02-24 21:41:05 +08:00
parent c1d1b0ed70
commit 9388f7d75b
7 changed files with 108 additions and 178 deletions

View File

@@ -10,7 +10,7 @@ const navConfig = [
order: 1,
items: [
{ name: '对标分析', path: 'content-style/benchmark', icon: 'grid', component: () => import('../views/content-style/Benchmark.vue') },
{ name: '文案创作', path: 'content-style/copywriting', icon: 'text', component: () => import('../views/content-style/Copywriting.vue') },
// { name: '文案创作', path: 'content-style/copywriting', icon: 'text', component: () => import('../views/content-style/Copywriting.vue') },
{ name: '热点趋势', path: 'trends/forecast', icon: 'text', component: () => import('../views/trends/Forecast.vue') },
{ name: '智能体', path: 'agents', icon: 'robot', component: () => import('../views/agents/Agents.vue') },
]
@@ -32,14 +32,14 @@ const navConfig = [
{ name: '任务中心', path: 'system/task-management/:type', icon: 'video', component: () => import('../views/system/task-management/layout/TaskLayout.vue'), requiresAuth: true, params: { type: 'mix-task' } },
]
},
{
group: '系统',
order: 4,
requiresAuth: true,
items: [
{ name: '风格设置', path: 'system/style-settings', icon: 'text', component: () => import('../views/system/style-settings/index.vue') },
]
}
// {
// group: '系统',
// order: 4,
// requiresAuth: true,
// items: [
// { name: '风格设置', path: 'system/style-settings', icon: 'text', component: () => import('../views/system/style-settings/index.vue') },
// ]
// }
]
// 导航图标定义
@@ -144,23 +144,34 @@ const router = createRouter({
routes,
})
// 白名单路由(无需登录)
const WHITE_LIST = ['/login']
// 路由守卫
router.beforeEach(async (to, from, next) => {
const userStore = useUserStore()
const authenToken = tokenManager.getAccessToken()
const token = tokenManager.getAccessToken()
if (to.meta.requiresAuth && !authenToken) {
// 1. 白名单路由直接放行
if (WHITE_LIST.includes(to.path)) {
// 已登录访问登录页 → 跳转首页
if (token) {
next({ path: '/', replace: true })
return
}
next()
return
}
// 2. 非白名单路由,必须有 token
if (!token) {
next({ path: '/login', query: { redirect: to.fullPath } })
return
}
if (to.path === '/login' && authenToken) {
next({ path: '/content-style/benchmark', replace: true })
return
}
if (authenToken && !userStore.isLoggedIn) {
userStore.fetchUserInfo()
// 3. 有 token 但未加载用户信息 → 加载
if (!userStore.isLoggedIn) {
await userStore.fetchUserInfo()
}
next()