32 KiB
HXOPS 前端重构架构方案
更新时间:2026-06-11
适用范围:frontend/目录
文档定位:定义推荐的目标架构(Feature-Module + Composables + Pinia),作为后续分阶段重构的基准。
1. 架构选型
在现有技术栈(Vue 3 + TypeScript + Vite + Vue Router + Vue I18n + TailwindCSS)基础上,采用 Feature-Module 垂直切分 + Composables 逻辑封装 + Pinia 共享状态 的组合架构。
选型理由:
- 与 Vue 3 Composition API 天然契合,学习成本低
- 业务域清晰(聊天 / 管理后台 / 知识库 / 认证),适合按 feature 垂直拆分
- 相比 FSD(Feature-Sliced Design)目录层级更浅,迁移成本可控
- 相比引入 Element Plus 等 UI 库,可继续沿用现有 Tailwind 设计体系(
tokens.css、components-ds.css)
保持不变的技术栈:
| 层级 | 选型 |
|---|---|
| 框架 | Vue 3(Composition API + <script setup>)+ TypeScript |
| 构建 | Vite |
| 路由 | Vue Router 4(子路由 + 懒加载) |
| 样式 | TailwindCSS + 现有 Design Tokens |
| 国际化 | Vue I18n(messages 外置并按域拆分) |
| 网络 | fetch + requestJson(shared/api/client.ts)+ SSE(useChat) |
| 状态 | 新增 Pinia(替代 localStorage + CustomEvent 为主的跨页状态) |
2. 目标目录结构
frontend/src/
├── main.ts # Vite 入口(保留在 src 根,不迁入 app/)
├── App.vue # 根组件(保留在 src 根)
├── app/ # 应用基础设施(路由 / 插件)
│ ├── router/
│ │ ├── index.ts # 汇总各域路由
│ │ ├── guards.ts # 认证 / 权限守卫
│ │ └── routes/ # 按业务域拆分路由表
│ │ ├── auth.routes.ts
│ │ ├── chat.routes.ts
│ │ ├── admin.routes.ts
│ │ ├── workspace.routes.ts
│ │ └── kb.routes.ts
│ └── plugins/
│ └── pinia.ts
│
├── shared/ # 跨域共享(无业务语义)
│ ├── api/
│ │ ├── client.ts # requestJson、BusinessError(权威实现)
│ │ └── types.ts # 通用 API 类型(待补充)
│ ├── types/
│ │ └── schedule.types.ts # admin / workspace 共用排程类型
│ ├── composables/ # useTheme、useIsMobile、useMessage 等
│ ├── components/ # 通用 UI:Dialog、DataTable、EmptyState、Pagination
│ ├── layouts/ # AppShell、ChatShell、MinimalShell、MarketingShell
│ ├── utils/ # auth、clipboard、wecom 等纯工具
│ ├── styles/ # tokens.css、components-ds.css、utilities.css
│ └── constants/
│
├── features/ # 按业务域垂直切分(核心)
│ ├── auth/
│ │ ├── api/
│ │ │ └── user.api.ts
│ │ ├── stores/
│ │ │ └── auth.store.ts
│ │ ├── composables/
│ │ │ └── useAuth.ts
│ │ ├── views/
│ │ │ ├── LoginView.vue
│ │ │ └── ResetPasswordView.vue
│ │ └── components/
│ │
│ ├── workspace/ # AI 工作台(自 auth 拆出,2026-06)
│ │ ├── api/
│ │ │ └── schedule.api.ts # 工作台排程记录
│ │ ├── views/
│ │ │ └── WorkspaceLayout.vue
│ │ ├── pages/ # HomePage、ProfilePage、ScheduleRunsPage 等
│ │ ├── composables/
│ │ └── components/
│ │
│ ├── chat/
│ │ ├── api/
│ │ │ ├── chat.api.ts
│ │ │ └── shipping.api.ts # 货代发货(/api/workspace/shipping-tasks)
│ │ ├── types/
│ │ │ └── chat.types.ts
│ │ ├── stores/
│ │ │ └── chat.store.ts # 会话列表、当前 agent 等
│ │ ├── composables/
│ │ │ ├── useChat.ts # SSE 流式对话(保留并增强)
│ │ │ ├── useChatSessions.ts
│ │ │ └── useSourceFiles.ts # 源文件 / 检索来源逻辑
│ │ ├── views/
│ │ │ └── ChatView.vue # 页面编排,目标 < 300 行
│ │ └── components/
│ │ ├── ChatSidebar.vue
│ │ ├── ChatMessageList.vue
│ │ ├── ChatInputBar.vue
│ │ ├── MessageBubble.vue
│ │ ├── SourceFilePanel.vue
│ │ └── AgentSwitcher.vue
│ │
│ ├── admin/
│ │ ├── api/
│ │ │ ├── admin.api.ts
│ │ │ └── schedule.api.ts # 管理后台定时任务
│ │ ├── stores/
│ │ │ └── admin-nav.store.ts
│ │ ├── views/
│ │ │ └── AdminLayout.vue # 壳层 + 侧边栏,子路由出口
│ │ ├── modules/ # 原 AdminView activeModule 各拆独立模块
│ │ │ ├── dashboard/
│ │ │ ├── agents/
│ │ │ ├── users/
│ │ │ ├── departments/
│ │ │ ├── permissions/
│ │ │ ├── requests/
│ │ │ ├── reports/
│ │ │ ├── approvals/
│ │ │ ├── announcements/
│ │ │ ├── questions/
│ │ │ ├── wecom/
│ │ │ ├── schedules/
│ │ │ └── knowledge-base/
│ │ └── components/
│ │ └── AdminNav.vue
│ │
│ └── kb/
│ ├── api/
│ │ └── kb.api.ts
│ ├── views/
│ │ └── KbWorkspaceView.vue
│ └── components/ # 迁移现有 components/kb/*
│
├── locales/ # i18n 按语言 + 业务域拆分
│ ├── zh-CN/
│ │ ├── common.json
│ │ ├── auth.json
│ │ ├── chat.json
│ │ ├── admin.json
│ │ ├── kb.json
│ │ └── errors.json
│ ├── zh-TW/
│ ├── en/
│ ├── th/
│ └── index.ts # 按需加载、合并 messages
│
└── config.ts # 应用级开关(loginMode、admin.modules 等)
2.1 与现有目录的映射关系
| 现有路径 | 目标路径 | 说明 |
|---|---|---|
src/main.ts、src/App.vue |
保留 src/ 根目录 |
Vite 入口约定;不迁入 app/ |
src/router/index.ts |
app/router/ |
路由表与守卫拆分 |
src/api/client.ts |
shared/api/client.ts |
权威实现;src/api/client.ts deprecated 转发 |
src/api/*.ts |
features/*/api/ |
按业务域归属(KB 暂缓,见 §12) |
src/composables/(通用) |
shared/composables/ |
useTheme、useMessage 等 |
src/composables/useChat.ts |
features/chat/composables/ |
聊天域专属 |
src/components/(通用 Dialog 等) |
shared/components/ |
跨域复用 UI |
src/components/kb/ |
shared/components/kb/ |
暂留 shared,KB redesign 后迁 features/kb/ |
src/layouts/ |
shared/layouts/ |
页面壳层 |
src/utils/ |
shared/utils/ |
纯工具函数 |
src/styles/ |
shared/styles/ |
设计 token 与全局样式 |
src/views/AdminView.vue |
features/admin/modules/*/ |
拆为 12+ 子模块页面 |
src/views/ChatView.vue |
features/chat/ |
View + 多个子组件 |
src/views/WorkspaceView.vue |
features/workspace/ + features/auth/views/LoginView.vue |
登录与工作台分离 |
src/i18n.ts |
locales/ |
按语言、域拆分 JSON |
3. 分层职责
各层职责边界如下,上层可依赖下层,下层不得反向依赖上层。
flowchart TB
subgraph Views["Views(页面编排层)"]
V1["布局组合、路由参数解析、模块装配"]
end
subgraph Components["Components(展示层)"]
C1["纯 UI:props / emits,不直接调用 API"]
end
subgraph Composables["Composables(逻辑层)"]
CO1["SSE 流、表单、分页、副作用封装"]
end
subgraph Stores["Pinia Stores(共享状态层)"]
S1["跨组件 / 跨页面需共享的可变状态"]
end
subgraph API["API Layer(数据访问层)"]
A1["requestJson 封装 + 领域 API 函数"]
end
Views --> Components
Views --> Composables
Composables --> Stores
Composables --> API
Stores --> API
Components --> Composables
3.1 Views(页面编排层)
- 职责:路由入口、Layout 组合、将 composable / store 的数据传给子组件
- 约束:单个 View 文件目标 < 300 行;不写复杂业务算法、不直接写大段
fetch - 示例:
ChatView.vue只负责组装ChatSidebar+ChatMessageList+ChatInputBar
3.2 Components(展示层)
- 职责:可复用的 UI 单元,通过
props/emits与外部通信 - 约束:不直接 import 领域 API;需要数据时由父组件或 composable 注入
- 划分:
shared/components/:Dialog、DataTable、EmptyState 等无业务语义组件features/*/components/:MessageBubble、AdminNav 等领域组件
3.3 Composables(逻辑层)
- 职责:封装可复用的响应式逻辑、副作用(SSE、语音识别、会话管理)
- 约束:可调用 API 与 Store;返回 ref / computed / 方法供 View / Component 使用
- 示例:
useChat:SSE 流式对话(保留现有实现,增强类型)useChatSessions:会话 CRUDuseSourceFiles:从 ChatView 抽出的源文件 / 检索来源解析
3.4 Pinia Stores(共享状态层)
- 职责:跨页面、跨组件需共享且需响应式更新的状态
- 约束:Store 可调用 API;View 优先通过 composable 访问 Store,避免在模板中散落 store 调用
| Store | 文件 | 职责 |
|---|---|---|
useAuthStore |
features/auth/stores/auth.store.ts |
当前用户、token、login / logout、角色 |
useChatStore |
features/chat/stores/chat.store.ts |
当前 agent、会话列表、侧边栏折叠状态 |
useAppStore |
app/stores/app.store.ts(可选) |
全局 locale、theme 同步 |
useAdminNavStore |
features/admin/stores/admin-nav.store.ts |
当前 admin 模块、报表 tab |
3.5 API Layer(数据访问层)
- 职责:所有 HTTP 请求的统一出口;类型定义与后端契约对齐
- 约束:
- 仅
shared/api/client.ts处理 envelope 解析与BusinessError - 领域 API 文件只做 URL 组装与类型标注,不写 UI 逻辑
- 仅
- 示例:
features/chat/api/chat.api.ts迁移自现有src/api/chat.ts
4. 各 Feature 模块说明
4.1 auth(认证 / 工作台)
| 项 | 说明 |
|---|---|
| 路由 | /、/workspace、/casdoor-callback、/reset-password |
| 核心 Store | authStore:替代 utils/auth.ts 的直接读写 + hxops:logout 事件 |
| 页面 | WorkspaceView(登录、Agent 列表)、ResetPasswordView |
| 迁移来源 | views/WorkspaceView.vue、views/ResetPasswordView.vue、utils/auth.ts |
4.2 chat(对话)
| 项 | 说明 |
|---|---|
| 路由 | /chat/:agentId |
| 核心 Composable | useChat(SSE)、useChatSessions、useSourceFiles |
| 核心 Store | chatStore:当前 agent、会话列表缓存 |
| 组件拆分 | Sidebar / MessageList / InputBar / MessageBubble / SourceFilePanel / AgentSwitcher |
| 迁移来源 | views/ChatView.vue(~3400 行)、composables/useChat.ts |
4.3 admin(管理后台)
| 项 | 说明 |
|---|---|
| 路由 | /admin/* 子路由(替代 ?module=xxx query) |
| 布局 | AdminLayout.vue:左侧 AdminNav + <router-view> |
| 子模块 | 与 config.admin.modules 一一对应,每个 module 独立页面 |
| 懒加载 | 各 module 使用 () => import(...),减小首屏体积 |
| 迁移来源 | views/AdminView.vue(~6000 行)、api/admin.ts、api/schedule.ts |
Admin 子路由示例:
// app/router/routes/admin.routes.ts
{
path: '/admin',
component: () => import('@/features/admin/views/AdminLayout.vue'),
meta: { requiresAdmin: true },
children: [
{ path: '', redirect: '/admin/dashboard' },
{ path: 'dashboard', component: () => import('@/features/admin/modules/dashboard/DashboardPage.vue') },
{ path: 'agents', component: () => import('@/features/admin/modules/agents/AgentsPage.vue') },
{ path: 'users', component: () => import('@/features/admin/modules/users/UsersPage.vue') },
{ path: 'reports/:table?', component: () => import('@/features/admin/modules/reports/ReportsPage.vue') },
{ path: 'knowledge-base', component: () => import('@/features/admin/modules/knowledge-base/KbAdminPage.vue') },
// ... 其余 module
],
}
兼容旧 URL: /admin?module=users → redirect 至 /admin/users
4.4 kb(知识库)
| 项 | 说明 |
|---|---|
| 路由 | /kb/workspace;/kb/admin redirect 至 /admin/knowledge-base |
| 组件 | 迁移 components/kb/KbAdminPanel.vue、DifyHealthDialog.vue 等 |
| 迁移来源 | views/KbWorkspaceView.vue(~2400 行)、api/kb.ts |
5. 共享层(shared)沉淀清单
在重构过程中,以下组件建议优先沉淀到 shared/components/,供 admin、chat、kb 共用:
| 组件 | 用途 | 现状 |
|---|---|---|
ConfirmDialog |
删除 / 操作确认 | 现有 DeleteConfirmDialog.vue |
LevelMessageDialog |
全局消息弹窗 | 现有,经 useGlobalMessageDialog 调用 |
DataTable |
管理后台表格 + 分页 | AdminView 内大量重复表格结构 |
FormField |
统一表单字段样式 | 分散在各 View |
Pagination |
分页控件 | 分散在 AdminView |
EmptyState |
空数据占位 | 分散实现 |
LoadingOverlay |
加载遮罩 | 分散实现 |
样式继续沿用 shared/styles/tokens.css 与 components-ds.css,不引入 Element Plus / Naive UI 等重型 UI 库。
6. 路径别名与 import 规范
建议在 vite.config.ts / tsconfig.json 中配置:
// vite.config.ts
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
import 规则:
features/chat/views/ChatView.vue
✅ import { useChat } from '../composables/useChat'
✅ import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue'
✅ import { listChatSessions } from '../api/chat.api'
❌ import { listAdminUsers } from '@/features/admin/api/admin.api' // 跨 feature 禁止
跨 feature 通信通过:路由跳转、shared 层工具、或 Pinia store(仅全局态如 auth),避免 feature 之间直接 import 页面或 API。
7. Phase 0 落地说明(已实现)
Phase 0 目标:搭好基础设施,不迁移现有 views,旧代码可继续运行。
7.1 已完成项
| 项 | 路径 / 说明 |
|---|---|
| Pinia | pinia@^3,app/plugins/pinia.ts |
@/ 别名 |
vite.config.ts、tsconfig.app.json |
| 路由拆分 | app/router/routes/{auth,chat,admin,kb}.routes.ts |
| 路由守卫 | app/router/guards.ts(setupRouterGuards) |
| Auth Store | features/auth/stores/auth.store.ts |
| Auth Composable | features/auth/composables/useAuth.ts |
| Chat Store 骨架 | features/chat/stores/chat.store.ts |
| API 转发层 | shared/api/client.ts 为权威实现;src/api/client.ts deprecated 转发 |
| 路由常量 | shared/constants/routes.ts |
| 兼容入口 | router/index.ts re-export app/router |
7.2 启动顺序(src/main.ts)
约定:
main.ts/App.vue留在src/根目录,与 Viteindex.html入口一致;app/仅放 router、plugins 等可拆分的基础设施。
app.use(pinia);
bindAuthStoreSync(); // Store 与 utils/auth 跨标签同步
app.use(router);
app.use(i18n);
7.3 新代码用法
// 认证(新代码优先)
import { useAuth } from '@/features/auth';
const { user, isLoggedIn, login, logout } = useAuth();
// 或直接使用 Store
import { useAuthStore } from '@/features/auth/stores/auth.store';
7.4 兼容策略
- 旧代码仍可使用
utils/auth的getStoredAuthUser/saveAuthUser - 路由守卫在每次导航前调用
auth.syncFromStorage(),保证 Store 与 storage 一致 utils/auth的logoutAuth触发hxops:logout后,Store 自动清空user
7.5 下一步
Phase 1 已完成,见 §8。
8. Phase 1 落地说明(已实现,后续全量拆分见 §9)
Phase 1 目标:管理后台嵌套子路由 + 首个独立模块 agents。
8.1 路由结构(初版)
| URL | 组件 | 说明 |
|---|---|---|
/admin |
redirect → /admin/dashboard |
|
/admin/agents |
AgentsPage.vue |
首个独立拆分 |
/admin/dashboard 等 |
AdminLegacyPage.vue |
内嵌 AdminView(content-only,已移除) |
/admin?module=xxx |
redirect | 兼容旧链接,跳转至 /admin/xxx |
2026-06 更新:全部 admin 子模块已独立,见 §9。
8.2 初版新增文件
features/admin/
├── views/AdminLayout.vue
├── modules/agents/ ...
├── stores/admin-nav.store.ts
└── ...
8.3 构建验证
npm run build 通过。
8.4 下一步
Admin 全量拆分 → §9;Chat 拆分 → §10。
9. Phase 1.5 Admin 全量拆分(已实现)
Phase 1.5 目标:移除 AdminView.vue / AdminLegacyPage.vue,全部 config.admin.modules 对应独立页面。
9.1 路由结构
| URL | 组件 |
|---|---|
/admin/dashboard |
DashboardPage.vue |
/admin/agents |
AgentsPage.vue |
/admin/users |
UsersPage.vue |
/admin/departments |
DepartmentsPage.vue |
/admin/permissions |
PermissionsPage.vue |
/admin/requests |
RequestsPage.vue |
/admin/approvals |
ApprovalsPage.vue |
/admin/announcements |
AnnouncementsPage.vue |
/admin/questions |
QuestionsPage.vue |
/admin/wecom |
WecomPage.vue |
/admin/schedules |
SchedulesPage.vue |
/admin/knowledge-base |
KnowledgeBasePage.vue |
/admin/platform-apps |
PlatformAppsPage.vue |
/admin/reports/:table? |
ReportsPage.vue |
9.2 模块目录
features/admin/modules/
├── dashboard/ ├── agents/ ├── users/
├── departments/ ├── permissions/ ├── requests/
├── approvals/ ├── announcements/├── questions/
├── wecom/ ├── schedules/ ├── knowledge-base/
├── platform-apps/ └── reports/
└── composables/use*Admin.ts + components/
9.3 构建验证
npm run build 通过;AdminView.vue 已删除。
10. Phase 2 Chat 域落地说明(已实现)
Phase 2 Chat 目标:将原 views/ChatView.vue(~5500 行)拆为 feature 模块,页面壳层 < 50 行。
10.1 已完成项
| 项 | 路径 / 说明 |
|---|---|
| 页面壳层 | features/chat/views/ChatView.vue(~19 行:useChatPage() + provide + ChatViewContent / ChatViewOverlays) |
| 主编排 | composables/useChatPage.ts(~400 行,组合 page/* 子模块与各域 composable) |
| 页面子模块 | features/chat/page/*:用户、本地消息、弹窗、语音、Markdown、会话、发送、handlers 打包 |
| 出货子模块 | features/chat/shipping/*:纯函数 + useChatShippingRefresh / Menu / Upload / Send handler 工厂;useChatShipping.ts ~360 行 |
| 请假子模块 | features/chat/leave/*:意图解析、OA 登录、代理人选择、表单提交、流程拦截;useChatLeave.ts ~130 行 |
| 子 composable | useChatAgent、useChatAttachments、useChatRouteSync、useChatBrowserPanel、useChatQueryPreview、useChatGuides、useChatScroll 等 |
| 子组件 | ChatSidebar、ChatMessageList、ChatInputBar、ChatMessageBubble、ChatViewContent、ChatViewOverlays、弹窗等 |
| 路由 lazy | app/router/routes/chat.routes.ts → features/chat/views/ChatView.vue |
| API | features/chat/api/chat.api.ts(src/api/chat.ts deprecated 转发) |
| 货代 API | features/chat/api/shipping.api.ts(src/api/shippingNotice.ts deprecated 转发) |
| 跨 Agent 历史 | features/chat/pages/HistoryPage.vue + useChatHistory |
| Pinia 接入 | chat.store:currentAgentId(路由同步)、sidebarCollapsed、sessionHistoryByAgent 缓存 |
| 内置浏览器 | 输入栏「打开/收起浏览器」按钮已恢复,逻辑在 useChatBrowserPanel |
| provide/inject | chat.context.ts:CHAT_PAGE_KEY + useChatPageContext();reactive(useChatPage()) 解包嵌套 Ref;markRaw 保留 template ref holder |
10.2 构建验证
历次拆分后 npm run build 通过。
10.3 待办(Chat 域内)
| 优先级 | 项 | 状态 |
|---|---|---|
| 中 | chat.context + provide/inject(ChatViewContent / ChatViewOverlays inject) |
✅ |
| 中 | ChatViewOverlays.vue 抽出全部弹窗 |
✅ |
| 中 | chat.store 按 Agent 缓存侧栏会话列表 |
✅ |
| 中 | 瘦身 useChatPage → page/* 子模块 |
✅ |
| 中 | 瘦身 useChatShipping → shipping/* 子模块 |
✅ |
| 中 | 瘦身 useChatLeave → leave/* 子模块 |
✅ |
| 低 | LeaveAgentOption 等类型已统一至 leave.types.ts 并 re-export |
✅ |
| 低 | chat.context 完善类型(ChatPageContextProvided + useChatPageContext()) |
✅ |
| 低 | shipping/*、leave/* 纯函数单元测试 |
待做 |
10.4 下一步
Admin 模块独立→ 见 §9- Workspace 壳层 → 见 §11
API 按 feature 归属→ 见 §12→ 见 §14shared/composables/components/layouts/utils/styles 迁移- KB 域重新设计(暂缓)
locales/按域拆分
11. Phase 3 Workspace 模块(部分实现)
Phase 3 目标:将原 WorkspaceView.vue 拆为独立 feature,路由 /workspace/*。
11.1 已完成项
| 项 | 路径 / 说明 |
|---|---|
| 布局壳 | features/workspace/views/WorkspaceLayout.vue + provide/inject |
| 子页面 | HomePage(应用管理)、ProfilePage、ScheduleRunsPage、FeedbackPage |
| 路由 | app/router/routes/workspace.routes.ts |
| Composable | useWorkspace、useWorkspaceHome、useWorkspaceNavigation 等 |
| 排程 API | features/workspace/api/schedule.api.ts |
| 历史页 | 复用 features/chat/pages/HistoryPage.vue |
11.2 薄包装页(待真正迁入 feature)
| 页面 | 现状 |
|---|---|
KnowledgeBasePage.vue |
嵌入 src/views/KbWorkspaceView.vue(KB 域暂缓 redesign) |
ShippingNoticePage.vue |
嵌入 src/views/ShippingNoticeView.vue |
11.3 路由
/workspace/applications → HomePage
/workspace/profile → ProfilePage
/workspace/schedule-runs → ScheduleRunsPage
/workspace/shipping-notice → ShippingNoticePage(legacy 嵌入)
/workspace/knowledge-base → KnowledgeBasePage(legacy 嵌入)
/workspace/history → chat/pages/HistoryPage
12. Phase 4 API 按 Feature 归属(已实现,KB 除外)
Phase 4 目标:领域 HTTP 请求迁入对应 features/*/api/,shared/api/client.ts 作为唯一 JSON 客户端。
12.1 迁移对照
| 原路径 | 新路径 | 状态 |
|---|---|---|
src/api/client.ts |
shared/api/client.ts |
✅ 权威实现;旧路径 deprecated 转发 |
src/api/user.ts |
features/auth/api/user.api.ts |
✅(Phase 0 已完成) |
src/api/chat.ts |
features/chat/api/chat.api.ts |
✅(Phase 2 已完成) |
src/api/admin.ts |
features/admin/api/admin.api.ts |
✅ |
src/api/schedule.ts(admin 部分) |
features/admin/api/schedule.api.ts |
✅ |
src/api/schedule.ts(workspace 部分) |
features/workspace/api/schedule.api.ts |
✅ |
| 排程共用类型 | shared/types/schedule.types.ts |
✅ |
src/api/shippingNotice.ts |
features/chat/api/shipping.api.ts |
✅ |
| 货代类型 | features/chat/types/shipping.api.types.ts |
✅ |
src/api/kb.ts |
— | ⏸ 暂缓(KB 域 redesign 后迁移) |
12.2 新代码 import 规范
// 共享 HTTP 客户端
import { requestJson, BusinessError } from '@/shared/api/client';
// 各域 API
import { listAdminUsers } from '@/features/admin/api/admin.api';
import { listAdminSchedules } from '@/features/admin/api/schedule.api';
import { listWorkspaceScheduleRuns } from '@/features/workspace/api/schedule.api';
import { listChatSessions } from '@/features/chat/api/chat.api';
import { getWorkspaceShippingTask } from '@/features/chat/api/shipping.api';
import { getUserProfile } from '@/features/auth/api/user.api';
或通过 feature 入口 re-export:
import { listAdminUsers } from '@/features/admin';
import { listWorkspaceScheduleRuns } from '@/features/workspace';
import { getWorkspaceShippingTask } from '@/features/chat';
12.3 兼容策略
→ 已删除(2026-06-11)src/api/{client,admin,schedule,shippingNotice,chat,user}.tsdeprecated 转发- 新代码必须使用 feature / shared 路径
src/api/kb.ts暂保留原位(KB redesign 后迁入features/kb/api/)
12.4 构建验证
迁移后 npm run build 须通过。
12.5 下一步
- KB API 待 redesign 后迁入
features/kb/api/kb.api.ts 清理 deprecated→ 已完成(仅保留src/api/*转发kb.ts)locales/按域拆分 → 见 §15
14. Phase 5 Shared 共享层迁移(已实现)
Phase 5 目标:将原 src/ 根目录下的跨域代码迁入 src/shared/,与 features/ 划清边界。
14.1 迁移对照
| 原路径 | 新路径 | 状态 |
|---|---|---|
src/composables/* |
shared/composables/* |
✅ |
src/components/* |
shared/components/* |
✅(含 kb/ 子目录,待 KB redesign) |
src/layouts/* |
shared/layouts/* |
✅ |
src/utils/* |
shared/utils/* |
✅ |
src/styles/* |
shared/styles/* |
✅ |
style.css 引用 |
@import './shared/styles/...' |
✅ |
14.2 目录结构
shared/
├── index.ts # 统一导出入口
├── api/client.ts
├── composables/ # useTheme、useMessage、useIsMobile 等
├── components/ # Dialog、LocaleToggle、kb/* 等
├── layouts/ # AppShell、ChatShell、MarketingShell 等
├── utils/ # auth、clipboard、wecom 等
├── styles/ # tokens.css、components-ds.css、utilities.css
├── constants/routes.ts
└── types/ # auth.types、schedule.types
14.3 新代码 import 规范
import { useTheme, useMessage } from '@/shared/composables/useTheme';
import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue';
import ChatShell from '@/shared/layouts/ChatShell.vue';
import { getAuthHeaders } from '@/shared/utils/auth';
// 或按需从入口导入
import { useTheme, requestJson } from '@/shared';
14.4 兼容策略
→ 已删除(2026-06-11)src/composables/、src/utils/、src/styles/deprecated 转发src/components/、src/layouts/已删除(全仓 import 已切换)- 新代码必须使用
@/shared/*路径 shared/components/kb/*仍依赖@/api/kb(KB redesign 后整体迁出)
14.5 构建验证
迁移后 npm run build 须通过。
14.6 下一步
- KB 组件/API 待 redesign 后迁入
features/kb/ 清理 deprecated 转发→ 已完成locales/按域拆分 → 见 §15
15. 架构对齐清理清单
目标:与 Vite/Vue 默认约定及本文档目标结构对齐。
状态更新时间:2026-06-11
15.1 已完成 ✅
| 项 | 说明 |
|---|---|
删除 src/composables/ |
7 个 deprecated 转发已移除 |
删除 src/utils/ |
6 个 deprecated 转发已移除 |
删除 src/styles/ |
3 个 CSS 转发已移除 |
删除 src/api/*(除 kb) |
client/admin/chat/user/schedule/shippingNotice 转发已移除 |
删除 src/router/index.ts |
全仓已改用 @/app/router |
修复 api/kb.ts |
改为引用 @/shared/api/client |
移除 axios 依赖 |
代码未使用,已从 package.json 删除 |
main.ts / App.vue |
保留在 src/ 根(见 §7.2 约定) |
15.2 i18n 按域拆分(进行中)
现状:src/i18n.ts 仍承载剩余内联 messages;errors、auth、workspace、chat、admin 域已外置。
已完成 ✅
| 域 | 路径 |
|---|---|
errors |
locales/{en,zh-CN,zh-TW,th}/errors.json |
auth |
locales/{en,zh-CN,zh-TW,th}/auth.json |
workspace |
locales/{en,zh-CN,zh-TW,th}/workspace.json |
chat |
locales/{en,zh-CN,zh-TW,th}/chat.json |
admin |
locales/{en,zh-CN,zh-TW,th}/admin.json |
| 合并入口 | locales/index.ts → mergeExternalLocales() |
i18n.ts 在 createI18n 前调用 mergeExternalLocales(messages),四语言外置域与拆分前行为一致。
目标结构(剩余域):
src/locales/
├── index.ts # createI18n + 合并 messages
├── zh-CN/
│ ├── common.json
│ ├── auth.json
│ ├── chat.json
│ ├── admin.json
│ ├── workspace.json
│ ├── kb.json
│ └── errors.json
├── zh-TW/ en/ th/ # 同上
建议步骤(可分 PR 执行):
拆✅errors.*→errors.json拆✅auth.*→auth.json拆✅workspace.*→workspace.json拆✅chat.*→chat.json拆✅admin.*→admin.json- 拆
kb(每域四语言 JSON;KB redesign 后可一并收口) - 每步
npm run build+ 四语言 spot check - 全部外置后,
i18n.ts仅保留createI18n注册与 locale 默认值
注意:AGENTS.md 要求四语言同步;拆分时用脚本或 CI 校验 key 对齐。
15.3 待办:清理 src/views/(优先级:低,依赖 KB redesign)
| 文件 | 引用方 | 处理方式 |
|---|---|---|
KbWorkspaceView.vue (~3000 行) |
/kb/workspace、workspace/knowledge-base |
KB redesign 后迁入 features/kb/ |
ShippingNoticeView.vue (~250 行) |
workspace/shipping-notice |
迁入 features/workspace/pages/ 或独立 feature |
当前可做:统一 import 为 @/api/kb、@/shared/*(已部分完成)。
15.4 待办:KB 域一次性收口(优先级:低,blocked on redesign)
src/api/kb.ts→features/kb/api/kb.api.tsshared/components/kb/*→features/kb/components/*- 路由
/kb/workspace与/workspace/knowledge-base合并
15.5 可选优化(非必须)
| 项 | 说明 |
|---|---|
index.html lang="zh-CN" |
主语言为中文,利于 SEO/无障碍 |
App.vue 文件头注释 |
与项目注释规范一致 |
frontend/.env.development |
若需纯前端多环境 API 地址,再用 VITE_* |
| Vite 8 beta → stable | 关注正式版发布后升级 |
15.6 推荐执行顺序
✅ Phase A:删 deprecated 转发 + 去 axios
→ Phase B:i18n 拆 locales/(errors ✅ → auth ✅ → workspace ✅ → chat ✅ → admin ✅ → kb)
→ Phase C:ShippingNoticeView 迁入 workspace
→ Phase D:KB redesign + views/api/components 收口