mock数据,AI对话,全部应用

This commit is contained in:
2025-12-12 18:17:38 +08:00
parent 8b211fbad6
commit 0a72416365
41 changed files with 5667 additions and 205 deletions

View File

@@ -1,29 +1,23 @@
import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'
import { SidebarLayout } from '../layouts'
import { TokenManager } from 'shared/api'
import { loadRoutesFromStorage } from './dynamicRoute'
const routes: RouteRecordRaw[] = [
{
path: '/',
redirect: '/home'
name: 'Root',
component: SidebarLayout,
children: []
},
{
path: '/login',
name: 'Login',
component: () => import('../views/public/Login.vue'),
component: () => import('@/views/public/Login/Login.vue'),
meta: {
title: '登录',
requiresAuth: false // 不需要登录
}
},
{
path: '/home',
name: 'Home',
component: SidebarLayout,
meta: {
title: '首页',
requiresAuth: true // 需要登录
}
}
]
@@ -32,6 +26,9 @@ const router = createRouter({
routes
})
// 标记动态路由是否已加载
let dynamicRoutesLoaded = false
// 路由守卫
router.beforeEach((to, from, next) => {
// 设置页面标题
@@ -49,12 +46,37 @@ router.beforeEach((to, from, next) => {
path: '/login',
query: { redirect: to.fullPath } // 保存原始路径
})
} else if (to.path === '/login' && hasToken) {
// 已登录但访问登录页,跳转到首页
next('/home')
} else {
next()
return
}
if (to.path === '/login' && hasToken) {
// 已登录但访问登录页,跳转到首页
next('/')
return
}
// 如果已登录且动态路由未加载,先加载动态路由
if (hasToken && !dynamicRoutesLoaded) {
dynamicRoutesLoaded = true
const loaded = loadRoutesFromStorage()
if (loaded && to.path !== '/') {
// 动态路由已加载,重新导航到目标路由
next({ ...to, replace: true })
return
}
}
next()
})
// 导出动态路由生成函数
export { addDynamicRoutes, loadRoutesFromStorage } from './dynamicRoute'
// 重置动态路由加载状态(用于登录后重新加载)
export function resetDynamicRoutes() {
dynamicRoutesLoaded = false
}
// 导出路由和辅助函数
export default router