Commit 7cc7d60d by 胡悦

feat(admin-web): 实现本地管理员登录、Agent列表与管理后台框架

配置 Tailwind CSS 作为项目样式工具
实现本地登录认证逻辑,包含登录态本地持久化与退出登录功能
添加路由保护守卫,拦截未登录用户访问后台页面
新增管理后台布局框架,包含导航菜单与用户退出控件
新增 Agent 管理列表页,支持关键词筛选、岗位筛选、分页与状态展示
更新组件库,新增状态占位组件、导航组件,修复 Select 下拉自动收起与分页选中态问题
新增前端契约文件目录,定义 Agent 列表 mock 数据规范
清理过时文档文件,重构 AGENTS.md 文档结构
新增管理员登录与管理后台框架的 OpenSpec 规范文件
1 parent be1840bf
Showing 60 changed files with 2968 additions and 209 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 数据结构表达,不锁定服务端实现。
## 验证规则
- 没有新鲜的验证结果,不声明工作完成。
- 如果改了代码,需要运行类型检查和相关测试。
- 如果开发前端页面,完成前需要在浏览器中验证布局和关键交互。
# Superpowers 配置目录
这里用于存放本项目的 Superpowers 工作流配置、团队约定或与外部 skills bundle 的引用说明。
当前项目默认使用本机已安装的 Superpowers/OpenSpec 相关 skills。若后续团队决定统一使用 `superpowers-openspec-team-skills`,可在这里补充安装和同步说明。
# 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 完成并获得确认后再开始。
......@@ -16,7 +16,7 @@
## 目录结构
```text
.codex/ # Codex 工作流配置,当前受本机沙箱限制暂未创建
AGENTS.md # 工作区级 Agent 协作规则
.agents/ # 团队 skills 引用,当前受本机沙箱限制暂未创建
architecture-spec/ # 全局架构、OpenSpec、UI 和工程规范
workspace/agent-admin/ # 首个业务项目:Agent 管理平台
......@@ -24,7 +24,7 @@ workspace/agent-admin/ # 首个业务项目:Agent 管理平台
## 工作流
本项目采用 Codex + OpenSpec + Superpowers 工作流:
本项目采用 OpenSpec + Superpowers 工作流:
1. Superpowers 负责需求澄清、方案比较、设计和计划。
2. OpenSpec 负责锁定行为规范和变更任务。
......
......@@ -6,16 +6,14 @@
它需要沉淀三类共享资产:
- 工作流资产:Codex + OpenSpec + Superpowers 的需求澄清、规范、计划、验证流程。
- 工作流资产:OpenSpec + Superpowers 的需求澄清、规范、计划、验证流程。
- UI 资产:公司 Web 桌面端设计 token、组件库、页面模式。
- 工程资产:前端通用配置、工具链、测试基线。
## 推荐目录
```text
.codex/
AGENTS.md # Codex 全局工作规则
superpowers/ # Superpowers 相关配置或引用
AGENTS.md # 工作区级 Agent 协作规则
.agents/
skills/ # 团队级 skills 引用
......@@ -56,6 +54,28 @@ workspace/
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` 或明确业务域名。
......
......@@ -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 个可选方案,说明取舍,并推荐一个。
......@@ -110,6 +110,7 @@ openspec/changes/<change-name>/
- 写每个 artifact 前,先运行对应的 `openspec instructions`。
- 按依赖顺序完成 `proposal.md`、`design.md`、`specs/.../spec.md`、`tasks.md`。
- 使用 `openspec validate "<change-name>" --strict` 校验。
- 如果 change 已存在,且用户后续新增问题、补充约束、要求调整方案或实现路径,先回到本阶段更新受影响的 OpenSpec artifacts 和 `tasks.md`。
- 用户确认 OpenSpec artifacts 后,才能进入编码。
退出条件:
......@@ -121,6 +122,7 @@ openspec/changes/<change-name>/
禁止事项:
- OpenSpec artifacts 未完成前,不进入编码。
- change 已存在但 OpenSpec artifacts 和 `tasks.md` 尚未同步最新讨论结果、或尚未再次获得用户确认前,不进入编码。
- 不把命令输出里的 instruction metadata 直接复制到 artifact。
- 不为无关重构创建混合 change。
......@@ -244,3 +246,60 @@ OpenSpec 已确认、准备实现时:
```text
检查代码、测试和 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 @@
- 定义默认前端技术栈、组件规则和页面协作规则。
- 将公司 Web 桌面端设计规范作为所有页面的 UI 基线。
- 定义后台页面的可复用组件使用规则。
- 定义使用 Codex + OpenSpec + Superpowers 的开发前工作流规则。
- 定义使用 OpenSpec + Superpowers 的开发前工作流规则。
- 记录阻塞业务实现的待确认需求问题。
- 本 change 仅覆盖前端与项目协作基线,不定义后端技术栈、数据库、队列、文件存储或接口契约。
......@@ -31,5 +31,5 @@
- 在 `architecture-spec/docs/` 下新增项目文档。
- 新增 OpenSpec 项目上下文和一个基线 change。
- 新增 `.superpowers-memory/` 文件,用于跨会话延续上下文。
- 新增 `AGENTS.md`,用于约束本仓库中的 Codex 行为。
- 新增 `AGENTS.md`,用于约束本仓库中的 Agent 协作行为。
- 不新增任何业务实现代码。
......@@ -3,7 +3,7 @@
## 1. 文档
- [x] 创建项目 README。
- [x] 在 `AGENTS.md` 中创建 Codex 项目规则。
- [x] 在 `AGENTS.md` 中创建 Agent 项目规则。
- [x] 创建 OpenSpec 项目上下文。
- [x] 创建技术栈基线。
- [x] 移除后端/API 强约定,保留前端页面协作基线。
......
......@@ -101,12 +101,24 @@
`Select` 与 `TreeSelect` SHALL 在选中后展示清晰选中态:触发器文字显示当前选中项,面板内对应项显示主色文字或浅主色背景,并暴露 `aria-selected`。树形节点展开后,父节点保持层级关系,叶子节点选中效果不得只依赖触发器文字。
`Select` 在用户点击某个选项后 SHALL 立即关闭当前下拉面板,避免面板停留在页面上遮挡后续字段或操作区。该关闭行为对受控与非受控用法保持一致。
`Select` 的清空入口 SHALL 保持显式可配置。业务页面未开启 `allowClear` 时,组件不得在控件下方自动渲染独立 `清空` 按钮;当业务页面将“恢复默认值”设计为重新选择 `全部` 选项时,组件只负责展示当前值和下拉面板,不额外叠加第二套重置入口。
后台页面的左侧菜单 SHALL 通过共享导航组件承载,不允许在业务页面或布局文件中手写一级/二级菜单结构、父子级选中态和展开交互。导航组件需要支持后台常见的层级导航场景:一级菜单作为分组入口展示,二级菜单作为当前页面入口展示;当二级菜单选中时,其父级一级菜单同步展示轻度选中样式。
该导航组件应提供稳定的数据驱动接口,至少覆盖菜单项标识、标题、层级、图标槽位、链接目标、是否展开、当前选中项以及父级联动样式,保证后台框架只负责传入导航配置和路由状态,而不再手写具体 DOM 结构。
`TreeSelect` 的父节点 SHALL 支持点击展开与再次点击收起。父节点展开时展示子节点并将 `aria-expanded` 置为 `true`;再次点击同一父节点时隐藏子节点并将 `aria-expanded` 置为 `false`。
同一页面同时存在多个 `Select` 或 `TreeSelect` 时,选择类下拉框 SHALL 互斥打开。用户打开新的选择类下拉框时,当前页面中其他已打开的选择类下拉框 SHALL 自动关闭,避免多个下拉面板同时显示在界面上。
`Select` 与 `TreeSelect` 的下拉面板 SHALL 定位在触发输入框下方,并脱离普通文档流。下拉面板打开或关闭不应改变触发器宽度,也不应把后续表单项、按钮或 Demo 元素向下挤开。
### 分页组件需要明确当前页和键盘跳转
`Pagination` SHALL 保持受控的 `current`、`pageSize` 和 `total` 语义。页码按钮中当前页 SHALL 通过 `aria-current="page"` 和可见选中样式同时表达状态,避免只具备语义标记而缺少视觉反馈。跳转输入框 SHALL 支持键盘提交,用户在输入目标页码后按 Enter 时,行为应与点击“跳转”按钮一致。
### 日期组件需符合桌面端面板结构
`DatePicker` 与 `DateRangePicker` SHALL 使用桌面端日期面板结构:触发器显示日期值,面板包含月份标题、上一月/下一月箭头、星期标题、按周排列日期网格、选中日描边/主色状态、今天快捷入口和禁用日期状态。日期面板不应固定单月数据,需根据当前显示月份生成日期。
......@@ -165,6 +177,18 @@
组件 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
- [风险] 已上传设计规范中存在看起来像组件的 demo-only 代码。-> 缓解:本 change 只纳入独立组件文件;demo-only 组件后续单独确认。
......@@ -182,6 +206,7 @@
- [风险] 日期弹窗打开后点击其他页面区域不关闭,用户需要重复点击触发器才能收起。-> 缓解:日期组件监听外部指针点击,触发器和弹窗内部点击保持正常交互,并补充外部点击关闭回归测试。
- [风险] 日期弹窗固定宽度参与布局计算,导致日期输入框随弹窗宽度变宽。-> 缓解:日期组件使用独立定位容器,弹窗绝对定位,补充触发器宽度不受弹窗影响的回归测试。
- [风险] 表格空态只用纯文本时,业务页面需要额外手写空状态布局,导致视觉不一致。-> 缓解:`Table` 内置统一空状态插槽,并在 Demo 路由展示空表格验收样例。
- [风险] 业务页面把加载失败和暂无数据混为一类,导致用户误判数据真实为空。-> 缓解:新增 `StatePlaceholder` 语义状态规范,明确失败态必须展示失败文案和重试操作。
- [风险] `FormItem` 只展示必填星号但不执行校验,会让业务页面重复编写表单校验逻辑。-> 缓解:新增 `Form` 容器和 `FormItem rules`,由组件库统一处理基础必填校验与错误展示。
- [风险] 错误信息动态出现会造成表单布局跳动。-> 缓解:`FormItem` 为错误信息预留稳定区域,并通过布局样式保证错误文案不挤压后续元素。
- [风险] `Upload` 容易被误解为真实上传 SDK。-> 缓解:组件库只提供 UI 形态和状态回调,不内置文件校验、接口传输、分片续传或预览弹层业务逻辑。
......
......@@ -8,6 +8,9 @@
- 仅纳入可复用 UI 组件,不处理 `App.tsx` 中声明的 demo-only 组件。
- 将基础输入类组件继续扩展到 `Textarea`,并为 `Input` 与 `Textarea` 补充简洁长度显示能力。
- 纳入 `Upload` 组件族,包含文件拖拽上传与图片/视频媒体墙两种规范形态。
- 补充通用状态占位组件,用于统一表达空数据、筛选无结果、加载失败、权限受限等页面或列表内容状态,并明确加载失败不得误用“暂无数据”。
- 补充可复用后台导航组件能力,承载一级/二级菜单、父子级选中态和层级结构,避免业务页面手写侧边菜单。
- 补齐 `Pagination` 的当前页可见选中态,以及跳转输入框按 Enter 直接触发跳转的键盘交互。
- 确认一期组件库使用 React、TypeScript、CSS Variables 与 CSS Modules / 普通 CSS 实现;组件内部不依赖 Tailwind CSS。
- 允许后续业务页面使用 Tailwind CSS 做页面级布局,但组件必须自带完整规范样式,并通过受控 API、`className`、`style` 和 CSS 变量支持扩展。
- 在保持当前目录结构不调整的前提下,将组件能力按全局可复用资产设计,避免绑定单一业务项目。
......@@ -27,6 +30,6 @@
## Impact
- 影响前端组件架构和后续业务页面实现规则。
- 预计涉及目标前端应用或 UI 包、共享 UI 组件导出、样式 token、组件测试工具链,以及组件 Demo 页路由。
- 预计涉及目标前端应用或 UI 包、共享 UI 组件导出、样式 token、状态占位组件、组件测试工具链,以及组件 Demo 页路由。
- 技术选型影响一期组件源码组织、样式实现方式、组件测试方式和后续业务页面使用边界。
- 不引入后端 API、数据存储或业务流程变更。
......@@ -3,7 +3,7 @@
### Requirement: 一期组件库范围
系统 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: 实现一期组件
- **WHEN** 实现组件库
......@@ -81,6 +81,40 @@
- **WHEN** 组件支持禁用、加载、选中、激活、空状态或错误状态
- **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: 组件实现采用测试先行
组件实现 SHALL 采用 TDD 方式推进:在实现或迁移组件前,先为组件的公开行为、关键状态和可访问交互编写测试或可执行验收样例。
......@@ -148,6 +182,61 @@
- **WHEN** 表格行存在可用操作
- **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: 反馈和浮层组件支持受控工作流
反馈和浮层组件 SHALL 支持后台常见受控使用方式,包括提示、弹窗、抽屉、二次确认、悬浮说明,以及适用场景下的浮层内容。
......
......@@ -32,6 +32,7 @@
- [x] 3.9 根据人工验收修正选择类下拉互斥:同一页面中 `Select` 与 `TreeSelect` 只能同时打开一个下拉面板,打开新的选择器时自动关闭旧面板,并补充回归测试。
- [x] 3.10 根据人工验收修正选择类下拉定位:`Select` 与 `TreeSelect` 下拉面板定位在触发器下方并脱离文档流,不挤压下面元素,补充样式回归测试。
- [x] 3.11 根据人工验收修正 `TreeSelect` 父节点收起交互:再次点击已展开父节点时收起子节点并更新箭头与 `aria-expanded`,补充回归测试。
- [ ] 3.12 根据人工验收补齐 `Select` 后台筛选交互:选中选项后自动收起下拉面板,并确认 `allowClear` 关闭时不展示独立 `清空` 按钮,补充回归测试。
## 4. 日期组件
......@@ -57,6 +58,7 @@
- [x] 5.3 实现 `Table` 状态逻辑:完成 loading、empty、排序、筛选、行选择和操作列逻辑,并补齐单元测试、审核注释。
- [x] 5.4 实现 `Table` 样式:完成表头、行 hover、选择列、操作列、loading 蒙层和空状态样式,并补齐渲染测试和审核注释。
- [x] 5.5 实现 `Pagination`:包含接口定义、页码/每页条数/总数/跳页逻辑、分页样式、单元测试、审核注释。
- [ ] 5.5a 根据人工验收补齐 `Pagination` 当前页选中态与键盘跳转:当前页按钮展示明显选中态,跳转输入框按 Enter 触发页码跳转,并补充回归测试和审核注释。
- [x] 5.6 验证 `Table` 与 `Pagination`、`Tag`、`Badge`、`Button`、`Popconfirm` 的组合示例和审核注释。
- [x] 5.7 根据人工验收增强 `Table` 空状态:保留 `emptyText` 兼容,新增可配置 `empty` 插槽,默认复用统一空状态视觉,并在 Demo 表格模块展示空表格样例,补充回归测试和审核注释。
......@@ -100,6 +102,9 @@
- [x] 8.4 实现 `Skeleton` 基础组件:包含接口定义、形状/尺寸/动画逻辑、骨架样式、单元测试、审核注释。
- [x] 8.5 实现 `SkeletonAvatar`、`SkeletonParagraph`、`SkeletonButton` 和 `SkeletonInput`:包含接口定义、组合逻辑、形态样式、单元测试、审核注释。
- [x] 8.6 根据人工验收统一 `Collapse` 等展开箭头:与选择类组件复用同一箭头图标资产,补充样式回归测试。
- [x] 8.7 实现 `StatePlaceholder` 基础接口与请求失败态:支持 `error` 状态、标题、说明、主操作、次操作、图标、可访问性角色、单元测试和审核注释,并确保失败态不使用“暂无数据”文案。
- [ ] 8.8 补齐 `StatePlaceholder` 其他语义状态验收:覆盖 `empty`、`filtered-empty`、`forbidden` 和 `offline` 的专项测试,确认默认标题、说明、角色和样式语义符合规范。
- [ ] 8.9 扩展共享 `Navigation` 组件以支持后台侧边导航:覆盖一级/二级菜单、父子级选中态、数据驱动渲染,补充单元测试、Demo 示例和审核注释。
## 9. 颜色能力组件
......@@ -119,6 +124,8 @@
- [x] 10.7 根据人工验收完善 `Button` Demo:在基础交互模块展示全部按钮类型、尺寸、loading、disabled 和图标场景,补充 Demo 回归测试。
- [x] 10.8 根据人工确认新增 `Upload` Demo:展示文件拖拽上传完成、上传中、失败状态,以及图片/视频媒体墙,补充 Demo 回归测试。
- [x] 10.9 根据人工确认补齐基础输入 Demo:展示 `Input` 与 `Textarea` 的简洁长度显示配置,补充 Demo 回归测试。
- [x] 10.10 补齐 `StatePlaceholder` 请求失败 Demo:展示加载失败状态,并覆盖加载失败提供重试操作、不展示“暂无数据”的验收样例。
- [ ] 10.11 补齐 `StatePlaceholder` 全状态 Demo:展示空数据、筛选无结果、权限受限和离线不可用状态,便于人工验收全部状态占位视觉。
## 10A. 上传组件
......@@ -133,3 +140,4 @@
- [x] 11.3 如果目标项目存在额外测试命令,运行相关自动化测试。
- [ ] 11.4 启动前端应用,并在浏览器中验证独立组件 Demo 路由的布局、交互和设计一致性。
- [ ] 11.5 确认 Demo 路由展示全部一期组件,并纳入 `Upload`,同时排除其他 `App.tsx` 中的 demo-only 组件。
- [x] 11.6 后续验证 `StatePlaceholder` 可在表格或列表内容区域承载失败态,并保持页面框架、筛选区和导航区可用。
......@@ -2,7 +2,7 @@
## 目标
建设一个可承载多个项目的独立 monorepo 工作区。当前优先沉淀前端规则、公司 Web 桌面端组件规范和 Codex + OpenSpec + Superpowers 工作流。首个业务项目是 AI 大模型后台管理平台,用于支持 Agent 管理、Agent 群管理、官网展示配置及相关运营工作流。
建设一个可承载多个项目的独立 monorepo 工作区。当前优先沉淀前端规则、公司 Web 桌面端组件规范和 OpenSpec + Superpowers 工作流。首个业务项目是 AI 大模型后台管理平台,用于支持 Agent 管理、Agent 群管理、官网展示配置及相关运营工作流。
## 流程
......
......@@ -20,15 +20,10 @@
需求沉淀:
- [前端范围与确认决策](./frontend-scope-and-decisions.md)
- [后台登录页需求沉淀](./requirements-admin-login.md)
- [Agent 管理需求沉淀](./requirements-agent-management.md)
- [Agent 群管理需求沉淀](./requirements-agent-group-management.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/`。
......
# 前端待确认事项
更新时间: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 @@
## 文档定位
本文档记录「广联岗位Agent」官网 H5 前台展示页的前端需求与交互确认内容,便于后续 `single-page/` 项目开发对齐。
本文档记录「广联Agent」官网 H5 前台展示页的前端需求与交互确认内容,便于后续 `single-page/` 项目开发对齐。
当前阶段只确认 H5 端展示和交互规则。PC 端展示规范后续补充。
## 项目范围确认
- `workspace/agent-admin/single-page` 负责官网移动端 H5。
- `single-page/` 产品名称统一为「广联Agent」。
- 本文档只约束 H5 端范围,不讨论后端接口实现、数据库、队列、任务和运行时能力。
- `web/` 管理后台前端的范围和规则以 `web/docs` 下的文档为准。
- H5 前台不采集任何埋点。
## 页面目标
官网 H5 前台展示页用于展示「广联岗位Agent」的岗位化智能服务体系。
官网 H5 前台展示页用于展示「广联Agent」的岗位化智能服务体系。
页面优先帮助用户建立“岗位 Agent 体系”的认知,再通过岗位体验入口引导用户扫码添加专属服务助手。
......@@ -32,7 +40,7 @@ PC 端展示规范后续补充,不在本文档展开。
Banner 内容全部来源于接口,包括标题、副标题、背景图等信息。
主标题展示接口返回内容,当前确认标题为:`广联岗位Agent`。
主标题展示接口返回内容,当前确认标题为:`广联Agent`。
副标题展示接口返回内容,示例为:`AI驱动的智能销售服务体系`。
......@@ -139,4 +147,3 @@ Banner 图片缺失时需展示占位背景,保证页面可正常访问。
PC 端展示效果后续补充。
当前阶段仅确认该页面需要兼容 PC 端访问。PC 端布局规则、模块排列和视觉细节将在后续单独补充。
......@@ -45,6 +45,12 @@ npm run build
- `/`:重定向到 `/components`。
- `/components`:UI 组件 Demo 承载路由。
目录演进原则:
- 当前优先保持 `src/App.tsx` 统一注册路由、`src/routes/` 存页面的模式。
- 菜单数量增加本身不构成重构理由,只有路由守卫、动态菜单、嵌套路由和路由元信息管理等复杂度上升时,才评估拆出 `src/router/`。
- 若后续需要演进,优先先抽路由配置和守卫,再考虑页面目录调整。
项目文档:
- [前端地基](./docs/frontend-foundation.md)
......
<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Codex API 等价费用估算</title>
<style>:root {
color-scheme: light;
--bg: #f7f8fb;
--panel: #ffffff;
--text: #1f2937;
--muted: #667085;
--border: #d8dee9;
}
* { box-sizing: border-box; }
body {
margin: 0;
background: var(--bg);
color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.page {
width: min(1080px, calc(100vw - 32px));
margin: 0 auto;
padding: 32px 0 48px;
}
.hero { padding: 8px 0 18px; }
h1 {
margin: 0;
font-size: 34px;
line-height: 1.18;
letter-spacing: 0;
}
.hero p {
margin: 8px 0 18px;
color: var(--muted);
}
.meta-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 10px;
}
.meta-grid div,
.panel {
background: var(--panel);
border: 1px solid var(--border);
border-radius: 8px;
}
.meta-grid div {
padding: 12px;
overflow-wrap: anywhere;
font-size: 18px;
font-weight: 700;
}
.meta-grid span {
display: block;
color: var(--muted);
font-size: 12px;
font-weight: 400;
margin-bottom: 5px;
}
.panel {
padding: 18px;
margin-top: 18px;
}
h2 {
margin: 0 0 14px;
font-size: 18px;
letter-spacing: 0;
}
.chart {
width: 100%;
height: auto;
display: block;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 10px;
color: var(--muted);
font-size: 13px;
}
.legend i {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 2px;
margin-right: 6px;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 14px;
}
th, td {
padding: 10px 8px;
border-bottom: 1px solid var(--border);
text-align: right;
}
th:first-child, td:first-child { text-align: left; }
.notes {
color: var(--muted);
margin: 0;
}
.notes li { margin: 6px 0; }
@media (max-width: 760px) {
.page { width: min(100vw - 20px, 1080px); padding-top: 18px; }
.meta-grid { grid-template-columns: 1fr; }
h1 { font-size: 28px; }
}</style>
</head>
<body>
<main class="page">
<header class="hero">
<h1>Codex API 等价费用估算</h1>
<p>时间窗口: 2026-05-20T00:00:00+08:00 -> 2026-05-20T10:02:06.956313+08:00</p>
<div class="meta-grid">
<div><span>API 等价金额</span>$3.56</div>
<div><span>Codex Credits</span>88.91</div>
<div><span>Total Tokens</span>4,778,002</div>
<div><span>Reasoning</span>2,308</div>
<div><span>数据来源</span>/Users/yuehu/.codex</div>
<div><span>Generated</span>2026-05-20T10:02:07+08:00</div>
</div>
</header>
<section class="panel"><h2>费用构成</h2><svg class="chart" viewBox="0 0 920 230" role="img" aria-label="费用构成">
<text x="22" y="50" fill="#1f2937" font-size="15">非缓存 input</text>
<rect x="150" y="28" width="172.91" height="30" rx="4" fill="#0f766e" />
<text x="334.91" y="49" fill="#1f2937" font-size="15">$0.57</text>
<text x="22" y="108" fill="#1f2937" font-size="15">Cached input</text>
<rect x="150" y="86" width="700.00" height="30" rx="4" fill="#2563eb" />
<text x="862.00" y="107" fill="#1f2937" font-size="15">$2.32</text>
<text x="22" y="166" fill="#1f2937" font-size="15">Output</text>
<rect x="150" y="144" width="199.79" height="30" rx="4" fill="#f59e0b" />
<text x="361.79" y="165" fill="#1f2937" font-size="15">$0.66</text>
</svg>
<div class="legend"><span><i style="background:#0f766e"></i>非缓存 input: 16.1%</span><span><i style="background:#2563eb"></i>Cached input: 65.3%</span><span><i style="background:#f59e0b"></i>Output: 18.6%</span></div></section>
<section class="panel"><h2>明细</h2><table>
<thead><tr><th>类型</th><th>Tokens</th><th>单价</th><th>美元估算</th><th>Codex Credits</th></tr></thead>
<tbody>
<tr><td>非缓存 input</td><td>114,644</td><td>$5 / 1M</td><td>$0.57</td><td>14.33</td></tr>
<tr><td>Cached input</td><td>4,641,280</td><td>$0.5 / 1M</td><td>$2.32</td><td>58.02</td></tr>
<tr><td>Output</td><td>22,078</td><td>$30 / 1M</td><td>$0.66</td><td>16.56</td></tr>
<tr><td><strong>合计</strong></td><td><strong>4,778,002</strong></td><td>-</td><td><strong>$3.56</strong></td><td><strong>88.91</strong></td></tr>
</tbody>
</table></section>
<section class="panel"><h2>说明:</h2><ul class="notes">
<li>这是基于本机 Codex token_count 日志的 API 等价估算,不代表订阅真实账单。</li>
<li>Reasoning token 只做展示,已经包含在 output 口径里,不重复计费。</li>
<li>模型或 rate card 变化时,可以通过费率参数调整单价。</li>
</ul></section>
</main>
</body>
</html>
<!doctype html>
<html lang="zh">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Codex 用量图表</title>
<style>:root {
color-scheme: light;
--bg: #f7f8fb;
--panel: #ffffff;
--text: #1f2937;
--muted: #667085;
--border: #d8dee9;
}
* { box-sizing: border-box; }
body {
margin: 0;
background: var(--bg);
color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}
.page {
width: min(1120px, calc(100vw - 32px));
margin: 0 auto;
padding: 32px 0 48px;
}
.hero {
padding: 8px 0 18px;
}
h1 {
margin: 0;
font-size: 34px;
line-height: 1.18;
letter-spacing: 0;
}
.hero p {
margin: 8px 0 18px;
color: var(--muted);
}
.meta-grid {
display: grid;
grid-template-columns: repeat(3, minmax(0, 1fr));
gap: 10px;
}
.meta-grid div,
.card,
.panel {
background: var(--panel);
border: 1px solid var(--border);
border-radius: 8px;
}
.meta-grid div {
padding: 12px;
overflow-wrap: anywhere;
font-size: 13px;
}
.meta-grid span,
.card span {
display: block;
color: var(--muted);
font-size: 12px;
margin-bottom: 5px;
}
.panel {
padding: 18px;
margin-top: 18px;
}
h2 {
margin: 0 0 14px;
font-size: 18px;
letter-spacing: 0;
}
.cards {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 10px;
}
.card {
padding: 14px;
}
.card strong {
display: block;
font-size: 24px;
line-height: 1.15;
overflow-wrap: anywhere;
}
.chart {
width: 100%;
height: auto;
display: block;
}
.legend {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin-top: 10px;
color: var(--muted);
font-size: 13px;
}
.legend i {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 2px;
margin-right: 6px;
}
table {
width: 100%;
border-collapse: collapse;
font-size: 14px;
}
th, td {
padding: 10px 8px;
border-bottom: 1px solid var(--border);
text-align: right;
}
th:first-child, td:first-child,
th:nth-child(2), td:nth-child(2) {
text-align: left;
}
td:first-child {
overflow-wrap: anywhere;
}
.empty,
.notes {
color: var(--muted);
margin: 0;
}
.notes li {
margin: 6px 0;
}
@media (max-width: 760px) {
.page { width: min(100vw - 20px, 1120px); padding-top: 18px; }
.meta-grid,
.cards { grid-template-columns: 1fr; }
h1 { font-size: 28px; }
.card strong { font-size: 22px; }
}</style>
</head>
<body>
<main class="page">
<header class="hero">
<h1>Codex 用量图表</h1>
<p>基于本地 token_count 日志生成</p>
<div class="meta-grid">
<div><span>时间窗口</span>2026-05-20T00:00:00+08:00 -> 2026-05-20T10:02:06.956313+08:00</div>
<div><span>数据来源</span>/Users/yuehu/.codex</div>
<div><span>生成时间</span>2026-05-20T10:02:07+08:00</div>
</div>
</header>
<section class="panel"><h2>总览</h2><div class="cards"><div class="card"><span>Total</span><strong>4,778,002</strong></div><div class="card"><span>Input</span><strong>4,755,924</strong></div><div class="card"><span>Cached Input</span><strong>4,641,280</strong></div><div class="card"><span>Non-cached Input</span><strong>114,644</strong></div><div class="card"><span>Output</span><strong>22,078</strong></div><div class="card"><span>Reasoning</span><strong>2,308</strong></div><div class="card"><span>Sessions</span><strong>1</strong></div><div class="card"><span>事件数</span><strong>103</strong></div></div></section>
<section class="panel"><h2>Token 构成</h2><svg class="chart" viewBox="0 0 900 116" role="img" aria-label="Token 构成">
<rect x="28" y="34" width="844" height="34" fill="#eef2f7" rx="6" />
<rect x="28.00" y="34" width="819.85" height="34" fill="#2563eb" />
<rect x="847.85" y="34" width="20.25" height="34" fill="#0f766e" />
<rect x="868.10" y="34" width="3.90" height="34" fill="#f59e0b" />
<text x="28" y="24" fill="#667085" font-size="13">Total: 4,778,002</text>
</svg>
<div class="legend"><span><i style="background:#2563eb"></i>Cached Input: 4,641,280 (97.1%)</span><span><i style="background:#0f766e"></i>Non-cached Input: 114,644 (2.4%)</span><span><i style="background:#f59e0b"></i>Output: 22,078 (0.5%)</span></div></section>
<section class="panel"><h2>随时间变化</h2><svg class="chart" viewBox="0 0 960 330" role="img" aria-label="随时间变化">
<line x1="78" y1="246.00" x2="920" y2="246.00" stroke="#d8dee9" />
<text x="68" y="250.00" fill="#667085" font-size="12" text-anchor="end">0</text>
<line x1="78" y1="191.00" x2="920" y2="191.00" stroke="#d8dee9" />
<text x="68" y="195.00" fill="#667085" font-size="12" text-anchor="end">1.2M</text>
<line x1="78" y1="136.00" x2="920" y2="136.00" stroke="#d8dee9" />
<text x="68" y="140.00" fill="#667085" font-size="12" text-anchor="end">2.4M</text>
<line x1="78" y1="81.00" x2="920" y2="81.00" stroke="#d8dee9" />
<text x="68" y="85.00" fill="#667085" font-size="12" text-anchor="end">3.6M</text>
<line x1="78" y1="26.00" x2="920" y2="26.00" stroke="#d8dee9" />
<text x="68" y="30.00" fill="#667085" font-size="12" text-anchor="end">4.8M</text>
<rect x="788.18" y="32.30" width="34.00" height="213.70" fill="#2563eb" />
<rect x="788.18" y="27.02" width="34.00" height="5.28" fill="#0f766e" />
<rect x="788.18" y="26.00" width="34.00" height="1.02" fill="#f59e0b" />
<line x1="78" y1="246" x2="920" y2="246" stroke="#667085" />
<text x="116.27" y="270.00" fill="#667085" font-size="12" text-anchor="middle">00:00</text>
<text x="192.82" y="270.00" fill="#667085" font-size="12" text-anchor="middle">01:00</text>
<text x="269.36" y="270.00" fill="#667085" font-size="12" text-anchor="middle">02:00</text>
<text x="345.91" y="270.00" fill="#667085" font-size="12" text-anchor="middle">03:00</text>
<text x="422.45" y="270.00" fill="#667085" font-size="12" text-anchor="middle">04:00</text>
<text x="499.00" y="270.00" fill="#667085" font-size="12" text-anchor="middle">05:00</text>
<text x="575.55" y="270.00" fill="#667085" font-size="12" text-anchor="middle">06:00</text>
<text x="652.09" y="270.00" fill="#667085" font-size="12" text-anchor="middle">07:00</text>
<text x="728.64" y="270.00" fill="#667085" font-size="12" text-anchor="middle">08:00</text>
<text x="805.18" y="270.00" fill="#667085" font-size="12" text-anchor="middle">09:00</text>
<text x="881.73" y="270.00" fill="#667085" font-size="12" text-anchor="middle">10:00</text>
</svg>
<div class="legend"><span><i style="background:#2563eb"></i>Cached Input</span><span><i style="background:#0f766e"></i>Non-cached Input</span><span><i style="background:#f59e0b"></i>Output</span></div></section>
<section class="panel"><h2>限额变化</h2><svg class="chart" viewBox="0 0 960 290" role="img" aria-label="限额变化">
<line x1="78" y1="216.00" x2="920" y2="216.00" stroke="#d8dee9" />
<text x="68" y="220.00" fill="#667085" font-size="12" text-anchor="end">0%</text>
<line x1="78" y1="168.50" x2="920" y2="168.50" stroke="#d8dee9" />
<text x="68" y="172.50" fill="#667085" font-size="12" text-anchor="end">25%</text>
<line x1="78" y1="121.00" x2="920" y2="121.00" stroke="#d8dee9" />
<text x="68" y="125.00" fill="#667085" font-size="12" text-anchor="end">50%</text>
<line x1="78" y1="73.50" x2="920" y2="73.50" stroke="#d8dee9" />
<text x="68" y="77.50" fill="#667085" font-size="12" text-anchor="end">75%</text>
<line x1="78" y1="26.00" x2="920" y2="26.00" stroke="#d8dee9" />
<text x="68" y="30.00" fill="#667085" font-size="12" text-anchor="end">100%</text>
<circle cx="835.80" cy="174.20" r="4" fill="#dc2626"><title>primary 已用 22%</title></circle>
<circle cx="835.80" cy="210.30" r="4" fill="#4f46e5"><title>secondary 已用 3%</title></circle>
<line x1="78" y1="216" x2="920" y2="216" stroke="#667085" />
<text x="78.00" y="240.00" fill="#667085" font-size="12" text-anchor="middle">00:00</text>
<text x="162.20" y="240.00" fill="#667085" font-size="12" text-anchor="middle">01:00</text>
<text x="246.40" y="240.00" fill="#667085" font-size="12" text-anchor="middle">02:00</text>
<text x="330.60" y="240.00" fill="#667085" font-size="12" text-anchor="middle">03:00</text>
<text x="414.80" y="240.00" fill="#667085" font-size="12" text-anchor="middle">04:00</text>
<text x="499.00" y="240.00" fill="#667085" font-size="12" text-anchor="middle">05:00</text>
<text x="583.20" y="240.00" fill="#667085" font-size="12" text-anchor="middle">06:00</text>
<text x="667.40" y="240.00" fill="#667085" font-size="12" text-anchor="middle">07:00</text>
<text x="751.60" y="240.00" fill="#667085" font-size="12" text-anchor="middle">08:00</text>
<text x="835.80" y="240.00" fill="#667085" font-size="12" text-anchor="middle">09:00</text>
<text x="920.00" y="240.00" fill="#667085" font-size="12" text-anchor="middle">10:00</text>
</svg>
<div class="legend"><span><i style="background:#dc2626"></i>primary 已用</span><span><i style="background:#4f46e5"></i>secondary 已用</span></div></section>
<section class="panel"><h2>Session 排行</h2><table>
<thead><tr><th>Session</th><th>最后事件</th><th>Total</th><th>Output</th><th>Reasoning</th></tr></thead>
<tbody>
<tr><td>rollout-2026-05-20T09-37-23-019e4307-c5c3-7791-8b85-73f4f49d3c31.jsonl</td><td>2026-05-20T09:58:07.634000+08:00</td><td>4,778,002</td><td>22,078</td><td>2,308</td></tr>
</tbody>
</table></section>
<section class="panel"><h2>说明</h2><ul class="notes">
<li>数值来自本机 Codex session 日志里的 token_count 事件。</li>
<li>Cached Input 是 Input 的子集。</li>
<li>Reasoning 单独展示,不会在 Token 构成里重复相加。</li>
</ul></section>
</main>
</body>
</html>
......@@ -8,6 +8,14 @@
当前阶段不把这些规则上升为 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. 当前边界
本项目当前负责岗位Agent管理后台 Web 页面:
......@@ -58,6 +66,9 @@ Tailwind CSS 暂不作为本项目已启用能力。后续如业务页面确有
- `/components` 当前作为组件 Demo 路由。
- 后续业务页面应按模块进入 `src/routes/<module>/`,再由统一路由入口注册。
- 管理后台页面默认使用项目基础布局,不在单个页面里重复实现侧边导航、顶部区域和基础内容容器。
- 当前阶段优先采用 `src/App.tsx` 统一注册路由、`src/routes/` 存页面的模式,不因为菜单数量增加就提前重构目录。
- 当路由守卫、动态菜单、嵌套路由、路由元信息管理等路由治理复杂度明显上升时,再按实际业务需要评估是否拆出 `src/router/`。
- 路由结构演进遵循“先抽路由配置/守卫,再调整页面目录”的原则,尽量避免一次性迁移页面和路由两层职责。
## 6. 组件使用规则
......@@ -78,6 +89,8 @@ Tailwind CSS 暂不作为本项目已启用能力。后续如业务页面确有
破坏性操作默认使用二次确认。表单字段错误显示在字段附近,非字段错误可使用全局反馈。
后台管理页面的埋点规则以对应需求文档和页面确认文档为准,当前只采集页面打开及少量指定操作事件。
## 8. 测试与验证规则
修改本项目代码时,至少按影响范围运行:
......@@ -91,4 +104,3 @@ npm run build
新增或修改页面交互时,应优先补充 Vitest + React Testing Library 测试。无法合理自动化覆盖的布局和关键交互,需要通过浏览器验证记录结果。
本文档本身只整理项目级规范,不改变页面功能代码。
## Why
岗位Agent管理后台需要先落下第一个可实现的产品切片,为后续 Agent 群管理、官网配置等模块提供稳定的登录入口、后台框架和列表页契约。本次变更把已确认的前端本地登录和 Agent 管理列表需求固化为 OpenSpec 规范,作为编码前的行为依据。
## What Changes
- 新增前端本地登录流程,产品名称为 `岗位Agent管理后台`,固定账号密码为 `admin` / `123456`。
- 新增管理后台的受保护路由、登录态本地持久化,以及顶部右侧头像加 `退出登录` 按钮的退出登录行为。
- 新增初始管理后台框架,包含适用于 Agent 管理和后续后台模块的导航结构。
- 新增 Agent 管理列表页,覆盖带 `搜索` / `重置` 按钮的查询区、岗位筛选、状态筛选、表格、分页、加载中、空数据、筛选无结果和失败状态。
- 新增列表行操作规则,覆盖编辑、上架、停用、删除,并为高影响操作提供确认。
- 调整退出登录、Agent 管理菜单层级和岗位筛选交互,使后台框架与列表查询区符合最新确认口径。
- 调整左侧一级菜单、筛选提交时机和分页页大小切换的交互,使管理页的导航和查询体验保持一致。
- 收紧 Agent 列表查询区的容器语义,避免原生 `label` 包裹下拉选择器导致选中后行为不稳定。
- 新增本切片所需的最小 mock 与契约边界,不定义后端实现、存储方案或运行时架构。
## Capabilities
### New Capabilities
- `admin-login`:管理后台前端本地登录、登录态持久化、路由守卫和退出登录行为。
- `admin-shell`:受保护的管理后台布局、导航、头部操作和默认落点行为。
- `agent-management-list`:Agent 管理列表页行为、筛选、表格字段、分页、页面状态、行操作和最小 mock/契约要求。
### Modified Capabilities
- 无。
## Impact
- 影响应用范围:`workspace/agent-admin/web`。
- 影响 UI 行为:登录页、受保护布局、顶部用户区、左侧导航、Agent 管理列表页查询区、高影响操作确认和本地 mock 数据状态。
- 影响共享组件:`Select` 需要补齐下拉选择后的自动收起和按业务关闭清空入口能力。
- 影响共享组件:`Navigation` 需要区分一级分组态和二级选中态,`Pagination` 需要正确接收页大小变更。
- 影响契约范围:Agent 列表和岗位筛选选项所需的前端 mock 结构与页面级数据契约。
- 影响查询区语义:所属岗位和状态筛选的外层容器需要采用普通布局容器,而不是原生 `label`。
- 后端影响:不新增登录接口,不决定后端框架,不设计数据库或队列,不改变运行时 Agent 行为。
## ADDED Requirements
### Requirement: 登录页展示
岗位 Agent 管理后台 SHALL 在用户访问受保护管理页面前提供 `岗位Agent管理后台` 登录页。
#### Scenario: 打开登录页
- **WHEN** 未登录用户打开登录路由
- **THEN** 登录页展示产品名称 `岗位Agent管理后台`
- **AND** 登录页展示账号、密码和登录控件
### Requirement: 本地账号密码校验
岗位 Agent 管理后台 SHALL 在本地校验一期固定账号密码,账号为 `admin`,密码为 `123456`。
#### Scenario: 登录成功
- **WHEN** 用户提交账号 `admin` 和密码 `123456`
- **THEN** 岗位 Agent 管理后台在本地记录用户已登录
- **AND** 岗位 Agent 管理后台跳转到用户原本请求的受保护路由;如果没有原始目标,则跳转到 Agent 管理列表页
#### Scenario: 账号为空
- **WHEN** 用户提交登录表单且账号为空
- **THEN** 登录页在账号字段展示必填提示
- **AND** 岗位 Agent 管理后台不把用户标记为已登录
#### Scenario: 密码为空
- **WHEN** 用户提交登录表单且密码为空
- **THEN** 登录页在密码字段展示必填提示
- **AND** 岗位 Agent 管理后台不把用户标记为已登录
#### Scenario: 账号或密码错误
- **WHEN** 用户提交的账号或密码与固定账号密码不匹配
- **THEN** 登录页展示 `账号或密码错误`
- **AND** 岗位 Agent 管理后台不把用户标记为已登录
### Requirement: 受保护路由守卫
岗位 Agent 管理后台 SHALL 阻止未登录用户查看受保护的管理页面。
#### Scenario: 未登录访问受保护路由
- **WHEN** 未登录用户打开受保护管理路由
- **THEN** 岗位 Agent 管理后台将用户重定向到登录路由
- **AND** 岗位 Agent 管理后台保留用户原本想访问的受保护目标,用于登录成功后跳转
### Requirement: 本地登录态持久化与退出登录
岗位 Agent 管理后台 SHALL 在页面刷新后保留本地登录态,并在用户退出登录时清除本地登录态。
#### Scenario: 登录后刷新
- **WHEN** 已登录用户刷新受保护管理页面
- **THEN** 岗位 Agent 管理后台保持用户停留在受保护管理页面
#### Scenario: 退出登录
- **WHEN** 已登录用户触发退出登录
- **THEN** 岗位 Agent 管理后台先展示退出登录二次确认
- **AND** 仅在用户确认后清除本地登录态
- **AND** 岗位 Agent 管理后台跳转到登录路由
#### Scenario: 取消退出登录
- **WHEN** 已登录用户触发退出登录后取消二次确认
- **THEN** 岗位 Agent 管理后台保持当前登录态
- **AND** 用户继续停留在当前受保护页面
### Requirement: 不调用登录相关接口
岗位 Agent 管理后台 SHALL NOT 在一期登录流程中调用后端登录、退出登录、用户信息、token 刷新或鉴权检查接口。
#### Scenario: 提交登录
- **WHEN** 用户提交任意登录账号密码
- **THEN** 岗位 Agent 管理后台在浏览器内完成校验
- **AND** 不需要发起任何鉴权接口请求
## ADDED Requirements
### Requirement: 受保护后台框架
岗位 Agent 管理后台 SHALL 在共享的受保护后台框架内展示管理页面。
#### Scenario: 展示受保护页面
- **WHEN** 已登录用户打开受保护管理页面
- **THEN** 岗位 Agent 管理后台展示共享后台框架
- **AND** 后台框架标识产品为 `岗位Agent管理后台`
- **AND** 后台框架在顶部右侧提供头像和 `退出登录` 按钮
### Requirement: 管理后台导航
岗位 Agent 管理后台 SHALL 将 Agent 管理作为首个可用管理模块提供导航,并为后续已确认模块保留扩展空间。
#### Scenario: Agent 管理路由激活
- **WHEN** 已登录用户打开 Agent 管理列表页
- **THEN** 后台框架将 `Agent管理` 显示为一级导航项
- **AND** 后台框架将 `Agent列表` 显示为其下的二级导航项
- **AND** `Agent列表` 使用主选中样式
- **AND** `Agent管理` 不使用主选中样式,只作为一级分组项展示
#### Scenario: 复用共享导航组件
- **WHEN** 后台框架渲染左侧导航
- **THEN** 后台框架通过共享 UI 导航组件渲染一级和二级菜单
- **AND** 后台框架 SHALL NOT 在页面内手写导航层级结构、选中态样式或展开交互
### Requirement: 左侧导航信息密度
岗位 Agent 管理后台 SHALL 使用适合桌面后台的左侧导航间距,并保证产品名称在默认桌面布局下不换行。
#### Scenario: 展示左侧导航
- **WHEN** 已登录用户在默认桌面宽度下查看后台框架
- **THEN** 左侧导航内边距保持紧凑,避免出现过大的顶部或左右留白
- **AND** 产品名称 `岗位Agent管理后台` 在左侧导航品牌区域保持单行展示
### Requirement: 默认受保护落点
岗位 Agent 管理后台 SHALL 将 Agent 管理列表页作为默认受保护落点。
#### Scenario: 已登录用户打开应用根路径
- **WHEN** 已登录用户打开应用根路径
- **THEN** 岗位 Agent 管理后台跳转到 Agent 管理列表页
#### Scenario: 登录成功且没有保存目标
- **WHEN** 登录成功且没有保存用户原本访问的受保护目标
- **THEN** 岗位 Agent 管理后台跳转到 Agent 管理列表页
### Requirement: 后台框架页面状态
岗位 Agent 管理后台 SHALL 在受保护页面展示加载中、空数据、筛选无结果或失败状态时,保持后台框架导航和退出登录可用。
#### Scenario: 页面数据加载失败
- **WHEN** Agent 管理列表页展示数据加载失败状态
- **THEN** 后台框架仍然可见
- **AND** 用户仍可导航或退出登录
## ADDED Requirements
### Requirement: Agent 列表页结构
岗位 Agent 管理后台 SHALL 提供 Agent 管理列表页,包含标题、搜索与筛选控件、主操作区、表格和分页。
#### Scenario: 打开 Agent 列表页
- **WHEN** 已登录用户打开 Agent 管理列表页
- **THEN** Agent 管理列表页展示页面标题 `Agent管理`
- **AND** Agent 管理列表页展示 Agent 名称搜索框、所属岗位下拉框、状态下拉框、`搜索` 按钮、`重置` 按钮、表格和分页控件
### Requirement: Agent 列表查询控件
Agent 管理列表页 SHALL 允许用户按名称关键词、单个岗位和状态值 `全部`、`已上架`、`已停用` 查询 Agent。
#### Scenario: 提交关键词搜索
- **WHEN** 用户在 Agent 列表搜索控件中输入关键词并点击 `搜索`
- **THEN** Agent 管理列表页使用该关键词刷新列表
- **AND** Agent 管理列表页将分页行为保持为筛选结果第一页
#### Scenario: 切换岗位筛选
- **WHEN** 用户选择一个岗位筛选选项
- **THEN** Agent 管理列表页仅更新当前岗位筛选值
- **AND** Agent 管理列表页不会立即刷新列表
#### Scenario: 选择全部岗位
- **WHEN** 用户打开所属岗位下拉框
- **THEN** 下拉选项中包含 `全部` 选项
- **AND** 用户选择 `全部` 后,Agent 管理列表页取消岗位筛选
#### Scenario: 切换状态筛选
- **WHEN** 用户选择 `已上架` 或 `已停用`
- **THEN** Agent 管理列表页仅更新当前状态筛选值
- **AND** Agent 管理列表页不会立即刷新列表
#### Scenario: 提交筛选条件
- **WHEN** 用户已调整关键词、岗位或状态筛选值后点击 `搜索`
- **THEN** Agent 管理列表页使用当前表单中的关键词、岗位和状态条件刷新列表
- **AND** Agent 管理列表页将分页行为保持为筛选结果第一页
#### Scenario: 重置查询条件
- **WHEN** 用户在 Agent 列表页点击 `重置`
- **THEN** Agent 管理列表页清空关键词、所属岗位和状态筛选值
- **AND** Agent 管理列表页恢复默认查询条件并回到第 `1` 页
#### Scenario: 查询区字段与顺序
- **WHEN** 用户查看 Agent 列表查询区
- **THEN** 查询区按 `Agent名称`、`所属岗位`、`状态` 的顺序展示字段标签和对应控件
- **AND** 查询区采用左右结构,字段标签在左、输入/下拉控件在右
- **AND** 查询区在右侧操作区展示 `搜索` 按钮和 `重置` 按钮
### Requirement: 查询区容器语义
Agent 管理列表页 SHALL 使用普通布局容器承载 `所属岗位` 和 `状态` 下拉框,不通过原生 `label` 包裹下拉选择器。
#### Scenario: 打开查询区
- **WHEN** 用户查看 Agent 列表查询区
- **THEN** `所属岗位` 和 `状态` 下拉框外层使用普通容器
- **AND** 下拉框点击选项时不会因为外层原生 `label` 的激活行为重新打开控件
#### Scenario: 查询区控件宽度
- **WHEN** 用户查看 Agent 名称搜索框、所属岗位下拉框和状态下拉框
- **THEN** 三个控件宽度保持一致
- **AND** 每个控件宽度为 `200px`
#### Scenario: 岗位筛选不展示额外清空按钮
- **WHEN** 用户已经选择具体岗位
- **THEN** 所属岗位控件下方不展示额外的 `清空` 按钮
- **AND** 用户可通过重新选择 `全部` 或点击查询区 `重置` 按钮恢复默认筛选
#### Scenario: 选择后收起下拉框
- **WHEN** 用户在所属岗位或状态下拉框中选择某个选项
- **THEN** 当前下拉面板立即关闭
### Requirement: Agent 表格列
Agent 管理列表页 SHALL 为每条 Agent 列表数据展示 Agent 名称、所属岗位、状态、绑定群数、绑定 Skill 数、更新时间和行操作。
#### Scenario: 展示普通 Agent 行
- **WHEN** 列表包含非管家 Agent
- **THEN** 行内展示 Agent 名称、岗位标签、状态标签、绑定群数、绑定 Skill 数、更新时间和允许执行的操作
#### Scenario: 展示管家 Agent 行
- **WHEN** 列表包含管家 Agent
- **THEN** 行内岗位展示为 `系统调度`
- **AND** 行内不展示绑定 Skill 数值
### Requirement: 管家 Agent 展示与排序
Agent 管理列表页 SHALL 在页面数据包含管家 Agent 时保持其可见,并将其置于普通 Agent 之前。
#### Scenario: 正常列表数据包含管家 Agent
- **WHEN** Agent 列表数据同时包含管家 Agent 和普通 Agent
- **THEN** Agent 管理列表页将管家 Agent 展示在普通 Agent 之前
#### Scenario: 不存在普通 Agent
- **WHEN** 不存在普通 Agent
- **THEN** 只要 mock 或页面数据提供管家 Agent,Agent 管理列表页仍展示管家 Agent
### Requirement: Agent 状态展示
Agent 管理列表页 SHALL 将启用 Agent 展示为 `已上架`,将停用 Agent 展示为 `已停用`,并使用视觉上可区分的状态标签。
#### Scenario: 展示已上架 Agent 行
- **WHEN** Agent 列表项状态为 `enable`
- **THEN** Agent 管理列表页展示状态文案 `已上架`
#### Scenario: 展示已停用 Agent 行
- **WHEN** Agent 列表项状态为 `disable`
- **THEN** Agent 管理列表页展示状态文案 `已停用`
### Requirement: Agent 行操作
Agent 管理列表页 SHALL 按 Agent 类型和状态展示行操作。
#### Scenario: 管家 Agent 操作
- **WHEN** 行数据代表管家 Agent
- **THEN** Agent 管理列表页允许编辑
- **AND** Agent 管理列表页不允许停用、上架或删除
#### Scenario: 已上架普通 Agent 操作
- **WHEN** 行数据代表已上架的非管家 Agent
- **THEN** Agent 管理列表页允许编辑、停用和删除
- **AND** 停用和删除在执行前需要确认
#### Scenario: 已停用普通 Agent 操作
- **WHEN** 行数据代表已停用的非管家 Agent
- **THEN** Agent 管理列表页允许编辑、上架和删除
- **AND** 删除在执行前需要确认
### Requirement: 删除确认
Agent 管理列表页 SHALL 在删除非管家 Agent 前展示已确认的删除影响文案。
#### Scenario: 请求删除
- **WHEN** 用户请求删除 Agent `复盘Agent`
- **THEN** 确认框展示 `确认删除 Agent "复盘Agent"?`
- **AND** 确认框说明该 Agent 的企微员工会从所有已关联群中退出、官网展示配置会被清理、渠道活码 Agent 列表中不再出现该 Agent、关联的岗位标签不受影响
### Requirement: 页面状态
Agent 管理列表页 SHALL 提供加载中、正常数据、空数据、筛选无结果和失败状态。
#### Scenario: 列表加载中
- **WHEN** Agent 列表数据正在加载
- **THEN** Agent 管理列表页在不离开受保护后台框架的情况下展示加载中状态
#### Scenario: 筛选无结果
- **WHEN** 当前搜索或筛选条件没有匹配的普通 Agent 行
- **THEN** Agent 管理列表页展示筛选无结果状态,并允许用户调整或清空筛选
#### Scenario: 数据加载失败
- **WHEN** Agent 列表数据加载失败
- **THEN** Agent 管理列表页使用组件库 `StatePlaceholder` 的 `error` 语义展示可恢复的失败状态
- **AND** Agent 管理列表页提供重试操作
- **AND** Agent 管理列表页 SHALL NOT 使用“暂无数据”作为失败态主文案
### Requirement: Agent 列表分页展示
Agent 管理列表页 SHALL 根据列表总数和每页条数展示正确的分页页码。
#### Scenario: 总数不足一页
- **WHEN** 当前列表总数为 `6` 且每页条数为 `10`
- **THEN** Agent 管理列表页只展示 `1` 页
- **AND** Agent 管理列表页不得展示第 `2` 页
#### Scenario: 切换每页条数
- **WHEN** 用户在分页中选择新的 `每页条数`
- **THEN** Agent 管理列表页更新当前每页条数
- **AND** Agent 管理列表页回到第 `1` 页
- **AND** 列表结果随新的每页条数重新计算
### Requirement: Agent 列表最小 mock 契约
前端 mock 契约 SHALL 提供本列表切片需要的 mock 数据和页面契约字段,并且不要求后端实现细节。
#### Scenario: 消费 mock Agent 列表项
- **WHEN** Agent 列表页渲染 mock Agent 项
- **THEN** 该项包含 `agent_id`、`name`、`is_manager`、`positions`、`status`、`bound_group_count`、`bound_skill_count`、`updated_at` 和可用操作信息
#### Scenario: 消费 mock 岗位选项
- **WHEN** Agent 列表页渲染岗位筛选
- **THEN** mock 契约提供包含稳定 id 和展示名称字段的岗位选项
#### Scenario: 消费 mock 页面状态 fixtures
- **WHEN** 测试或本地开发需要列表页状态
- **THEN** mock 契约提供正常数据、空数据、筛选无结果、加载中、失败、长文本、不可用操作和分页边界场景 fixtures
## 1. 路由与登录基础
- [x] 1.1 新增登录页、应用根路径重定向和 Agent 管理列表页的路由定义。
- [x] 1.2 新增本地登录态 helper,覆盖固定账号密码校验、登录态持久化、访问目标保留和退出登录。
- [x] 1.3 补充测试,覆盖登录成功、必填校验、账号密码错误、刷新后保持登录、受保护路由跳转和退出登录。
## 2. 受保护后台框架
- [x] 2.1 实现共享受保护后台框架,包含产品标识、Agent 管理导航、内容出口和退出登录控件。
- [x] 2.2 补充后台框架行为测试,覆盖 Agent 管理导航激活、登录后默认落点和页面失败状态下框架仍可见。
- [x] 2.3 验证后台框架布局符合 Web 桌面端后台设计规则:导航信息密度合理、视觉克制、不采用营销页构图。
- [x] 2.4 调整后台头部右侧用户区,明确展示头像和 `退出登录` 按钮,并更新对应测试。
- [ ] 2.5 收紧左侧导航间距,确保 `岗位Agent管理后台` 在默认桌面宽度下单行展示,并完成浏览器验证。
- [x] 2.6 基于共享 UI 导航组件将后台左侧导航调整为 `Agent管理` 一级菜单 + `Agent列表` 二级菜单,并确保一级菜单不展示主选中效果、二级菜单承担主选中样式,补充对应测试。
- [x] 2.7 为顶部 `退出登录` 增加二次确认弹窗,并补充确认/取消两条行为测试。
## 3. Agent 列表 mock 契约
- [x] 3.1 定义前端 Agent 列表 mock 类型和 fixtures,覆盖正常数据、仅管家 Agent、空数据、筛选无结果、加载中、失败、长文本、不可用操作和分页边界。
- [x] 3.2 更新 `packages/contracts/frontend-api-contract.md` 或相邻契约模块,记录列表页最小字段:`agent_id`、`name`、`is_manager`、`positions`、`status`、`bound_group_count`、`bound_skill_count`、`updated_at` 和可用操作。
- [x] 3.3 补充契约或 fixture 测试,证明 Agent 列表页可以在没有后端接口的情况下消费最小 mock 数据。
## 4. Agent 管理列表页
- [x] 4.1 实现 Agent 管理列表页结构,包含标题、关键词搜索、岗位筛选、状态筛选、主操作区、表格和分页。
- [x] 4.2 实现表格展示规则,覆盖管家 Agent 置顶、`系统调度` 岗位展示、管家 Agent 隐藏 Skill 数、状态标签、数量字段、更新时间和行操作。
- [x] 4.3 实现查询控件行为,覆盖关键词搜索、岗位单选筛选、状态筛选、回到第一页和分页。
- [x] 4.4 实现页面状态,覆盖加载中、正常数据、仅管家 Agent 或空数据、筛选无结果、失败和重试;失败态使用 `StatePlaceholder state="error"`,不得展示“暂无数据”主文案。
- [x] 4.5 实现行操作行为,覆盖编辑入口、上架、停用确认、删除确认和管家 Agent 操作限制。
- [x] 4.6 补充测试,覆盖列表渲染、筛选、分页、管家 Agent 规则、行操作可用性、删除确认文案和可恢复失败状态;断言失败态展示重试操作且不展示“暂无数据”主文案。
- [x] 4.7 调整查询区结构,按 `Agent名称`、`所属岗位`、`状态` 的顺序展示控件,并补齐 `搜索` / `重置` 按钮。
- [x] 4.8 将 Agent 名称搜索框、所属岗位下拉框和状态下拉框宽度统一为 `200px`,并使用 Tailwind CSS 实现,不为该功能新增独立样式文件。
- [x] 4.9 修正分页逻辑,确保总数 `6`、每页 `10` 条时只展示 `1` 页,同时接通每页条数切换并补充对应测试。
- [x] 4.10 调整所属岗位与状态筛选的外层结构,改用普通布局容器替代原生 `label` 包裹,避免选中后控件被重新激活,并补充对应测试。
- [x] 4.11 调整所属岗位筛选:下拉项补齐 `全部` 选项,已选具体岗位后不展示额外 `清空` 按钮,并补充对应测试。
- [x] 4.12 调整查询条件提交时机,确保所属岗位和状态下拉改值只更新表单状态、不自动触发搜索,只有点击 `搜索` 后才提交当前条件,并补充对应测试。
- [x] 4.13 修正查询区 `重置` 行为,确保已选择的所属岗位、状态和关键词都会清空,并补充对应测试。
## 5. Verification
- [x] 5.1 运行登录、后台框架、mock 契约和 Agent 列表行为相关单元测试。
- [x] 5.2 在 `workspace/agent-admin/web` 运行类型检查和生产构建。
- [x] 5.3 运行浏览器验证,覆盖登录、受保护路由跳转、退出登录、Agent 列表筛选、行操作、页面状态和桌面端响应式布局。
- [x] 5.4 重新运行浏览器验证,重点覆盖顶部用户区、左侧导航单行展示、查询区字段顺序、`搜索` / `重置` 按钮、`200px` 控件宽度和单页分页场景。
- [x] 5.5 重新运行浏览器验证,覆盖退出登录二次确认、左侧导航仅二级主选中且一级无主选中效果、所属岗位 `全部` 选项、下拉选择后自动收起、无额外清空按钮、岗位/状态下拉改值不自动搜索、每页条数切换生效,以及普通容器承载下拉控件后不会被 label 重新激活。
- [x] 5.6 重新运行浏览器验证,覆盖查询区 `重置` 后关键词、所属岗位、状态都回到默认值。
- [x] 5.7 请求 OpenSpec 归档前,按真实实现结果更新本任务清单。
# admin-login Specification
## Purpose
TBD - created by archiving change add-admin-login-agent-list-mock. Update Purpose after archive.
## Requirements
### Requirement: 登录页展示
岗位 Agent 管理后台 SHALL 在用户访问受保护管理页面前提供 `岗位Agent管理后台` 登录页。
#### Scenario: 打开登录页
- **WHEN** 未登录用户打开登录路由
- **THEN** 登录页展示产品名称 `岗位Agent管理后台`
- **AND** 登录页展示账号、密码和登录控件
### Requirement: 本地账号密码校验
岗位 Agent 管理后台 SHALL 在本地校验一期固定账号密码,账号为 `admin`,密码为 `123456`。
#### Scenario: 登录成功
- **WHEN** 用户提交账号 `admin` 和密码 `123456`
- **THEN** 岗位 Agent 管理后台在本地记录用户已登录
- **AND** 岗位 Agent 管理后台跳转到用户原本请求的受保护路由;如果没有原始目标,则跳转到 Agent 管理列表页
#### Scenario: 账号为空
- **WHEN** 用户提交登录表单且账号为空
- **THEN** 登录页在账号字段展示必填提示
- **AND** 岗位 Agent 管理后台不把用户标记为已登录
#### Scenario: 密码为空
- **WHEN** 用户提交登录表单且密码为空
- **THEN** 登录页在密码字段展示必填提示
- **AND** 岗位 Agent 管理后台不把用户标记为已登录
#### Scenario: 账号或密码错误
- **WHEN** 用户提交的账号或密码与固定账号密码不匹配
- **THEN** 登录页展示 `账号或密码错误`
- **AND** 岗位 Agent 管理后台不把用户标记为已登录
### Requirement: 受保护路由守卫
岗位 Agent 管理后台 SHALL 阻止未登录用户查看受保护的管理页面。
#### Scenario: 未登录访问受保护路由
- **WHEN** 未登录用户打开受保护管理路由
- **THEN** 岗位 Agent 管理后台将用户重定向到登录路由
- **AND** 岗位 Agent 管理后台保留用户原本想访问的受保护目标,用于登录成功后跳转
### Requirement: 本地登录态持久化与退出登录
岗位 Agent 管理后台 SHALL 在页面刷新后保留本地登录态,并在用户退出登录时清除本地登录态。
#### Scenario: 登录后刷新
- **WHEN** 已登录用户刷新受保护管理页面
- **THEN** 岗位 Agent 管理后台保持用户停留在受保护管理页面
#### Scenario: 退出登录
- **WHEN** 已登录用户触发退出登录
- **THEN** 岗位 Agent 管理后台先展示退出登录二次确认
- **AND** 仅在用户确认后清除本地登录态
- **AND** 岗位 Agent 管理后台跳转到登录路由
#### Scenario: 取消退出登录
- **WHEN** 已登录用户触发退出登录后取消二次确认
- **THEN** 岗位 Agent 管理后台保持当前登录态
- **AND** 用户继续停留在当前受保护页面
### Requirement: 不调用登录相关接口
岗位 Agent 管理后台 SHALL NOT 在一期登录流程中调用后端登录、退出登录、用户信息、token 刷新或鉴权检查接口。
#### Scenario: 提交登录
- **WHEN** 用户提交任意登录账号密码
- **THEN** 岗位 Agent 管理后台在浏览器内完成校验
- **AND** 不需要发起任何鉴权接口请求
# admin-shell Specification
## Purpose
TBD - created by archiving change add-admin-login-agent-list-mock. Update Purpose after archive.
## Requirements
### Requirement: 受保护后台框架
岗位 Agent 管理后台 SHALL 在共享的受保护后台框架内展示管理页面。
#### Scenario: 展示受保护页面
- **WHEN** 已登录用户打开受保护管理页面
- **THEN** 岗位 Agent 管理后台展示共享后台框架
- **AND** 后台框架标识产品为 `岗位Agent管理后台`
- **AND** 后台框架在顶部右侧提供头像和 `退出登录` 按钮
### Requirement: 管理后台导航
岗位 Agent 管理后台 SHALL 将 Agent 管理作为首个可用管理模块提供导航,并为后续已确认模块保留扩展空间。
#### Scenario: Agent 管理路由激活
- **WHEN** 已登录用户打开 Agent 管理列表页
- **THEN** 后台框架将 `Agent管理` 显示为一级导航项
- **AND** 后台框架将 `Agent列表` 显示为其下的二级导航项
- **AND** `Agent列表` 使用主选中样式
- **AND** `Agent管理` 不使用主选中样式,只作为一级分组项展示
#### Scenario: 复用共享导航组件
- **WHEN** 后台框架渲染左侧导航
- **THEN** 后台框架通过共享 UI 导航组件渲染一级和二级菜单
- **AND** 后台框架 SHALL NOT 在页面内手写导航层级结构、选中态样式或展开交互
### Requirement: 左侧导航信息密度
岗位 Agent 管理后台 SHALL 使用适合桌面后台的左侧导航间距,并保证产品名称在默认桌面布局下不换行。
#### Scenario: 展示左侧导航
- **WHEN** 已登录用户在默认桌面宽度下查看后台框架
- **THEN** 左侧导航内边距保持紧凑,避免出现过大的顶部或左右留白
- **AND** 产品名称 `岗位Agent管理后台` 在左侧导航品牌区域保持单行展示
### Requirement: 默认受保护落点
岗位 Agent 管理后台 SHALL 将 Agent 管理列表页作为默认受保护落点。
#### Scenario: 已登录用户打开应用根路径
- **WHEN** 已登录用户打开应用根路径
- **THEN** 岗位 Agent 管理后台跳转到 Agent 管理列表页
#### Scenario: 登录成功且没有保存目标
- **WHEN** 登录成功且没有保存用户原本访问的受保护目标
- **THEN** 岗位 Agent 管理后台跳转到 Agent 管理列表页
### Requirement: 后台框架页面状态
岗位 Agent 管理后台 SHALL 在受保护页面展示加载中、空数据、筛选无结果或失败状态时,保持后台框架导航和退出登录可用。
#### Scenario: 页面数据加载失败
- **WHEN** Agent 管理列表页展示数据加载失败状态
- **THEN** 后台框架仍然可见
- **AND** 用户仍可导航或退出登录
# agent-management-list Specification
## Purpose
TBD - created by archiving change add-admin-login-agent-list-mock. Update Purpose after archive.
## Requirements
### Requirement: Agent 列表页结构
岗位 Agent 管理后台 SHALL 提供 Agent 管理列表页,包含标题、搜索与筛选控件、主操作区、表格和分页。
#### Scenario: 打开 Agent 列表页
- **WHEN** 已登录用户打开 Agent 管理列表页
- **THEN** Agent 管理列表页展示页面标题 `Agent管理`
- **AND** Agent 管理列表页展示 Agent 名称搜索框、所属岗位下拉框、状态下拉框、`搜索` 按钮、`重置` 按钮、表格和分页控件
### Requirement: Agent 列表查询控件
Agent 管理列表页 SHALL 允许用户按名称关键词、单个岗位和状态值 `全部`、`已上架`、`已停用` 查询 Agent。
#### Scenario: 提交关键词搜索
- **WHEN** 用户在 Agent 列表搜索控件中输入关键词并点击 `搜索`
- **THEN** Agent 管理列表页使用该关键词刷新列表
- **AND** Agent 管理列表页将分页行为保持为筛选结果第一页
#### Scenario: 切换岗位筛选
- **WHEN** 用户选择一个岗位筛选选项
- **THEN** Agent 管理列表页仅更新当前岗位筛选值
- **AND** Agent 管理列表页不会立即刷新列表
#### Scenario: 选择全部岗位
- **WHEN** 用户打开所属岗位下拉框
- **THEN** 下拉选项中包含 `全部` 选项
- **AND** 用户选择 `全部` 后,Agent 管理列表页取消岗位筛选
#### Scenario: 切换状态筛选
- **WHEN** 用户选择 `已上架` 或 `已停用`
- **THEN** Agent 管理列表页仅更新当前状态筛选值
- **AND** Agent 管理列表页不会立即刷新列表
#### Scenario: 提交筛选条件
- **WHEN** 用户已调整关键词、岗位或状态筛选值后点击 `搜索`
- **THEN** Agent 管理列表页使用当前表单中的关键词、岗位和状态条件刷新列表
- **AND** Agent 管理列表页将分页行为保持为筛选结果第一页
#### Scenario: 重置查询条件
- **WHEN** 用户在 Agent 列表页点击 `重置`
- **THEN** Agent 管理列表页清空关键词、所属岗位和状态筛选值
- **AND** Agent 管理列表页恢复默认查询条件并回到第 `1` 页
#### Scenario: 查询区字段与顺序
- **WHEN** 用户查看 Agent 列表查询区
- **THEN** 查询区按 `Agent名称`、`所属岗位`、`状态` 的顺序展示字段标签和对应控件
- **AND** 查询区采用左右结构,字段标签在左、输入/下拉控件在右
- **AND** 查询区在右侧操作区展示 `搜索` 按钮和 `重置` 按钮
### Requirement: 查询区容器语义
Agent 管理列表页 SHALL 使用普通布局容器承载 `所属岗位` 和 `状态` 下拉框,不通过原生 `label` 包裹下拉选择器。
#### Scenario: 打开查询区
- **WHEN** 用户查看 Agent 列表查询区
- **THEN** `所属岗位` 和 `状态` 下拉框外层使用普通容器
- **AND** 下拉框点击选项时不会因为外层原生 `label` 的激活行为重新打开控件
#### Scenario: 查询区控件宽度
- **WHEN** 用户查看 Agent 名称搜索框、所属岗位下拉框和状态下拉框
- **THEN** 三个控件宽度保持一致
- **AND** 每个控件宽度为 `200px`
#### Scenario: 岗位筛选不展示额外清空按钮
- **WHEN** 用户已经选择具体岗位
- **THEN** 所属岗位控件下方不展示额外的 `清空` 按钮
- **AND** 用户可通过重新选择 `全部` 或点击查询区 `重置` 按钮恢复默认筛选
#### Scenario: 选择后收起下拉框
- **WHEN** 用户在所属岗位或状态下拉框中选择某个选项
- **THEN** 当前下拉面板立即关闭
### Requirement: Agent 表格列
Agent 管理列表页 SHALL 为每条 Agent 列表数据展示 Agent 名称、所属岗位、状态、绑定群数、绑定 Skill 数、更新时间和行操作。
#### Scenario: 展示普通 Agent 行
- **WHEN** 列表包含非管家 Agent
- **THEN** 行内展示 Agent 名称、岗位标签、状态标签、绑定群数、绑定 Skill 数、更新时间和允许执行的操作
#### Scenario: 展示管家 Agent 行
- **WHEN** 列表包含管家 Agent
- **THEN** 行内岗位展示为 `系统调度`
- **AND** 行内不展示绑定 Skill 数值
### Requirement: 管家 Agent 展示与排序
Agent 管理列表页 SHALL 在页面数据包含管家 Agent 时保持其可见,并将其置于普通 Agent 之前。
#### Scenario: 正常列表数据包含管家 Agent
- **WHEN** Agent 列表数据同时包含管家 Agent 和普通 Agent
- **THEN** Agent 管理列表页将管家 Agent 展示在普通 Agent 之前
#### Scenario: 不存在普通 Agent
- **WHEN** 不存在普通 Agent
- **THEN** 只要 mock 或页面数据提供管家 Agent,Agent 管理列表页仍展示管家 Agent
### Requirement: Agent 状态展示
Agent 管理列表页 SHALL 将启用 Agent 展示为 `已上架`,将停用 Agent 展示为 `已停用`,并使用视觉上可区分的状态标签。
#### Scenario: 展示已上架 Agent 行
- **WHEN** Agent 列表项状态为 `enable`
- **THEN** Agent 管理列表页展示状态文案 `已上架`
#### Scenario: 展示已停用 Agent 行
- **WHEN** Agent 列表项状态为 `disable`
- **THEN** Agent 管理列表页展示状态文案 `已停用`
### Requirement: Agent 行操作
Agent 管理列表页 SHALL 按 Agent 类型和状态展示行操作。
#### Scenario: 管家 Agent 操作
- **WHEN** 行数据代表管家 Agent
- **THEN** Agent 管理列表页允许编辑
- **AND** Agent 管理列表页不允许停用、上架或删除
#### Scenario: 已上架普通 Agent 操作
- **WHEN** 行数据代表已上架的非管家 Agent
- **THEN** Agent 管理列表页允许编辑、停用和删除
- **AND** 停用和删除在执行前需要确认
#### Scenario: 已停用普通 Agent 操作
- **WHEN** 行数据代表已停用的非管家 Agent
- **THEN** Agent 管理列表页允许编辑、上架和删除
- **AND** 删除在执行前需要确认
### Requirement: 删除确认
Agent 管理列表页 SHALL 在删除非管家 Agent 前展示已确认的删除影响文案。
#### Scenario: 请求删除
- **WHEN** 用户请求删除 Agent `复盘Agent`
- **THEN** 确认框展示 `确认删除 Agent "复盘Agent"?`
- **AND** 确认框说明该 Agent 的企微员工会从所有已关联群中退出、官网展示配置会被清理、渠道活码 Agent 列表中不再出现该 Agent、关联的岗位标签不受影响
### Requirement: 页面状态
Agent 管理列表页 SHALL 提供加载中、正常数据、空数据、筛选无结果和失败状态。
#### Scenario: 列表加载中
- **WHEN** Agent 列表数据正在加载
- **THEN** Agent 管理列表页在不离开受保护后台框架的情况下展示加载中状态
#### Scenario: 筛选无结果
- **WHEN** 当前搜索或筛选条件没有匹配的普通 Agent 行
- **THEN** Agent 管理列表页展示筛选无结果状态,并允许用户调整或清空筛选
#### Scenario: 数据加载失败
- **WHEN** Agent 列表数据加载失败
- **THEN** Agent 管理列表页使用组件库 `StatePlaceholder` 的 `error` 语义展示可恢复的失败状态
- **AND** Agent 管理列表页提供重试操作
- **AND** Agent 管理列表页 SHALL NOT 使用“暂无数据”作为失败态主文案
### Requirement: Agent 列表分页展示
Agent 管理列表页 SHALL 根据列表总数和每页条数展示正确的分页页码。
#### Scenario: 总数不足一页
- **WHEN** 当前列表总数为 `6` 且每页条数为 `10`
- **THEN** Agent 管理列表页只展示 `1` 页
- **AND** Agent 管理列表页不得展示第 `2` 页
#### Scenario: 切换每页条数
- **WHEN** 用户在分页中选择新的 `每页条数`
- **THEN** Agent 管理列表页更新当前每页条数
- **AND** Agent 管理列表页回到第 `1` 页
- **AND** 列表结果随新的每页条数重新计算
### Requirement: Agent 列表最小 mock 契约
前端 mock 契约 SHALL 提供本列表切片需要的 mock 数据和页面契约字段,并且不要求后端实现细节。
#### Scenario: 消费 mock Agent 列表项
- **WHEN** Agent 列表页渲染 mock Agent 项
- **THEN** 该项包含 `agent_id`、`name`、`is_manager`、`positions`、`status`、`bound_group_count`、`bound_skill_count`、`updated_at` 和可用操作信息
#### Scenario: 消费 mock 岗位选项
- **WHEN** Agent 列表页渲染岗位筛选
- **THEN** mock 契约提供包含稳定 id 和展示名称字段的岗位选项
#### Scenario: 消费 mock 页面状态 fixtures
- **WHEN** 测试或本地开发需要列表页状态
- **THEN** mock 契约提供正常数据、空数据、筛选无结果、加载中、失败、长文本、不可用操作和分页边界场景 fixtures
......@@ -13,11 +13,11 @@
},
"dependencies": {
"@vitejs/plugin-react": "^5.1.2",
"vite": "^7.3.0",
"typescript": "^5.9.3",
"react": "^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": {
"@testing-library/jest-dom": "^6.9.1",
......@@ -25,7 +25,10 @@
"@types/node": "^25.0.1",
"@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3",
"autoprefixer": "^10.5.0",
"jsdom": "^27.3.0",
"postcss": "^8.5.15",
"tailwindcss": "^3.4.17",
"vitest": "^4.0.15"
}
}
import { describe, expect, it } from 'vitest';
import {
agentListMockFixtures,
agentPositionOptions,
getAgentListPage,
sortAgentsForDisplay,
} from './agent-list-mock';
describe('agent list mock contract', () => {
it('provides the minimal page-facing fields and stable position options', () => {
const [agent] = agentListMockFixtures.normal.items;
expect(agent).toMatchObject({
agent_id: expect.any(Number),
name: expect.any(String),
is_manager: expect.any(Boolean),
positions: expect.any(Array),
status: expect.stringMatching(/enable|disable/),
bound_group_count: expect.any(Number),
bound_skill_count: expect.any(Number),
updated_at: expect.any(String),
available_actions: expect.any(Array),
});
expect(agentPositionOptions[0]).toEqual({ id: 'sales', name: '驻店销售岗' });
});
it('covers required page state fixtures without a backend service', () => {
expect(Object.keys(agentListMockFixtures).sort()).toEqual([
'disabledActions',
'empty',
'error',
'filteredEmpty',
'loading',
'longText',
'managerOnly',
'normal',
'paginationBoundary',
]);
});
it('keeps manager agents visible and sorted before ordinary agents', () => {
const sorted = sortAgentsForDisplay(agentListMockFixtures.normal.items);
expect(sorted[0].is_manager).toBe(true);
expect(sorted[0].positions).toEqual([]);
});
it('filters and paginates mock data from page-facing query fields', () => {
const result = getAgentListPage({ keyword: '复盘', positionId: 'sales', status: 'enable', page: 1, pageSize: 10 });
expect(result.total).toBe(1);
expect(result.items[0].name).toBe('复盘Agent');
});
});
export type AgentStatus = 'enable' | 'disable';
export type AgentAction = 'edit' | 'enable' | 'disable' | 'delete';
export interface AgentPositionOption {
id: string;
name: string;
}
export interface AgentListMockItem extends Record<string, unknown> {
agent_id: number;
name: string;
is_manager: boolean;
positions: AgentPositionOption[];
status: AgentStatus;
bound_group_count: number;
bound_skill_count: number;
updated_at: string;
available_actions: AgentAction[];
}
export interface AgentListMockFixture {
loading?: boolean;
error?: boolean;
items: AgentListMockItem[];
total?: number;
}
export interface AgentListPageQuery {
keyword?: string;
positionId?: string;
status?: AgentStatus | 'all';
page: number;
pageSize: number;
source?: AgentListMockItem[];
}
export const agentPositionOptions: AgentPositionOption[] = [
{ id: 'sales', name: '驻店销售岗' },
{ id: 'service', name: '客服岗' },
{ id: 'ops', name: '运营岗' },
];
const managerAgent: AgentListMockItem = {
agent_id: 1,
name: '管家Agent',
is_manager: true,
positions: [],
status: 'enable',
bound_group_count: 12,
bound_skill_count: 0,
updated_at: '2026-05-19 10:30:00',
available_actions: ['edit'],
};
const normalAgents: AgentListMockItem[] = [
{
agent_id: 101,
name: '复盘Agent',
is_manager: false,
positions: [agentPositionOptions[0]],
status: 'enable',
bound_group_count: 8,
bound_skill_count: 4,
updated_at: '2026-05-18 16:20:00',
available_actions: ['edit', 'disable', 'delete'],
},
{
agent_id: 102,
name: '质检Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 3,
bound_skill_count: 2,
updated_at: '2026-05-17 09:15:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 103,
name: '销售助手Agent',
is_manager: false,
positions: [agentPositionOptions[0], agentPositionOptions[2]],
status: 'enable',
bound_group_count: 15,
bound_skill_count: 6,
updated_at: '2026-05-16 13:05:00',
available_actions: ['edit', 'disable', 'delete'],
},
{
agent_id: 104,
name: '线索跟进Agent',
is_manager: false,
positions: [agentPositionOptions[2]],
status: 'enable',
bound_group_count: 5,
bound_skill_count: 3,
updated_at: '2026-05-15 18:40:00',
available_actions: ['edit', 'disable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
{
agent_id: 105,
name: '客诉安抚Agent',
is_manager: false,
positions: [agentPositionOptions[1]],
status: 'disable',
bound_group_count: 1,
bound_skill_count: 1,
updated_at: '2026-05-14 11:25:00',
available_actions: ['edit', 'enable', 'delete'],
},
];
export const agentListMockFixtures = {
normal: { items: [managerAgent, ...normalAgents], total: 6 },
managerOnly: { items: [managerAgent], total: 1 },
empty: { items: [], total: 0 },
filteredEmpty: { items: [], total: 0 },
loading: { loading: true, items: [] },
error: { error: true, items: [] },
longText: {
items: [
{
...normalAgents[0],
agent_id: 201,
name: '超长名称用于验证表格截断和换行规则的复盘Agent',
updated_at: '2026-05-13 08:00:00',
},
],
total: 1,
},
disabledActions: { items: [{ ...managerAgent, available_actions: ['edit'] }], total: 1 },
paginationBoundary: { items: [managerAgent, ...normalAgents], total: 51 },
} satisfies Record<string, AgentListMockFixture>;
export function sortAgentsForDisplay(items: AgentListMockItem[]) {
return [...items].sort((left, right) => Number(right.is_manager) - Number(left.is_manager));
}
export function getAgentListPage({ keyword = '', page, pageSize, positionId, source, status = 'all' }: AgentListPageQuery) {
const normalizedKeyword = keyword.trim().toLowerCase();
const filtered = sortAgentsForDisplay(source ?? agentListMockFixtures.normal.items).filter((agent) => {
const matchesKeyword = !normalizedKeyword || agent.name.toLowerCase().includes(normalizedKeyword);
const matchesPosition = !positionId || agent.positions.some((position) => position.id === positionId);
const matchesStatus = status === 'all' || agent.status === status;
return matchesKeyword && matchesPosition && matchesStatus;
});
const start = (page - 1) * pageSize;
return {
items: filtered.slice(start, start + pageSize),
page,
pageSize,
total: filtered.length,
};
}
......@@ -134,6 +134,66 @@ type JobTagOption = Pick<JobTagListItem, "tag_id" | "name" | "code">;
### 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`
查询参数:
......
......@@ -11,6 +11,69 @@ export interface TabsItem {
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 {
/** Tabs 采用受控 activeKey,切换只通过 onChange 通知业务侧。 */
activeKey: string;
......@@ -109,6 +172,46 @@ export function Empty({ action, description = '暂无数据' }: EmptyProps) {
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 }) {
return <div aria-label="加载占位" className={cx(styles.skeleton, active && styles.stack)} style={{ width: '100%', height: 16 }} />;
}
......
import { useState } from 'react';
import styles from './Shared.module.css';
import { cx } from './utils';
export interface PaginationProps {
/** current/pageSize/total 共同描述后台列表分页状态。 */
......@@ -15,13 +16,14 @@ export function Pagination({ current, pageSize, pageSizeOptions = [10, 20, 50],
const [jump, setJump] = useState('');
const totalPages = Math.max(1, Math.ceil(total / pageSize));
const pages = Array.from({ length: Math.min(totalPages, 5) }, (_, index) => index + 1);
const submitJump = () => onChange?.(Number(jump), pageSize);
return (
<div className={styles.between}>
<span className={styles.muted}>共 {total} 条</span>
<div className={styles.row}>
{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}
</button>
))}
......@@ -32,8 +34,16 @@ export function Pagination({ current, pageSize, pageSizeOptions = [10, 20, 50],
</option>
))}
</select>
<input aria-label="跳至页码" className={styles.control} value={jump} onChange={(event) => setJump(event.target.value)} />
<button className={styles.control} type="button" onClick={() => onChange?.(Number(jump), pageSize)}>
<input
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>
</div>
......
......@@ -22,16 +22,18 @@ export interface SelectProps extends Omit<ButtonHTMLAttributes<HTMLButtonElement
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 popupId = useExclusivePopup(selectPopupOpenEvent, setOpen);
const [innerValue, setInnerValue] = useState<string | undefined>(value);
const currentValue = value ?? innerValue;
const isControlled = Object.prototype.hasOwnProperty.call(props, 'value');
const [innerValue, setInnerValue] = useState<string | undefined>(undefined);
const currentValue = isControlled ? value : innerValue;
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) => {
if (value === undefined) {
if (!isControlled) {
setInnerValue(nextValue);
}
onChange?.(nextValue, option);
......@@ -47,7 +49,7 @@ export function Select({ allowClear, options, placeholder = '请选择', value,
return (
<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>
<Icon className={styles.fieldIcon} name={open ? 'chevron-down' : 'chevron-right'} />
</button>
......
......@@ -7,6 +7,13 @@
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 {
display: inline-flex;
width: 100%;
......@@ -316,6 +323,59 @@
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 {
display: grid;
width: 100%;
......@@ -621,6 +681,55 @@
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 {
border-radius: var(--gl-radius-sm);
background: linear-gradient(90deg, #eef2f7 25%, #f8fafc 37%, #eef2f7 63%);
......
......@@ -14,10 +14,12 @@ import {
Modal,
Popconfirm,
Progress,
StatePlaceholder,
Statistic,
Tag,
Timeline,
Tooltip,
Table,
} from '../index';
import buttonStyles from './Button.module.css';
import styles from './Shared.module.css';
......@@ -314,4 +316,60 @@ describe('feedback and display components', () => {
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 { describe, expect, it, vi } from 'vitest';
import styles from './Shared.module.css';
import {
Collapse,
ColorInput,
ColorPicker,
Empty,
Navigation,
Skeleton,
SkeletonAvatar,
SkeletonButton,
......@@ -84,6 +86,36 @@ describe('navigation, placeholder and color components', () => {
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', () => {
const onPickerChange = vi.fn();
const onInputChange = vi.fn();
......
import { fireEvent, render, screen, within } from '@testing-library/react';
import { useState } from 'react';
import { describe, expect, it, vi } from 'vitest';
import sharedStyles from './Shared.module.css';
......@@ -46,6 +47,13 @@ describe('selection, date, table and pagination components', () => {
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', () => {
render(
<>
......@@ -140,6 +148,52 @@ describe('selection, date, table and pagination components', () => {
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', () => {
render(
<TreeSelect
......@@ -399,14 +453,20 @@ describe('selection, date, table and pagination components', () => {
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.change(screen.getByLabelText('每页条数'), { target: { value: '20' } });
fireEvent.change(screen.getByLabelText('跳至页码'), { target: { value: '5' } });
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(onChange).toHaveBeenNthCalledWith(1, 3, 10);
expect(onChange).toHaveBeenNthCalledWith(2, 1, 20);
expect(onChange).toHaveBeenNthCalledWith(3, 5, 10);
expect(onChange).toHaveBeenNthCalledWith(4, 6, 10);
});
});
......@@ -16,8 +16,8 @@ export type { InputProps, SearchInputProps } from './components/Input';
export { Input, SearchInput } from './components/Input';
export type { TextareaProps } from './components/Textarea';
export { Textarea } from './components/Textarea';
export type { CollapseItem, CollapseProps, EmptyProps, StepsProps, TabsItem, TabsProps } from './components/Navigation';
export { Collapse, Empty, Skeleton, SkeletonAvatar, SkeletonButton, SkeletonInput, SkeletonParagraph, Steps, Tabs } from './components/Navigation';
export type { CollapseItem, CollapseProps, EmptyProps, NavigationItem, NavigationProps, StatePlaceholderProps, StepsProps, TabsItem, TabsProps } 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 { Pagination } from './components/Pagination';
export type { RadioProps } from './components/Radio';
......
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
};
import { render, screen } from '@testing-library/react';
import { fireEvent, render, screen } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { describe, expect, it } from 'vitest';
import { beforeEach, describe, expect, it } from 'vitest';
import { App } from './App';
const loginStorageKey = 'agent-admin-local-login';
function renderApp(path: string) {
return render(
<MemoryRouter initialEntries={[path]}>
<App />
</MemoryRouter>,
);
}
describe('App foundation', () => {
beforeEach(() => {
window.localStorage.clear();
});
it('renders the root layout for the React application', () => {
render(
<MemoryRouter initialEntries={['/']}>
<App />
</MemoryRouter>,
);
renderApp('/components');
expect(screen.getByRole('main')).toBeInTheDocument();
expect(screen.getByText('Agent Admin Web')).toBeInTheDocument();
});
it('renders the independent component demo route', () => {
render(
<MemoryRouter initialEntries={['/components']}>
<App />
</MemoryRouter>,
);
renderApp('/components');
expect(screen.getByRole('heading', { name: '组件库 Demo' })).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 { AdminShell } from './layouts/AdminShell';
import { RootLayout } from './layouts/RootLayout';
import { AgentListPage } from './routes/agents/AgentListPage';
import { ComponentsDemoPage } from './routes/components/ComponentsDemoPage';
import { LoginPage } from './routes/login/LoginPage';
import { ProtectedRoute } from './routes/ProtectedRoute';
export function App() {
return (
<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 index element={<Navigate to="/components" replace />} />
<Route path="components" element={<ComponentsDemoPage />} />
</Route>
<Route path="*" element={<Navigate to="/agents" replace />} />
</Routes>
);
}
export const localLoginStorageKey = 'agent-admin-local-login';
export const adminCredentials = {
username: 'admin',
password: '123456',
} as const;
export function isLoggedIn() {
return window.localStorage.getItem(localLoginStorageKey) === 'true';
}
export function login(username: string, password: string) {
const ok = username === adminCredentials.username && password === adminCredentials.password;
if (ok) {
window.localStorage.setItem(localLoginStorageKey, 'true');
}
return ok;
}
export function logout() {
window.localStorage.removeItem(localLoginStorageKey);
}
import { useState } from 'react';
import { Outlet, useLocation, useNavigate } from 'react-router-dom';
import { Avatar, Button, Modal, Navigation } from '../../packages/ui/src';
import { logout } from '../auth/localAuth';
export function AdminShell() {
const location = useLocation();
const navigate = useNavigate();
const [logoutConfirmOpen, setLogoutConfirmOpen] = useState(false);
const activeNavigationKey = location.pathname.startsWith('/agents') ? 'agent-list' : undefined;
const navigationItems = [
{
key: 'agent-management',
label: 'Agent管理',
children: [{ key: 'agent-list', label: 'Agent列表' }],
},
];
return (
<div className="grid min-h-screen grid-cols-[180px_1fr] bg-[var(--gl-color-bg-page)] text-[var(--gl-color-text-primary)] max-[760px]:grid-cols-1">
<aside className="flex flex-col gap-4 border-r border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] p-4">
<div className="grid gap-1">
<p className="m-0 text-xs leading-[var(--gl-line-height-sm)] text-[var(--gl-color-text-secondary)]">Admin Console</p>
<h1 className="m-0 whitespace-nowrap text-base font-semibold leading-[var(--gl-line-height-lg)]">岗位Agent管理后台</h1>
</div>
<Navigation
activeKey={activeNavigationKey}
ariaLabel="管理后台导航"
items={navigationItems}
onChange={(key) => {
if (key === 'agent-list') navigate('/agents');
}}
/>
</aside>
<div className="grid min-w-0 grid-rows-[auto_1fr]">
<header className="flex min-h-14 items-center justify-between border-b border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 text-sm text-[var(--gl-color-text-secondary)] max-[760px]:px-4">
<span>Agent管理 / Agent列表</span>
<div className="flex items-center gap-3">
<Avatar name="管理员" />
<Button
variant="outline"
onClick={() => setLogoutConfirmOpen(true)}
>
退出登录
</Button>
</div>
</header>
<main className="p-8 max-[760px]:p-4">
<Outlet />
</main>
</div>
<Modal
open={logoutConfirmOpen}
title="确认退出登录?"
onCancel={() => setLogoutConfirmOpen(false)}
onOk={() => {
setLogoutConfirmOpen(false);
logout();
navigate('/login', { replace: true, state: { from: location } });
}}
>
<p className="m-0 text-sm leading-[var(--gl-line-height-md)] text-[var(--gl-color-text-secondary)]">
退出后将返回登录页,当前后台操作上下文不会保留。
</p>
</Modal>
</div>
);
}
import { Navigate, Outlet, useLocation } from 'react-router-dom';
import { isLoggedIn } from '../auth/localAuth';
export function ProtectedRoute() {
const location = useLocation();
if (!isLoggedIn()) {
return <Navigate to="/login" replace state={{ from: location }} />;
}
return <Outlet />;
}
import { fireEvent, render, screen, within } from '@testing-library/react';
import { MemoryRouter } from 'react-router-dom';
import { beforeEach, describe, expect, it } from 'vitest';
import { App } from '../../App';
function renderAgents(path = '/agents') {
window.localStorage.setItem('agent-admin-local-login', 'true');
return render(
<MemoryRouter initialEntries={[path]}>
<App />
</MemoryRouter>,
);
}
describe('AgentListPage', () => {
beforeEach(() => {
window.localStorage.clear();
});
it('renders the list structure, manager row rules, status tags and pagination', () => {
renderAgents();
expect(screen.getByRole('heading', { name: 'Agent管理' })).toBeInTheDocument();
expect(screen.getByText('Agent名称:')).toBeInTheDocument();
expect(screen.getByText('所属岗位:')).toBeInTheDocument();
expect(screen.getByText('状态:')).toBeInTheDocument();
expect(screen.getByLabelText('搜索Agent名称')).toBeInTheDocument();
expect(screen.getByRole('combobox', { name: '岗位筛选' })).toBeInTheDocument();
expect(screen.getByRole('combobox', { name: '状态筛选' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '搜索' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '重置' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '新建Agent' })).toBeInTheDocument();
const rows = screen.getAllByRole('row');
expect(within(rows[1]).getByText('管家Agent')).toBeInTheDocument();
expect(within(rows[1]).getByText('系统调度')).toBeInTheDocument();
expect(within(rows[1]).getByText('-')).toBeInTheDocument();
expect(within(rows[2]).getByText('复盘Agent')).toBeInTheDocument();
expect(screen.getAllByText('已上架').length).toBeGreaterThan(0);
expect(screen.getByText('共 6 条')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '第 1 页' })).toHaveAttribute('aria-current', 'page');
expect(screen.queryByRole('button', { name: '第 2 页' })).not.toBeInTheDocument();
});
it('keeps search controls at a consistent 200px width', () => {
renderAgents();
expect(screen.getByTestId('agent-keyword-control')).toHaveClass('w-[200px]');
expect(screen.getByTestId('agent-position-control')).toHaveClass('w-[200px]');
expect(screen.getByTestId('agent-status-control')).toHaveClass('w-[200px]');
});
it('lays out search fields as label-control rows with actions on the right', () => {
renderAgents();
const toolbar = screen.getByTestId('agent-search-toolbar');
const keywordField = screen.getByTestId('agent-keyword-field');
const positionField = screen.getByTestId('agent-position-field');
const statusField = screen.getByTestId('agent-status-field');
const actionGroup = screen.getByTestId('agent-search-actions');
expect(toolbar).toHaveClass('justify-between');
expect(keywordField).toHaveClass('flex', 'items-center');
expect(positionField).toHaveClass('flex', 'items-center');
expect(statusField).toHaveClass('flex', 'items-center');
expect(positionField.tagName).toBe('DIV');
expect(statusField.tagName).toBe('DIV');
expect(within(keywordField).getByText('Agent名称:')).toHaveClass('shrink-0');
expect(actionGroup).toHaveClass('ml-auto', 'justify-end');
expect(within(actionGroup).getByRole('button', { name: '搜索' })).toBeInTheDocument();
expect(within(actionGroup).getByRole('button', { name: '重置' })).toBeInTheDocument();
});
it('filters only after search submission and resets to the first page', () => {
renderAgents();
fireEvent.change(screen.getByLabelText('搜索Agent名称'), { target: { value: '复盘' } });
fireEvent.click(screen.getByRole('combobox', { name: '岗位筛选' }));
fireEvent.click(screen.getByRole('option', { name: '客服岗' }));
expect(screen.getByText('复盘Agent')).toBeInTheDocument();
expect(screen.queryByRole('status', { name: '未找到匹配结果' })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('combobox', { name: '状态筛选' }));
fireEvent.click(screen.getByRole('option', { name: '已停用' }));
expect(screen.getByText('复盘Agent')).toBeInTheDocument();
expect(screen.queryByRole('status', { name: '未找到匹配结果' })).not.toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '搜索' }));
expect(screen.getByRole('button', { name: '第 1 页' })).toHaveAttribute('aria-current', 'page');
expect(screen.getByRole('status', { name: '未找到匹配结果' })).toBeInTheDocument();
expect(screen.getByRole('combobox', { name: '岗位筛选' })).toHaveTextContent('客服岗');
fireEvent.click(screen.getByRole('button', { name: '重置' }));
expect(screen.getByLabelText('搜索Agent名称')).toHaveValue('');
expect(screen.getByRole('combobox', { name: '岗位筛选' })).toHaveTextContent('全部');
expect(screen.getByText('复盘Agent')).toBeInTheDocument();
expect(screen.getByText('质检Agent')).toBeInTheDocument();
});
it('keeps pagination in sync with the selected page size', () => {
renderAgents();
expect(screen.getByLabelText('每页条数')).toHaveValue('10');
fireEvent.change(screen.getByRole('combobox', { name: '每页条数' }), { target: { value: '20' } });
expect(screen.getByLabelText('每页条数')).toHaveValue('20');
expect(screen.getByRole('button', { name: '第 1 页' })).toHaveAttribute('aria-current', 'page');
});
it('uses the 全部 position option as the reset entry and hides the extra clear button', () => {
renderAgents();
fireEvent.click(screen.getByRole('combobox', { name: '岗位筛选' }));
expect(screen.getByRole('option', { name: '全部' })).toBeInTheDocument();
fireEvent.click(screen.getByRole('option', { name: '客服岗' }));
fireEvent.click(screen.getByRole('button', { name: '搜索' }));
expect(screen.queryByRole('button', { name: '清空岗位筛选' })).not.toBeInTheDocument();
expect(screen.queryByText('清空')).not.toBeInTheDocument();
expect(screen.getByText('质检Agent')).toBeInTheDocument();
expect(screen.queryByText('复盘Agent')).not.toBeInTheDocument();
});
it('shows operation availability and deletion confirmation copy', () => {
renderAgents();
const managerRow = screen.getByRole('row', { name: /管家Agent/ });
expect(within(managerRow).getByRole('button', { name: '编辑管家Agent' })).toBeEnabled();
expect(within(managerRow).queryByRole('button', { name: '停用管家Agent' })).not.toBeInTheDocument();
expect(within(managerRow).queryByRole('button', { name: '删除管家Agent' })).not.toBeInTheDocument();
const reviewRow = screen.getByRole('row', { name: /复盘Agent/ });
fireEvent.click(within(reviewRow).getByRole('button', { name: '删除复盘Agent' }));
expect(screen.getByRole('dialog', { name: '确认删除 Agent "复盘Agent"?' })).toBeInTheDocument();
expect(screen.getByText(/企微员工会从所有已关联群中退出/)).toBeInTheDocument();
expect(screen.getByText(/关联的岗位标签不受影响/)).toBeInTheDocument();
});
it('shows a recoverable failure state without the empty-data headline', () => {
renderAgents('/agents?scenario=error');
expect(screen.getByRole('alert', { name: '加载失败' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '重试' })).toBeInTheDocument();
expect(screen.queryByText('暂无数据')).not.toBeInTheDocument();
expect(screen.getByRole('button', { name: '退出登录' })).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '重试' }));
expect(screen.getByText('复盘Agent')).toBeInTheDocument();
});
});
import { useMemo, useState } from 'react';
import { useSearchParams } from 'react-router-dom';
import { Button, Input, Modal, Pagination, Select, StatePlaceholder, Table, Tag } from '../../../packages/ui/src';
import {
agentListMockFixtures,
agentPositionOptions,
getAgentListPage,
type AgentListMockItem,
type AgentListMockFixture,
type AgentStatus,
} from '../../../packages/contracts/agent-list-mock';
const defaultPageSize = 10;
function getFixtureByScenario(scenario: string): AgentListMockFixture {
switch (scenario) {
case 'error':
return agentListMockFixtures.error;
case 'loading':
return agentListMockFixtures.loading;
case 'empty':
return agentListMockFixtures.empty;
case 'filteredEmpty':
return agentListMockFixtures.filteredEmpty;
case 'managerOnly':
return agentListMockFixtures.managerOnly;
case 'longText':
return agentListMockFixtures.longText;
case 'disabledActions':
return agentListMockFixtures.disabledActions;
case 'paginationBoundary':
return agentListMockFixtures.paginationBoundary;
default:
return agentListMockFixtures.normal;
}
}
function statusText(status: AgentStatus) {
return status === 'enable' ? '已上架' : '已停用';
}
function statusTag(status: AgentStatus) {
return status === 'enable' ? 'success' : 'warning';
}
function AgentActions({ agent }: { agent: AgentListMockItem }) {
const [deleteOpen, setDeleteOpen] = useState(false);
return (
<span className="flex flex-wrap gap-1">
<Button aria-label={`编辑${agent.name}`} size="small" variant="text">编辑</Button>
{agent.available_actions.includes('disable') ? <Button aria-label={`停用${agent.name}`} size="small" variant="text">停用</Button> : null}
{agent.available_actions.includes('enable') ? <Button aria-label={`上架${agent.name}`} size="small" variant="text">上架</Button> : null}
{agent.available_actions.includes('delete') ? (
<>
<Button aria-label={`删除${agent.name}`} size="small" variant="danger" onClick={() => setDeleteOpen(true)}>删除</Button>
<Modal open={deleteOpen} title={`确认删除 Agent "${agent.name}"?`} onCancel={() => setDeleteOpen(false)} onOk={() => setDeleteOpen(false)}>
<p className="m-0 max-w-[360px] leading-[var(--gl-line-height-md)] text-[var(--gl-color-text-secondary)]">
该 Agent 的企微员工会从所有已关联群中退出、官网展示配置会被清理、渠道活码 Agent 列表中不再出现该 Agent、关联的岗位标签不受影响
</p>
</Modal>
</>
) : null}
</span>
);
}
export function AgentListPage() {
const [searchParams] = useSearchParams();
const [scenario, setScenario] = useState(searchParams.get('scenario') ?? 'normal');
const [keyword, setKeyword] = useState('');
const [submittedKeyword, setSubmittedKeyword] = useState('');
const [positionId, setPositionId] = useState<string | undefined>();
const [submittedPositionId, setSubmittedPositionId] = useState<string | undefined>();
const [status, setStatus] = useState<AgentStatus | 'all'>('all');
const [submittedStatus, setSubmittedStatus] = useState<AgentStatus | 'all'>('all');
const [page, setPage] = useState(1);
const [pageSize, setPageSize] = useState(defaultPageSize);
const fixture = getFixtureByScenario(scenario);
const result = useMemo(
() => getAgentListPage({ keyword: submittedKeyword, page, pageSize, positionId: submittedPositionId, status: submittedStatus, source: fixture.items }),
[fixture.items, page, pageSize, submittedKeyword, submittedPositionId, submittedStatus],
);
const hasFilter = Boolean(submittedKeyword || submittedPositionId || submittedStatus !== 'all');
const resetToFirstPage = () => setPage(1);
const submitFilters = () => {
setSubmittedKeyword(keyword);
setSubmittedPositionId(positionId);
setSubmittedStatus(status);
resetToFirstPage();
};
const resetFilters = () => {
setKeyword('');
setSubmittedKeyword('');
setPositionId(undefined);
setSubmittedPositionId(undefined);
setStatus('all');
setSubmittedStatus('all');
resetToFirstPage();
};
const columns = [
{
title: 'Agent名称',
key: 'name',
render: (_: unknown, agent: AgentListMockItem) => (
<span className="grid gap-0.5">
<strong>{agent.name}</strong>
<span className="text-xs text-[var(--gl-color-text-secondary)]">ID: {agent.agent_id}</span>
</span>
),
},
{
title: '所属岗位',
key: 'positions',
render: (_: unknown, agent: AgentListMockItem) => (
<span className="flex flex-wrap gap-1">
{agent.is_manager ? <Tag status="info">系统调度</Tag> : agent.positions.map((position) => <Tag key={position.id}>{position.name}</Tag>)}
</span>
),
},
{ title: '状态', dataIndex: 'status', render: (value: unknown) => <Tag status={statusTag(value as AgentStatus)}>{statusText(value as AgentStatus)}</Tag> },
{ title: '绑定群数', dataIndex: 'bound_group_count' },
{ title: '绑定Skill数', key: 'skill', render: (_: unknown, agent: AgentListMockItem) => (agent.is_manager ? '-' : agent.bound_skill_count) },
{ title: '更新时间', dataIndex: 'updated_at' },
{
title: '操作',
key: 'actions',
render: (_: unknown, agent: AgentListMockItem) => <AgentActions agent={agent} />,
},
];
return (
<section className="grid gap-6">
<header className="flex items-center justify-between gap-6 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-6">
<div>
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">Agent管理</h2>
<p className="m-0 mt-1 text-sm text-[var(--gl-color-text-secondary)]">管理岗位 Agent、管家 Agent 与列表 mock 数据状态</p>
</div>
<Button variant="primary">新建Agent</Button>
</header>
<div className="flex flex-wrap items-center justify-between gap-4 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] p-6" data-testid="agent-search-toolbar">
<div className="flex flex-wrap items-center gap-x-6 gap-y-4">
<div className="flex items-center gap-2 text-sm" data-testid="agent-keyword-field">
<span className="shrink-0">Agent名称:</span>
<span className="w-[200px]" data-testid="agent-keyword-control">
<Input
aria-label="搜索Agent名称"
className="w-full"
placeholder="搜索 Agent 名称"
value={keyword}
allowClear
onChange={setKeyword}
onKeyDown={(event) => {
if (event.key === 'Enter') submitFilters();
}}
/>
</span>
</div>
<div className="flex items-center gap-2 text-sm" data-testid="agent-position-field">
<span className="shrink-0">所属岗位:</span>
<span className="w-[200px]" data-testid="agent-position-control">
<Select
aria-label="岗位筛选"
options={[{ label: '全部', value: 'all' }, ...agentPositionOptions.map((option) => ({ label: option.name, value: option.id }))]}
placeholder="全部"
value={positionId}
onChange={(value) => {
setPositionId(value === 'all' ? undefined : value);
}}
/>
</span>
</div>
<div className="flex items-center gap-2 text-sm" data-testid="agent-status-field">
<span className="shrink-0">状态:</span>
<span className="w-[200px]" data-testid="agent-status-control">
<Select
aria-label="状态筛选"
options={[
{ label: '全部', value: 'all' },
{ label: '已上架', value: 'enable' },
{ label: '已停用', value: 'disable' },
]}
value={status}
onChange={(value) => {
setStatus((value as AgentStatus | 'all') ?? 'all');
}}
/>
</span>
</div>
</div>
<div className="ml-auto flex items-center justify-end gap-3" data-testid="agent-search-actions">
<Button variant="primary" onClick={submitFilters}>搜索</Button>
<Button variant="outline" onClick={resetFilters}>重置</Button>
</div>
</div>
<div className="grid gap-6 overflow-x-auto rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] p-6">
{fixture.error ? (
<StatePlaceholder
state="error"
title="加载失败"
description="Agent 列表请求失败,当前数据状态未知"
primaryAction={<Button size="small" onClick={() => setScenario('normal')}>重试</Button>}
/>
) : (
<>
<Table
rowKey="agent_id"
columns={columns}
dataSource={result.items}
loading={fixture.loading}
empty={{
description: hasFilter ? '未找到匹配结果' : '当前还没有 Agent',
action: hasFilter ? <Button size="small" onClick={resetFilters}>清空筛选</Button> : undefined,
}}
/>
{result.items.length === 0 && hasFilter ? <StatePlaceholder state="filtered-empty" /> : null}
<Pagination
current={page}
pageSize={pageSize}
total={result.total}
onChange={(nextPage, nextPageSize) => {
setPage(nextPage);
setPageSize(nextPageSize);
}}
/>
</>
)}
</div>
</section>
);
}
......@@ -72,3 +72,9 @@
gap: var(--gl-spacing-xl);
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', () => {
expect(screen.getByText('上传')).toBeInTheDocument();
expect(screen.getByText('暂无审批记录')).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('4/20')).toBeInTheDocument();
......@@ -115,4 +120,11 @@ describe('ComponentsDemoPage', () => {
expect(screen.getByLabelText('视频')).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 {
Message,
MediaWall,
Modal,
Navigation,
Pagination,
Popconfirm,
Progress,
......@@ -28,6 +29,7 @@ import {
SearchInput,
Select,
Skeleton,
StatePlaceholder,
Steps,
Switch,
Table,
......@@ -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';
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';
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 (
<section className={styles.page}>
......@@ -169,9 +192,33 @@ export function ComponentsDemoPage() {
<section className={styles.group}>
<h3>导航与占位</h3>
<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: '高级内容' }]} />
<Steps current={1} items={[{ title: '提交' }, { title: '审批' }, { title: '完成' }]} />
<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 />
<Collapse activeKeys={['one']} items={[{ key: 'one', title: '基础设置', children: '设置内容' }]} />
</div>
......
import { type FormEvent, useState } from 'react';
import { Navigate, useLocation, useNavigate } from 'react-router-dom';
import { Button, Input } from '../../../packages/ui/src';
import { isLoggedIn, login } from '../../auth/localAuth';
interface LocationState {
from?: {
pathname?: string;
search?: string;
};
}
export function LoginPage() {
const location = useLocation();
const navigate = useNavigate();
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const [errors, setErrors] = useState<{ username?: string; password?: string; form?: string }>({});
if (isLoggedIn()) {
return <Navigate to="/agents" replace />;
}
const state = location.state as LocationState | null;
const target = `${state?.from?.pathname ?? '/agents'}${state?.from?.search ?? ''}`;
const submit = (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
const nextErrors = {
username: username.trim() ? undefined : '请输入账号',
password: password ? undefined : '请输入密码',
};
if (nextErrors.username || nextErrors.password) {
setErrors(nextErrors);
return;
}
if (!login(username.trim(), password)) {
setErrors({ form: '账号或密码错误' });
return;
}
navigate(target, { replace: true });
};
return (
<main className="grid min-h-screen place-items-center bg-[var(--gl-color-bg-page)] p-8">
<section className="grid w-full max-w-[420px] gap-6 rounded-[14px] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] p-8 shadow-[0_24px_60px_rgb(16_24_40_/_12%)]">
<div className="grid gap-1">
<h1 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">岗位Agent管理后台</h1>
<p className="m-0 text-sm text-[var(--gl-color-text-secondary)]">使用一期固定管理员账号进入本地管理后台</p>
</div>
<form className="grid gap-4" onSubmit={submit}>
<label className="grid gap-1 text-sm">
账号
<Input aria-label="账号" status={errors.username ? 'error' : 'default'} value={username} onChange={setUsername} />
{errors.username ? <span className="m-0 text-xs text-[#d92d20]">{errors.username}</span> : null}
</label>
<label className="grid gap-1 text-sm">
密码
<Input aria-label="密码" status={errors.password ? 'error' : 'default'} type="password" value={password} onChange={setPassword} />
{errors.password ? <span className="m-0 text-xs text-[#d92d20]">{errors.password}</span> : null}
</label>
{errors.form ? <p className="m-0 text-xs text-[#d92d20]">{errors.form}</p> : null}
<Button type="submit" variant="primary">登录</Button>
</form>
</section>
</main>
);
}
@import './tokens.css';
@import './reset.css';
@tailwind utilities;
import type { Config } from 'tailwindcss';
export default {
content: ['./index.html', './src/**/*.{ts,tsx}', './packages/**/*.{ts,tsx}'],
theme: {
extend: {},
},
plugins: [],
} satisfies Config;
......@@ -19,5 +19,5 @@
"jsx": "react-jsx",
"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!