diff --git a/docs/refactor/frontend_architecture_refactor.md b/docs/refactor/frontend_architecture_refactor.md index f31518f9..2441e9d0 100644 --- a/docs/refactor/frontend_architecture_refactor.md +++ b/docs/refactor/frontend_architecture_refactor.md @@ -1,6 +1,6 @@ # HXOPS 前端重构架构方案 -> 更新时间:2026-06-02 +> 更新时间:2026-06-11 > 适用范围:`frontend/` 目录 > 文档定位:定义推荐的目标架构(Feature-Module + Composables + Pinia),作为后续分阶段重构的基准。 @@ -35,25 +35,27 @@ ```text frontend/src/ -├── app/ # 应用启动层 -│ ├── main.ts -│ ├── App.vue +├── main.ts # Vite 入口(保留在 src 根,不迁入 app/) +├── App.vue # 根组件(保留在 src 根) +├── app/ # 应用基础设施(路由 / 插件) │ ├── router/ │ │ ├── index.ts # 汇总各域路由 -│ │ ├── guards.ts # 认证 / 权限守卫(从 router/index.ts 抽出) +│ │ ├── guards.ts # 认证 / 权限守卫 │ │ └── routes/ # 按业务域拆分路由表 │ │ ├── auth.routes.ts │ │ ├── chat.routes.ts │ │ ├── admin.routes.ts +│ │ ├── workspace.routes.ts │ │ └── kb.routes.ts │ └── plugins/ -│ ├── i18n.ts # 仅注册 i18n 实例,messages 外置 │ └── pinia.ts │ ├── shared/ # 跨域共享(无业务语义) │ ├── api/ -│ │ ├── client.ts # requestJson、BusinessError、响应 envelope 解析 -│ │ └── types.ts # 通用 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 @@ -70,13 +72,23 @@ frontend/src/ │ │ ├── composables/ │ │ │ └── useAuth.ts │ │ ├── views/ -│ │ │ ├── WorkspaceView.vue +│ │ │ ├── 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 +│ │ │ ├── chat.api.ts +│ │ │ └── shipping.api.ts # 货代发货(/api/workspace/shipping-tasks) │ │ ├── types/ │ │ │ └── chat.types.ts │ │ ├── stores/ @@ -98,7 +110,7 @@ frontend/src/ │ ├── admin/ │ │ ├── api/ │ │ │ ├── admin.api.ts -│ │ │ └── schedule.api.ts +│ │ │ └── schedule.api.ts # 管理后台定时任务 │ │ ├── stores/ │ │ │ └── admin-nav.store.ts │ │ ├── views/ @@ -147,20 +159,20 @@ frontend/src/ | 现有路径 | 目标路径 | 说明 | |----------|----------|------| -| `src/main.ts`、`src/App.vue` | `app/` | 启动与全局插件注册 | +| `src/main.ts`、`src/App.vue` | **保留 `src/` 根目录** | Vite 入口约定;不迁入 `app/` | | `src/router/index.ts` | `app/router/` | 路由表与守卫拆分 | -| `src/api/client.ts` | `shared/api/client.ts` | 保持不变,作为统一 HTTP 层 | -| `src/api/*.ts` | `features/*/api/` | 按业务域归属 | +| `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/` | `features/kb/components/` | 知识库域 | +| `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/auth/views/` | 登录 / 工作台 | +| `src/views/WorkspaceView.vue` | `features/workspace/` + `features/auth/views/LoginView.vue` | 登录与工作台分离 | | `src/i18n.ts` | `locales/` | 按语言、域拆分 JSON | --- @@ -343,7 +355,7 @@ resolve: { ```text features/chat/views/ChatView.vue ✅ import { useChat } from '../composables/useChat' - ✅ import { BaseDialog } from '@/shared/components/BaseDialog.vue' + ✅ import DeleteConfirmDialog from '@/shared/components/DeleteConfirmDialog.vue' ✅ import { listChatSessions } from '../api/chat.api' ❌ import { listAdminUsers } from '@/features/admin/api/admin.api' // 跨 feature 禁止 ``` @@ -367,11 +379,13 @@ Phase 0 目标:搭好基础设施,**不迁移现有 views**,旧代码可 | 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` → 现有 `api/client.ts` | +| API 转发层 | `shared/api/client.ts` 为权威实现;`src/api/client.ts` deprecated 转发 | | 路由常量 | `shared/constants/routes.ts` | | 兼容入口 | `router/index.ts` re-export `app/router` | -### 7.2 启动顺序(main.ts) +### 7.2 启动顺序(`src/main.ts`) + +> **约定**:`main.ts` / `App.vue` 留在 `src/` 根目录,与 Vite `index.html` 入口一致;`app/` 仅放 router、plugins 等可拆分的基础设施。 ```typescript app.use(pinia); @@ -404,49 +418,388 @@ Phase 1 已完成,见 §8。 --- -## 8. Phase 1 落地说明(已实现) +## 8. Phase 1 落地说明(已实现,后续全量拆分见 §9) Phase 1 目标:管理后台嵌套子路由 + 首个独立模块 `agents`。 -### 8.1 路由结构 +### 8.1 路由结构(初版) | URL | 组件 | 说明 | |-----|------|------| | `/admin` | redirect → `/admin/dashboard` | | -| `/admin/agents` | `AgentsPage.vue` | **已独立拆分** | -| `/admin/dashboard` 等 | `AdminLegacyPage.vue` | 内嵌 `AdminView`(content-only) | -| `/admin/reports/:table?` | `AdminLegacyPage.vue` | 报表模块 | +| `/admin/agents` | `AgentsPage.vue` | **首个独立拆分** | +| `/admin/dashboard` 等 | `AdminLegacyPage.vue` | 内嵌 `AdminView`(content-only,已移除) | | `/admin?module=xxx` | redirect | 兼容旧链接,跳转至 `/admin/xxx` | -### 8.2 新增文件(均含文件头注释) +> **2026-06 更新**:全部 admin 子模块已独立,见 §9。 + +### 8.2 初版新增文件 ```text features/admin/ -├── views/AdminLayout.vue # 壳层:顶栏 + AdminNav + router-view -├── views/AdminLegacyPage.vue # 未拆分模块的过渡容器 -├── components/AdminNav.vue # 子路由导航 -├── modules/agents/ -│ ├── AgentsPage.vue -│ ├── composables/useAgentsAdmin.ts -│ └── components/{AgentTestModal,AgentPermissionModal}.vue +├── views/AdminLayout.vue +├── modules/agents/ ... ├── stores/admin-nav.store.ts -├── composables/useAdminNavBadges.ts -├── constants/modules.ts -└── types/{admin,agent}.types.ts +└── ... ``` ### 8.3 构建验证 -`npm run build` 通过;`AgentsPage`、`AdminLayout`、`AdminLegacyPage` 已代码分割为独立 chunk。 +`npm run build` 通过。 -### 8.4 下一步(Phase 2) +### 8.4 下一步 -- 继续拆分 `users`、`permissions` 等 admin 模块 -- 拆分 `ChatView.vue` 为 `features/chat/components/*` +Admin 全量拆分 → §9;Chat 拆分 → §10。 --- -## 9. 相关文档 +## 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 模块目录 + +```text +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 +- ~~`shared/` composables/components/layouts/utils/styles 迁移~~ → 见 §14 +- 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 路由 + +```text +/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 规范 + +```typescript +// 共享 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: + +```typescript +import { listAdminUsers } from '@/features/admin'; +import { listWorkspaceScheduleRuns } from '@/features/workspace'; +import { getWorkspaceShippingTask } from '@/features/chat'; +``` + +### 12.3 兼容策略 + +- ~~`src/api/{client,admin,schedule,shippingNotice,chat,user}.ts` deprecated 转发~~ → **已删除**(2026-06-11) +- **新代码必须使用 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 目录结构 + +```text +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 规范 + +```typescript +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 兼容策略 + +- ~~`src/composables/`、`src/utils/`、`src/styles/` deprecated 转发~~ → **已删除**(2026-06-11) +- `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)`,四语言外置域与拆分前行为一致。 + +**目标结构**(剩余域): + +```text +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 执行): + +1. ~~拆 `errors.*` → `errors.json`~~ ✅ +2. ~~拆 `auth.*` → `auth.json`~~ ✅ +3. ~~拆 `workspace.*` → `workspace.json`~~ ✅ +4. ~~拆 `chat.*` → `chat.json`~~ ✅ +5. ~~拆 `admin.*` → `admin.json`~~ ✅ +6. 拆 `kb`(每域四语言 JSON;KB redesign 后可一并收口) +7. 每步 `npm run build` + 四语言 spot check +8. 全部外置后,`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.ts` +- `shared/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 推荐执行顺序 + +```text +✅ 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 收口 +``` + +--- - [项目上下文与技术栈](./project_context.md) - [UI 设计系统](./ui/DESIGN_SYSTEM.md) diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 573be8c1..a24ab69c 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -13,7 +13,6 @@ "@vue-office/docx": "^1.6.3", "@vue-office/excel": "^1.7.14", "@vue-office/pdf": "^1.6.5", - "axios": "^1.13.5", "highlight.js": "^11.11.1", "lucide-vue-next": "^0.575.0", "marked": "^17.0.3", @@ -862,12 +861,6 @@ "integrity": "sha512-PYjyFOLKQ9y57JvQ6QLo8dAgNqswh8M1RMJYdQduT6xbWSgK36P/Z/v+p888pM69jMMfS8Xd8F6I1kQ/I9HUGg==", "license": "MIT" }, - "node_modules/asynckit": { - "version": "0.4.0", - "resolved": "https://mirrors.tencent.com/npm/asynckit/-/asynckit-0.4.0.tgz", - "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", - "license": "MIT" - }, "node_modules/autoprefixer": { "version": "10.4.24", "resolved": "https://mirrors.tencent.com/npm/autoprefixer/-/autoprefixer-10.4.24.tgz", @@ -905,17 +898,6 @@ "postcss": "^8.1.0" } }, - "node_modules/axios": { - "version": "1.13.5", - "resolved": "https://mirrors.tencent.com/npm/axios/-/axios-1.13.5.tgz", - "integrity": "sha512-cz4ur7Vb0xS4/KUN0tPWe44eqxrIu31me+fbang3ijiNscE129POzipJJA6zniq2C/Z6sJCjMimjS8Lc/GAs8Q==", - "license": "MIT", - "dependencies": { - "follow-redirects": "^1.15.11", - "form-data": "^4.0.5", - "proxy-from-env": "^1.1.0" - } - }, "node_modules/baseline-browser-mapping": { "version": "2.10.0", "resolved": "https://mirrors.tencent.com/npm/baseline-browser-mapping/-/baseline-browser-mapping-2.10.0.tgz", @@ -996,19 +978,6 @@ "node": "^6 || ^7 || ^8 || ^9 || ^10 || ^11 || ^12 || >=13.7" } }, - "node_modules/call-bind-apply-helpers": { - "version": "1.0.2", - "resolved": "https://mirrors.tencent.com/npm/call-bind-apply-helpers/-/call-bind-apply-helpers-1.0.2.tgz", - "integrity": "sha512-Sp1ablJ0ivDkSzjcaJdxEunN5/XvksFJ2sMBFfq6x0ryhQV/2b/KwFe21cMpmHtPOSij8K99/wSfoEuTObmuMQ==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "function-bind": "^1.1.2" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/camelcase-css": { "version": "2.0.1", "resolved": "https://mirrors.tencent.com/npm/camelcase-css/-/camelcase-css-2.0.1.tgz", @@ -1097,18 +1066,6 @@ "node": ">=0.8" } }, - "node_modules/combined-stream": { - "version": "1.0.8", - "resolved": "https://mirrors.tencent.com/npm/combined-stream/-/combined-stream-1.0.8.tgz", - "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", - "license": "MIT", - "dependencies": { - "delayed-stream": "~1.0.0" - }, - "engines": { - "node": ">= 0.8" - } - }, "node_modules/commander": { "version": "4.1.1", "resolved": "https://mirrors.tencent.com/npm/commander/-/commander-4.1.1.tgz", @@ -1163,15 +1120,6 @@ "integrity": "sha512-z1HGKcYy2xA8AGQfwrn0PAy+PB7X/GSj3UVJW9qKyn43xWa+gl5nXmU4qqLMRzWVLFC8KusUX8T/0kCiOYpAIQ==", "license": "MIT" }, - "node_modules/delayed-stream": { - "version": "1.0.0", - "resolved": "https://mirrors.tencent.com/npm/delayed-stream/-/delayed-stream-1.0.0.tgz", - "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", - "license": "MIT", - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/detect-libc": { "version": "2.1.2", "resolved": "https://mirrors.tencent.com/npm/detect-libc/-/detect-libc-2.1.2.tgz", @@ -1194,20 +1142,6 @@ "integrity": "sha512-+HlytyjlPKnIG8XuRG8WvmBP8xs8P71y+SKKS6ZXWoEgLuePxtDoUEiH7WkdePWrQ5JBpE6aoVqfZfJUQkjXwA==", "license": "MIT" }, - "node_modules/dunder-proto": { - "version": "1.0.1", - "resolved": "https://mirrors.tencent.com/npm/dunder-proto/-/dunder-proto-1.0.1.tgz", - "integrity": "sha512-KIN/nDJBQRcXw0MLVhZE9iQHmG68qAVIBg9CqmUYjmQIhgij9U5MFvrqkUL5FbtyyzZuOeOt0zdeRe4UY7ct+A==", - "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.1", - "es-errors": "^1.3.0", - "gopd": "^1.2.0" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/electron-to-chromium": { "version": "1.5.302", "resolved": "https://mirrors.tencent.com/npm/electron-to-chromium/-/electron-to-chromium-1.5.302.tgz", @@ -1227,51 +1161,6 @@ "url": "https://github.com/fb55/entities?sponsor=1" } }, - "node_modules/es-define-property": { - "version": "1.0.1", - "resolved": "https://mirrors.tencent.com/npm/es-define-property/-/es-define-property-1.0.1.tgz", - "integrity": "sha512-e3nRfgfUZ4rNGL232gUgX06QNyyez04KdjFrF+LTRoOXmrOgFKDg4BCdsjW8EnT69eqdYGmRpJwiPVYNrCaW3g==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-errors": { - "version": "1.3.0", - "resolved": "https://mirrors.tencent.com/npm/es-errors/-/es-errors-1.3.0.tgz", - "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-object-atoms": { - "version": "1.1.1", - "resolved": "https://mirrors.tencent.com/npm/es-object-atoms/-/es-object-atoms-1.1.1.tgz", - "integrity": "sha512-FGgH2h8zKNim9ljj7dankFPcICIK9Cp5bm+c2gQSYePhpaG5+esrLODihIorn+Pe6FGJzWhXQotPv73jTaldXA==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0" - }, - "engines": { - "node": ">= 0.4" - } - }, - "node_modules/es-set-tostringtag": { - "version": "2.1.0", - "resolved": "https://mirrors.tencent.com/npm/es-set-tostringtag/-/es-set-tostringtag-2.1.0.tgz", - "integrity": "sha512-j6vWzfrGVfyXxge+O0x5sh6cvxAog0a/4Rdd2K36zCMV5eJ+/+tOAngRO8cODMNWbVRdVlmGZQL2YS3yR8bIUA==", - "license": "MIT", - "dependencies": { - "es-errors": "^1.3.0", - "get-intrinsic": "^1.2.6", - "has-tostringtag": "^1.0.2", - "hasown": "^2.0.2" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/escalade": { "version": "3.2.0", "resolved": "https://mirrors.tencent.com/npm/escalade/-/escalade-3.2.0.tgz", @@ -1354,42 +1243,6 @@ "node": ">=8" } }, - "node_modules/follow-redirects": { - "version": "1.15.11", - "resolved": "https://mirrors.tencent.com/npm/follow-redirects/-/follow-redirects-1.15.11.tgz", - "integrity": "sha512-deG2P0JfjrTxl50XGCDyfI97ZGVCxIpfKYmfyrQ54n5FO/0gfIES8C/Psl6kWVDolizcaaxZJnTS0QSMxvnsBQ==", - "funding": [ - { - "type": "individual", - "url": "https://github.com/sponsors/RubenVerborgh" - } - ], - "license": "MIT", - "engines": { - "node": ">=4.0" - }, - "peerDependenciesMeta": { - "debug": { - "optional": true - } - } - }, - "node_modules/form-data": { - "version": "4.0.5", - "resolved": "https://mirrors.tencent.com/npm/form-data/-/form-data-4.0.5.tgz", - "integrity": "sha512-8RipRLol37bNs2bhoV67fiTEvdTrbMUYcFTiy3+wuuOnUog2QBHCZWXDRijWQfAkhBj2Uf5UnVaiWwA5vdd82w==", - "license": "MIT", - "dependencies": { - "asynckit": "^0.4.0", - "combined-stream": "^1.0.8", - "es-set-tostringtag": "^2.1.0", - "hasown": "^2.0.2", - "mime-types": "^2.1.12" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/frac": { "version": "1.1.2", "resolved": "https://mirrors.tencent.com/npm/frac/-/frac-1.1.2.tgz", @@ -1436,43 +1289,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/get-intrinsic": { - "version": "1.3.0", - "resolved": "https://mirrors.tencent.com/npm/get-intrinsic/-/get-intrinsic-1.3.0.tgz", - "integrity": "sha512-9fSjSaos/fRIVIp+xSJlE6lfwhES7LNtKaCBIamHsjr2na1BiABJPo0mOjjz8GJDURarmCPGqaiVg5mfjb98CQ==", - "license": "MIT", - "dependencies": { - "call-bind-apply-helpers": "^1.0.2", - "es-define-property": "^1.0.1", - "es-errors": "^1.3.0", - "es-object-atoms": "^1.1.1", - "function-bind": "^1.1.2", - "get-proto": "^1.0.1", - "gopd": "^1.2.0", - "has-symbols": "^1.1.0", - "hasown": "^2.0.2", - "math-intrinsics": "^1.1.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/get-proto": { - "version": "1.0.1", - "resolved": "https://mirrors.tencent.com/npm/get-proto/-/get-proto-1.0.1.tgz", - "integrity": "sha512-sTSfBjoXBp89JvIKIefqw7U2CCebsc74kiY6awiGogKtoSGbgjYE/G/+l9sF3MWFPNc9IcoOC4ODfKHfxFmp0g==", - "license": "MIT", - "dependencies": { - "dunder-proto": "^1.0.1", - "es-object-atoms": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - } - }, "node_modules/glob-parent": { "version": "6.0.2", "resolved": "https://mirrors.tencent.com/npm/glob-parent/-/glob-parent-6.0.2.tgz", @@ -1485,45 +1301,6 @@ "node": ">=10.13.0" } }, - "node_modules/gopd": { - "version": "1.2.0", - "resolved": "https://mirrors.tencent.com/npm/gopd/-/gopd-1.2.0.tgz", - "integrity": "sha512-ZUKRh6/kUFoAiTAtTYPZJ3hw9wNxx+BIBOijnlG9PnrJsCcSjs1wyyD6vJpaYtgnzDrKYRSqf3OO6Rfa93xsRg==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-symbols": { - "version": "1.1.0", - "resolved": "https://mirrors.tencent.com/npm/has-symbols/-/has-symbols-1.1.0.tgz", - "integrity": "sha512-1cDNdwJ2Jaohmb3sg4OmKaMBwuC48sYni5HUw2DvsC8LjGTLK9h+eb1X6RyuOHe4hT0ULCW68iomhjUoKUqlPQ==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/has-tostringtag": { - "version": "1.0.2", - "resolved": "https://mirrors.tencent.com/npm/has-tostringtag/-/has-tostringtag-1.0.2.tgz", - "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", - "license": "MIT", - "dependencies": { - "has-symbols": "^1.0.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/hasown": { "version": "2.0.2", "resolved": "https://mirrors.tencent.com/npm/hasown/-/hasown-2.0.2.tgz", @@ -1938,15 +1715,6 @@ "node": ">= 20" } }, - "node_modules/math-intrinsics": { - "version": "1.1.0", - "resolved": "https://mirrors.tencent.com/npm/math-intrinsics/-/math-intrinsics-1.1.0.tgz", - "integrity": "sha512-/IXtbwEk5HTPyEwyKX6hGkYXxM9nbj64B+ilVJnC/R6B0pH5G4V3b0pVbL7DBj4tkhBAppbQUlf6F6Xl9LHu1g==", - "license": "MIT", - "engines": { - "node": ">= 0.4" - } - }, "node_modules/merge2": { "version": "1.4.1", "resolved": "https://mirrors.tencent.com/npm/merge2/-/merge2-1.4.1.tgz", @@ -1981,27 +1749,6 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, - "node_modules/mime-db": { - "version": "1.52.0", - "resolved": "https://mirrors.tencent.com/npm/mime-db/-/mime-db-1.52.0.tgz", - "integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, - "node_modules/mime-types": { - "version": "2.1.35", - "resolved": "https://mirrors.tencent.com/npm/mime-types/-/mime-types-2.1.35.tgz", - "integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==", - "license": "MIT", - "dependencies": { - "mime-db": "1.52.0" - }, - "engines": { - "node": ">= 0.6" - } - }, "node_modules/mini-svg-data-uri": { "version": "1.4.4", "resolved": "https://mirrors.tencent.com/npm/mini-svg-data-uri/-/mini-svg-data-uri-1.4.4.tgz", @@ -2321,12 +2068,6 @@ "integrity": "sha512-1NNCs6uurfkVbeXG4S8JFT9t19m45ICnif8zWLd5oPSZ50QnwMfK+H3jv408d4jw/7Bttv5axS5IiHoLaVNHeQ==", "license": "MIT" }, - "node_modules/proxy-from-env": { - "version": "1.1.0", - "resolved": "https://mirrors.tencent.com/npm/proxy-from-env/-/proxy-from-env-1.1.0.tgz", - "integrity": "sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==", - "license": "MIT" - }, "node_modules/queue-microtask": { "version": "1.2.3", "resolved": "https://mirrors.tencent.com/npm/queue-microtask/-/queue-microtask-1.2.3.tgz", diff --git a/frontend/package.json b/frontend/package.json index c33dcd9b..c4bf85ab 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -14,7 +14,6 @@ "@vue-office/docx": "^1.6.3", "@vue-office/excel": "^1.7.14", "@vue-office/pdf": "^1.6.5", - "axios": "^1.13.5", "highlight.js": "^11.11.1", "lucide-vue-next": "^0.575.0", "marked": "^17.0.3", diff --git a/frontend/scripts/extract-i18n-domain.mjs b/frontend/scripts/extract-i18n-domain.mjs new file mode 100644 index 00000000..5cfb7c65 --- /dev/null +++ b/frontend/scripts/extract-i18n-domain.mjs @@ -0,0 +1,49 @@ +/** + * scripts/extract-i18n-domain.mjs + * 从 i18n.ts 内联 messages 提取指定域至 locales/{locale}/{domain}.json 并移除内联键。 + * + * Usage: node scripts/extract-i18n-domain.mjs + * Example: node scripts/extract-i18n-domain.mjs workspace + */ +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const domain = process.argv[2]; +if (!domain) { + console.error('Usage: node scripts/extract-i18n-domain.mjs '); + process.exit(1); +} + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const root = path.resolve(__dirname, '..'); +const i18nPath = path.resolve(root, 'src/i18n.ts'); +const localesRoot = path.resolve(root, 'src/locales'); +const locales = ['en', 'zh-CN', 'zh-TW', 'th']; + +const content = fs.readFileSync(i18nPath, 'utf8'); +const start = content.indexOf('const messages = {') + 'const messages = '.length; +const end = content.indexOf('const i18n = createI18n'); +const messagesStr = content.slice(start, end).trim().replace(/,\s*$/, ''); +const messages = new Function(`return ${messagesStr}`)(); + +for (const locale of locales) { + const block = messages[locale]?.[domain]; + if (!block) { + console.error(`Missing messages.${locale}.${domain}`); + process.exit(1); + } + const outDir = path.join(localesRoot, locale); + fs.mkdirSync(outDir, { recursive: true }); + const outPath = path.join(outDir, `${domain}.json`); + fs.writeFileSync(outPath, `${JSON.stringify(block, null, 2)}\n`, 'utf8'); + delete messages[locale][domain]; + console.log(`Wrote ${path.relative(root, outPath)}`); +} + +const header = content.slice(0, content.indexOf('const messages = {')); +const footer = content.slice(end); +const serialized = JSON.stringify(messages, null, 2); +const newContent = `${header}const messages = ${serialized};\n\n${footer}`; +fs.writeFileSync(i18nPath, newContent, 'utf8'); +console.log(`Stripped ${domain} from i18n.ts`); diff --git a/frontend/scripts/strip-i18n-auth.mjs b/frontend/scripts/strip-i18n-auth.mjs new file mode 100644 index 00000000..64795620 --- /dev/null +++ b/frontend/scripts/strip-i18n-auth.mjs @@ -0,0 +1,30 @@ +/** + * scripts/strip-i18n-auth.mjs + * 从 i18n.ts 内联 messages 中移除已外置至 locales 下 auth.json 的键。 + */ +import fs from 'node:fs'; +import path from 'node:path'; +import { fileURLToPath } from 'node:url'; + +const __dirname = path.dirname(fileURLToPath(import.meta.url)); +const i18nPath = path.resolve(__dirname, '../src/i18n.ts'); + +const content = fs.readFileSync(i18nPath, 'utf8'); +const start = content.indexOf('const messages = {') + 'const messages = '.length; +const end = content.indexOf('const i18n = createI18n'); +const messagesStr = content.slice(start, end).trim().replace(/,\s*$/, ''); +const messages = new Function(`return ${messagesStr}`)(); + +for (const loc of ['en', 'zh-CN', 'zh-TW', 'th']) { + delete messages[loc].title; + delete messages[loc].login; + delete messages[loc].landing; + delete messages[loc].register; +} + +const header = content.slice(0, content.indexOf('const messages = {')); +const footer = content.slice(end); +const serialized = JSON.stringify(messages, null, 2); +const newContent = `${header}const messages = ${serialized};\n\n${footer}`; +fs.writeFileSync(i18nPath, newContent, 'utf8'); +console.log('Stripped auth keys from i18n.ts'); diff --git a/frontend/src/App.vue b/frontend/src/App.vue index 1855bdf5..31cd9c13 100644 --- a/frontend/src/App.vue +++ b/frontend/src/App.vue @@ -2,11 +2,11 @@