refactor: 重构前端骨架,及admin模块子路由和懒加载
refactor: 优化多次请求,并使用pinia状态管理
This commit is contained in:
1 parent
f877f61efd
commit
61693d014d
74 files changed
+9493
-6418
No files matched your search
@@ -1,103 +1,2 @@
|
||||
|
||||
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import WorkspaceView from '../views/WorkspaceView.vue';
|
||||
import ChatView from '../views/ChatView.vue';
|
||||
import AdminView from '../views/AdminView.vue';
|
||||
import ResetPasswordView from '../views/ResetPasswordView.vue';
|
||||
import KbWorkspaceView from '../views/KbWorkspaceView.vue';
|
||||
import { config } from '../config';
|
||||
import { getStoredAuthUser } from '../utils/auth';
|
||||
|
||||
const routes = [
|
||||
{
|
||||
path: '/',
|
||||
name: 'Home',
|
||||
component: WorkspaceView
|
||||
},
|
||||
{
|
||||
path: '/workspace',
|
||||
name: 'Workspace',
|
||||
component: WorkspaceView
|
||||
},
|
||||
{
|
||||
path: '/casdoor-callback',
|
||||
name: 'CasdoorCallback',
|
||||
component: WorkspaceView
|
||||
},
|
||||
{
|
||||
path: '/reset-password',
|
||||
name: 'ResetPassword',
|
||||
component: ResetPasswordView
|
||||
},
|
||||
{
|
||||
path: '/chat/:agentId',
|
||||
name: 'Chat',
|
||||
component: ChatView,
|
||||
props: true
|
||||
},
|
||||
{
|
||||
path: '/admin',
|
||||
name: 'Admin',
|
||||
component: AdminView
|
||||
},
|
||||
{
|
||||
path: '/kb/workspace',
|
||||
name: 'KbWorkspace',
|
||||
component: KbWorkspaceView,
|
||||
meta: { title: '知识库工作台' }
|
||||
},
|
||||
{
|
||||
path: '/kb/admin',
|
||||
redirect: { path: '/admin', query: { module: 'knowledge_base' } }
|
||||
},
|
||||
|
||||
];
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes
|
||||
});
|
||||
|
||||
const DEFAULT_CHAT_AGENT_ID = 16;
|
||||
|
||||
const publicPaths = ['/', '/workspace', '/casdoor-callback', '/reset-password'];
|
||||
|
||||
router.beforeEach((to, _from, next) => {
|
||||
const user = getStoredAuthUser();
|
||||
const isLoggedIn = !!user && user.role !== 'guest';
|
||||
|
||||
if (to.path === '/admin') {
|
||||
if (!user || user.role !== 'admin') {
|
||||
next('/workspace');
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (to.path === '/') {
|
||||
if (isLoggedIn) {
|
||||
next(`/chat/${DEFAULT_CHAT_AGENT_ID}`);
|
||||
return;
|
||||
}
|
||||
next('/workspace');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isLoggedIn && !publicPaths.includes(to.path)) {
|
||||
next('/workspace');
|
||||
return;
|
||||
}
|
||||
|
||||
next();
|
||||
});
|
||||
|
||||
router.afterEach((to) => {
|
||||
const baseTitle = config.appTitle || 'AI工作台';
|
||||
if (to.meta.title) {
|
||||
document.title = `${to.meta.title} - ${baseTitle}`;
|
||||
} else {
|
||||
document.title = baseTitle;
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
||||
/** @deprecated 请改用 `@/app/router`;保留此文件以兼容现有 import。 */
|
||||
export { default } from '@/app/router';
|
||||
Reference in new issue
Block a user