refactor: 重构前端骨架,及admin模块子路由和懒加载
refactor: 优化多次请求,并使用pinia状态管理
This commit is contained in:
1 parent
f877f61efd
commit
61693d014d
74 files changed
+9493
-6418
No files matched your search
@@ -0,0 +1,49 @@
|
||||
/**
|
||||
* app/router/guards.ts
|
||||
* 全局路由守卫:认证、权限、旧 URL 兼容、document.title。
|
||||
*/
|
||||
import type { Router } from 'vue-router';
|
||||
import { config } from '@/config';
|
||||
import { adminModulePath } from '@/features/admin/constants/modules';
|
||||
import { useAuthStore } from '@/features/auth/stores/auth.store';
|
||||
import { DEFAULT_CHAT_AGENT_ID, isPublicPath } from '@/shared/constants/routes';
|
||||
|
||||
export function setupRouterGuards(router: Router): void {
|
||||
router.beforeEach((to, _from, next) => {
|
||||
const auth = useAuthStore();
|
||||
auth.syncFromStorage();
|
||||
|
||||
if (to.path === '/admin' && typeof to.query.module === 'string' && to.query.module) {
|
||||
next(adminModulePath(to.query.module));
|
||||
return;
|
||||
}
|
||||
|
||||
if (to.matched.some((r) => r.meta.requiresAdmin)) {
|
||||
if (!auth.isAdmin) {
|
||||
next('/workspace');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (to.path === '/') {
|
||||
if (auth.isLoggedIn) {
|
||||
next(`/chat/${DEFAULT_CHAT_AGENT_ID}`);
|
||||
return;
|
||||
}
|
||||
next('/workspace');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!auth.isLoggedIn && !isPublicPath(to.path)) {
|
||||
next('/workspace');
|
||||
return;
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
router.afterEach((to) => {
|
||||
const baseTitle = config.appTitle || 'AI工作台';
|
||||
document.title = to.meta.title ? `${String(to.meta.title)} - ${baseTitle}` : baseTitle;
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user