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,7 @@
|
||||
/**
|
||||
* app/plugins/pinia.ts
|
||||
* 创建并导出 Pinia 实例,在 main.ts 中注册。
|
||||
*/
|
||||
import { createPinia } from 'pinia';
|
||||
|
||||
export const pinia = createPinia();
|
||||
@@ -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;
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* app/router/index.ts
|
||||
* 创建 Vue Router 实例并注册守卫。
|
||||
*/
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import { appRoutes } from './routes';
|
||||
import { setupRouterGuards } from './guards';
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(),
|
||||
routes: appRoutes,
|
||||
});
|
||||
|
||||
setupRouterGuards(router);
|
||||
|
||||
export default router;
|
||||
@@ -0,0 +1,110 @@
|
||||
/**␍
|
||||
* app/router/routes/admin.routes.ts␍
|
||||
* 管理后台嵌套路由;全部 admin 模块已独立拆分。␍
|
||||
*/␍
|
||||
import type { RouteRecordRaw } from 'vue-router';␍
|
||||
␍
|
||||
const AdminLayout = () => import('@/features/admin/views/AdminLayout.vue');␍
|
||||
const AgentsPage = () => import('@/features/admin/modules/agents/AgentsPage.vue');␍
|
||||
const UsersPage = () => import('@/features/admin/modules/users/UsersPage.vue');␍
|
||||
const DepartmentsPage = () => import('@/features/admin/modules/departments/DepartmentsPage.vue');␍
|
||||
const ApprovalsPage = () => import('@/features/admin/modules/approvals/ApprovalsPage.vue');␍
|
||||
const AnnouncementsPage = () => import('@/features/admin/modules/announcements/AnnouncementsPage.vue');␍
|
||||
const QuestionsPage = () => import('@/features/admin/modules/questions/QuestionsPage.vue');␍
|
||||
const RequestsPage = () => import('@/features/admin/modules/requests/RequestsPage.vue');␍
|
||||
const PermissionsPage = () => import('@/features/admin/modules/permissions/PermissionsPage.vue');␍
|
||||
const DashboardPage = () => import('@/features/admin/modules/dashboard/DashboardPage.vue');␍
|
||||
const SchedulesPage = () => import('@/features/admin/modules/schedules/SchedulesPage.vue');␍
|
||||
const KnowledgeBasePage = () => import('@/features/admin/modules/knowledge-base/KnowledgeBasePage.vue');␍
|
||||
const WecomPage = () => import('@/features/admin/modules/wecom/WecomPage.vue');␍
|
||||
const ReportsPage = () => import('@/features/admin/modules/reports/ReportsPage.vue');␍
|
||||
␍
|
||||
export const adminRoutes: RouteRecordRaw[] = [␍
|
||||
{␍
|
||||
path: '/admin',␍
|
||||
component: AdminLayout,␍
|
||||
meta: { requiresAdmin: true },␍
|
||||
children: [␍
|
||||
{ path: '', redirect: '/admin/dashboard' },␍
|
||||
{␍
|
||||
path: 'dashboard',␍
|
||||
name: 'AdminDashboard',␍
|
||||
component: DashboardPage,␍
|
||||
meta: { requiresAdmin: true, adminModule: 'dashboard', title: '概览' },␍
|
||||
},␍
|
||||
{␍
|
||||
path: 'schedules',␍
|
||||
name: 'AdminSchedules',␍
|
||||
component: SchedulesPage,␍
|
||||
meta: { requiresAdmin: true, adminModule: 'schedules', title: '定时任务' },␍
|
||||
},␍
|
||||
{␍
|
||||
path: 'knowledge-base',␍
|
||||
name: 'AdminKnowledgeBase',␍
|
||||
component: KnowledgeBasePage,␍
|
||||
meta: { requiresAdmin: true, adminModule: 'knowledge_base', title: '知识库' },␍
|
||||
},␍
|
||||
{␍
|
||||
path: 'wecom',␍
|
||||
name: 'AdminWecom',␍
|
||||
component: WecomPage,␍
|
||||
meta: { requiresAdmin: true, adminModule: 'wecom', title: '企业微信' },␍
|
||||
},␍
|
||||
{␍
|
||||
path: 'approvals',␍
|
||||
name: 'AdminApprovals',␍
|
||||
component: ApprovalsPage,␍
|
||||
meta: { requiresAdmin: true, adminModule: 'approvals', title: '用户审批' },␍
|
||||
},␍
|
||||
{␍
|
||||
path: 'agents',␍
|
||||
name: 'AdminAgents',␍
|
||||
component: AgentsPage,␍
|
||||
meta: { requiresAdmin: true, adminModule: 'agents', title: '应用管理' },␍
|
||||
},␍
|
||||
{␍
|
||||
path: 'users',␍
|
||||
name: 'AdminUsers',␍
|
||||
component: UsersPage,␍
|
||||
meta: { requiresAdmin: true, adminModule: 'users', title: '用户管理' },␍
|
||||
},␍
|
||||
{␍
|
||||
path: 'departments',␍
|
||||
name: 'AdminDepartments',␍
|
||||
component: DepartmentsPage,␍
|
||||
meta: { requiresAdmin: true, adminModule: 'departments', title: '部门管理' },␍
|
||||
},␍
|
||||
{␍
|
||||
path: 'announcements',␍
|
||||
name: 'AdminAnnouncements',␍
|
||||
component: AnnouncementsPage,␍
|
||||
meta: { requiresAdmin: true, adminModule: 'announcements', title: '公告管理' },␍
|
||||
},␍
|
||||
{␍
|
||||
path: 'questions',␍
|
||||
name: 'AdminQuestions',␍
|
||||
component: QuestionsPage,␍
|
||||
meta: { requiresAdmin: true, adminModule: 'questions', title: '常用问题' },␍
|
||||
},␍
|
||||
{␍
|
||||
path: 'requests',␍
|
||||
name: 'AdminRequests',␍
|
||||
component: RequestsPage,␍
|
||||
meta: { requiresAdmin: true, adminModule: 'requests', title: '权限申请' },␍
|
||||
},␍
|
||||
{␍
|
||||
path: 'permissions',␍
|
||||
name: 'AdminPermissions',␍
|
||||
component: PermissionsPage,␍
|
||||
meta: { requiresAdmin: true, adminModule: 'permissions', title: '权限管理' },␍
|
||||
},␍
|
||||
{␍
|
||||
path: 'reports/:table?',␍
|
||||
name: 'AdminReports',␍
|
||||
component: ReportsPage,␍
|
||||
meta: { requiresAdmin: true, adminModule: 'reports', title: '报表' },␍
|
||||
},␍
|
||||
],␍
|
||||
},␍
|
||||
];␍
|
||||
␍
|
||||
@@ -0,0 +1,14 @@
|
||||
/**
|
||||
* app/router/routes/auth.routes.ts
|
||||
* 认证 / 工作台相关路由。
|
||||
*/
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
import WorkspaceView from '@/views/WorkspaceView.vue';
|
||||
import ResetPasswordView from '@/views/ResetPasswordView.vue';
|
||||
|
||||
export const authRoutes: RouteRecordRaw[] = [
|
||||
{ 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 },
|
||||
];
|
||||
@@ -0,0 +1,10 @@
|
||||
/**
|
||||
* app/router/routes/chat.routes.ts
|
||||
* 对话相关路由。
|
||||
*/
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
import ChatView from '@/views/ChatView.vue';
|
||||
|
||||
export const chatRoutes: RouteRecordRaw[] = [
|
||||
{ path: '/chat/:agentId', name: 'Chat', component: ChatView, props: true },
|
||||
];
|
||||
@@ -0,0 +1,16 @@
|
||||
/**
|
||||
* app/router/routes/index.ts
|
||||
* 汇总各业务域路由表。
|
||||
*/
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
import { adminRoutes } from './admin.routes';
|
||||
import { authRoutes } from './auth.routes';
|
||||
import { chatRoutes } from './chat.routes';
|
||||
import { kbRoutes } from './kb.routes';
|
||||
|
||||
export const appRoutes: RouteRecordRaw[] = [
|
||||
...authRoutes,
|
||||
...chatRoutes,
|
||||
...adminRoutes,
|
||||
...kbRoutes,
|
||||
];
|
||||
@@ -0,0 +1,11 @@
|
||||
/**
|
||||
* app/router/routes/kb.routes.ts
|
||||
* 知识库相关路由。
|
||||
*/
|
||||
import type { RouteRecordRaw } from 'vue-router';
|
||||
import KbWorkspaceView from '@/views/KbWorkspaceView.vue';
|
||||
|
||||
export const kbRoutes: RouteRecordRaw[] = [
|
||||
{ path: '/kb/workspace', name: 'KbWorkspace', component: KbWorkspaceView, meta: { title: '知识库工作台' } },
|
||||
{ path: '/kb/admin', redirect: { path: '/admin/knowledge-base' } },
|
||||
];
|
||||
Reference in new issue
Block a user