菜单布局等初步完成

This commit is contained in:
2025-10-08 14:11:54 +08:00
parent d9ea2e842b
commit 4bc587ecf5
29 changed files with 4472 additions and 11977 deletions

View File

@@ -15,6 +15,7 @@ const WHITE_LIST = [
'/login',
'/register',
'/forgot-password',
'/home',
'/404',
'/403',
'/500'
@@ -68,7 +69,7 @@ async function handleRouteGuard(
store: Store<any>
) {
const authState: AuthState = store.state.auth;
const { isAuthenticated } = store.getters['auth/isAuthenticated'];
const isAuthenticated = store.getters['auth/isAuthenticated'];
// 检查是否在白名单中
if (isInWhiteList(to.path)) {
@@ -87,15 +88,19 @@ async function handleRouteGuard(
}
// 用户已登录,检查是否需要生成动态路由
if (!authState.routesLoaded) {
// 注意:通常情况下路由应该在 main.ts 初始化时就已经生成
// 这里主要处理登录后首次生成路由的情况
if (!authState.routesLoaded && authState.menus && authState.menus.length > 0) {
try {
console.log('[路由守卫] 路由未加载,开始生成动态路由');
// 生成动态路由
await store.dispatch('auth/generateRoutes');
console.log('[路由守卫] 动态路由生成成功,重新导航');
// 重新导航到目标路由
return next({ ...to, replace: true });
} catch (error) {
console.error('生成动态路由失败:', error);
console.error('[路由守卫] 生成动态路由失败:', error);
// 清除认证信息并跳转到登录页
store.commit('auth/CLEAR_AUTH');
return next('/login');