From c38a56536e931915e5ecf3fd86c8032fdba8a4af Mon Sep 17 00:00:00 2001 From: sophie Date: Mon, 22 Jun 2026 10:30:18 +0800 Subject: [PATCH] =?UTF-8?q?docs(agents.md):=20=E8=A1=A5=E5=85=85=E5=89=8D?= =?UTF-8?q?=E7=AB=AF=E6=9E=B6=E6=9E=84=E7=BA=A6=E6=9D=9F=E4=B8=8E=E9=94=99?= =?UTF-8?q?=E8=AF=AF=E5=A4=84=E7=90=86=E8=A7=84=E8=8C=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AGENTS.md | 20 +- .../frontend_architecture_refactor.md | 1125 ++++------------- .../frontend_architecture_refactor_phases.md | 948 ++++++++++++++ 3 files changed, 1230 insertions(+), 863 deletions(-) create mode 100644 docs/refactor/frontend_architecture_refactor_phases.md diff --git a/AGENTS.md b/AGENTS.md index 3e88cfe4..c231030a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -43,14 +43,23 @@ backend/app/ response_utils.py / errors.py / decorators.py # 统一返回、异常、权限装饰器 backend/migrations/ # Alembic 迁移文件 frontend/src/ - features/ # 按业务域组织(admin / auth / chat) - composables/# Hooks(如 useChat.ts) - views/ components/ i18n.ts + main.ts · App.vue · i18n.ts · config.ts # Vite 入口(保留 src 根) + app/ # 应用基础设施:router/(routes/* · guards)、plugins/pinia + shared/ # 跨域共享(无业务语义) + # api/client · composables · components · layouts · utils · styles + features/ # 业务域垂直切分(新代码主要落在这里) + # auth · workspace · chat · admin · kb + # 域内:api/ · composables/ · views/ · stores/ · components/ + # admin 子模块:modules//*Page.vue + use*Admin.ts + locales/ # i18n 四语言 JSON(zh-CN / zh-TW / en / th),按域拆分 scripts/ # 部署与运维脚本(deploy_compose.sh、healthcheck.sh ...) docs/ # 权威文档(规范、上下文、流程、发布说明) ``` -**约定**:新逻辑优先放入对应 `services/`(后端)或 `features/composables/`(前端),复用既有 `response_utils` / `errors` / `decorators` 模式,不要另造轮子。 +**约定**: + +- **后端**:新逻辑优先放入 `services/`,复用 `response_utils` / `errors` / `decorators` 模式,不要另造轮子。 +- **前端**:Feature-Module + Composables + Pinia;新功能放入 `features//`(`api/` · `composables/` · `views/` 等),跨域通用代码放 `shared/`;HTTP 统一 `@/shared/api/client`。**禁止**在已废弃的 `src/api/`、`src/views/`、`src/composables/` 等路径新增代码。完整规范见 **[docs/refactor/frontend_architecture_refactor.md](docs/refactor/frontend_architecture_refactor.md)**。 --- @@ -143,6 +152,7 @@ docker compose logs -f hxops-backend - 🔌 **外部集成依赖**:Oracle Instant Client 19.30 / `pyodbc` / `zeep`(OA、PLM、HR)等本地未必可运行,涉及这些 service 时谨慎并说明。 - ➕ **新增依赖需克制**:不擅自引入未经评审的第三方依赖;如需新增,在提交说明中给出理由。 - 📝 **注释两层标准(强制)**:新建或调整代码须满足 §5 文件层 + 函数层注释;AI 生成/重构代码同样适用,不得省略。 +- ⚠️ **错误处理统一契约**:JSON API 使用 `{ success, data | error, request_id }` envelope;后端业务失败 **`raise AppError` 子类**(`app/errors.py`),禁止新写 `jsonify({"error": ...})`;前端 HTTP 统一 **`requestJson`**(`@/shared/api/client`),失败为 **`BusinessError`**,在 composable/view 用 **`useMessage()`** 展示;新增 `error.code` 须同步四语言 **`locales/*/errors.json`**。详见 **[docs/convention/error_handling.md](docs/convention/error_handling.md)**。 - ⚠️ 改动**数据库结构、部署脚本(`scripts/`、`Jenkinsfile`、`docker-compose.yml`)或敏感配置**前,先说明影响面再动手。 合并前最低自检(详见 [新人文档 §3.3](docs/新人环境搭建与配置文档.md)):前后端可启动、`frontend/` 改动后 `npm run build` 通过、关键页面与登录可用。 @@ -183,3 +193,5 @@ docker compose logs -f hxops-backend | Excel/CSV 切块与 Dify 分段 | [docs/kb-excel-dify-chunking.md](docs/kb-excel-dify-chunking.md) | | FAQ 缓存 / 热点发现运维 | [docs/faq_cache_ops_manual.md](docs/faq_cache_ops_manual.md) | | 测试计划 | [docs/test_plan_matrix.md](docs/test_plan_matrix.md) | +| 前端架构规范 | [docs/refactor/frontend_architecture_refactor.md](docs/refactor/frontend_architecture_refactor.md) | +| 错误处理规范 | [docs/convention/error_handling.md](docs/convention/error_handling.md) | diff --git a/docs/refactor/frontend_architecture_refactor.md b/docs/refactor/frontend_architecture_refactor.md index 0ffa783b..12f42c7b 100644 --- a/docs/refactor/frontend_architecture_refactor.md +++ b/docs/refactor/frontend_architecture_refactor.md @@ -1,942 +1,349 @@ -# HXOPS 前端重构架构方案 +# HXOPS 前端架构规范(总览版) -> 更新时间:2026-06-11 +> 更新时间:2026-06-22 > 适用范围:`frontend/` 目录 -> 文档定位:定义推荐的目标架构(Feature-Module + Composables + Pinia),作为后续分阶段重构的基准。 +> 读者:组内同事、AI 编程助手(Cursor / Codex 等) +> 文档定位:**当前权威架构与编码约束**。新功能开发与既有代码修改均须遵循本文,避免架构漂移。 +> 分阶段迁移细节见附录:[frontend_architecture_refactor_phases.md](./frontend_architecture_refactor_phases.md) + +--- + +## 0. 如何使用本文 + +| 场景 | 先看 | +|------|------| +| 新增业务功能 | §2 目录结构 → §3 分层 → §6 新功能清单 | +| 修改现有页面 | §4 设计原则 → §5 各域模式 → 对照同域已有代码 | +| AI Agent 写代码 | §4.1 依赖红线 + §7 禁止项 + §8 import 规范 | +| UI / 样式 | [UI 设计系统](../ui/DESIGN_SYSTEM.md) · [UI 编码规范](../ui/UI_CODING_GUIDELINES.md) | + +**合并前自检**:`cd frontend && npm run build` 通过;新增文案四语言齐全(`zh-CN` / `zh-TW` / `en-US` / `th-TH`)。 --- ## 1. 架构选型 -在现有技术栈(Vue 3 + TypeScript + Vite + Vue Router + Vue I18n + TailwindCSS)基础上,采用 **Feature-Module 垂直切分 + Composables 逻辑封装 + Pinia 共享状态** 的组合架构。 +在既有技术栈上,采用 **Feature-Module 垂直切分 + Composables 逻辑封装 + Pinia 共享状态**。 -**选型理由:** +| 维度 | 选型 | 说明 | +|------|------|------| +| 组织方式 | Feature-Module | 按业务域(auth / workspace / chat / admin / kb)垂直拆分,域内自包含 api / composables / views | +| 逻辑封装 | Composables | 副作用、表单、SSE、分页等放入 `use*`,View 只做编排 | +| 跨页状态 | Pinia | 替代 localStorage + CustomEvent 为主的跨组件可变状态 | +| 未采用 | FSD、Element Plus | 目录层级更浅、迁移成本可控;继续 Tailwind + Design Tokens | -- 与 Vue 3 Composition API 天然契合,学习成本低 -- 业务域清晰(聊天 / 管理后台 / 知识库 / 认证),适合按 feature 垂直拆分 -- 相比 FSD(Feature-Sliced Design)目录层级更浅,迁移成本可控 -- 相比引入 Element Plus 等 UI 库,可继续沿用现有 Tailwind 设计体系(`tokens.css`、`components-ds.css`) +**固定技术栈(勿擅自替换):** -**保持不变的技术栈:** - -| 层级 | 选型 | +| 层级 | 技术 | |------|------| -| 框架 | Vue 3(Composition API + `