Commit 0c7ed7c5 by imwangxiaozhou

Merge branch 'ai-workflow-dev' of http://192.168.3.233:8090/ai/ai-workflow into ai-workflow-dev

2 parents f9a57fab 7f24fd58
Showing 47 changed files with 1041 additions and 233 deletions
# Codex 项目规则
## OpenSpec + Superpowers 工作流
对于非平凡 feature,默认使用四阶段组合流程:
1. Superpowers 探索性规划。
2. OpenSpec 锁定规范。
3. Superpowers 执行编码、测试、验证。
4. OpenSpec 归档。
详细使用说明见 `architecture-spec/docs/architecture/openspec-superpowers-workflow.md`。
### 阶段速查
- Superpowers 探索性规划:读取上下文、澄清需求、比较方案、确认设计;常用触发语:`使用 $superpowers-openspec-execution-workflow,先进入 Superpowers 探索阶段,不要写代码。`
- OpenSpec 锁定规范:创建 `openspec/changes/<change-name>/`,按顺序完成 `proposal.md`、`design.md`、`specs/.../spec.md`、`tasks.md`;常用命令:`openspec status --change "<change-name>" --json`、`openspec instructions <artifact> --change "<change-name>" --json`、`openspec validate "<change-name>" --strict`。
- Superpowers 执行编码、测试、验证:按 OpenSpec tasks 和实施计划用 TDD 实现,运行类型检查、测试、构建和必要的浏览器验证;常用命令:`npm run typecheck`、`npm test`、`npm run build`。
- OpenSpec 归档:确认代码、测试、规范对齐后归档;常用命令:`openspec archive "<change-name>"`。
## 强制规则
- 设计未确认前,不进入 OpenSpec。
- OpenSpec artifacts 未完成前,不进入编码。
- 行为变更默认使用 TDD。
- 完成前必须运行真实验证命令。
- 代码、测试、规范未对齐前,不归档。
- 需求确认前,不写业务实现代码。
- 在业务需求最终确认前,可以先创建项目级规范、架构决策、前端组件规则和页面数据草案。
- 每个会改变系统行为的功能,都必须在 `openspec/changes/<change-name>/` 下有对应的 OpenSpec change。
## 文档优先
文档按以下位置归档:
- `architecture-spec/docs/architecture/`:全局技术规范。
- `architecture-spec/docs/requirements/`:PRD 分析、待确认问题、确认记录。
- `architecture-spec/docs/decisions/`:长期有效的架构和产品决策。
- `architecture-spec/openspec/`:全局 OpenSpec 规范和工作区级 change。
- `workspace/<project>/openspec/`:具体业务项目的 OpenSpec 规范和 change。
- `workspace/<project>/docs/`:具体业务项目文档。
- `.superpowers-memory/`:跨会话项目记忆。其中 `CURRENT_STATE.md` 仅作为状态索引;具体当前状态按“人/项目”写入 `.superpowers-memory/current/<owner>/<project>.md`,避免多人协作时反复冲突。
## 前端规则
- 所有 Web 桌面端页面必须遵循公司设计规范:`/Users/yuehu/Documents/广联web桌面端设计规范`。
- 优先使用可复用的内部组件,不在页面里临时堆一次性 UI。
- 管理后台页面应保持信息密度和可扫读性:工具栏/搜索区、表格、分页、弹窗/抽屉表单、状态标签、清晰的操作按钮。
- 后台工作流页面不要做成营销页风格。
## 后端规则
- 后端技术栈暂不固化,后续可根据确认结果选择 Python 或其他方案。
- 当前阶段不制定后端框架、数据库、队列、ORM 和运行时实现规则。
- 如前端需要联调契约,先以页面字段、交互状态、错误展示和 mock 数据结构表达,不锁定服务端实现。
## 现有后端结构(单独罗列)
当前仓库已存在一个后端工程骨架,位于:
- `workspace/agent-admin/backend/`:Agent 管理平台后端(API + 业务能力 + 数据迁移 + 测试)。
目录结构(仅列出当前已存在的一级目录/文件,用于快速定位):
- `workspace/agent-admin/backend/app/`:应用代码(API/Service/Infrastructure/Config/Model/Schema 等分层以该工程内 `AGENTS.md` 为准)。
- `workspace/agent-admin/backend/migrations/`:数据库变更脚本(SQL 迁移)。
- `workspace/agent-admin/backend/tests/`:单元测试/接口测试。
- `workspace/agent-admin/backend/openspec/`:后端相关 OpenSpec(接口、业务规则、数据行为等)。
- `workspace/agent-admin/backend/docs/`:后端工程文档(与项目级 `docs/` 区分)。
- `workspace/agent-admin/backend/README.md`:该后端工程说明。
- `workspace/agent-admin/backend/AGENTS.md`:该后端工程的更细粒度规则(在该目录树下工作时优先遵循)。
- `workspace/agent-admin/backend/sitecustomize.py`:后端工程运行时环境/路径等辅助配置(以文件内说明为准)。
### 后端目录说明(约定边界)
- 该仓库的“后端”以 `workspace/<project>/backend/` 为项目级归属单位;不同业务项目各自管理自己的 OpenSpec、模块与工程配置。
- 项目级规则(本文档)只描述“在哪里/边界是什么”;具体后端技术栈、分层、代码规范等,以对应后端工程目录下的 `AGENTS.md` 为准(例如 `workspace/agent-admin/backend/AGENTS.md`)。
## 验证规则
- 没有新鲜的验证结果,不声明工作完成。
- 如果改了代码,需要运行类型检查和相关测试。
- 如果开发前端页面,完成前需要在浏览器中验证布局和关键交互。
# Superpowers 配置目录
这里用于存放本项目的 Superpowers 工作流配置、团队约定或与外部 skills bundle 的引用说明。
当前项目默认使用本机已安装的 Superpowers/OpenSpec 相关 skills。若后续团队决定统一使用 `superpowers-openspec-team-skills`,可在这里补充安装和同步说明。
...@@ -29,6 +29,13 @@ __pycache__/ ...@@ -29,6 +29,13 @@ __pycache__/
.idea/ .idea/
.vscode/ .vscode/
# Claude Code
.claude/
CLAUDE.md
# Vibe coding workspace
Vibe coding for SQ/
# Runtime uploads and temp # Runtime uploads and temp
tmp/ tmp/
uploads/ uploads/
......
# Agent 规则入口 # Agent 项目规则
本项目 Codex 规则以 `.codex/AGENTS.md` 为准。 ## OpenSpec + Superpowers 工作流
进入本仓库工作时,请优先读取并遵循 `.codex/AGENTS.md`。根目录保留此入口文件,是为了兼容 Codex 和其他 Agent 工具在仓库根目录自动发现 `AGENTS.md` 的习惯。 对于非平凡 feature,默认使用四阶段组合流程:
1. Superpowers 探索性规划。
2. OpenSpec 锁定规范。
3. Superpowers 执行编码、测试、验证。
4. OpenSpec 归档。
详细使用说明见 `architecture-spec/docs/architecture/openspec-superpowers-workflow.md`。
### 阶段速查
- Superpowers 探索性规划:读取上下文、澄清需求、比较方案、确认设计;常用触发语:`使用 $superpowers-openspec-execution-workflow,先进入 Superpowers 探索阶段,不要写代码。`
- `@fixbug + <change name> + 描述内容`:如果用户明确指定对应的 OpenSpec change,则直接修改该 change 下受影响的 OpenSpec artifacts 与 `tasks.md`;如果未指定,则先检查是否已有对应 OpenSpec,若没有则创建新的 change,若已有则先更新受影响的 OpenSpec artifacts 与 `tasks.md`。用户确认文档后,再进入代码修改,不直接改代码。
- OpenSpec 锁定规范:创建 `openspec/changes/<change-name>/`,按顺序完成 `proposal.md`、`design.md`、`specs/.../spec.md`、`tasks.md`;常用命令:`openspec status --change "<change-name>" --json`、`openspec instructions <artifact> --change "<change-name>" --json`、`openspec validate "<change-name>" --strict`。
- Superpowers 执行编码、测试、验证:按 OpenSpec tasks 和实施计划用 TDD 实现,运行类型检查、测试、构建和必要的浏览器验证;常用命令:`npm run typecheck`、`npm test`、`npm run build`。
- OpenSpec 归档:确认代码、测试、规范对齐后归档;常用命令:`openspec archive "<change-name>"`。
## 强制规则
- 设计未确认前,不进入 OpenSpec。
- OpenSpec artifacts 未完成前,不进入编码。
- 当某个需求已进入对应的 OpenSpec change 后,用户后续新增问题、补充约束、要求调整方案或实现路径时,必须先更新受影响的 OpenSpec artifacts 和 `tasks.md`,并在用户确认后再进入编码。
- 行为变更默认使用 TDD。
- 完成前必须运行真实验证命令。
- 代码、测试、规范未对齐前,不归档。
- 需求确认前,不写业务实现代码。
- 所有会修改系统行为的 bug 修复,必须先对齐对应的 OpenSpec:如果用户已明确指定 change name,则直接更新该 change 下相关 artifacts 和 `tasks.md`;如果未指定,则按原流程判断,没有对应 change 时先创建新的 change,已有对应 change 时先更新相关 artifacts 和 `tasks.md`。在用户确认文档前,不直接修改代码。
- 在业务需求最终确认前,可以先创建项目级规范、架构决策、前端组件规则和页面数据草案。
- 每个会改变系统行为的功能,都必须在 `openspec/changes/<change-name>/` 下有对应的 OpenSpec change。
## 文档优先
文档按以下位置归档:
- `architecture-spec/docs/architecture/`:全局技术规范。
- `architecture-spec/docs/requirements/`:PRD 分析、待确认问题、确认记录。
- `architecture-spec/docs/decisions/`:长期有效的架构和产品决策。
- `architecture-spec/openspec/`:全局 OpenSpec 规范和工作区级 change。
- `workspace/<project>/openspec/`:具体业务项目的 OpenSpec 规范和 change。
- `workspace/<project>/docs/`:具体业务项目文档。
- `.superpowers-memory/`:跨会话项目记忆。其中 `CURRENT_STATE.md` 仅作为状态索引;具体当前状态按“人/项目”写入 `.superpowers-memory/current/<owner>/<project>.md`,避免多人协作时反复冲突。
## 文档语言
- 本仓库的 OpenSpec、需求沉淀、设计说明、任务清单、架构决策和协作说明默认使用中文。
- 代码标识、接口字段、枚举值、命令、路径、文件名、依赖名和 OpenSpec 校验所需关键字可以保留英文。
- 如必须引用英文原文,应补充中文说明,避免只留下英文规格或任务描述。
## 前端规则
- 所有 Web 桌面端页面必须遵循公司设计规范:`/Users/yuehu/Documents/广联web桌面端设计规范`。
- 优先使用可复用的内部组件,不在页面里临时堆一次性 UI。
- 管理后台页面应保持信息密度和可扫读性:工具栏/搜索区、表格、分页、弹窗/抽屉表单、状态标签、清晰的操作按钮。
- 后台工作流页面不要做成营销页风格。
## 后端规则
- 后端技术栈暂不固化,后续可根据确认结果选择 Python 或其他方案。
- 当前阶段不制定后端框架、数据库、队列、ORM 和运行时实现规则。
- 如前端需要联调契约,先以页面字段、交互状态、错误展示和 mock 数据结构表达,不锁定服务端实现。
## 验证规则
- 没有新鲜的验证结果,不声明工作完成。
- 如果改了代码,需要运行类型检查和相关测试。
- 如果开发前端页面,完成前需要在浏览器中验证布局和关键交互。
# 多项目前端工作区 # 多项目前端工作区
这是一个独立新建的 monorepo 工作区,用于沉淀 Codex + OpenSpec + Superpowers 工作流、公司 Web 桌面端设计规范、前端工程规则和后续多个项目可复用的组件规范。 这是一个独立新建的 monorepo 工作区,用于沉淀 OpenSpec + Superpowers 工作流、公司 Web 桌面端设计规范、前端工程规则和后续多个项目可复用的组件规范。
首个业务项目是 AI 大模型后台管理平台,放在 `workspace/agent-admin/`。当前阶段只沉淀项目规范和需求确认流程;业务开发需等待 PRD 二次确认、OpenSpec change 完成并获得确认后再开始。 首个业务项目是 AI 大模型后台管理平台,放在 `workspace/agent-admin/`。当前阶段只沉淀项目规范和需求确认流程;业务开发需等待 PRD 二次确认、OpenSpec change 完成并获得确认后再开始。
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
## 目录结构 ## 目录结构
```text ```text
.codex/ # Codex 工作流配置,当前受本机沙箱限制暂未创建 AGENTS.md # 工作区级 Agent 协作规则
.agents/ # 团队 skills 引用,当前受本机沙箱限制暂未创建 .agents/ # 团队 skills 引用,当前受本机沙箱限制暂未创建
architecture-spec/ # 全局架构、OpenSpec、UI 和工程规范 architecture-spec/ # 全局架构、OpenSpec、UI 和工程规范
workspace/agent-admin/ # 首个业务项目:Agent 管理平台 workspace/agent-admin/ # 首个业务项目:Agent 管理平台
...@@ -24,7 +24,7 @@ workspace/agent-admin/ # 首个业务项目:Agent 管理平台 ...@@ -24,7 +24,7 @@ workspace/agent-admin/ # 首个业务项目:Agent 管理平台
## 工作流 ## 工作流
本项目采用 Codex + OpenSpec + Superpowers 工作流: 本项目采用 OpenSpec + Superpowers 工作流:
1. Superpowers 负责需求澄清、方案比较、设计和计划。 1. Superpowers 负责需求澄清、方案比较、设计和计划。
2. OpenSpec 负责锁定行为规范和变更任务。 2. OpenSpec 负责锁定行为规范和变更任务。
......
...@@ -6,16 +6,14 @@ ...@@ -6,16 +6,14 @@
它需要沉淀三类共享资产: 它需要沉淀三类共享资产:
- 工作流资产:Codex + OpenSpec + Superpowers 的需求澄清、规范、计划、验证流程。 - 工作流资产:OpenSpec + Superpowers 的需求澄清、规范、计划、验证流程。
- UI 资产:公司 Web 桌面端设计 token、组件库、页面模式。 - UI 资产:公司 Web 桌面端设计 token、组件库、页面模式。
- 工程资产:前端通用配置、工具链、测试基线。 - 工程资产:前端通用配置、工具链、测试基线。
## 推荐目录 ## 推荐目录
```text ```text
.codex/ AGENTS.md # 工作区级 Agent 协作规则
AGENTS.md # Codex 全局工作规则
superpowers/ # Superpowers 相关配置或引用
.agents/ .agents/
skills/ # 团队级 skills 引用 skills/ # 团队级 skills 引用
...@@ -56,6 +54,28 @@ workspace/ ...@@ -56,6 +54,28 @@ workspace/
docs/ docs/
``` ```
推荐目录职责示例(以 `workspace/agent-admin/` 为例):
| 模块 | 职责 |
| --- | --- |
| `AGENTS.md` | 仓库规则入口,统一承载项目级规则、OpenSpec + Superpowers 工作流门禁,以及不同 IDE / Agent 的协作约束。 |
| `architecture-spec/` | 全局规范中心,沉淀架构、技术栈、组件规范、决策和工作区级 OpenSpec。 |
| `workspace/agent-admin/` | Agent 管理相关业务项目总目录。 |
| `workspace/agent-admin/web/` | 后台管理前端,当前可承载 React + TypeScript + Vite 等前端基座。 |
| `workspace/agent-admin/single-page/` | Agent 管理相关单页面项目,适合承载独立展示或轻量交互场景。 |
| `workspace/agent-admin/backend/` | 后端预留区,当前只定义目录边界,不预先锁定技术栈。 |
| `workspace/agent-admin/web/packages/ui/` | 后台前端可复用 UI 组件。 |
| `workspace/agent-admin/web/packages/contracts/` | 后台前端视角的字段、枚举、payload、mock 数据和接口契约沉淀区。 |
| `workspace/agent-admin/web/packages/config/` | 后台前端工程配置。 |
| `workspace/agent-admin/web/packages/utils/` | 无业务上下文的前端通用工具。 |
| `workspace/agent-admin/single-page/packages/ui/` | 单页面项目可复用 UI 组件。 |
| `workspace/agent-admin/single-page/packages/contracts/` | 单页面项目视角的字段、枚举、payload、mock 数据和接口契约沉淀区。 |
| `workspace/agent-admin/single-page/packages/config/` | 单页面项目工程配置。 |
| `workspace/agent-admin/single-page/packages/utils/` | 单页面项目通用工具。 |
| `workspace/agent-admin/backend/packages/contracts/` | 后端视角的接口、schema、错误码和 mock 响应示例。 |
| `workspace/agent-admin/backend/packages/config/` | 后端工程配置。 |
| `workspace/agent-admin/backend/packages/utils/` | 无业务上下文的后端通用工具。 |
## 命名规则 ## 命名规则
- workspace 项目命名:`<domain>-admin`、`<domain>-portal` 或明确业务域名。 - workspace 项目命名:`<domain>-admin`、`<domain>-portal` 或明确业务域名。
......
...@@ -28,7 +28,7 @@ OpenSpec 负责“把行为变更固化为规范”:proposal、design、spec ...@@ -28,7 +28,7 @@ OpenSpec 负责“把行为变更固化为规范”:proposal、design、spec
应做事项: 应做事项:
- 读取项目上下文,例如 `.codex/AGENTS.md`、`README.md`、`.superpowers-memory/`、现有 docs、OpenSpec changes 和相关代码。 - 读取项目上下文,例如根目录 `AGENTS.md`、`README.md`、`.superpowers-memory/`、现有 docs、OpenSpec changes 和相关代码。
- 一次只问一个澄清问题。 - 一次只问一个澄清问题。
- 明确目标、非目标、约束、成功标准和风险。 - 明确目标、非目标、约束、成功标准和风险。
- 给出 2-3 个可选方案,说明取舍,并推荐一个。 - 给出 2-3 个可选方案,说明取舍,并推荐一个。
...@@ -110,6 +110,7 @@ openspec/changes/<change-name>/ ...@@ -110,6 +110,7 @@ openspec/changes/<change-name>/
- 写每个 artifact 前,先运行对应的 `openspec instructions`。 - 写每个 artifact 前,先运行对应的 `openspec instructions`。
- 按依赖顺序完成 `proposal.md`、`design.md`、`specs/.../spec.md`、`tasks.md`。 - 按依赖顺序完成 `proposal.md`、`design.md`、`specs/.../spec.md`、`tasks.md`。
- 使用 `openspec validate "<change-name>" --strict` 校验。 - 使用 `openspec validate "<change-name>" --strict` 校验。
- 如果 change 已存在,且用户后续新增问题、补充约束、要求调整方案或实现路径,先回到本阶段更新受影响的 OpenSpec artifacts 和 `tasks.md`。
- 用户确认 OpenSpec artifacts 后,才能进入编码。 - 用户确认 OpenSpec artifacts 后,才能进入编码。
退出条件: 退出条件:
...@@ -121,6 +122,7 @@ openspec/changes/<change-name>/ ...@@ -121,6 +122,7 @@ openspec/changes/<change-name>/
禁止事项: 禁止事项:
- OpenSpec artifacts 未完成前,不进入编码。 - OpenSpec artifacts 未完成前,不进入编码。
- change 已存在但 OpenSpec artifacts 和 `tasks.md` 尚未同步最新讨论结果、或尚未再次获得用户确认前,不进入编码。
- 不把命令输出里的 instruction metadata 直接复制到 artifact。 - 不把命令输出里的 instruction metadata 直接复制到 artifact。
- 不为无关重构创建混合 change。 - 不为无关重构创建混合 change。
...@@ -244,3 +246,60 @@ OpenSpec 已确认、准备实现时: ...@@ -244,3 +246,60 @@ OpenSpec 已确认、准备实现时:
```text ```text
检查代码、测试和 OpenSpec 是否对齐;如果对齐,归档 <change-name>。 检查代码、测试和 OpenSpec 是否对齐;如果对齐,归档 <change-name>。
``` ```
## 提示词举例
建议按“阶段 + 约束 + 产物”的方式写提示词。这样可以让 Agent 清楚知道当前是在探索、锁规范、实现,还是归档,也能避免过早写代码或遗漏验证。
| 场景 | 提示词模板 | 预期产物 |
| --- | --- | --- |
| 需求探索 | 使用 `$superpowers-openspec-execution-workflow`,先进入 Superpowers 探索阶段,不要写代码。需求是:`<需求描述>`。请先澄清边界、成功标准和风险,并给出 2-3 个方案。 | 需求边界、方案比较、推荐方案、待确认问题 |
| 设计确认 | 基于刚才的探索结论,整理一版设计确认稿。请明确目标、非目标、用户流程、关键状态、异常场景和后续 OpenSpec change name 建议。 | 设计说明、确认项、change name 建议 |
| 锁定规范 | 基于已确认设计,进入 OpenSpec 锁定规范阶段,change name 使用 `<change-name>`。请先运行 `openspec status` 和对应 `openspec instructions`,再创建 proposal、design、spec 和 tasks。 | OpenSpec artifacts、严格校验结果 |
| 执行实现 | 按 `<change-name>` 的 OpenSpec tasks 执行实现。请使用 TDD,逐项完成 tasks,完成前运行类型检查、测试、构建和必要的浏览器验证。 | 代码变更、测试、验证结果、tasks 更新 |
| 前后端协作 | 围绕 `<业务场景>` 先做前后端契约对齐。请输出页面字段、接口字段、状态枚举、错误码、Mock 数据和联调检查清单,不要先写后端实现。 | 契约草案、Mock 数据、联调清单 |
| 归档收尾 | 检查 `<change-name>` 的代码、测试、tasks 和长期 spec 是否一致;如果一致,执行 OpenSpec 归档,并同步必要的项目记忆。 | 归档后的 specs、change 状态、记忆更新 |
### 可直接复制的完整提示词
新功能从探索开始:
```text
使用 $superpowers-openspec-execution-workflow,先进入 Superpowers 探索阶段,不要写代码。
需求是:<这里写需求>。
请先读取项目规则和相关上下文,帮我明确:
1. 目标和非目标;
2. 关键用户流程;
3. 需要确认的问题;
4. 2-3 个可选方案及取舍;
5. 推荐方案和建议的 OpenSpec change name。
```
前后端契约先行:
```text
围绕 <业务场景> 做前后端协作设计,先不要实现。
请输出:
1. 前端页面字段和交互状态;
2. 后端接口列表、请求参数、响应字段;
3. 状态枚举、错误码和权限边界;
4. 前端 Mock 数据结构;
5. 联调检查清单;
6. 哪些内容需要进入 OpenSpec spec。
```
OpenSpec 到实现:
```text
基于已确认设计,进入 OpenSpec 锁定规范阶段,change name 使用 <change-name>。
请按顺序执行:
1. 运行 openspec status --change "<change-name>" --json;
2. 针对 proposal、design、spec、tasks 分别读取 openspec instructions;
3. 创建并完善 OpenSpec artifacts;
4. 运行 openspec validate "<change-name>" --strict;
5. 等我确认后,再按 tasks 使用 TDD 实现并运行验证。
```
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
- 定义默认前端技术栈、组件规则和页面协作规则。 - 定义默认前端技术栈、组件规则和页面协作规则。
- 将公司 Web 桌面端设计规范作为所有页面的 UI 基线。 - 将公司 Web 桌面端设计规范作为所有页面的 UI 基线。
- 定义后台页面的可复用组件使用规则。 - 定义后台页面的可复用组件使用规则。
- 定义使用 Codex + OpenSpec + Superpowers 的开发前工作流规则。 - 定义使用 OpenSpec + Superpowers 的开发前工作流规则。
- 记录阻塞业务实现的待确认需求问题。 - 记录阻塞业务实现的待确认需求问题。
- 本 change 仅覆盖前端与项目协作基线,不定义后端技术栈、数据库、队列、文件存储或接口契约。 - 本 change 仅覆盖前端与项目协作基线,不定义后端技术栈、数据库、队列、文件存储或接口契约。
...@@ -31,5 +31,5 @@ ...@@ -31,5 +31,5 @@
- 在 `architecture-spec/docs/` 下新增项目文档。 - 在 `architecture-spec/docs/` 下新增项目文档。
- 新增 OpenSpec 项目上下文和一个基线 change。 - 新增 OpenSpec 项目上下文和一个基线 change。
- 新增 `.superpowers-memory/` 文件,用于跨会话延续上下文。 - 新增 `.superpowers-memory/` 文件,用于跨会话延续上下文。
- 新增 `AGENTS.md`,用于约束本仓库中的 Codex 行为。 - 新增 `AGENTS.md`,用于约束本仓库中的 Agent 协作行为。
- 不新增任何业务实现代码。 - 不新增任何业务实现代码。
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
## 1. 文档 ## 1. 文档
- [x] 创建项目 README。 - [x] 创建项目 README。
- [x] 在 `AGENTS.md` 中创建 Codex 项目规则。 - [x] 在 `AGENTS.md` 中创建 Agent 项目规则。
- [x] 创建 OpenSpec 项目上下文。 - [x] 创建 OpenSpec 项目上下文。
- [x] 创建技术栈基线。 - [x] 创建技术栈基线。
- [x] 移除后端/API 强约定,保留前端页面协作基线。 - [x] 移除后端/API 强约定,保留前端页面协作基线。
......
...@@ -101,12 +101,24 @@ ...@@ -101,12 +101,24 @@
`Select` 与 `TreeSelect` SHALL 在选中后展示清晰选中态:触发器文字显示当前选中项,面板内对应项显示主色文字或浅主色背景,并暴露 `aria-selected`。树形节点展开后,父节点保持层级关系,叶子节点选中效果不得只依赖触发器文字。 `Select` 与 `TreeSelect` SHALL 在选中后展示清晰选中态:触发器文字显示当前选中项,面板内对应项显示主色文字或浅主色背景,并暴露 `aria-selected`。树形节点展开后,父节点保持层级关系,叶子节点选中效果不得只依赖触发器文字。
`Select` 在用户点击某个选项后 SHALL 立即关闭当前下拉面板,避免面板停留在页面上遮挡后续字段或操作区。该关闭行为对受控与非受控用法保持一致。
`Select` 的清空入口 SHALL 保持显式可配置。业务页面未开启 `allowClear` 时,组件不得在控件下方自动渲染独立 `清空` 按钮;当业务页面将“恢复默认值”设计为重新选择 `全部` 选项时,组件只负责展示当前值和下拉面板,不额外叠加第二套重置入口。
后台页面的左侧菜单 SHALL 通过共享导航组件承载,不允许在业务页面或布局文件中手写一级/二级菜单结构、父子级选中态和展开交互。导航组件需要支持后台常见的层级导航场景:一级菜单作为分组入口展示,二级菜单作为当前页面入口展示;当二级菜单选中时,其父级一级菜单同步展示轻度选中样式。
该导航组件应提供稳定的数据驱动接口,至少覆盖菜单项标识、标题、层级、图标槽位、链接目标、是否展开、当前选中项以及父级联动样式,保证后台框架只负责传入导航配置和路由状态,而不再手写具体 DOM 结构。
`TreeSelect` 的父节点 SHALL 支持点击展开与再次点击收起。父节点展开时展示子节点并将 `aria-expanded` 置为 `true`;再次点击同一父节点时隐藏子节点并将 `aria-expanded` 置为 `false`。 `TreeSelect` 的父节点 SHALL 支持点击展开与再次点击收起。父节点展开时展示子节点并将 `aria-expanded` 置为 `true`;再次点击同一父节点时隐藏子节点并将 `aria-expanded` 置为 `false`。
同一页面同时存在多个 `Select` 或 `TreeSelect` 时,选择类下拉框 SHALL 互斥打开。用户打开新的选择类下拉框时,当前页面中其他已打开的选择类下拉框 SHALL 自动关闭,避免多个下拉面板同时显示在界面上。 同一页面同时存在多个 `Select` 或 `TreeSelect` 时,选择类下拉框 SHALL 互斥打开。用户打开新的选择类下拉框时,当前页面中其他已打开的选择类下拉框 SHALL 自动关闭,避免多个下拉面板同时显示在界面上。
`Select` 与 `TreeSelect` 的下拉面板 SHALL 定位在触发输入框下方,并脱离普通文档流。下拉面板打开或关闭不应改变触发器宽度,也不应把后续表单项、按钮或 Demo 元素向下挤开。 `Select` 与 `TreeSelect` 的下拉面板 SHALL 定位在触发输入框下方,并脱离普通文档流。下拉面板打开或关闭不应改变触发器宽度,也不应把后续表单项、按钮或 Demo 元素向下挤开。
### 分页组件需要明确当前页和键盘跳转
`Pagination` SHALL 保持受控的 `current`、`pageSize` 和 `total` 语义。页码按钮中当前页 SHALL 通过 `aria-current="page"` 和可见选中样式同时表达状态,避免只具备语义标记而缺少视觉反馈。跳转输入框 SHALL 支持键盘提交,用户在输入目标页码后按 Enter 时,行为应与点击“跳转”按钮一致。
### 日期组件需符合桌面端面板结构 ### 日期组件需符合桌面端面板结构
`DatePicker` 与 `DateRangePicker` SHALL 使用桌面端日期面板结构:触发器显示日期值,面板包含月份标题、上一月/下一月箭头、星期标题、按周排列日期网格、选中日描边/主色状态、今天快捷入口和禁用日期状态。日期面板不应固定单月数据,需根据当前显示月份生成日期。 `DatePicker` 与 `DateRangePicker` SHALL 使用桌面端日期面板结构:触发器显示日期值,面板包含月份标题、上一月/下一月箭头、星期标题、按周排列日期网格、选中日描边/主色状态、今天快捷入口和禁用日期状态。日期面板不应固定单月数据,需根据当前显示月份生成日期。
...@@ -165,6 +177,18 @@ ...@@ -165,6 +177,18 @@
组件 Demo 路由 SHALL 在表格模块中展示至少一个空表格示例,确保人工验收时能直接看到表格内置空状态,而不是只看到独立 `Empty` 占位组件。 组件 Demo 路由 SHALL 在表格模块中展示至少一个空表格示例,确保人工验收时能直接看到表格内置空状态,而不是只看到独立 `Empty` 占位组件。
### 通用状态占位组件需要区分空态与失败态
组件库 SHALL 提供通用状态占位组件,命名为 `StatePlaceholder`。该组件用于页面内容区、表格内容区、抽屉内容区等需要表达“当前没有可展示内容或内容不可用”的位置,公开状态值覆盖 `empty`、`filtered-empty`、`error`、`forbidden` 和 `offline`。组件 SHALL 支持标题、说明、主操作、次操作、语义图标和可访问性角色;后续如业务页面需要更细的布局控制,可再扩展 `className`、`style` 或 CSS 变量。
`StatePlaceholder` SHALL 明确区分“请求成功但没有数据”和“请求失败导致数据未知”。空数据或筛选无结果可以使用“暂无数据”“未找到匹配结果”等文案;加载失败必须使用“加载失败”“数据加载失败,请重试”等失败文案,并提供可恢复操作,例如重试按钮。失败态 SHALL NOT 使用“暂无数据”作为主文案,避免误导用户认为接口已成功返回空结果。
列表页请求失败 SHALL 作为项目通用规则处理:任意后台列表、表格列表、卡片列表或资源列表在主数据请求失败且当前数据是否为空未知时,均使用 `StatePlaceholder state="error"` 承载内容区失败状态,并保留页面框架、筛选区、导航区和可恢复操作可用。列表请求失败 SHALL NOT 回退为 `Empty`、表格默认空态、“暂无数据”文案、`Alert` 或 `Message`。
`Empty` MAY 继续作为轻量空状态组件保留,用于请求成功后的简单无数据场景;`Table`、列表页和复杂页面 SHALL 通过 `StatePlaceholder` 统一承载可恢复失败、权限受限和筛选无结果等状态。`Alert` 和 `Message` 仍用于提示反馈,不替代内容区域的状态占位。
备选方案:继续使用 `Empty` 组件组合失败文案和重试按钮。该方案被拒绝作为长期方案,因为失败态、空态、筛选无结果和权限态语义不同,如果都复用 `Empty`,容易在业务页面中出现“加载失败却展示暂无数据”的误导性体验。
## Risks / Trade-offs ## Risks / Trade-offs
- [风险] 已上传设计规范中存在看起来像组件的 demo-only 代码。-> 缓解:本 change 只纳入独立组件文件;demo-only 组件后续单独确认。 - [风险] 已上传设计规范中存在看起来像组件的 demo-only 代码。-> 缓解:本 change 只纳入独立组件文件;demo-only 组件后续单独确认。
...@@ -182,6 +206,7 @@ ...@@ -182,6 +206,7 @@
- [风险] 日期弹窗打开后点击其他页面区域不关闭,用户需要重复点击触发器才能收起。-> 缓解:日期组件监听外部指针点击,触发器和弹窗内部点击保持正常交互,并补充外部点击关闭回归测试。 - [风险] 日期弹窗打开后点击其他页面区域不关闭,用户需要重复点击触发器才能收起。-> 缓解:日期组件监听外部指针点击,触发器和弹窗内部点击保持正常交互,并补充外部点击关闭回归测试。
- [风险] 日期弹窗固定宽度参与布局计算,导致日期输入框随弹窗宽度变宽。-> 缓解:日期组件使用独立定位容器,弹窗绝对定位,补充触发器宽度不受弹窗影响的回归测试。 - [风险] 日期弹窗固定宽度参与布局计算,导致日期输入框随弹窗宽度变宽。-> 缓解:日期组件使用独立定位容器,弹窗绝对定位,补充触发器宽度不受弹窗影响的回归测试。
- [风险] 表格空态只用纯文本时,业务页面需要额外手写空状态布局,导致视觉不一致。-> 缓解:`Table` 内置统一空状态插槽,并在 Demo 路由展示空表格验收样例。 - [风险] 表格空态只用纯文本时,业务页面需要额外手写空状态布局,导致视觉不一致。-> 缓解:`Table` 内置统一空状态插槽,并在 Demo 路由展示空表格验收样例。
- [风险] 业务页面把加载失败和暂无数据混为一类,导致用户误判数据真实为空。-> 缓解:新增 `StatePlaceholder` 语义状态规范,明确失败态必须展示失败文案和重试操作。
- [风险] `FormItem` 只展示必填星号但不执行校验,会让业务页面重复编写表单校验逻辑。-> 缓解:新增 `Form` 容器和 `FormItem rules`,由组件库统一处理基础必填校验与错误展示。 - [风险] `FormItem` 只展示必填星号但不执行校验,会让业务页面重复编写表单校验逻辑。-> 缓解:新增 `Form` 容器和 `FormItem rules`,由组件库统一处理基础必填校验与错误展示。
- [风险] 错误信息动态出现会造成表单布局跳动。-> 缓解:`FormItem` 为错误信息预留稳定区域,并通过布局样式保证错误文案不挤压后续元素。 - [风险] 错误信息动态出现会造成表单布局跳动。-> 缓解:`FormItem` 为错误信息预留稳定区域,并通过布局样式保证错误文案不挤压后续元素。
- [风险] `Upload` 容易被误解为真实上传 SDK。-> 缓解:组件库只提供 UI 形态和状态回调,不内置文件校验、接口传输、分片续传或预览弹层业务逻辑。 - [风险] `Upload` 容易被误解为真实上传 SDK。-> 缓解:组件库只提供 UI 形态和状态回调,不内置文件校验、接口传输、分片续传或预览弹层业务逻辑。
......
...@@ -8,6 +8,9 @@ ...@@ -8,6 +8,9 @@
- 仅纳入可复用 UI 组件,不处理 `App.tsx` 中声明的 demo-only 组件。 - 仅纳入可复用 UI 组件,不处理 `App.tsx` 中声明的 demo-only 组件。
- 将基础输入类组件继续扩展到 `Textarea`,并为 `Input` 与 `Textarea` 补充简洁长度显示能力。 - 将基础输入类组件继续扩展到 `Textarea`,并为 `Input` 与 `Textarea` 补充简洁长度显示能力。
- 纳入 `Upload` 组件族,包含文件拖拽上传与图片/视频媒体墙两种规范形态。 - 纳入 `Upload` 组件族,包含文件拖拽上传与图片/视频媒体墙两种规范形态。
- 补充通用状态占位组件,用于统一表达空数据、筛选无结果、加载失败、权限受限等页面或列表内容状态,并明确加载失败不得误用“暂无数据”。
- 补充可复用后台导航组件能力,承载一级/二级菜单、父子级选中态和层级结构,避免业务页面手写侧边菜单。
- 补齐 `Pagination` 的当前页可见选中态,以及跳转输入框按 Enter 直接触发跳转的键盘交互。
- 确认一期组件库使用 React、TypeScript、CSS Variables 与 CSS Modules / 普通 CSS 实现;组件内部不依赖 Tailwind CSS。 - 确认一期组件库使用 React、TypeScript、CSS Variables 与 CSS Modules / 普通 CSS 实现;组件内部不依赖 Tailwind CSS。
- 允许后续业务页面使用 Tailwind CSS 做页面级布局,但组件必须自带完整规范样式,并通过受控 API、`className`、`style` 和 CSS 变量支持扩展。 - 允许后续业务页面使用 Tailwind CSS 做页面级布局,但组件必须自带完整规范样式,并通过受控 API、`className`、`style` 和 CSS 变量支持扩展。
- 在保持当前目录结构不调整的前提下,将组件能力按全局可复用资产设计,避免绑定单一业务项目。 - 在保持当前目录结构不调整的前提下,将组件能力按全局可复用资产设计,避免绑定单一业务项目。
...@@ -27,6 +30,6 @@ ...@@ -27,6 +30,6 @@
## Impact ## Impact
- 影响前端组件架构和后续业务页面实现规则。 - 影响前端组件架构和后续业务页面实现规则。
- 预计涉及目标前端应用或 UI 包、共享 UI 组件导出、样式 token、组件测试工具链,以及组件 Demo 页路由。 - 预计涉及目标前端应用或 UI 包、共享 UI 组件导出、样式 token、状态占位组件、组件测试工具链,以及组件 Demo 页路由。
- 技术选型影响一期组件源码组织、样式实现方式、组件测试方式和后续业务页面使用边界。 - 技术选型影响一期组件源码组织、样式实现方式、组件测试方式和后续业务页面使用边界。
- 不引入后端 API、数据存储或业务流程变更。 - 不引入后端 API、数据存储或业务流程变更。
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
### Requirement: 一期组件库范围 ### Requirement: 一期组件库范围
系统 SHALL 基于已上传设计规范中的独立组件文件,提供一期 Web 桌面端 UI 组件库。 系统 SHALL 基于已上传设计规范中的独立组件文件,提供一期 Web 桌面端 UI 组件库。
一期范围 SHALL 包含 `Button`、`Input`、`Textarea`、`SearchInput`、`TreeSelect`、`Table`、`Badge`、`Pagination`、`Alert`、`Message`、`Modal`、`FormItem`、`Card`、`DatePicker`、`DateRangePicker`、`Switch`、`Tag`、`Avatar`、`AvatarGroup`、`Tooltip`、`Popconfirm`、`Progress`、`Statistic`、`Timeline`、`Tabs`、`Drawer`、`Steps`、`Checkbox`、`Radio`、`Select`、`Empty`、`Skeleton`、`SkeletonAvatar`、`SkeletonParagraph`、`SkeletonButton`、`SkeletonInput`、`Collapse`、`ColorPicker`、`ColorInput` 和 `Upload`。 一期范围 SHALL 包含 `Button`、`Input`、`Textarea`、`SearchInput`、`TreeSelect`、`Table`、`Badge`、`Pagination`、`Alert`、`Message`、`Modal`、`FormItem`、`Card`、`DatePicker`、`DateRangePicker`、`Switch`、`Tag`、`Avatar`、`AvatarGroup`、`Tooltip`、`Popconfirm`、`Progress`、`Statistic`、`Timeline`、`Tabs`、`Drawer`、`Steps`、`Checkbox`、`Radio`、`Select`、`Empty`、`StatePlaceholder`、`Skeleton`、`SkeletonAvatar`、`SkeletonParagraph`、`SkeletonButton`、`SkeletonInput`、`Collapse`、`ColorPicker`、`ColorInput` 和 `Upload`。
#### Scenario: 实现一期组件 #### Scenario: 实现一期组件
- **WHEN** 实现组件库 - **WHEN** 实现组件库
...@@ -81,6 +81,40 @@ ...@@ -81,6 +81,40 @@
- **WHEN** 组件支持禁用、加载、选中、激活、空状态或错误状态 - **WHEN** 组件支持禁用、加载、选中、激活、空状态或错误状态
- **THEN** 这些状态使用项目 Web 桌面端设计 token,并与已上传设计规范保持视觉一致 - **THEN** 这些状态使用项目 Web 桌面端设计 token,并与已上传设计规范保持视觉一致
### Requirement: Select 支持后台筛选工作流
`Select` SHALL 支持后台筛选类表单的标准交互,包括选择后自动收起,以及按业务决定是否展示独立清空入口。
#### Scenario: 选择后关闭下拉面板
- **WHEN** 用户在 `Select` 下拉面板中选择任一可用选项
- **THEN** 组件更新当前值
- **AND** 当前下拉面板立即关闭
#### Scenario: 未开启清空能力
- **WHEN** 业务页面未为 `Select` 开启 `allowClear`
- **THEN** 组件不展示独立的 `清空` 按钮
#### Scenario: 开启清空能力
- **WHEN** 业务页面为 `Select` 开启 `allowClear` 且当前已有选中值
- **THEN** 组件展示独立的 `清空` 按钮
- **AND** 用户点击后将当前值重置为空
### Requirement: Navigation 支持后台层级菜单
共享导航组件 SHALL 支持后台左侧层级菜单工作流,统一承载一级/二级菜单结构、父子级选中态和数据驱动渲染。
#### Scenario: 渲染一级和二级菜单
- **WHEN** 后台框架传入包含父子层级的导航数据
- **THEN** 组件渲染一级菜单项及其对应的二级菜单项
- **AND** 业务页面无需手写导航层级 DOM 结构
#### Scenario: 二级菜单激活时联动父级样式
- **WHEN** 当前选中项是某个一级菜单下的二级菜单
- **THEN** 该二级菜单展示主选中样式
- **AND** 对应一级菜单同步展示轻度选中样式
#### Scenario: 通过配置驱动导航
- **WHEN** 后台框架传入菜单项标识、标题、层级、链接和当前选中项
- **THEN** 组件根据配置渲染导航,而不是要求业务页面手写交互和样式逻辑
### Requirement: 组件实现采用测试先行 ### Requirement: 组件实现采用测试先行
组件实现 SHALL 采用 TDD 方式推进:在实现或迁移组件前,先为组件的公开行为、关键状态和可访问交互编写测试或可执行验收样例。 组件实现 SHALL 采用 TDD 方式推进:在实现或迁移组件前,先为组件的公开行为、关键状态和可访问交互编写测试或可执行验收样例。
...@@ -148,6 +182,61 @@ ...@@ -148,6 +182,61 @@
- **WHEN** 表格行存在可用操作 - **WHEN** 表格行存在可用操作
- **THEN** 表格可以在操作列中渲染紧凑操作控件 - **THEN** 表格可以在操作列中渲染紧凑操作控件
### Requirement: Pagination 支持当前页反馈和键盘跳转
分页组件 SHALL 在后台列表场景中明确展示当前页选中态,并支持跳转输入框的 Enter 键提交行为。
#### Scenario: 展示当前页
- **WHEN** 分页渲染当前页码
- **THEN** 当前页按钮 SHALL 展示可见选中态
- **AND** 当前页按钮 SHALL 暴露 `aria-current="page"`
#### Scenario: 按回车跳转
- **WHEN** 用户在跳转输入框输入目标页码并按下 Enter
- **THEN** 分页组件 SHALL 触发与点击“跳转”按钮一致的页码跳转行为
### Requirement: StatePlaceholder 统一内容状态占位
`StatePlaceholder` SHALL 作为组件库统一内容状态占位组件,覆盖空数据、筛选无结果、加载失败、权限受限和离线不可用等状态。
`StatePlaceholder` 的公开状态值 SHALL 使用 `empty`、`filtered-empty`、`error`、`forbidden` 和 `offline`。
项目内所有后台列表、表格列表、卡片列表或资源列表 SHALL 在主数据请求失败且当前数据是否为空未知时使用 `StatePlaceholder` 的 `error` 语义承载内容区失败状态。
#### Scenario: 展示空数据
- **WHEN** 请求成功且当前内容没有任何数据
- **THEN** `StatePlaceholder` 使用空状态语义展示“暂无数据”或业务自定义空态文案
#### Scenario: 展示筛选无结果
- **WHEN** 请求成功但当前搜索或筛选条件没有匹配结果
- **THEN** `StatePlaceholder` 使用 `filtered-empty` 语义展示“未找到匹配结果”或业务自定义文案,并允许业务侧提供清空筛选操作
#### Scenario: 展示加载失败
- **WHEN** 内容数据加载失败且当前数据是否为空未知
- **THEN** `StatePlaceholder` 使用 `error` 语义展示加载失败文案
- **AND** `StatePlaceholder` SHALL NOT 使用“暂无数据”作为失败态主文案
- **AND** `StatePlaceholder` 支持业务侧提供重试操作
#### Scenario: 列表请求失败
- **WHEN** 任意后台列表、表格列表、卡片列表或资源列表的主数据请求失败
- **THEN** 页面使用 `StatePlaceholder` 的 `error` 语义展示列表失败状态
- **AND** 页面保留框架、筛选区、导航区和重试操作可用
- **AND** 页面 SHALL NOT 使用 `Empty`、表格默认空态、“暂无数据”文案、`Alert` 或 `Message` 替代列表内容区失败状态
#### Scenario: 展示权限受限
- **WHEN** 当前账号没有访问内容的权限
- **THEN** `StatePlaceholder` 使用 `forbidden` 语义展示权限受限文案
#### Scenario: 展示离线不可用
- **WHEN** 当前内容因网络不可用无法加载
- **THEN** `StatePlaceholder` 使用 `offline` 语义展示网络不可用文案,并允许业务侧提供重试操作
#### Scenario: 嵌入表格内容区域
- **WHEN** 表格、列表或页面内容区需要展示可恢复失败状态
- **THEN** 业务页面可以在内容区域使用 `StatePlaceholder`,并保持页面框架、筛选区和导航区可用
#### Scenario: 区分反馈组件
- **WHEN** 页面需要表达内容区不可用或数据未知
- **THEN** 页面使用 `StatePlaceholder` 展示内容状态,而不是只使用 `Message` 或 `Alert` 替代内容占位
### Requirement: 反馈和浮层组件支持受控工作流 ### Requirement: 反馈和浮层组件支持受控工作流
反馈和浮层组件 SHALL 支持后台常见受控使用方式,包括提示、弹窗、抽屉、二次确认、悬浮说明,以及适用场景下的浮层内容。 反馈和浮层组件 SHALL 支持后台常见受控使用方式,包括提示、弹窗、抽屉、二次确认、悬浮说明,以及适用场景下的浮层内容。
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
- [x] 3.9 根据人工验收修正选择类下拉互斥:同一页面中 `Select` 与 `TreeSelect` 只能同时打开一个下拉面板,打开新的选择器时自动关闭旧面板,并补充回归测试。 - [x] 3.9 根据人工验收修正选择类下拉互斥:同一页面中 `Select` 与 `TreeSelect` 只能同时打开一个下拉面板,打开新的选择器时自动关闭旧面板,并补充回归测试。
- [x] 3.10 根据人工验收修正选择类下拉定位:`Select` 与 `TreeSelect` 下拉面板定位在触发器下方并脱离文档流,不挤压下面元素,补充样式回归测试。 - [x] 3.10 根据人工验收修正选择类下拉定位:`Select` 与 `TreeSelect` 下拉面板定位在触发器下方并脱离文档流,不挤压下面元素,补充样式回归测试。
- [x] 3.11 根据人工验收修正 `TreeSelect` 父节点收起交互:再次点击已展开父节点时收起子节点并更新箭头与 `aria-expanded`,补充回归测试。 - [x] 3.11 根据人工验收修正 `TreeSelect` 父节点收起交互:再次点击已展开父节点时收起子节点并更新箭头与 `aria-expanded`,补充回归测试。
- [ ] 3.12 根据人工验收补齐 `Select` 后台筛选交互:选中选项后自动收起下拉面板,并确认 `allowClear` 关闭时不展示独立 `清空` 按钮,补充回归测试。
## 4. 日期组件 ## 4. 日期组件
...@@ -57,6 +58,7 @@ ...@@ -57,6 +58,7 @@
- [x] 5.3 实现 `Table` 状态逻辑:完成 loading、empty、排序、筛选、行选择和操作列逻辑,并补齐单元测试、审核注释。 - [x] 5.3 实现 `Table` 状态逻辑:完成 loading、empty、排序、筛选、行选择和操作列逻辑,并补齐单元测试、审核注释。
- [x] 5.4 实现 `Table` 样式:完成表头、行 hover、选择列、操作列、loading 蒙层和空状态样式,并补齐渲染测试和审核注释。 - [x] 5.4 实现 `Table` 样式:完成表头、行 hover、选择列、操作列、loading 蒙层和空状态样式,并补齐渲染测试和审核注释。
- [x] 5.5 实现 `Pagination`:包含接口定义、页码/每页条数/总数/跳页逻辑、分页样式、单元测试、审核注释。 - [x] 5.5 实现 `Pagination`:包含接口定义、页码/每页条数/总数/跳页逻辑、分页样式、单元测试、审核注释。
- [ ] 5.5a 根据人工验收补齐 `Pagination` 当前页选中态与键盘跳转:当前页按钮展示明显选中态,跳转输入框按 Enter 触发页码跳转,并补充回归测试和审核注释。
- [x] 5.6 验证 `Table` 与 `Pagination`、`Tag`、`Badge`、`Button`、`Popconfirm` 的组合示例和审核注释。 - [x] 5.6 验证 `Table` 与 `Pagination`、`Tag`、`Badge`、`Button`、`Popconfirm` 的组合示例和审核注释。
- [x] 5.7 根据人工验收增强 `Table` 空状态:保留 `emptyText` 兼容,新增可配置 `empty` 插槽,默认复用统一空状态视觉,并在 Demo 表格模块展示空表格样例,补充回归测试和审核注释。 - [x] 5.7 根据人工验收增强 `Table` 空状态:保留 `emptyText` 兼容,新增可配置 `empty` 插槽,默认复用统一空状态视觉,并在 Demo 表格模块展示空表格样例,补充回归测试和审核注释。
...@@ -100,6 +102,9 @@ ...@@ -100,6 +102,9 @@
- [x] 8.4 实现 `Skeleton` 基础组件:包含接口定义、形状/尺寸/动画逻辑、骨架样式、单元测试、审核注释。 - [x] 8.4 实现 `Skeleton` 基础组件:包含接口定义、形状/尺寸/动画逻辑、骨架样式、单元测试、审核注释。
- [x] 8.5 实现 `SkeletonAvatar`、`SkeletonParagraph`、`SkeletonButton` 和 `SkeletonInput`:包含接口定义、组合逻辑、形态样式、单元测试、审核注释。 - [x] 8.5 实现 `SkeletonAvatar`、`SkeletonParagraph`、`SkeletonButton` 和 `SkeletonInput`:包含接口定义、组合逻辑、形态样式、单元测试、审核注释。
- [x] 8.6 根据人工验收统一 `Collapse` 等展开箭头:与选择类组件复用同一箭头图标资产,补充样式回归测试。 - [x] 8.6 根据人工验收统一 `Collapse` 等展开箭头:与选择类组件复用同一箭头图标资产,补充样式回归测试。
- [x] 8.7 实现 `StatePlaceholder` 基础接口与请求失败态:支持 `error` 状态、标题、说明、主操作、次操作、图标、可访问性角色、单元测试和审核注释,并确保失败态不使用“暂无数据”文案。
- [ ] 8.8 补齐 `StatePlaceholder` 其他语义状态验收:覆盖 `empty`、`filtered-empty`、`forbidden` 和 `offline` 的专项测试,确认默认标题、说明、角色和样式语义符合规范。
- [ ] 8.9 扩展共享 `Navigation` 组件以支持后台侧边导航:覆盖一级/二级菜单、父子级选中态、数据驱动渲染,补充单元测试、Demo 示例和审核注释。
## 9. 颜色能力组件 ## 9. 颜色能力组件
...@@ -119,6 +124,8 @@ ...@@ -119,6 +124,8 @@
- [x] 10.7 根据人工验收完善 `Button` Demo:在基础交互模块展示全部按钮类型、尺寸、loading、disabled 和图标场景,补充 Demo 回归测试。 - [x] 10.7 根据人工验收完善 `Button` Demo:在基础交互模块展示全部按钮类型、尺寸、loading、disabled 和图标场景,补充 Demo 回归测试。
- [x] 10.8 根据人工确认新增 `Upload` Demo:展示文件拖拽上传完成、上传中、失败状态,以及图片/视频媒体墙,补充 Demo 回归测试。 - [x] 10.8 根据人工确认新增 `Upload` Demo:展示文件拖拽上传完成、上传中、失败状态,以及图片/视频媒体墙,补充 Demo 回归测试。
- [x] 10.9 根据人工确认补齐基础输入 Demo:展示 `Input` 与 `Textarea` 的简洁长度显示配置,补充 Demo 回归测试。 - [x] 10.9 根据人工确认补齐基础输入 Demo:展示 `Input` 与 `Textarea` 的简洁长度显示配置,补充 Demo 回归测试。
- [x] 10.10 补齐 `StatePlaceholder` 请求失败 Demo:展示加载失败状态,并覆盖加载失败提供重试操作、不展示“暂无数据”的验收样例。
- [ ] 10.11 补齐 `StatePlaceholder` 全状态 Demo:展示空数据、筛选无结果、权限受限和离线不可用状态,便于人工验收全部状态占位视觉。
## 10A. 上传组件 ## 10A. 上传组件
...@@ -133,3 +140,4 @@ ...@@ -133,3 +140,4 @@
- [x] 11.3 如果目标项目存在额外测试命令,运行相关自动化测试。 - [x] 11.3 如果目标项目存在额外测试命令,运行相关自动化测试。
- [ ] 11.4 启动前端应用,并在浏览器中验证独立组件 Demo 路由的布局、交互和设计一致性。 - [ ] 11.4 启动前端应用,并在浏览器中验证独立组件 Demo 路由的布局、交互和设计一致性。
- [ ] 11.5 确认 Demo 路由展示全部一期组件,并纳入 `Upload`,同时排除其他 `App.tsx` 中的 demo-only 组件。 - [ ] 11.5 确认 Demo 路由展示全部一期组件,并纳入 `Upload`,同时排除其他 `App.tsx` 中的 demo-only 组件。
- [x] 11.6 后续验证 `StatePlaceholder` 可在表格或列表内容区域承载失败态,并保持页面框架、筛选区和导航区可用。
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
## 目标 ## 目标
建设一个可承载多个项目的独立 monorepo 工作区。当前优先沉淀前端规则、公司 Web 桌面端组件规范和 Codex + OpenSpec + Superpowers 工作流。首个业务项目是 AI 大模型后台管理平台,用于支持 Agent 管理、Agent 群管理、官网展示配置及相关运营工作流。 建设一个可承载多个项目的独立 monorepo 工作区。当前优先沉淀前端规则、公司 Web 桌面端组件规范和 OpenSpec + Superpowers 工作流。首个业务项目是 AI 大模型后台管理平台,用于支持 Agent 管理、Agent 群管理、官网展示配置及相关运营工作流。
## 流程 ## 流程
......
from app.api.v1.endpoints import agents, position_tags, agent_group_helper, agent_hub
__all__ = ["agents", "position_tags", "agent_group_helper", "agent_hub"]
...@@ -16,3 +16,4 @@ api_router.include_router(official_site_agent_display.router, tags=["official-si ...@@ -16,3 +16,4 @@ api_router.include_router(official_site_agent_display.router, tags=["official-si
api_router.include_router(official_site_upload.router, tags=["official-site-upload"]) api_router.include_router(official_site_upload.router, tags=["official-site-upload"])
api_router.include_router(official_site_home.router, tags=["official-site-home"]) api_router.include_router(official_site_home.router, tags=["official-site-home"])
api_router.include_router(methodology.router, tags=["methodology"]) api_router.include_router(methodology.router, tags=["methodology"])
api_router.include_router(agent_hub.router, prefix="/api/v1/chat", tags=["chat"])
from app.config.loader import ConfigLoader, ConfigLoadError
from app.config.settings import Settings, ModelConfig, AgentConfig, SkillConfig
__all__ = ["ConfigLoader", "ConfigLoadError", "Settings", "ModelConfig", "AgentConfig", "SkillConfig"]
...@@ -3,9 +3,15 @@ from sqlalchemy import create_engine ...@@ -3,9 +3,15 @@ from sqlalchemy import create_engine
import os import os
# 数据库连接配置,实际开发中应从 config 读取 # 数据库连接配置,实际开发中应从 config 读取
SQLALCHEMY_DATABASE_URL = os.getenv("DATABASE_URL", "mysql+pymysql://root:123456@localhost:3306/agent_admin?charset=utf8mb4") SQLALCHEMY_DATABASE_URL = os.getenv(
"DATABASE_URL",
"sqlite:///./dev.db"
)
engine = create_engine(SQLALCHEMY_DATABASE_URL) engine = create_engine(
SQLALCHEMY_DATABASE_URL,
connect_args={"check_same_thread": False} if SQLALCHEMY_DATABASE_URL.startswith("sqlite") else {}
)
SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine) SessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
Base = declarative_base() Base = declarative_base()
......
import os
from pathlib import Path
from contextlib import asynccontextmanager
from fastapi import FastAPI from fastapi import FastAPI
from app.api.v1.router import api_router from app.api.v1.router import api_router
from app.config.loader import ConfigLoader
from app.service.session_service import SessionService
from app.service.im_service import IMService
from app.service.console_im_service import ConsoleIMService
from app.service.agent_hub import AgentHub
from app.service.skill_scanner import update_skills_json
from app.infrastructure.database import SessionLocal, engine
from app.model.session import Base
app = FastAPI(title="Agent管理后台 API", version="1.0.0") agent_hub_instance = None
@asynccontextmanager
async def lifespan(app: FastAPI):
global agent_hub_instance
Base.metadata.create_all(bind=engine)
# 启动时扫描 skills 目录,生成 skills.json 索引缓存
skills_dir = Path(__file__).parent.parent / "skills"
config_dir = Path(__file__).parent.parent / "config"
update_skills_json(skills_dir, config_dir)
config_loader = ConfigLoader()
db = SessionLocal()
session_service = SessionService(db)
if os.getenv("USE_CONSOLE_IM", "true").lower() == "true":
im_service = ConsoleIMService()
print("[startup] 使用 ConsoleIMService — hook 输出将打印到控制台")
else:
im_service = IMService(
base_url=os.getenv("IM_BASE_URL", "http://localhost:8080"),
api_key=os.getenv("IM_API_KEY", "your-api-key")
)
print(f"[startup] 使用 IMService → {os.getenv('IM_BASE_URL', 'http://localhost:8080')}")
agent_hub_instance = AgentHub(
config_loader=config_loader,
session_service=session_service,
im_service=im_service
)
yield
if agent_hub_instance:
await agent_hub_instance.close()
app = FastAPI(title="Agent管理后台 API", version="1.0.0", lifespan=lifespan)
app.include_router(api_router) app.include_router(api_router)
@app.get("/health") @app.get("/health")
def health_check(): def health_check():
return {"status": "ok"} return {"status": "ok"}
if __name__ == "__main__":
import uvicorn
uvicorn.run("app.main:app", host="0.0.0.0", port=8000, reload=True)
from app.model.agent import Agent, AgentPosition, AgentSkill, AgentStatus
from app.model.session import Session, SessionMessage, SessionStatus
__all__ = [
"Agent", "AgentPosition", "AgentSkill", "AgentStatus",
"Session", "SessionMessage", "SessionStatus"
]
from app.schema.agent import AgentCreate, AgentUpdate, AgentStatusUpdate, AgentDetailResponse
from app.schema.session import SessionResponse, MessageSchema
__all__ = [
"AgentCreate", "AgentUpdate", "AgentStatusUpdate", "AgentDetailResponse",
"SessionResponse", "MessageSchema"
]
from app.service.agent_service import AgentService
from app.service.session_service import SessionService
from app.service.im_service import IMService, IMServiceError
from app.service.agent_hub import AgentHub, AgentHubError
__all__ = ["AgentService", "SessionService", "IMService", "IMServiceError", "AgentHub", "AgentHubError"]
...@@ -20,15 +20,10 @@ ...@@ -20,15 +20,10 @@
需求沉淀: 需求沉淀:
- [前端范围与确认决策](./frontend-scope-and-decisions.md)
- [后台登录页需求沉淀](./requirements-admin-login.md) - [后台登录页需求沉淀](./requirements-admin-login.md)
- [Agent 管理需求沉淀](./requirements-agent-management.md) - [Agent 管理需求沉淀](./requirements-agent-management.md)
- [Agent 群管理需求沉淀](./requirements-agent-group-management.md) - [Agent 群管理需求沉淀](./requirements-agent-group-management.md)
- [官网配置与 H5 展示需求沉淀](./requirements-official-site-config.md) - [官网配置与 H5 展示需求沉淀](./requirements-official-site-config.md)
- [官网 H5 前端需求交互确认内容](./frontend-h5-official-site-interaction-confirmation.md)
- [PC 管理后台整体框架与布局确认内容](./frontend-pc-admin-framework-layout-confirmation.md)
- [后端接口文档对齐待确认事项](./backend-api-alignment-open-questions.md)
- [前端待确认事项](./frontend-open-questions.md)
当前阶段只做需求确认、前端规范落地和 OpenSpec 草案准备。确认完成后,再为具体功能创建对应端的 OpenSpec change:管理后台前端放 `web/openspec/changes/`,官网 H5 放 `single-page/openspec/changes/`。 当前阶段只做需求确认、前端规范落地和 OpenSpec 草案准备。确认完成后,再为具体功能创建对应端的 OpenSpec change:管理后台前端放 `web/openspec/changes/`,官网 H5 放 `single-page/openspec/changes/`。
......
# 前端待确认事项
更新时间:2026-05-15
当前 PRD 已基本完成需求边界收敛。以下为进入 OpenSpec 前建议再确认的前端细节,不阻塞需求沉淀。
## 页面与交互
1. 删除 Agent、删除官网 Tab、停用活码等高影响操作是否统一使用二次确认 Modal。
2. 文件上传是否已有统一组件,包括进度、失败重试、格式校验和大小校验。
已确认:后台管理页本期需要登录页,由前端写死账号密码校验,不调用接口;权限仍按管理员单角色处理。
已确认:登录成功后的默认落点为 `Agent管理 > Agent列表`;如果未登录访问业务页面,登录成功后优先回到原访问路径。
已确认:Skill 说明使用抽屉展示 Markdown,支持基础 Markdown 渲染、代码块样式、抽屉内部滚动、加载态、失败态和空态;本期不要求目录和代码块复制。
## H5 展示
1. H5 Banner 的汽车飞驰背景图由设计提供、运营上传,还是前端内置静态资源。
2. 渠道活码图片加载失败时,前台 H5 展示的占位图和文案是否需要设计确认。
3. MP4 不静音自动播放在移动端浏览器可能受系统策略限制,是否接受降级为用户手势后播放。
4. H5 无埋点已确认,但是否需要基础错误日志或资源加载失败日志仍可由研发另行决定。
## 联调契约
1. API 契约由研发独立维护。前端 OpenSpec 前仍需要拿到字段、枚举、分页、错误码、上传返回值和 mock 数据。
2. 后端运行时异常流不由前端实现,但如果管理后台需要展示异常状态,需要后端提供状态字段和文案。
3. 渠道活码图片 URL 的过期策略、鉴权方式、跨域策略需要在联调契约中明确。
# 前端范围与确认决策
更新时间:2026-05-15
## 文档来源
| 模块 | 飞书文档 | 已读取版本 |
|-|-|-|
| Agent 管理 | `PyimdH3hioAaY4xL8GTcOcoTnUf` | revision 60 |
| Agent 群管理 | `OZR8dSxJEox0eBxnV2fcmTWyn0f` | revision 32 |
| 官网配置 | `FYN4d3Nbro8a0XxnBCecLK5mn5d` | revision 24 |
## 产品定位
产品后台名称统一为「岗位Agent管理后台」。
PRD 标题、H5 Banner、项目文件命名和页面展示文案均以「岗位Agent管理后台」为准,不再使用「智享车生活」作为后台产品名称。
## 前端边界
当前需求沉淀只覆盖前端范围:
- `web/`:岗位Agent管理后台,包含前端本地登录页、Agent 管理、Agent 群管理、官网配置后台。
- `single-page/`:官网移动端 H5 展示,包含岗位 Tab、渠道活码展示、Agent 卡片、方法论模块。
- 前端契约草案:页面需要的字段、枚举、状态、校验、空态、错误态、loading 态和 mock 数据。
## 后端边界
以下内容归属后端范围,本前端需求沉淀不展开实现设计:
- 管家 Agent 运行时路由、记忆、多模态处理。
- 嘀加企微管家 API 对接、企微建群、拉人、解散群、异常推送。
- 后端接口实现、数据表、任务、队列、错误码实现。
前端文档中只把这些能力作为「依赖后端返回的数据或状态」描述。
## 已确认决策
1. 本期交付范围为管理后台前端和官网移动端 H5 展示。管家 Agent 路由、记忆、多模态处理归属后端运行时能力,前端只展示和配置相关界面。
2. 权限统一收窄为管理员。前端页面按管理员单角色设计,不做多角色差异化。
3. 非管家 Agent 可直接删除。删除弹窗文案使用「删除后系统将执行以下操作」,展示 4 条执行项。
4. 群模板概念删除。后续建群均按建群当时的岗位与 Agent 状态实时查询企微员工清单。
5. 同岗位仅允许创建一个渠道活码,启用和停用状态均占用唯一名额。同岗位已有活码时只能编辑原活码。
6. 渠道活码停用仅受「展示中的」官网 Tab 阻止。已下架 Tab 仍可关联活码,但不阻止活码停用。
7. 官网 Tab 可删除。删除后清理该 Tab 下 Agent 展示配置,不影响 Agent 原始数据和渠道活码。
8. 二维码来源为嘀加 API 返回后由后台转存或提供访问 URL,H5 前端只负责渲染图片,不在前端生成二维码。
9. Agent 展示素材移动端约束:GIF/MP4、最大 20MB、推荐 1:1、进入视口自动播放、MP4 循环播放、不静音、不需要封面、加载失败展示占位图。
10. 异常流第一版不重试,由后端记录并推送运维人工处理。前端只按后端状态展示。
11. API 契约不在 PRD 定义,由研发独立维护;前端阶段先沉淀页面字段和 mock 数据。
12. C 端 H5 前台不采集任何埋点。后台管理页面按 PRD 采集页面打开及少量指定操作事件。
13. 管理后台登录页本期由前端写死账号密码校验,不调用后端接口。固定账号为 `admin`,固定密码为 `123456`。
## 后续文档原则
- 不进入业务代码实现。
- 不创建或维护 `backend/` 设计文档。
- 不进入 OpenSpec,直到需求确认完成。
- 如果需要表达联调边界,先写前端需要的字段、枚举、页面状态和 mock 示例。
...@@ -4,13 +4,21 @@ ...@@ -4,13 +4,21 @@
## 文档定位 ## 文档定位
本文档记录「广联岗位Agent」官网 H5 前台展示页的前端需求与交互确认内容,便于后续 `single-page/` 项目开发对齐。 本文档记录「广联Agent」官网 H5 前台展示页的前端需求与交互确认内容,便于后续 `single-page/` 项目开发对齐。
当前阶段只确认 H5 端展示和交互规则。PC 端展示规范后续补充。 当前阶段只确认 H5 端展示和交互规则。PC 端展示规范后续补充。
## 项目范围确认
- `workspace/agent-admin/single-page` 负责官网移动端 H5。
- `single-page/` 产品名称统一为「广联Agent」。
- 本文档只约束 H5 端范围,不讨论后端接口实现、数据库、队列、任务和运行时能力。
- `web/` 管理后台前端的范围和规则以 `web/docs` 下的文档为准。
- H5 前台不采集任何埋点。
## 页面目标 ## 页面目标
官网 H5 前台展示页用于展示「广联岗位Agent」的岗位化智能服务体系。 官网 H5 前台展示页用于展示「广联Agent」的岗位化智能服务体系。
页面优先帮助用户建立“岗位 Agent 体系”的认知,再通过岗位体验入口引导用户扫码添加专属服务助手。 页面优先帮助用户建立“岗位 Agent 体系”的认知,再通过岗位体验入口引导用户扫码添加专属服务助手。
...@@ -32,7 +40,7 @@ PC 端展示规范后续补充,不在本文档展开。 ...@@ -32,7 +40,7 @@ PC 端展示规范后续补充,不在本文档展开。
Banner 内容全部来源于接口,包括标题、副标题、背景图等信息。 Banner 内容全部来源于接口,包括标题、副标题、背景图等信息。
主标题展示接口返回内容,当前确认标题为:`广联岗位Agent`。 主标题展示接口返回内容,当前确认标题为:`广联Agent`。
副标题展示接口返回内容,示例为:`AI驱动的智能销售服务体系`。 副标题展示接口返回内容,示例为:`AI驱动的智能销售服务体系`。
...@@ -139,4 +147,3 @@ Banner 图片缺失时需展示占位背景,保证页面可正常访问。 ...@@ -139,4 +147,3 @@ Banner 图片缺失时需展示占位背景,保证页面可正常访问。
PC 端展示效果后续补充。 PC 端展示效果后续补充。
当前阶段仅确认该页面需要兼容 PC 端访问。PC 端布局规则、模块排列和视觉细节将在后续单独补充。 当前阶段仅确认该页面需要兼容 PC 端访问。PC 端布局规则、模块排列和视觉细节将在后续单独补充。
...@@ -45,6 +45,12 @@ npm run build ...@@ -45,6 +45,12 @@ npm run build
- `/`:重定向到 `/components`。 - `/`:重定向到 `/components`。
- `/components`:UI 组件 Demo 承载路由。 - `/components`:UI 组件 Demo 承载路由。
目录演进原则:
- 当前优先保持 `src/App.tsx` 统一注册路由、`src/routes/` 存页面的模式。
- 菜单数量增加本身不构成重构理由,只有路由守卫、动态菜单、嵌套路由和路由元信息管理等复杂度上升时,才评估拆出 `src/router/`。
- 若后续需要演进,优先先抽路由配置和守卫,再考虑页面目录调整。
项目文档: 项目文档:
- [前端地基](./docs/frontend-foundation.md) - [前端地基](./docs/frontend-foundation.md)
......
...@@ -8,6 +8,14 @@ ...@@ -8,6 +8,14 @@
当前阶段不把这些规则上升为 monorepo 全局前端地基。后续只有在多个项目复用并验证稳定后,再迁移或沉淀到 `architecture-spec/docs/architecture/`。 当前阶段不把这些规则上升为 monorepo 全局前端地基。后续只有在多个项目复用并验证稳定后,再迁移或沉淀到 `architecture-spec/docs/architecture/`。
## 1.1 项目范围确认
- `workspace/agent-admin/web` 负责管理后台前端。
- `workspace/agent-admin/single-page` 负责官网移动端 H5。
- `web/` 产品名称统一为「岗位Agent管理后台」。
- 本文档只约束 `web/` 项目,不讨论后端接口实现、数据库、队列、任务和运行时能力。
- `single-page/` 的范围、命名和页面规则以 `single-page/docs` 下的文档为准。
## 2. 当前边界 ## 2. 当前边界
本项目当前负责岗位Agent管理后台 Web 页面: 本项目当前负责岗位Agent管理后台 Web 页面:
...@@ -58,6 +66,9 @@ Tailwind CSS 暂不作为本项目已启用能力。后续如业务页面确有 ...@@ -58,6 +66,9 @@ Tailwind CSS 暂不作为本项目已启用能力。后续如业务页面确有
- `/components` 当前作为组件 Demo 路由。 - `/components` 当前作为组件 Demo 路由。
- 后续业务页面应按模块进入 `src/routes/<module>/`,再由统一路由入口注册。 - 后续业务页面应按模块进入 `src/routes/<module>/`,再由统一路由入口注册。
- 管理后台页面默认使用项目基础布局,不在单个页面里重复实现侧边导航、顶部区域和基础内容容器。 - 管理后台页面默认使用项目基础布局,不在单个页面里重复实现侧边导航、顶部区域和基础内容容器。
- 当前阶段优先采用 `src/App.tsx` 统一注册路由、`src/routes/` 存页面的模式,不因为菜单数量增加就提前重构目录。
- 当路由守卫、动态菜单、嵌套路由、路由元信息管理等路由治理复杂度明显上升时,再按实际业务需要评估是否拆出 `src/router/`。
- 路由结构演进遵循“先抽路由配置/守卫,再调整页面目录”的原则,尽量避免一次性迁移页面和路由两层职责。
## 6. 组件使用规则 ## 6. 组件使用规则
...@@ -78,6 +89,8 @@ Tailwind CSS 暂不作为本项目已启用能力。后续如业务页面确有 ...@@ -78,6 +89,8 @@ Tailwind CSS 暂不作为本项目已启用能力。后续如业务页面确有
破坏性操作默认使用二次确认。表单字段错误显示在字段附近,非字段错误可使用全局反馈。 破坏性操作默认使用二次确认。表单字段错误显示在字段附近,非字段错误可使用全局反馈。
后台管理页面的埋点规则以对应需求文档和页面确认文档为准,当前只采集页面打开及少量指定操作事件。
## 8. 测试与验证规则 ## 8. 测试与验证规则
修改本项目代码时,至少按影响范围运行: 修改本项目代码时,至少按影响范围运行:
...@@ -91,4 +104,3 @@ npm run build ...@@ -91,4 +104,3 @@ npm run build
新增或修改页面交互时,应优先补充 Vitest + React Testing Library 测试。无法合理自动化覆盖的布局和关键交互,需要通过浏览器验证记录结果。 新增或修改页面交互时,应优先补充 Vitest + React Testing Library 测试。无法合理自动化覆盖的布局和关键交互,需要通过浏览器验证记录结果。
本文档本身只整理项目级规范,不改变页面功能代码。 本文档本身只整理项目级规范,不改变页面功能代码。
...@@ -13,11 +13,11 @@ ...@@ -13,11 +13,11 @@
}, },
"dependencies": { "dependencies": {
"@vitejs/plugin-react": "^5.1.2", "@vitejs/plugin-react": "^5.1.2",
"vite": "^7.3.0",
"typescript": "^5.9.3",
"react": "^19.2.3", "react": "^19.2.3",
"react-dom": "^19.2.3", "react-dom": "^19.2.3",
"react-router-dom": "^7.10.1" "react-router-dom": "^7.10.1",
"typescript": "^5.9.3",
"vite": "^7.3.0"
}, },
"devDependencies": { "devDependencies": {
"@testing-library/jest-dom": "^6.9.1", "@testing-library/jest-dom": "^6.9.1",
...@@ -25,7 +25,10 @@ ...@@ -25,7 +25,10 @@
"@types/node": "^25.0.1", "@types/node": "^25.0.1",
"@types/react": "^19.2.7", "@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3", "@types/react-dom": "^19.2.3",
"autoprefixer": "^10.5.0",
"jsdom": "^27.3.0", "jsdom": "^27.3.0",
"postcss": "^8.5.15",
"tailwindcss": "^3.4.17",
"vitest": "^4.0.15" "vitest": "^4.0.15"
} }
} }
...@@ -134,6 +134,66 @@ type JobTagOption = Pick<JobTagListItem, "tag_id" | "name" | "code">; ...@@ -134,6 +134,66 @@ type JobTagOption = Pick<JobTagListItem, "tag_id" | "name" | "code">;
### 4.1 Agent 列表 ### 4.1 Agent 列表
#### 4.1.1 本期前端 mock 最小契约
`add-admin-login-agent-list-mock` 切片在没有后端接口的情况下,先使用前端本地 mock 数据驱动 Agent 管理列表页。该 mock 契约只覆盖当前列表页、筛选控件、分页和行操作需要的页面字段,不约束后端存储、鉴权、运行时 Agent 能力或真实接口字段。
```ts
type AgentStatus = "enable" | "disable";
type AgentAction = "edit" | "enable" | "disable" | "delete";
interface AgentPositionOption {
/** 稳定岗位选项 ID,用于前端筛选。 */
id: string;
/** 岗位展示名称。 */
name: string;
}
interface AgentListMockItem {
/** Agent 标识。 */
agent_id: number;
/** Agent 展示名称。 */
name: string;
/** 是否为管家 Agent。 */
is_manager: boolean;
/** 普通 Agent 的岗位列表;管家 Agent 前端固定展示为「系统调度」。 */
positions: AgentPositionOption[];
/** Agent 状态。 */
status: AgentStatus;
/** 已绑定群数量。 */
bound_group_count: number;
/** 已绑定 Skill 数量;管家 Agent 列表展示为 `-`。 */
bound_skill_count: number;
/** 更新时间展示字符串。 */
updated_at: string;
/** 当前行可展示的操作。 */
available_actions: AgentAction[];
}
```
本期 fixture 至少覆盖:
| fixture | 场景 |
|-|-|
| `normal` | 正常列表,包含管家 Agent 和普通 Agent。 |
| `managerOnly` | 仅管家 Agent。 |
| `empty` | 初始无数据。 |
| `filteredEmpty` | 筛选无结果。 |
| `loading` | 列表加载中。 |
| `error` | 列表加载失败。 |
| `longText` | 长文本列表项。 |
| `disabledActions` | 不可用操作或受限操作。 |
| `paginationBoundary` | 分页边界。 |
页面规则:
- 管家 Agent 必须保持可见,并排序在普通 Agent 之前。
- 管家 Agent 岗位展示为「系统调度」,不展示绑定 Skill 数值。
- 失败态使用 `StatePlaceholder state="error"`,不得用“暂无数据”作为主文案。
- 删除普通 Agent 前展示确认文案:该 Agent 的企微员工会从所有已关联群中退出、官网展示配置会被清理、渠道活码 Agent 列表中不再出现该 Agent、关联的岗位标签不受影响。
#### 4.1.2 后续接口草案
`GET /api/v1/agents` `GET /api/v1/agents`
查询参数: 查询参数:
......
...@@ -11,6 +11,69 @@ export interface TabsItem { ...@@ -11,6 +11,69 @@ export interface TabsItem {
children?: ReactNode; children?: ReactNode;
} }
export interface NavigationItem {
key: string;
label: ReactNode;
disabled?: boolean;
children?: NavigationItem[];
}
export interface NavigationProps {
/** Navigation 通过受控 activeKey 承载后台层级菜单,业务侧只传配置和路由状态。 */
activeKey?: string;
items: NavigationItem[];
ariaLabel?: string;
onChange?: (key: string) => void;
}
export function Navigation({ activeKey, ariaLabel = '导航', items, onChange }: NavigationProps) {
return (
<nav className={styles.navigation} aria-label={ariaLabel}>
{items.map((item) => {
const hasChildren = Boolean(item.children?.length);
const parentActive = hasChildren && item.children?.some((child) => child.key === activeKey);
return (
<div key={item.key} className={styles.navigationGroup}>
<button
className={styles.navigationItem}
data-active-parent={parentActive ? 'true' : undefined}
disabled={item.disabled}
type="button"
onClick={() => {
if (!item.disabled) onChange?.(item.key);
}}
>
{item.label}
</button>
{hasChildren ? (
<div className={styles.navigationChildren}>
{item.children?.map((child) => {
const selected = child.key === activeKey;
return (
<button
key={child.key}
className={cx(styles.navigationItem, styles.navigationChild, selected && styles.navigationItemActive)}
aria-current={selected ? 'page' : undefined}
disabled={child.disabled}
type="button"
onClick={() => {
if (!child.disabled) onChange?.(child.key);
}}
>
{child.label}
</button>
);
})}
</div>
) : null}
</div>
);
})}
</nav>
);
}
export interface TabsProps { export interface TabsProps {
/** Tabs 采用受控 activeKey,切换只通过 onChange 通知业务侧。 */ /** Tabs 采用受控 activeKey,切换只通过 onChange 通知业务侧。 */
activeKey: string; activeKey: string;
...@@ -109,6 +172,46 @@ export function Empty({ action, description = '暂无数据' }: EmptyProps) { ...@@ -109,6 +172,46 @@ export function Empty({ action, description = '暂无数据' }: EmptyProps) {
return <div className={styles.stack}><div className={styles.muted}>{description}</div>{action}</div>; return <div className={styles.stack}><div className={styles.muted}>{description}</div>{action}</div>;
} }
export interface StatePlaceholderProps {
/** StatePlaceholder 表达内容区状态;失败态明确区别于空数据,不使用“暂无数据”兜底。 */
state: 'empty' | 'filtered-empty' | 'error' | 'forbidden' | 'offline';
title?: ReactNode;
description?: ReactNode;
primaryAction?: ReactNode;
secondaryAction?: ReactNode;
icon?: ReactNode;
}
const stateDefaults: Record<StatePlaceholderProps['state'], { title: string; description: string; role: 'status' | 'alert'; icon: ReactNode }> = {
empty: { title: '暂无数据', description: '当前内容为空', role: 'status', icon: <Icon name="file" /> },
'filtered-empty': { title: '未找到匹配结果', description: '请调整搜索或筛选条件', role: 'status', icon: <Icon name="search" /> },
error: { title: '加载失败', description: '数据请求失败,请稍后重试', role: 'alert', icon: <Icon name="warning-circle" /> },
forbidden: { title: '权限受限', description: '当前账号暂无访问权限', role: 'alert', icon: <Icon name="close-circle" /> },
offline: { title: '网络不可用', description: '请检查网络连接后重试', role: 'alert', icon: <Icon name="refresh" /> },
};
const stateClassNames: Record<StatePlaceholderProps['state'], string | undefined> = {
empty: undefined,
'filtered-empty': styles.statePlaceholderFiltered,
error: styles.statePlaceholderError,
forbidden: styles.statePlaceholderForbidden,
offline: styles.statePlaceholderOffline,
};
export function StatePlaceholder({ description, icon, primaryAction, secondaryAction, state, title }: StatePlaceholderProps) {
const defaults = stateDefaults[state];
const resolvedTitle = title ?? defaults.title;
return (
<div className={cx(styles.statePlaceholder, stateClassNames[state])} role={defaults.role} aria-label={String(resolvedTitle)}>
<div className={styles.statePlaceholderIcon} aria-hidden="true">{icon ?? defaults.icon}</div>
<strong className={styles.statePlaceholderTitle}>{resolvedTitle}</strong>
<div className={styles.muted}>{description ?? defaults.description}</div>
{(primaryAction || secondaryAction) ? <div className={styles.statePlaceholderActions}>{primaryAction}{secondaryAction}</div> : null}
</div>
);
}
export function Skeleton({ active = false }: { active?: boolean }) { export function Skeleton({ active = false }: { active?: boolean }) {
return <div aria-label="加载占位" className={cx(styles.skeleton, active && styles.stack)} style={{ width: '100%', height: 16 }} />; return <div aria-label="加载占位" className={cx(styles.skeleton, active && styles.stack)} style={{ width: '100%', height: 16 }} />;
} }
......
import { useState } from 'react'; import { useState } from 'react';
import styles from './Shared.module.css'; import styles from './Shared.module.css';
import { cx } from './utils';
export interface PaginationProps { export interface PaginationProps {
/** current/pageSize/total 共同描述后台列表分页状态。 */ /** current/pageSize/total 共同描述后台列表分页状态。 */
...@@ -15,13 +16,14 @@ export function Pagination({ current, pageSize, pageSizeOptions = [10, 20, 50], ...@@ -15,13 +16,14 @@ export function Pagination({ current, pageSize, pageSizeOptions = [10, 20, 50],
const [jump, setJump] = useState(''); const [jump, setJump] = useState('');
const totalPages = Math.max(1, Math.ceil(total / pageSize)); const totalPages = Math.max(1, Math.ceil(total / pageSize));
const pages = Array.from({ length: Math.min(totalPages, 5) }, (_, index) => index + 1); const pages = Array.from({ length: Math.min(totalPages, 5) }, (_, index) => index + 1);
const submitJump = () => onChange?.(Number(jump), pageSize);
return ( return (
<div className={styles.between}> <div className={styles.between}>
<span className={styles.muted}>共 {total} 条</span> <span className={styles.muted}>共 {total} 条</span>
<div className={styles.row}> <div className={styles.row}>
{pages.map((page) => ( {pages.map((page) => (
<button key={page} className={styles.control} type="button" aria-label={`第 ${page} 页`} aria-current={page === current ? 'page' : undefined} onClick={() => onChange?.(page, pageSize)}> <button key={page} className={cx(styles.control, page === current && styles.paginationCurrent)} type="button" aria-label={`第 ${page} 页`} aria-current={page === current ? 'page' : undefined} onClick={() => onChange?.(page, pageSize)}>
{page} {page}
</button> </button>
))} ))}
...@@ -32,8 +34,16 @@ export function Pagination({ current, pageSize, pageSizeOptions = [10, 20, 50], ...@@ -32,8 +34,16 @@ export function Pagination({ current, pageSize, pageSizeOptions = [10, 20, 50],
</option> </option>
))} ))}
</select> </select>
<input aria-label="跳至页码" className={styles.control} value={jump} onChange={(event) => setJump(event.target.value)} /> <input
<button className={styles.control} type="button" onClick={() => onChange?.(Number(jump), pageSize)}> aria-label="跳至页码"
className={styles.control}
value={jump}
onChange={(event) => setJump(event.target.value)}
onKeyDown={(event) => {
if (event.key === 'Enter') submitJump();
}}
/>
<button className={styles.control} type="button" onClick={submitJump}>
跳转 跳转
</button> </button>
</div> </div>
......
...@@ -22,16 +22,18 @@ export interface SelectProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement ...@@ -22,16 +22,18 @@ export interface SelectProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement
onChange?: (value: string | undefined, option: SelectOption | undefined) => void; onChange?: (value: string | undefined, option: SelectOption | undefined) => void;
} }
export function Select({ allowClear, options, placeholder = '请选择', value, onChange, ...props }: SelectProps) { export function Select(props: SelectProps) {
const { allowClear, options, placeholder = '请选择', value, onChange, ...buttonProps } = props;
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const popupId = useExclusivePopup(selectPopupOpenEvent, setOpen); const popupId = useExclusivePopup(selectPopupOpenEvent, setOpen);
const [innerValue, setInnerValue] = useState<string | undefined>(value); const isControlled = Object.prototype.hasOwnProperty.call(props, 'value');
const currentValue = value ?? innerValue; const [innerValue, setInnerValue] = useState<string | undefined>(undefined);
const currentValue = isControlled ? value : innerValue;
const currentOption = options.find((option) => option.value === currentValue); const currentOption = options.find((option) => option.value === currentValue);
const label = props['aria-label'] ?? '选择框'; const label = buttonProps['aria-label'] ?? '选择框';
const commit = (nextValue: string | undefined, option: SelectOption | undefined) => { const commit = (nextValue: string | undefined, option: SelectOption | undefined) => {
if (value === undefined) { if (!isControlled) {
setInnerValue(nextValue); setInnerValue(nextValue);
} }
onChange?.(nextValue, option); onChange?.(nextValue, option);
...@@ -47,7 +49,7 @@ export function Select({ allowClear, options, placeholder = '请选择', value, ...@@ -47,7 +49,7 @@ export function Select({ allowClear, options, placeholder = '请选择', value,
return ( return (
<span className={styles.selectWrapper}> <span className={styles.selectWrapper}>
<button {...props} className={cx(styles.control, styles.fieldButton)} role="combobox" aria-expanded={open} type="button" onClick={toggleOpen}> <button {...buttonProps} className={cx(styles.control, styles.fieldButton)} role="combobox" aria-expanded={open} type="button" onClick={toggleOpen}>
<span>{currentOption?.label ?? placeholder}</span> <span>{currentOption?.label ?? placeholder}</span>
<Icon className={styles.fieldIcon} name={open ? 'chevron-down' : 'chevron-right'} /> <Icon className={styles.fieldIcon} name={open ? 'chevron-down' : 'chevron-right'} />
</button> </button>
......
...@@ -7,6 +7,13 @@ ...@@ -7,6 +7,13 @@
font-size: var(--gl-font-size-sm); font-size: var(--gl-font-size-sm);
} }
.paginationCurrent {
border-color: var(--gl-color-primary);
background: color-mix(in srgb, var(--gl-color-primary) 10%, #fff);
color: var(--gl-color-primary);
font-weight: 600;
}
.fieldButton { .fieldButton {
display: inline-flex; display: inline-flex;
width: 100%; width: 100%;
...@@ -316,6 +323,59 @@ ...@@ -316,6 +323,59 @@
gap: var(--gl-spacing-sm); gap: var(--gl-spacing-sm);
} }
.navigation {
display: grid;
gap: var(--gl-spacing-sm);
}
.navigationGroup {
display: grid;
gap: 6px;
}
.navigationChildren {
display: grid;
gap: 4px;
padding-left: var(--gl-spacing-sm);
}
.navigationItem {
display: inline-flex;
min-height: 36px;
width: 100%;
align-items: center;
border: 0;
border-radius: var(--gl-radius-md);
background: transparent;
color: var(--gl-color-text-secondary);
cursor: pointer;
font: inherit;
font-size: var(--gl-font-size-sm);
text-align: left;
transition: background 0.15s ease, color 0.15s ease;
padding: 0 var(--gl-spacing-md);
}
.navigationItem:hover:not(:disabled) {
background: var(--gl-color-fill-hover);
color: var(--gl-color-text-primary);
}
.navigationItem:disabled {
cursor: not-allowed;
opacity: 0.5;
}
.navigationItemActive {
background: color-mix(in srgb, var(--gl-color-primary) 12%, #fff);
color: var(--gl-color-primary);
font-weight: 600;
}
.navigationChild {
min-height: 34px;
}
.form { .form {
display: grid; display: grid;
width: 100%; width: 100%;
...@@ -621,6 +681,55 @@ ...@@ -621,6 +681,55 @@
color: var(--gl-color-primary); color: var(--gl-color-primary);
} }
.statePlaceholder {
display: grid;
justify-items: center;
gap: var(--gl-spacing-sm);
min-height: 132px;
padding: var(--gl-spacing-xl);
color: var(--gl-color-text-primary);
text-align: center;
}
.statePlaceholderIcon {
display: inline-grid;
width: 40px;
height: 40px;
place-items: center;
border-radius: 50%;
background: color-mix(in srgb, var(--gl-color-primary) 10%, #fff);
color: var(--gl-color-primary);
}
.statePlaceholderTitle {
font-size: var(--gl-font-size-md);
line-height: var(--gl-line-height-lg);
}
.statePlaceholderActions {
display: inline-flex;
flex-wrap: wrap;
justify-content: center;
gap: var(--gl-spacing-sm);
margin-top: var(--gl-spacing-xs);
}
.statePlaceholderFiltered .statePlaceholderIcon {
background: color-mix(in srgb, var(--gl-color-warning, #dc6803) 10%, #fff);
color: var(--gl-color-warning, #dc6803);
}
.statePlaceholderError .statePlaceholderIcon,
.statePlaceholderForbidden .statePlaceholderIcon {
background: color-mix(in srgb, var(--gl-color-danger, #d92d20) 10%, #fff);
color: var(--gl-color-danger, #d92d20);
}
.statePlaceholderOffline .statePlaceholderIcon {
background: color-mix(in srgb, var(--gl-color-text-secondary) 10%, #fff);
color: var(--gl-color-text-secondary);
}
.skeleton { .skeleton {
border-radius: var(--gl-radius-sm); border-radius: var(--gl-radius-sm);
background: linear-gradient(90deg, #eef2f7 25%, #f8fafc 37%, #eef2f7 63%); background: linear-gradient(90deg, #eef2f7 25%, #f8fafc 37%, #eef2f7 63%);
......
...@@ -14,10 +14,12 @@ import { ...@@ -14,10 +14,12 @@ import {
Modal, Modal,
Popconfirm, Popconfirm,
Progress, Progress,
StatePlaceholder,
Statistic, Statistic,
Tag, Tag,
Timeline, Timeline,
Tooltip, Tooltip,
Table,
} from '../index'; } from '../index';
import buttonStyles from './Button.module.css'; import buttonStyles from './Button.module.css';
import styles from './Shared.module.css'; import styles from './Shared.module.css';
...@@ -314,4 +316,60 @@ describe('feedback and display components', () => { ...@@ -314,4 +316,60 @@ describe('feedback and display components', () => {
expect(screen.queryByText('68%')).not.toBeInTheDocument(); expect(screen.queryByText('68%')).not.toBeInTheDocument();
}); });
it('renders StatePlaceholder failed requests without using empty-state copy', () => {
const onRetry = vi.fn();
render(
<StatePlaceholder
state="error"
title="加载失败"
description="数据请求失败,请稍后重试"
primaryAction={<button type="button" onClick={onRetry}>重试</button>}
/>,
);
expect(screen.getByRole('alert', { name: '加载失败' })).toHaveClass(styles.statePlaceholderError);
expect(screen.getByText('数据请求失败,请稍后重试')).toBeInTheDocument();
expect(screen.queryByText('暂无数据')).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '重试' }));
expect(onRetry).toHaveBeenCalledTimes(1);
});
it('renders the remaining StatePlaceholder semantic states with matching roles and defaults', () => {
render(
<>
<StatePlaceholder state="empty" />
<StatePlaceholder state="filtered-empty" />
<StatePlaceholder state="forbidden" />
<StatePlaceholder state="offline" />
</>,
);
expect(screen.getByRole('status', { name: '暂无数据' })).toBeInTheDocument();
expect(screen.getByRole('status', { name: '未找到匹配结果' })).toBeInTheDocument();
expect(screen.getByRole('alert', { name: '权限受限' })).toHaveClass(styles.statePlaceholderForbidden);
expect(screen.getByRole('alert', { name: '网络不可用' })).toHaveClass(styles.statePlaceholderOffline);
expect(screen.getByText('当前内容为空')).toBeInTheDocument();
expect(screen.getByText('请调整搜索或筛选条件')).toBeInTheDocument();
expect(screen.getByText('当前账号暂无访问权限')).toBeInTheDocument();
expect(screen.getByText('请检查网络连接后重试')).toBeInTheDocument();
});
it('allows Table content areas to render a recoverable failed request placeholder', () => {
render(
<Table
rowKey="id"
columns={[{ title: '名称', dataIndex: 'name' }]}
dataSource={[]}
empty={<StatePlaceholder state="error" title="列表加载失败" description="当前列表数据未知" primaryAction={<button type="button">重新加载</button>} />}
/>,
);
expect(screen.getByRole('alert', { name: '列表加载失败' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '重新加载' })).toBeInTheDocument();
expect(screen.queryByText('暂无数据')).not.toBeInTheDocument();
});
}); });
import { fireEvent, render, screen } from '@testing-library/react'; import { fireEvent, render, screen } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest'; import { describe, expect, it, vi } from 'vitest';
import styles from './Shared.module.css';
import { import {
Collapse, Collapse,
ColorInput, ColorInput,
ColorPicker, ColorPicker,
Empty, Empty,
Navigation,
Skeleton, Skeleton,
SkeletonAvatar, SkeletonAvatar,
SkeletonButton, SkeletonButton,
...@@ -84,6 +86,36 @@ describe('navigation, placeholder and color components', () => { ...@@ -84,6 +86,36 @@ describe('navigation, placeholder and color components', () => {
expect(onChange).toHaveBeenCalledWith(['one', 'two']); expect(onChange).toHaveBeenCalledWith(['one', 'two']);
}); });
it('renders hierarchical navigation with active child and parent states', () => {
const onChange = vi.fn();
render(
<Navigation
activeKey="agent-list"
onChange={onChange}
items={[
{
key: 'agent-management',
label: 'Agent管理',
children: [{ key: 'agent-list', label: 'Agent列表' }],
},
]}
/>,
);
const parentItem = screen.getByRole('button', { name: 'Agent管理' });
const childItem = screen.getByRole('button', { name: 'Agent列表' });
expect(parentItem).toHaveAttribute('data-active-parent', 'true');
expect(parentItem).not.toHaveClass('navigationItemParentActive');
expect(childItem).toHaveAttribute('aria-current', 'page');
expect(childItem).toHaveClass(styles.navigationItemActive, styles.navigationChild);
fireEvent.click(childItem);
expect(onChange).toHaveBeenCalledWith('agent-list');
});
it('selects preset colors and edits color input values', () => { it('selects preset colors and edits color input values', () => {
const onPickerChange = vi.fn(); const onPickerChange = vi.fn();
const onInputChange = vi.fn(); const onInputChange = vi.fn();
......
import { fireEvent, render, screen, within } from '@testing-library/react'; import { fireEvent, render, screen, within } from '@testing-library/react';
import { useState } from 'react';
import { describe, expect, it, vi } from 'vitest'; import { describe, expect, it, vi } from 'vitest';
import sharedStyles from './Shared.module.css'; import sharedStyles from './Shared.module.css';
...@@ -46,6 +47,13 @@ describe('selection, date, table and pagination components', () => { ...@@ -46,6 +47,13 @@ describe('selection, date, table and pagination components', () => {
expect(onChange).toHaveBeenCalledTimes(2); expect(onChange).toHaveBeenCalledTimes(2);
}); });
it('keeps the clear affordance hidden when allowClear is disabled', () => {
render(<Select aria-label="负责人" value="zhang" options={[{ label: '张三', value: 'zhang' }]} />);
expect(screen.getByRole('combobox', { name: '负责人' })).toHaveTextContent('张三');
expect(screen.queryByRole('button', { name: '清空负责人' })).not.toBeInTheDocument();
});
it('renders select trigger arrows with the softer helper icon color', () => { it('renders select trigger arrows with the softer helper icon color', () => {
render( render(
<> <>
...@@ -140,6 +148,52 @@ describe('selection, date, table and pagination components', () => { ...@@ -140,6 +148,52 @@ describe('selection, date, table and pagination components', () => {
expect(screen.getByRole('combobox', { name: '组织' })).toHaveTextContent('财务部'); expect(screen.getByRole('combobox', { name: '组织' })).toHaveTextContent('财务部');
}); });
it('closes the select popup immediately after choosing an option', () => {
render(<Select aria-label="所属岗位" options={[{ label: '全部', value: 'all' }, { label: '客服岗', value: 'customer-service' }]} />);
fireEvent.click(screen.getByRole('combobox', { name: '所属岗位' }));
expect(screen.getByRole('listbox')).toBeInTheDocument();
fireEvent.click(screen.getByRole('option', { name: '客服岗' }));
expect(screen.queryByRole('listbox')).not.toBeInTheDocument();
expect(screen.getByRole('combobox', { name: '所属岗位' })).toHaveTextContent('客服岗');
});
it('resets to the placeholder when a controlled select clears its value', () => {
function ControlledSelect() {
const [value, setValue] = useState<string | undefined>();
return (
<>
<Select
aria-label="所属岗位"
options={[{ label: '全部', value: 'all' }, { label: '客服岗', value: 'customer-service' }]}
placeholder="全部"
value={value}
onChange={(nextValue) => {
setValue(nextValue === 'all' ? undefined : nextValue);
}}
/>
<button type="button" onClick={() => setValue(undefined)}>
重置
</button>
</>
);
}
render(<ControlledSelect />);
fireEvent.click(screen.getByRole('combobox', { name: '所属岗位' }));
fireEvent.click(screen.getByRole('option', { name: '客服岗' }));
expect(screen.getByRole('combobox', { name: '所属岗位' })).toHaveTextContent('客服岗');
fireEvent.click(screen.getByRole('button', { name: '重置' }));
expect(screen.getByRole('combobox', { name: '所属岗位' })).toHaveTextContent('全部');
});
it('collapses an expanded TreeSelect parent when clicking it again', () => { it('collapses an expanded TreeSelect parent when clicking it again', () => {
render( render(
<TreeSelect <TreeSelect
...@@ -399,14 +453,20 @@ describe('selection, date, table and pagination components', () => { ...@@ -399,14 +453,20 @@ describe('selection, date, table and pagination components', () => {
render(<Pagination current={2} pageSize={10} total={95} onChange={onChange} />); render(<Pagination current={2} pageSize={10} total={95} onChange={onChange} />);
expect(screen.getByRole('button', { name: '第 2 页' })).toHaveAttribute('aria-current', 'page');
expect(screen.getByRole('button', { name: '第 2 页' })).toHaveClass(sharedStyles.paginationCurrent);
fireEvent.click(screen.getByRole('button', { name: '第 3 页' })); fireEvent.click(screen.getByRole('button', { name: '第 3 页' }));
fireEvent.change(screen.getByLabelText('每页条数'), { target: { value: '20' } }); fireEvent.change(screen.getByLabelText('每页条数'), { target: { value: '20' } });
fireEvent.change(screen.getByLabelText('跳至页码'), { target: { value: '5' } }); fireEvent.change(screen.getByLabelText('跳至页码'), { target: { value: '5' } });
fireEvent.click(screen.getByRole('button', { name: '跳转' })); fireEvent.click(screen.getByRole('button', { name: '跳转' }));
fireEvent.change(screen.getByLabelText('跳至页码'), { target: { value: '6' } });
fireEvent.keyDown(screen.getByLabelText('跳至页码'), { key: 'Enter' });
expect(screen.getByText('共 95 条')).toBeInTheDocument(); expect(screen.getByText('共 95 条')).toBeInTheDocument();
expect(onChange).toHaveBeenNthCalledWith(1, 3, 10); expect(onChange).toHaveBeenNthCalledWith(1, 3, 10);
expect(onChange).toHaveBeenNthCalledWith(2, 1, 20); expect(onChange).toHaveBeenNthCalledWith(2, 1, 20);
expect(onChange).toHaveBeenNthCalledWith(3, 5, 10); expect(onChange).toHaveBeenNthCalledWith(3, 5, 10);
expect(onChange).toHaveBeenNthCalledWith(4, 6, 10);
}); });
}); });
...@@ -16,8 +16,8 @@ export type { InputProps, SearchInputProps } from './components/Input'; ...@@ -16,8 +16,8 @@ export type { InputProps, SearchInputProps } from './components/Input';
export { Input, SearchInput } from './components/Input'; export { Input, SearchInput } from './components/Input';
export type { TextareaProps } from './components/Textarea'; export type { TextareaProps } from './components/Textarea';
export { Textarea } from './components/Textarea'; export { Textarea } from './components/Textarea';
export type { CollapseItem, CollapseProps, EmptyProps, StepsProps, TabsItem, TabsProps } from './components/Navigation'; export type { CollapseItem, CollapseProps, EmptyProps, NavigationItem, NavigationProps, StatePlaceholderProps, StepsProps, TabsItem, TabsProps } from './components/Navigation';
export { Collapse, Empty, Skeleton, SkeletonAvatar, SkeletonButton, SkeletonInput, SkeletonParagraph, Steps, Tabs } from './components/Navigation'; export { Collapse, Empty, Navigation, Skeleton, SkeletonAvatar, SkeletonButton, SkeletonInput, SkeletonParagraph, StatePlaceholder, Steps, Tabs } from './components/Navigation';
export type { PaginationProps } from './components/Pagination'; export type { PaginationProps } from './components/Pagination';
export { Pagination } from './components/Pagination'; export { Pagination } from './components/Pagination';
export type { RadioProps } from './components/Radio'; export type { RadioProps } from './components/Radio';
......
import { render, screen } from '@testing-library/react'; import { fireEvent, render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom'; import { MemoryRouter } from 'react-router-dom';
import { describe, expect, it } from 'vitest'; import { beforeEach, describe, expect, it } from 'vitest';
import { App } from './App'; import { App } from './App';
describe('App foundation', () => { const loginStorageKey = 'agent-admin-local-login';
it('renders the root layout for the React application', () => {
render( function renderApp(path: string) {
<MemoryRouter initialEntries={['/']}> return render(
<MemoryRouter initialEntries={[path]}>
<App /> <App />
</MemoryRouter>, </MemoryRouter>,
); );
}
describe('App foundation', () => {
beforeEach(() => {
window.localStorage.clear();
});
it('renders the root layout for the React application', () => {
renderApp('/components');
expect(screen.getByRole('main')).toBeInTheDocument(); expect(screen.getByRole('main')).toBeInTheDocument();
expect(screen.getByText('Agent Admin Web')).toBeInTheDocument(); expect(screen.getByText('Agent Admin Web')).toBeInTheDocument();
}); });
it('renders the independent component demo route', () => { it('renders the independent component demo route', () => {
render( renderApp('/components');
<MemoryRouter initialEntries={['/components']}>
<App />
</MemoryRouter>,
);
expect(screen.getByRole('heading', { name: '组件库 Demo' })).toBeInTheDocument(); expect(screen.getByRole('heading', { name: '组件库 Demo' })).toBeInTheDocument();
expect(screen.getByText('全局 UI 组件库展示入口')).toBeInTheDocument(); expect(screen.getByText('全局 UI 组件库展示入口')).toBeInTheDocument();
expect(screen.queryByRole('heading', { name: 'Agent管理' })).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: '退出登录' })).not.toBeInTheDocument();
});
});
describe('Admin login and protected routes', () => {
beforeEach(() => {
window.localStorage.clear();
});
it('redirects anonymous users to login and returns to the requested protected route after login', () => {
renderApp('/agents?scenario=error');
expect(screen.getByRole('heading', { name: '岗位Agent管理后台' })).toBeInTheDocument();
expect(screen.getByLabelText('账号')).toBeInTheDocument();
expect(screen.getByLabelText('密码')).toBeInTheDocument();
fireEvent.change(screen.getByLabelText('账号'), { target: { value: 'admin' } });
fireEvent.change(screen.getByLabelText('密码'), { target: { value: '123456' } });
fireEvent.click(screen.getByRole('button', { name: '登录' }));
expect(window.localStorage.getItem(loginStorageKey)).toBe('true');
expect(screen.getByRole('heading', { name: 'Agent管理' })).toBeInTheDocument();
expect(screen.getByRole('alert', { name: '加载失败' })).toBeInTheDocument();
expect(screen.getByText('岗位Agent管理后台')).toBeInTheDocument();
expect(screen.getByLabelText('管理员')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '退出登录' })).toBeInTheDocument();
});
it('shows validation and credential errors without marking the user as logged in', () => {
renderApp('/login');
fireEvent.click(screen.getByRole('button', { name: '登录' }));
expect(screen.getByText('请输入账号')).toBeInTheDocument();
expect(screen.getByText('请输入密码')).toBeInTheDocument();
expect(window.localStorage.getItem(loginStorageKey)).toBeNull();
fireEvent.change(screen.getByLabelText('账号'), { target: { value: 'admin' } });
fireEvent.change(screen.getByLabelText('密码'), { target: { value: 'wrong' } });
fireEvent.click(screen.getByRole('button', { name: '登录' }));
expect(screen.getByText('账号或密码错误')).toBeInTheDocument();
expect(window.localStorage.getItem(loginStorageKey)).toBeNull();
});
it('keeps logged-in users on refresh and clears local state on logout', () => {
window.localStorage.setItem(loginStorageKey, 'true');
renderApp('/agents');
expect(screen.getByRole('heading', { name: 'Agent管理' })).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '退出登录' }));
expect(screen.getByRole('dialog', { name: '确认退出登录?' })).toBeInTheDocument();
expect(window.localStorage.getItem(loginStorageKey)).toBe('true');
fireEvent.click(screen.getByRole('button', { name: '取消' }));
expect(screen.queryByRole('dialog', { name: '确认退出登录?' })).not.toBeInTheDocument();
expect(window.localStorage.getItem(loginStorageKey)).toBe('true');
fireEvent.click(screen.getByRole('button', { name: '退出登录' }));
fireEvent.click(screen.getByRole('button', { name: '确定' }));
expect(window.localStorage.getItem(loginStorageKey)).toBeNull();
expect(screen.getByRole('heading', { name: '岗位Agent管理后台' })).toBeInTheDocument();
});
it('renders hierarchical admin navigation with the child route selected', () => {
window.localStorage.setItem(loginStorageKey, 'true');
renderApp('/agents');
expect(screen.getByRole('button', { name: 'Agent管理' })).toHaveAttribute('data-active-parent', 'true');
expect(screen.getByRole('button', { name: 'Agent列表' })).toHaveAttribute('aria-current', 'page');
}); });
}); });
import { Navigate, Route, Routes } from 'react-router-dom'; import { Navigate, Route, Routes } from 'react-router-dom';
import { AdminShell } from './layouts/AdminShell';
import { RootLayout } from './layouts/RootLayout'; import { RootLayout } from './layouts/RootLayout';
import { AgentListPage } from './routes/agents/AgentListPage';
import { ComponentsDemoPage } from './routes/components/ComponentsDemoPage'; import { ComponentsDemoPage } from './routes/components/ComponentsDemoPage';
import { LoginPage } from './routes/login/LoginPage';
import { ProtectedRoute } from './routes/ProtectedRoute';
export function App() { export function App() {
return ( return (
<Routes> <Routes>
<Route path="login" element={<LoginPage />} />
<Route element={<ProtectedRoute />}>
<Route element={<AdminShell />}>
<Route index element={<Navigate to="/agents" replace />} />
<Route path="agents" element={<AgentListPage />} />
</Route>
</Route>
<Route element={<RootLayout />}> <Route element={<RootLayout />}>
<Route index element={<Navigate to="/components" replace />} />
<Route path="components" element={<ComponentsDemoPage />} /> <Route path="components" element={<ComponentsDemoPage />} />
</Route> </Route>
<Route path="*" element={<Navigate to="/agents" replace />} />
</Routes> </Routes>
); );
} }
...@@ -72,3 +72,9 @@ ...@@ -72,3 +72,9 @@
gap: var(--gl-spacing-xl); gap: var(--gl-spacing-xl);
align-items: start; align-items: start;
} }
.placeholderDemo {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
gap: var(--gl-spacing-lg);
}
...@@ -19,6 +19,11 @@ describe('ComponentsDemoPage', () => { ...@@ -19,6 +19,11 @@ describe('ComponentsDemoPage', () => {
expect(screen.getByText('上传')).toBeInTheDocument(); expect(screen.getByText('上传')).toBeInTheDocument();
expect(screen.getByText('暂无审批记录')).toBeInTheDocument(); expect(screen.getByText('暂无审批记录')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '新建审批' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '新建审批' })).toBeInTheDocument();
expect(screen.getByRole('alert', { name: '加载失败' })).toBeInTheDocument();
expect(screen.getByRole('status', { name: '暂无数据' })).toBeInTheDocument();
expect(screen.getByRole('status', { name: '未找到匹配结果' })).toBeInTheDocument();
expect(screen.getByRole('alert', { name: '权限受限' })).toBeInTheDocument();
expect(screen.getByRole('alert', { name: '网络不可用' })).toBeInTheDocument();
expect(screen.getByText('点击或拖拽业务资料到此上传')).toBeInTheDocument(); expect(screen.getByText('点击或拖拽业务资料到此上传')).toBeInTheDocument();
expect(screen.getByText('图片/视频')).toBeInTheDocument(); expect(screen.getByText('图片/视频')).toBeInTheDocument();
expect(screen.getByText('4/20')).toBeInTheDocument(); expect(screen.getByText('4/20')).toBeInTheDocument();
...@@ -115,4 +120,11 @@ describe('ComponentsDemoPage', () => { ...@@ -115,4 +120,11 @@ describe('ComponentsDemoPage', () => {
expect(screen.getByLabelText('视频')).toBeInTheDocument(); expect(screen.getByLabelText('视频')).toBeInTheDocument();
expect(screen.getByText('支持 JPG、PNG、MP4、MOV,图片单张不超过 10MB,视频单个不超过 500MB')).toBeInTheDocument(); expect(screen.getByText('支持 JPG、PNG、MP4、MOV,图片单张不超过 10MB,视频单个不超过 500MB')).toBeInTheDocument();
}); });
it('keeps the component demo route isolated from the admin shell copy', () => {
render(<ComponentsDemoPage />);
expect(screen.queryByText('岗位Agent管理后台')).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: '退出登录' })).not.toBeInTheDocument();
});
}); });
...@@ -21,6 +21,7 @@ import { ...@@ -21,6 +21,7 @@ import {
Message, Message,
MediaWall, MediaWall,
Modal, Modal,
Navigation,
Pagination, Pagination,
Popconfirm, Popconfirm,
Progress, Progress,
...@@ -28,6 +29,7 @@ import { ...@@ -28,6 +29,7 @@ import {
SearchInput, SearchInput,
Select, Select,
Skeleton, Skeleton,
StatePlaceholder,
Steps, Steps,
Switch, Switch,
Table, Table,
...@@ -54,6 +56,27 @@ export function ComponentsDemoPage() { ...@@ -54,6 +56,27 @@ export function ComponentsDemoPage() {
'data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2296%22 height=%2296%22 viewBox=%220 0 96 96%22%3E%3Crect width=%2296%22 height=%2296%22 fill=%22%23dbeafe%22/%3E%3Ccircle cx=%2232%22 cy=%2235%22 r=%2210%22 fill=%22%232468f2%22/%3E%3Cpath d=%22M12 78 39 52l14 13 12-17 19 30Z%22 fill=%22%231f5bd6%22/%3E%3C/svg%3E'; 'data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2296%22 height=%2296%22 viewBox=%220 0 96 96%22%3E%3Crect width=%2296%22 height=%2296%22 fill=%22%23dbeafe%22/%3E%3Ccircle cx=%2232%22 cy=%2235%22 r=%2210%22 fill=%22%232468f2%22/%3E%3Cpath d=%22M12 78 39 52l14 13 12-17 19 30Z%22 fill=%22%231f5bd6%22/%3E%3C/svg%3E';
const mediaVideo = const mediaVideo =
'data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2296%22 height=%2296%22 viewBox=%220 0 96 96%22%3E%3Crect width=%2296%22 height=%2296%22 fill=%22%231f2633%22/%3E%3Cpath d=%22M18 72 38 45l13 12 11-18 16 33Z%22 fill=%22%23667085%22/%3E%3Ccircle cx=%2270%22 cy=%2226%22 r=%2210%22 fill=%22%23f59e0b%22/%3E%3C/svg%3E'; 'data:image/svg+xml,%3Csvg xmlns=%22http://www.w3.org/2000/svg%22 width=%2296%22 height=%2296%22 viewBox=%220 0 96 96%22%3E%3Crect width=%2296%22 height=%2296%22 fill=%22%231f2633%22/%3E%3Cpath d=%22M18 72 38 45l13 12 11-18 16 33Z%22 fill=%22%23667085%22/%3E%3Ccircle cx=%2270%22 cy=%2226%22 r=%2210%22 fill=%22%23f59e0b%22/%3E%3C/svg%3E';
const placeholderStates = [
{ state: 'empty' as const, title: '暂无数据', description: '请先创建项目' },
{
state: 'filtered-empty' as const,
title: '未找到匹配结果',
description: '请调整搜索或筛选条件',
secondaryAction: <Button size="small">清空筛选</Button>,
},
{
state: 'forbidden' as const,
title: '权限受限',
description: '当前账号暂无访问权限',
primaryAction: <Button size="small">申请权限</Button>,
},
{
state: 'offline' as const,
title: '网络不可用',
description: '请检查网络连接后重试',
primaryAction: <Button size="small">重新连接</Button>,
},
];
return ( return (
<section className={styles.page}> <section className={styles.page}>
...@@ -169,9 +192,33 @@ export function ComponentsDemoPage() { ...@@ -169,9 +192,33 @@ export function ComponentsDemoPage() {
<section className={styles.group}> <section className={styles.group}>
<h3>导航与占位</h3> <h3>导航与占位</h3>
<div className={styles.grid}> <div className={styles.grid}>
<Navigation
activeKey="agent-list"
items={[
{ key: 'agent-management', label: 'Agent管理', children: [{ key: 'agent-list', label: 'Agent列表' }] },
]}
/>
<Tabs activeKey="base" items={[{ key: 'base', label: '基础信息', children: '基础内容' }, { key: 'advanced', label: '高级配置', children: '高级内容' }]} /> <Tabs activeKey="base" items={[{ key: 'base', label: '基础信息', children: '基础内容' }, { key: 'advanced', label: '高级配置', children: '高级内容' }]} />
<Steps current={1} items={[{ title: '提交' }, { title: '审批' }, { title: '完成' }]} /> <Steps current={1} items={[{ title: '提交' }, { title: '审批' }, { title: '完成' }]} />
<Empty description="暂无项目" action={<Button>新建项目</Button>} /> <Empty description="暂无项目" action={<Button>新建项目</Button>} />
<StatePlaceholder
state="error"
title="加载失败"
description="列表请求失败,当前数据状态未知"
primaryAction={<Button size="small">重试</Button>}
/>
<div className={styles.placeholderDemo}>
{placeholderStates.map((item) => (
<StatePlaceholder
key={item.state}
state={item.state}
title={item.title}
description={item.description}
primaryAction={item.primaryAction}
secondaryAction={item.secondaryAction}
/>
))}
</div>
<Skeleton active /> <Skeleton active />
<Collapse activeKeys={['one']} items={[{ key: 'one', title: '基础设置', children: '设置内容' }]} /> <Collapse activeKeys={['one']} items={[{ key: 'one', title: '基础设置', children: '设置内容' }]} />
</div> </div>
......
@import './tokens.css'; @import './tokens.css';
@import './reset.css'; @import './reset.css';
@tailwind utilities;
...@@ -19,5 +19,5 @@ ...@@ -19,5 +19,5 @@
"jsx": "react-jsx", "jsx": "react-jsx",
"types": ["vitest/globals", "@testing-library/jest-dom"] "types": ["vitest/globals", "@testing-library/jest-dom"]
}, },
"include": ["src", "packages/ui/src"] "include": ["src", "packages/ui/src", "packages/contracts"]
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!