Commit 225566d2 by 胡悦

chore: update agent admin ui foundation

1 parent ffcb6057
Showing 35 changed files with 1981 additions and 56 deletions
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
**Non-Goals:** **Non-Goals:**
- 本 change 不实现业务页面。 - 本 change 不实现业务页面。
- 本 change 不实现 `Upload`,因为上传组件规范尚未确认。 - 本 change 纳入 `Upload` 组件族,基于已确认的文件拖拽上传与图片/视频媒体墙规范落地。
- 本 change 不把 `App.tsx` 中的 demo-only 组件转成可复用组件。 - 本 change 不把 `App.tsx` 中的 demo-only 组件转成可复用组件。
- 本 change 不定义后端 API、持久化方案或业务数据契约。 - 本 change 不定义后端 API、持久化方案或业务数据契约。
- 本 change 不引入成品第三方 UI 组件库作为实现基础,例如 Ant Design、MUI、Arco Design、Semi UI。 - 本 change 不引入成品第三方 UI 组件库作为实现基础,例如 Ant Design、MUI、Arco Design、Semi UI。
...@@ -57,17 +57,29 @@ ...@@ -57,17 +57,29 @@
备选方案:只写 Demo 不写测试。该方案被拒绝,因为组件库会成为后续业务页面的基础依赖,需要在实现阶段通过 TDD 锁定组件契约。 备选方案:只写 Demo 不写测试。该方案被拒绝,因为组件库会成为后续业务页面的基础依赖,需要在实现阶段通过 TDD 锁定组件契约。
### 基础输入类组件需要共享长度显示语义
`Input` 和新纳入的一期 `Textarea` SHALL 共享一致的长度显示语义。长度展示 SHALL 通过 `showCount` 显式开启,文案 SHOULD 使用简洁格式,例如 `12/100`;当未配置 `maxLength` 时,组件 MAY 只展示当前长度。长度显示是 UI 呈现能力,不替代业务校验,超限提示和提交拦截仍由表单规则或业务逻辑负责。
`Input` 的长度展示 SHALL 保持单行紧凑布局,不影响前后缀和清空按钮的基础交互。`Textarea` SHALL 作为独立基础输入组件实现,保持与 `Input` 一致的状态语义、受控/非受控值处理和设计 token 对齐,同时以多行文本区域的布局方式展示计数信息。
备选方案:把长度显示做成统一的表单层能力,而不是输入组件自身能力。该方案被拒绝,因为 `Input`、`Textarea` 和后续可能的更多输入类控件都需要可复用的本地长度反馈,放在组件层更利于一致性和复用。
### 以独立组件文件作为一期范围 ### 以独立组件文件作为一期范围
实现范围 SHALL 基于已上传设计规范中 `src/components` 目录下的独立组件文件。这样可以保证一期范围围绕可复用组件边界展开,而不是复制演示页中的一次性代码。 实现范围 SHALL 基于已上传设计规范中 `src/components` 目录下的独立组件文件。这样可以保证一期范围围绕可复用组件边界展开,而不是复制演示页中的一次性代码。
备选方案:把 `App.tsx` 中所有看起来像组件的代码也纳入一期。该方案被拒绝,因为这些代码主要是演示页脚手架,会在核心组件库稳定前扩大范围。 备选方案:把 `App.tsx` 中所有看起来像组件的代码也纳入一期。该方案被拒绝,因为这些代码主要是演示页脚手架,会在核心组件库稳定前扩大范围。
### `Upload` 等待规范确认后再实现 ### `Upload` 采用文件拖拽上传与媒体墙双形态
`Upload` SHALL 作为组件族纳入一期组件库,但不绑定真实上传传输实现。组件库负责上传入口、文件任务列表、媒体缩略图、状态和操作展示;业务侧负责校验、Toast、接口上传、分片续传、预览弹层和下载行为。
文件上传 SHALL 使用截图确认的大拖拽上传框 + 下方文件项列表形态。上传框默认宽度为 500px、高度约 208px,图标使用浅品牌色圆形底 + 品牌色上传箭头,限制说明固定写在上传框辅助文案中。文件项完成态右侧预留预览、下载、删除入口;上传失败态展示重试和删除;上传中展示进度和取消。校验失败暂不进入文件列表,由业务侧使用 Toast 提示。
`component-guidelines.md` 中已经记录了上传交互方向,但用户已确认上传组件规范尚未定义。本 change SHALL 不实现 `Upload`;后续在上传交互规则确认后,通过新的 OpenSpec change 补充。 媒体墙 SHALL 支持图片和视频。媒体格默认 96px × 96px,图片展示缩略图,视频展示封面缩略图和播放图标。上传入口固定放在媒体项最后;格式和大小说明放在媒体墙下方。点击图片或视频时组件只触发预览回调,放大图片或播放视频的弹层由业务侧组合 `Modal` 实现。
备选方案:先实现一个最小上传组件。该方案被拒绝,因为文件类型、大小限制、进度、预览、替换、删除和失败原因展示都需要明确的产品与设计契约。 备选方案:把文件上传和媒体墙合并为一个高度通用的组件。该方案被拒绝,因为两者的信息重点不同:文件上传强调文件名、大小、状态和任务操作;媒体墙强调可视化素材识别和预览入口。拆成双形态能保持 API 清晰,也避免基础组件过重。
### 提供独立 Demo 路由 ### 提供独立 Demo 路由
...@@ -172,7 +184,7 @@ ...@@ -172,7 +184,7 @@
- [风险] 表格空态只用纯文本时,业务页面需要额外手写空状态布局,导致视觉不一致。-> 缓解:`Table` 内置统一空状态插槽,并在 Demo 路由展示空表格验收样例。 - [风险] 表格空态只用纯文本时,业务页面需要额外手写空状态布局,导致视觉不一致。-> 缓解:`Table` 内置统一空状态插槽,并在 Demo 路由展示空表格验收样例。
- [风险] `FormItem` 只展示必填星号但不执行校验,会让业务页面重复编写表单校验逻辑。-> 缓解:新增 `Form` 容器和 `FormItem rules`,由组件库统一处理基础必填校验与错误展示。 - [风险] `FormItem` 只展示必填星号但不执行校验,会让业务页面重复编写表单校验逻辑。-> 缓解:新增 `Form` 容器和 `FormItem rules`,由组件库统一处理基础必填校验与错误展示。
- [风险] 错误信息动态出现会造成表单布局跳动。-> 缓解:`FormItem` 为错误信息预留稳定区域,并通过布局样式保证错误文案不挤压后续元素。 - [风险] 错误信息动态出现会造成表单布局跳动。-> 缓解:`FormItem` 为错误信息预留稳定区域,并通过布局样式保证错误文案不挤压后续元素。
- [风险] 现有规范中提到 `Upload`,但本次排除。-> 缓解:明确记录排除原因,并在上传规则准备好后创建新的 OpenSpec change。 - [风险] `Upload` 容易被误解为真实上传 SDK。-> 缓解:组件库只提供 UI 形态和状态回调,不内置文件校验、接口传输、分片续传或预览弹层业务逻辑。
## Migration Plan ## Migration Plan
......
...@@ -6,7 +6,8 @@ ...@@ -6,7 +6,8 @@
- 基于 `/Users/yuehu/Documents/广联web桌面端设计规范/src/components` 中的独立组件文件,定义一期 UI 组件库范围。 - 基于 `/Users/yuehu/Documents/广联web桌面端设计规范/src/components` 中的独立组件文件,定义一期 UI 组件库范围。
- 仅纳入可复用 UI 组件,不处理 `App.tsx` 中声明的 demo-only 组件。 - 仅纳入可复用 UI 组件,不处理 `App.tsx` 中声明的 demo-only 组件。
- 暂缓 `Upload`,待上传交互规范确认后再单独补充。 - 将基础输入类组件继续扩展到 `Textarea`,并为 `Input` 与 `Textarea` 补充简洁长度显示能力。
- 纳入 `Upload` 组件族,包含文件拖拽上传与图片/视频媒体墙两种规范形态。
- 确认一期组件库使用 React、TypeScript、CSS Variables 与 CSS Modules / 普通 CSS 实现;组件内部不依赖 Tailwind CSS。 - 确认一期组件库使用 React、TypeScript、CSS Variables 与 CSS Modules / 普通 CSS 实现;组件内部不依赖 Tailwind CSS。
- 允许后续业务页面使用 Tailwind CSS 做页面级布局,但组件必须自带完整规范样式,并通过受控 API、`className`、`style` 和 CSS 变量支持扩展。 - 允许后续业务页面使用 Tailwind CSS 做页面级布局,但组件必须自带完整规范样式,并通过受控 API、`className`、`style` 和 CSS 变量支持扩展。
- 在保持当前目录结构不调整的前提下,将组件能力按全局可复用资产设计,避免绑定单一业务项目。 - 在保持当前目录结构不调整的前提下,将组件能力按全局可复用资产设计,避免绑定单一业务项目。
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
### Requirement: 一期组件库范围 ### Requirement: 一期组件库范围
系统 SHALL 基于已上传设计规范中的独立组件文件,提供一期 Web 桌面端 UI 组件库。 系统 SHALL 基于已上传设计规范中的独立组件文件,提供一期 Web 桌面端 UI 组件库。
一期范围 SHALL 包含 `Button`、`Input`、`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`。 一期范围 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`。
#### Scenario: 实现一期组件 #### Scenario: 实现一期组件
- **WHEN** 实现组件库 - **WHEN** 实现组件库
...@@ -13,12 +13,66 @@ ...@@ -13,12 +13,66 @@
- **WHEN** `App.tsx` 中存在不是独立组件文件的 demo-only 组件 - **WHEN** `App.tsx` 中存在不是独立组件文件的 demo-only 组件
- **THEN** 本 change 不要求实现这些 demo-only 组件 - **THEN** 本 change 不要求实现这些 demo-only 组件
### Requirement: 暂缓 Upload 组件 ### Requirement: Upload 支持文件拖拽上传形态
系统 SHALL 在本组件库 change 中排除 `Upload`,直到上传交互规范完成确认。 `Upload` SHALL 提供大拖拽上传框与下方文件项列表,用于资料、附件、合同、导入文件等非媒体文件上传场景。
#### Scenario: 审查组件范围 #### Scenario: 展示文件上传入口
- **WHEN** 审查一期组件清单 - **WHEN** 页面渲染文件上传入口
- **THEN** `Upload` 被记录为本 change 范围外 - **THEN** 上传框 SHALL 采用约 500px 宽、208px 高的大拖拽区域,使用浅品牌色圆形底上传图标,并在框内展示主文案和限制辅助文案
#### Scenario: 展示文件任务状态
- **WHEN** 文件进入上传任务列表
- **THEN** 文件项 SHALL 展示文件图标、文件名、文件大小、状态和状态对应操作
#### Scenario: 操作完成文件
- **WHEN** 文件上传已完成
- **THEN** 文件项 SHALL 预留预览、下载和删除入口
#### Scenario: 操作失败文件
- **WHEN** 文件上传失败
- **THEN** 文件项 SHALL 展示失败状态,并提供重试和删除入口
#### Scenario: 处理校验失败
- **WHEN** 文件在业务校验阶段失败
- **THEN** 文件 SHALL NOT 进入上传任务列表,业务侧 SHOULD 使用 Toast 提示校验原因
### Requirement: Upload 支持图片和视频媒体墙形态
`Upload` SHALL 提供媒体墙形态,用于图片和视频资源上传与管理。
#### Scenario: 展示媒体墙
- **WHEN** 页面渲染媒体墙
- **THEN** 媒体项 SHALL 使用约 96px × 96px 的方形格,图片展示缩略图,视频展示封面缩略图和播放图标
#### Scenario: 继续添加媒体
- **WHEN** 媒体墙存在已上传素材
- **THEN** 上传入口 SHALL 放在所有媒体项最后
#### Scenario: 展示媒体限制说明
- **WHEN** 媒体墙需要说明格式、大小或数量限制
- **THEN** 限制说明 SHALL 展示在媒体墙下方,而不是塞入上传格内部
#### Scenario: 预览媒体
- **WHEN** 用户点击图片或视频媒体项
- **THEN** 组件 SHALL 触发预览回调;图片放大展示和视频播放弹层由业务侧组合实现
### Requirement: 基础输入组件支持简洁长度显示
基础输入组件 SHALL 支持简洁长度显示能力,覆盖单行 `Input` 与多行 `Textarea`。
#### Scenario: 展示单行输入长度
- **WHEN** `Input` 启用 `showCount` 且提供 `maxLength`
- **THEN** 组件 SHALL 在输入框内展示当前长度与上限的简洁格式,例如 `12/100`
#### Scenario: 展示多行输入长度
- **WHEN** `Textarea` 启用 `showCount` 且提供 `maxLength`
- **THEN** 组件 SHALL 在控件右下方或等效的紧凑位置展示当前长度与上限的简洁格式,例如 `12/100`
#### Scenario: 仅展示当前长度
- **WHEN** `showCount` 已开启但未配置 `maxLength`
- **THEN** 组件 MAY 只展示当前长度,不强制显示上限
#### Scenario: 保持业务校验独立
- **WHEN** 输入内容超出业务允许范围
- **THEN** 组件 SHALL NOT 代替表单校验或业务拦截,超限处理仍由业务侧决定
### Requirement: 组件遵循 Web 桌面端设计规则 ### Requirement: 组件遵循 Web 桌面端设计规则
组件库 SHALL 遵循项目 Web 桌面端设计规则,包括颜色、字号、间距、圆角、控件尺寸、加载态、禁用态、错误态和交互反馈。 组件库 SHALL 遵循项目 Web 桌面端设计规则,包括颜色、字号、间距、圆角、控件尺寸、加载态、禁用态、错误态和交互反馈。
......
...@@ -4,13 +4,14 @@ ...@@ -4,13 +4,14 @@
- [x] 1.2 确认技术选型和依赖边界:组件库使用 React、TypeScript、CSS Variables、CSS Modules / 普通 CSS、Vitest、React Testing Library;组件内部不依赖 Tailwind CSS 或成品 UI 组件库。 - [x] 1.2 确认技术选型和依赖边界:组件库使用 React、TypeScript、CSS Variables、CSS Modules / 普通 CSS、Vitest、React Testing Library;组件内部不依赖 Tailwind CSS 或成品 UI 组件库。
- [x] 1.3 确认业务页面使用边界:业务页面可用 Tailwind CSS 做页面级布局,组件变化优先通过 props、CSS 变量、`className` 和 `style` 受控扩展。 - [x] 1.3 确认业务页面使用边界:业务页面可用 Tailwind CSS 做页面级布局,组件变化优先通过 props、CSS 变量、`className` 和 `style` 受控扩展。
- [x] 1.4 创建或对齐共享 UI 组件目录结构、测试目录结构和样式组织方式。 - [x] 1.4 创建或对齐共享 UI 组件目录结构、测试目录结构和样式组织方式。
- [x] 1.5 为全部一期组件创建稳定的共享 UI 导出入口,并记录 `Upload` 暂缓。 - [x] 1.5 为全部一期组件创建稳定的共享 UI 导出入口。
- [x] 1.6 确认组件 TDD 与注释约定:每个组件实现前必须先有接口定义、失败中的单元测试或验收样例,再补逻辑实现、样式和审核注释。 - [x] 1.6 确认组件 TDD 与注释约定:每个组件实现前必须先有接口定义、失败中的单元测试或验收样例,再补逻辑实现、样式和审核注释。
## 2. 基础交互组件 ## 2. 基础交互组件
- [x] 2.1 实现 `Button`:包含接口定义、点击与 loading/disabled 逻辑、类型/尺寸/图标样式、单元测试、审核注释。 - [x] 2.1 实现 `Button`:包含接口定义、点击与 loading/disabled 逻辑、类型/尺寸/图标样式、单元测试、审核注释。
- [x] 2.2 实现 `Input`:包含接口定义、受控/非受控输入逻辑、禁用/错误/前后缀样式、单元测试、审核注释。 - [x] 2.2 实现 `Input`:包含接口定义、受控/非受控输入逻辑、禁用/错误/前后缀样式、`showCount` 长度显示、单元测试、审核注释。
- [x] 2.2b 实现 `Textarea`:包含接口定义、受控/非受控输入逻辑、禁用/错误样式、`showCount` 长度显示、单元测试、审核注释。
- [x] 2.3 实现 `SearchInput`:包含接口定义、搜索触发与清空逻辑、搜索图标/按钮样式、单元测试、审核注释。 - [x] 2.3 实现 `SearchInput`:包含接口定义、搜索触发与清空逻辑、搜索图标/按钮样式、单元测试、审核注释。
- [x] 2.3a 根据人工验收调整 `SearchInput`:前缀搜索图标统一为组件库图标资产并放大到设计规范尺寸,补充图标尺寸回归测试和审核注释。 - [x] 2.3a 根据人工验收调整 `SearchInput`:前缀搜索图标统一为组件库图标资产并放大到设计规范尺寸,补充图标尺寸回归测试和审核注释。
- [x] 2.4 实现 `Checkbox`:包含接口定义、选中/半选/禁用逻辑、勾选状态样式、单元测试、审核注释。 - [x] 2.4 实现 `Checkbox`:包含接口定义、选中/半选/禁用逻辑、勾选状态样式、单元测试、审核注释。
...@@ -116,6 +117,14 @@ ...@@ -116,6 +117,14 @@
- [x] 10.5 添加后台业务组合示例,包括表格操作、表单字段、状态标签、分页、弹窗和抽屉。 - [x] 10.5 添加后台业务组合示例,包括表格操作、表单字段、状态标签、分页、弹窗和抽屉。
- [x] 10.6 根据人工验收完善 Demo 状态:TreeSelect、DatePicker、Checkbox、Switch、SearchInput 示例覆盖可交互、选中态和图标尺寸验收。 - [x] 10.6 根据人工验收完善 Demo 状态:TreeSelect、DatePicker、Checkbox、Switch、SearchInput 示例覆盖可交互、选中态和图标尺寸验收。
- [x] 10.7 根据人工验收完善 `Button` Demo:在基础交互模块展示全部按钮类型、尺寸、loading、disabled 和图标场景,补充 Demo 回归测试。 - [x] 10.7 根据人工验收完善 `Button` Demo:在基础交互模块展示全部按钮类型、尺寸、loading、disabled 和图标场景,补充 Demo 回归测试。
- [x] 10.8 根据人工确认新增 `Upload` Demo:展示文件拖拽上传完成、上传中、失败状态,以及图片/视频媒体墙,补充 Demo 回归测试。
- [x] 10.9 根据人工确认补齐基础输入 Demo:展示 `Input` 与 `Textarea` 的简洁长度显示配置,补充 Demo 回归测试。
## 10A. 上传组件
- [x] 10A.1 根据人工确认实现 `UploadDragger`:包含 500×208 大拖拽上传框、框内辅助文案、文件任务列表、上传中/失败/完成操作、单元测试和审核注释。
- [x] 10A.2 根据人工确认实现 `MediaWall`:包含 96×96 图片/视频格、视频播放标识、上传入口最后展示、限制说明下置、预览回调、单元测试和审核注释。
- [x] 10A.3 为 `Upload` 补齐稳定导出入口和组件库内部图标资产。
## 11. 验证 ## 11. 验证
...@@ -123,4 +132,4 @@ ...@@ -123,4 +132,4 @@
- [x] 11.2 运行组件相关单元测试,确认每个组件的接口定义、逻辑实现、样式状态和关键交互均被覆盖。 - [x] 11.2 运行组件相关单元测试,确认每个组件的接口定义、逻辑实现、样式状态和关键交互均被覆盖。
- [x] 11.3 如果目标项目存在额外测试命令,运行相关自动化测试。 - [x] 11.3 如果目标项目存在额外测试命令,运行相关自动化测试。
- [ ] 11.4 启动前端应用,并在浏览器中验证独立组件 Demo 路由的布局、交互和设计一致性。 - [ ] 11.4 启动前端应用,并在浏览器中验证独立组件 Demo 路由的布局、交互和设计一致性。
- [x] 11.5 确认 Demo 路由展示全部一期组件,并排除 `Upload` 和 `App.tsx` 中的 demo-only 组件。 - [ ] 11.5 确认 Demo 路由展示全部一期组件,并纳入 `Upload`,同时排除其他 `App.tsx` 中的 demo-only 组件。
# Input and Textarea Length Count Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Add concise length display to `Input` and a new shared `Textarea` component, then expose both through the UI library, demo page, and OpenSpec change.
**Architecture:** Keep `Input` as the existing single-line control and add a lightweight `showCount` footer/affix presentation without changing its core value handling. Introduce `Textarea` as a sibling base input component with the same status and value contract, a bottom-right count display, and a focused CSS module so the shared UI boundary stays small and easy to reason about.
**Tech Stack:** React, TypeScript, CSS Modules, Vitest, React Testing Library, OpenSpec
---
### Task 1: Lock the spec and plan scope
**Files:**
- Modify: `architecture-spec/openspec/changes/define-ui-component-library/proposal.md`
- Modify: `architecture-spec/openspec/changes/define-ui-component-library/design.md`
- Modify: `architecture-spec/openspec/changes/define-ui-component-library/specs/ui-component-library/spec.md`
- Modify: `architecture-spec/openspec/changes/define-ui-component-library/tasks.md`
- [ ] **Step 1: Update the OpenSpec artifacts**
Add a concise input-control requirement that covers `Input` and `Textarea`, with `showCount` using the compact `12/100` style, and mark the implementation/demo tasks that will deliver it.
- [ ] **Step 2: Validate the change**
Run: `openspec validate define-ui-component-library --strict`
Expected: PASS
### Task 2: Add tests for length count behavior
**Files:**
- Modify: `workspace/agent-admin/web/packages/ui/src/components/basic-controls.test.tsx`
- [ ] **Step 1: Write the failing tests**
Add assertions that `Input` renders a concise count when `showCount` is enabled and `maxLength` is present, and that `Textarea` is exported and shows the same style of count.
- [ ] **Step 2: Run the targeted test file**
Run: `npm test -- packages/ui/src/components/basic-controls.test.tsx`
Expected: FAIL because `Textarea` is not exported yet and count rendering is not implemented.
- [ ] **Step 3: Keep the tests red until implementation lands**
Do not change production code in this task.
### Task 3: Implement `Input` count and new `Textarea`
**Files:**
- Modify: `workspace/agent-admin/web/packages/ui/src/components/Input.tsx`
- Create: `workspace/agent-admin/web/packages/ui/src/components/Textarea.tsx`
- Create: `workspace/agent-admin/web/packages/ui/src/components/Textarea.module.css`
- Modify: `workspace/agent-admin/web/packages/ui/src/index.ts`
- [ ] **Step 1: Implement the minimal component changes**
Add `showCount` support to `Input` and build a new `Textarea` that matches the same value/status contract, keeps the count display concise, and uses the existing shared UI token system.
- [ ] **Step 2: Run the focused tests**
Run: `npm test -- packages/ui/src/components/basic-controls.test.tsx`
Expected: PASS
### Task 4: Surface the new controls in the demo
**Files:**
- Modify: `workspace/agent-admin/web/src/routes/components/ComponentsDemoPage.tsx`
- Modify: `workspace/agent-admin/web/src/routes/components/ComponentsDemoPage.test.tsx`
- [ ] **Step 1: Add demo examples**
Show one `Input` with concise count and one `Textarea` with concise count in the basic interaction section so the component library demo reflects the new API.
- [ ] **Step 2: Run the demo test**
Run: `npm test -- src/routes/components/ComponentsDemoPage.test.tsx`
Expected: PASS
### Task 5: Verify the library end to end
**Files:**
- None
- [ ] **Step 1: Run typecheck, unit tests, and build**
Run: `npm run typecheck && npm test && npm run build`
Expected: PASS
- [ ] **Step 2: Confirm the demo visually**
Open the `/components` route in the browser and verify the new `Input` and `Textarea` count display looks compact, aligned, and consistent with the design system.
# Upload Component Library Implementation Plan
> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking.
**Goal:** Add the approved Upload design pattern to the shared Web desktop UI component library.
**Architecture:** Implement Upload as two focused React components inside `packages/ui`: `UploadDragger` for file uploads and task records, and `MediaWall` for image/video thumbnails. Keep upload transport outside the component; the library renders states and emits callbacks.
**Tech Stack:** React, TypeScript, CSS Modules, Vitest, React Testing Library, existing design tokens.
---
### Task 1: Spec And Scope
**Files:**
- Modify: `architecture-spec/openspec/changes/define-ui-component-library/proposal.md`
- Modify: `architecture-spec/openspec/changes/define-ui-component-library/design.md`
- Modify: `architecture-spec/openspec/changes/define-ui-component-library/specs/ui-component-library/spec.md`
- Modify: `architecture-spec/openspec/changes/define-ui-component-library/tasks.md`
- [ ] Replace the old Upload exclusion with the confirmed Upload scope: file dragger plus media wall.
- [ ] Add file upload rules: 500px by 208px dragger, helper text inside the drop zone, validation failure via Toast, uploading/cancel, failed retry/delete, completed preview/download/delete.
- [ ] Add media wall rules: 96px tiles, image thumbnails, video cover plus play icon, upload tile last, helper text below the wall, modal preview behavior left to consumers.
### Task 2: Component Tests
**Files:**
- Create: `workspace/agent-admin/web/packages/ui/src/components/upload.test.tsx`
- [ ] Add tests for `UploadDragger` rendering the helper text, dimensions class, completed operations, failed operations, and uploading progress.
- [ ] Add tests for `UploadDragger` file selection calling `onSelectFiles`.
- [ ] Add tests for `MediaWall` rendering image thumbnails, video cover thumbnails with a play marker, upload tile last, helper text below the wall, and media preview callbacks.
### Task 3: Component Implementation
**Files:**
- Create: `workspace/agent-admin/web/packages/ui/src/components/Upload.tsx`
- Create: `workspace/agent-admin/web/packages/ui/src/components/Upload.module.css`
- Modify: `workspace/agent-admin/web/packages/ui/src/components/Icon.tsx`
- Modify: `workspace/agent-admin/web/packages/ui/src/index.ts`
- [ ] Add icon names for upload, file, eye, download, retry, trash, plus, and play.
- [ ] Implement `UploadDragger` with controlled `files`, hidden file input, drag-over visual state, and action callbacks.
- [ ] Implement `MediaWall` with controlled `items`, upload tile last, hidden media input, preview callback, and video play overlay.
- [ ] Export component and prop types from the package entry.
### Task 4: Demo And Verification
**Files:**
- Modify: `workspace/agent-admin/web/src/routes/components/ComponentsDemoPage.tsx`
- Modify: `workspace/agent-admin/web/src/routes/components/ComponentsDemoPage.module.css`
- Modify: `workspace/agent-admin/web/src/routes/components/ComponentsDemoPage.test.tsx`
- [ ] Add an Upload demo group showing file upload states and media wall.
- [ ] Update the demo test so Upload is included in the component groups.
- [ ] Run `npm test`, `npm run typecheck`, and `npm run build` from `workspace/agent-admin/web`.
- [ ] Start the dev server and verify `/components` visually in a browser.
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
- `backend/`:后端项目,由其他负责人维护;本目录不沉淀后端实现设计。 - `backend/`:后端项目,由其他负责人维护;本目录不沉淀后端实现设计。
- `web/packages/contracts/`:前端视角的字段、枚举、payload 和 mock 数据。 - `web/packages/contracts/`:前端视角的字段、枚举、payload 和 mock 数据。
- `single-page/packages/contracts/`:单页面项目视角的字段、枚举、payload 和 mock 数据。 - `single-page/packages/contracts/`:单页面项目视角的字段、枚举、payload 和 mock 数据。
- `web/docs/`:管理后台 Web 项目级前端地基、页面模式、mock 与业务探索准备文档。
需求沉淀: 需求沉淀:
...@@ -24,7 +25,11 @@ ...@@ -24,7 +25,11 @@
- [Agent 管理需求沉淀](./requirements-agent-management.md) - [Agent 管理需求沉淀](./requirements-agent-management.md)
- [Agent 群管理需求沉淀](./requirements-agent-group-management.md) - [Agent 群管理需求沉淀](./requirements-agent-group-management.md)
- [官网配置与 H5 展示需求沉淀](./requirements-official-site-config.md) - [官网配置与 H5 展示需求沉淀](./requirements-official-site-config.md)
- [官网 H5 前端需求交互确认内容](./frontend-h5-official-site-interaction-confirmation.md)
- [PC 管理后台整体框架与布局确认内容](./frontend-pc-admin-framework-layout-confirmation.md)
- [后端接口文档对齐待确认事项](./backend-api-alignment-open-questions.md) - [后端接口文档对齐待确认事项](./backend-api-alignment-open-questions.md)
- [前端待确认事项](./frontend-open-questions.md) - [前端待确认事项](./frontend-open-questions.md)
当前阶段只做需求确认、前端规范落地和 OpenSpec 草案准备。确认完成后,再为具体功能创建对应端的 OpenSpec change:管理后台前端放 `web/openspec/changes/`,官网 H5 放 `single-page/openspec/changes/`。 当前阶段只做需求确认、前端规范落地和 OpenSpec 草案准备。确认完成后,再为具体功能创建对应端的 OpenSpec change:管理后台前端放 `web/openspec/changes/`,官网 H5 放 `single-page/openspec/changes/`。
当前前端地基先收敛在 `web/docs/`。全局前端地基待多个项目复用验证后,再沉淀到 `architecture-spec/docs/architecture/`。
...@@ -6,13 +6,15 @@ ...@@ -6,13 +6,15 @@
## 页面与交互 ## 页面与交互
1. 登录成功后的默认落点是否为 Agent 管理列表页。 1. 删除 Agent、删除官网 Tab、停用活码等高影响操作是否统一使用二次确认 Modal。
2. 删除 Agent、删除官网 Tab、停用活码等高影响操作是否统一使用二次确认 Modal。 2. 文件上传是否已有统一组件,包括进度、失败重试、格式校验和大小校验。
3. 文件上传是否已有统一组件,包括进度、失败重试、格式校验和大小校验。
4. Skill 说明 Markdown 弹窗是否需要目录、代码块复制、最大高度和滚动策略。
已确认:后台管理页本期需要登录页,由前端写死账号密码校验,不调用接口;权限仍按管理员单角色处理。 已确认:后台管理页本期需要登录页,由前端写死账号密码校验,不调用接口;权限仍按管理员单角色处理。
已确认:登录成功后的默认落点为 `Agent管理 > Agent列表`;如果未登录访问业务页面,登录成功后优先回到原访问路径。
已确认:Skill 说明使用抽屉展示 Markdown,支持基础 Markdown 渲染、代码块样式、抽屉内部滚动、加载态、失败态和空态;本期不要求目录和代码块复制。
## H5 展示 ## H5 展示
1. H5 Banner 的汽车飞驰背景图由设计提供、运营上传,还是前端内置静态资源。 1. H5 Banner 的汽车飞驰背景图由设计提供、运营上传,还是前端内置静态资源。
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
- Agent 上架/停用/删除操作 - Agent 上架/停用/删除操作
- 岗位标签管理 - 岗位标签管理
- Skill 目录只读展示 - Skill 目录只读展示
- Skill 说明文档弹窗 - Skill 说明文档抽屉
管家 Agent 路由、意图识别、会话记忆和多模态处理为后端运行时能力,前端仅维护 Agent 描述、Skill 绑定、状态等配置字段。 管家 Agent 路由、意图识别、会话记忆和多模态处理为后端运行时能力,前端仅维护 Agent 描述、Skill 绑定、状态等配置字段。
...@@ -144,7 +144,15 @@ Skill 皞隞葉輕瘜典蝵脩 ...@@ -144,7 +144,15 @@ Skill 皞隞葉輕瘜典蝵脩
| 说明 | 文本 | | 说明 | 文本 |
| 操作 | 查看详情 | | 操作 | 查看详情 |
查看详情以 Modal 展示 Markdown 文档内容。 查看详情以抽屉展示 Markdown 文档内容。
Skill 说明抽屉展示策略:
- 支持 Markdown 基础渲染。
- 支持代码块样式,本期不要求代码块复制。
- 抽屉内容区域内部滚动,不撑开页面。
- 支持加载中、加载失败和空内容状态。
- 本期不要求目录锚点。
## 埋点 ## 埋点
......
# 官网 H5 前端需求交互确认内容
更新时间:2026-05-19
## 文档定位
本文档记录「广联岗位Agent」官网 H5 前台展示页的前端需求与交互确认内容,便于后续 `single-page/` 项目开发对齐。
当前阶段只确认 H5 端展示和交互规则。PC 端展示规范后续补充。
## 页面目标
官网 H5 前台展示页用于展示「广联岗位Agent」的岗位化智能服务体系。
页面优先帮助用户建立“岗位 Agent 体系”的认知,再通过岗位体验入口引导用户扫码添加专属服务助手。
页面整体采用接口驱动渲染,前端不写死岗位数量、岗位名称、Banner 内容、二维码、Agent 卡片或方法论内容。
## 页面结构
H5 页面从上到下包含以下模块:
1. Banner 展示区
2. 岗位 Tab 导航区
3. 当前岗位体验入口
4. 当前岗位 Agent 卡片区
5. 方法论模块
PC 端展示规范后续补充,不在本文档展开。
## Banner 展示区
Banner 内容全部来源于接口,包括标题、副标题、背景图等信息。
主标题展示接口返回内容,当前确认标题为:`广联岗位Agent`。
副标题展示接口返回内容,示例为:`AI驱动的智能销售服务体系`。
当接口未返回 Banner 图片时,前端展示默认占位背景。占位背景需保证标题和副标题可读,不影响页面整体视觉完整性。
## 岗位 Tab 导航区
岗位 Tab 数据来源于接口配置,岗位数量不固定,可能随后台配置变化。
当接口返回岗位数量为 `0` 时,不展示岗位 Tab 导航区,同时不展示当前岗位体验入口和当前岗位 Agent 卡片区。
当接口返回岗位数量大于 `0` 时,展示岗位 Tab,并默认选中第一个岗位。
用户切换岗位 Tab 后,当前岗位体验入口和当前岗位 Agent 卡片内容同步切换。
当岗位 Tab 数量较多时,H5 端采用横向滚动展示,不换行。
## 当前岗位体验入口
每个岗位均由后台配置对应的活码和 Agent 卡片。
只要接口返回岗位 Tab,即认为该岗位配置完整,前台不额外处理“有岗位但无活码”或“有岗位但无 Agent 卡片”的空状态。
当前岗位区域展示“立即体验”按钮。用户点击后弹出二维码弹窗。
二维码弹窗结构固定为:
| 位置 | 内容 |
|-|-|
| 顶部 | 当前岗位名称 |
| 中间 | 当前岗位二维码 |
| 底部 | `扫码添加专属服务助手` |
二维码来源于接口返回的图片 URL,H5 前端只负责渲染图片,不在前端生成二维码。
二维码弹窗需支持关闭操作。关闭后回到当前页面状态,不改变当前选中的岗位 Tab。
## 当前岗位 Agent 卡片区
Agent 卡片数据来源于当前选中岗位的接口数据。
H5 端采用 2 列网格展示。每张卡片用于展示该岗位下的 Agent 能力,包含动图或图片、Agent 名称、简短描述等内容。
Agent 卡片仅用于展示,不需要点击跳转、打开详情或触发其他交互。
卡片可保留轻量视觉反馈,但不能让用户误以为卡片可点击。
## 方法论模块
方法论模块为全局展示内容,不绑定具体岗位 Tab。
用户切换岗位时,方法论模块内容不随岗位变化。
方法论模块数据来源于接口配置,当前规划包含 4 个步骤:
1. 系统架构
2. 智能协同
3. 价值闭环
4. 策略中枢
模块支持用户点击切换步骤,并可支持轻量自动轮播。
用户手动点击步骤后,建议暂停自动轮播一段时间,避免内容立即被自动切换。
每个步骤展示对应标题、说明内容和配图或流程图。H5 端重点保证内容清晰可读,步骤导航可横向滑动或紧凑排列。
## H5 适配要求
H5 页面需适配主流手机屏幕宽度。页面以纵向浏览为主,模块顺序保持稳定:
```text
Banner -> 岗位 Tab -> 体验入口 -> Agent 卡片 -> 方法论模块
```
岗位 Tab 超出屏幕宽度时横向滚动。
Agent 卡片保持 2 列展示。
二维码不直接平铺在页面中,统一通过“立即体验”按钮弹窗展示。
页面文字、按钮、卡片和弹窗内容需避免遮挡、溢出和重叠。
Banner 图片缺失时需展示占位背景,保证页面可正常访问。
## 数据来源
本页面所有展示内容均来自接口,包括但不限于:
| 数据 | 来源说明 |
|-|-|
| Banner 标题 | 接口返回 |
| Banner 副标题 | 接口返回 |
| Banner 背景图 | 接口返回;缺失时展示占位背景 |
| 岗位 Tab 列表 | 接口返回,数量不固定 |
| 岗位二维码 | 当前岗位接口数据 |
| Agent 卡片列表 | 当前岗位接口数据 |
| 方法论步骤 | 接口返回 |
| 方法论文案和图片 | 接口返回 |
前端根据接口返回结果进行渲染,不维护固定岗位枚举。
## PC 端说明
PC 端展示效果后续补充。
当前阶段仅确认该页面需要兼容 PC 端访问。PC 端布局规则、模块排列和视觉细节将在后续单独补充。
# Agent Admin Web # Agent Admin Web
这里放 Agent 管理平台前端项目。 这里放岗位Agent管理后台前端项目。
React + Vite + TypeScript 应用代码放在本目录下。页面实现必须遵循公司 Web 桌面端设计规范,以及 `architecture-spec/docs/architecture/` 中的前端和组件规则。 React + Vite + TypeScript 应用代码放在本目录下。页面实现必须遵循公司 Web 桌面端设计规范,并优先遵循本项目 `docs/` 下的项目级前端地基文档。
本目录独立管理前端的 OpenSpec、组件和工程配置。 本目录独立管理后台前端的 OpenSpec、组件、接口契约和工程配置。当前阶段只沉淀项目级前端地基,不把本项目实践直接升级为 monorepo 全局前端地基。
职责范围: 职责范围:
...@@ -20,15 +20,16 @@ React + Vite + TypeScript 应用代码放在本目录下。页面实现必须遵 ...@@ -20,15 +20,16 @@ React + Vite + TypeScript 应用代码放在本目录下。页面实现必须遵
- `packages/utils/`:前端通用工具。 - `packages/utils/`:前端通用工具。
- `packages/contracts/`:前端视角的字段、枚举、payload 和 mock 数据。 - `packages/contracts/`:前端视角的字段、枚举、payload 和 mock 数据。
- `src/`:当前前端应用入口、路由、布局、样式和测试基座。 - `src/`:当前前端应用入口、路由、布局、样式和测试基座。
- `docs/`:项目级前端地基、页面模式、mock 与业务探索准备文档。
技术基座: 技术基座:
- React + TypeScript 作为统一前端技术栈。 - React + TypeScript 作为本项目当前前端技术栈。
- Vite 作为开发服务器和构建工具。 - Vite 作为开发服务器和构建工具。
- React Router 管理客户端路由。 - React Router 管理客户端路由。
- Vitest + React Testing Library 用于 TDD 和组件行为测试。 - Vitest + React Testing Library 用于 TDD 和组件行为测试。
- 组件内部样式使用 CSS Variables + CSS Modules / 普通 CSS。 - 组件内部样式使用 CSS Variables + CSS Modules / 普通 CSS。
- Tailwind CSS 仅作为后续业务页面布局层的可选能力,不作为全局 UI 组件内部样式依赖。 - Tailwind CSS 仅作为后续业务页面布局层的可选能力,暂不作为已启用能力。
常用命令: 常用命令:
...@@ -42,4 +43,11 @@ npm run build ...@@ -42,4 +43,11 @@ npm run build
当前基础路由: 当前基础路由:
- `/`:重定向到 `/components`。 - `/`:重定向到 `/components`。
- `/components`:全局 UI 组件库 Demo 承载路由。 - `/components`:UI 组件 Demo 承载路由。
项目文档:
- [前端地基](./docs/frontend-foundation.md)
- [页面模式草案](./docs/page-patterns.md)
- [Mock 与接口契约协作规则](./docs/mock-and-contract.md)
- [业务探索前准备清单](./docs/business-exploration-prep.md)
# 业务探索前准备清单
更新时间:2026-05-18
## 1. 文档定位
本文档记录岗位Agent管理后台进入业务需求探索前,需要准备或确认的前端地基事项。
当前目标是支撑 `workspace/agent-admin/web` 项目,不沉淀全局前端地基。
## 2. 已具备
- Vite + React + TypeScript 应用结构。
- React Router 基础路由。
- `/components` 组件 Demo 承载路由。
- Vitest + React Testing Library 测试基座。
- 全局样式入口、reset 和设计 token。
- `packages/ui` 内的基础组件雏形。
- `packages/contracts/frontend-api-contract.md` 接口契约草案。
- 项目需求沉淀文档位于 `workspace/agent-admin/docs/`。
## 3. 业务探索前建议补齐
### 页面信息架构
- 后台一级菜单。
- 每个模块的列表页、详情页、创建页、编辑入口。
- 登录成功后的默认落点。
### 页面数据草案
- 每个页面的展示字段。
- 搜索筛选字段。
- 表单字段。
- 行操作和批量操作。
- 状态枚举与展示文案。
### Mock 数据场景
- 正常数据。
- 空数据。
- 筛选无结果。
- 加载失败。
- 权限或操作不可用。
- 长文本和边界值。
### 权限与登录态
本期已确认按管理员单角色处理,登录页由前端写死账号密码校验。仍建议在页面探索时保留以下边界:
- 未登录访问的跳转。
- 登录成功后的落点。
- 本地登录态存储和清理。
- 后续接入真实鉴权时的替换点。
### 页面模式
先按 `page-patterns.md` 统一列表、表单、详情、状态流转和高影响操作的表达方式,再进入具体页面设计。
## 4. 暂缓事项
以下事项暂不在本轮固化:
- monorepo 全局前端地基。
- 后端框架、数据库、队列和运行时选型。
- 多角色权限模型。
- Tailwind CSS 是否启用。
- 新的顶层 monorepo 目录重组。
## 5. 后续进入 OpenSpec 的条件
单个业务功能进入 OpenSpec 前,至少需要明确:
- 页面范围。
- 字段与枚举。
- 用户操作。
- 状态流转。
- 接口契约草案。
- mock 场景。
- 验收标准。
改变页面行为的功能应在 `workspace/agent-admin/web/openspec/changes/` 下创建对应 change。
# 岗位Agent管理后台前端地基
更新时间:2026-05-18
## 1. 文档定位
本文档沉淀 `workspace/agent-admin/web` 的项目级前端地基,用于支撑后续业务需求探索、页面草案、接口联调和 OpenSpec 编写。
当前阶段不把这些规则上升为 monorepo 全局前端地基。后续只有在多个项目复用并验证稳定后,再迁移或沉淀到 `architecture-spec/docs/architecture/`。
## 2. 当前边界
本项目当前负责岗位Agent管理后台 Web 页面:
- 本地登录页。
- Agent 管理。
- Agent 群管理。
- 官网配置后台。
- 全局 UI 组件库在本项目内的 Demo 承载。
本项目当前不负责:
- 后端接口实现、数据库、队列、任务和第三方 API 对接。
- 管家 Agent 运行时能力。
- 官网移动端 H5 展示,该范围属于 `workspace/agent-admin/single-page`。
- monorepo 全局前端规范最终定稿。
## 3. 技术地基
本项目当前采用:
- React + TypeScript 作为页面开发技术栈。
- Vite 作为开发服务器和构建工具。
- React Router 管理客户端路由。
- Vitest + React Testing Library 编写组件行为和页面交互测试。
- CSS Variables + CSS Modules / 普通 CSS 管理组件和项目样式。
Tailwind CSS 暂不作为本项目已启用能力。后续如业务页面确有需要,可作为页面布局层能力单独评估,但不得依赖 Tailwind 覆盖组件内部结构样式。
## 4. 目录职责
| 路径 | 职责 |
|-|-|
| `src/` | 应用入口、路由、布局、页面、样式和测试基座。 |
| `src/layouts/` | 管理后台基础布局。 |
| `src/routes/` | 路由页面和页面级组合。 |
| `src/styles/` | reset、设计 token、全局样式入口。 |
| `packages/ui/` | 本项目当前使用的可复用 UI 组件。 |
| `packages/contracts/` | 前端视角接口契约、字段、枚举、payload 和 mock 数据。 |
| `packages/config/` | 前端工程配置沉淀。 |
| `packages/utils/` | 前端通用工具沉淀。 |
| `docs/` | 项目级前端地基、页面模式、mock 与业务探索准备文档。 |
| `openspec/` | 本项目具体功能或行为变更的 OpenSpec。 |
## 5. 路由与布局规则
- `/` 当前重定向到 `/components`,用于在业务页面未落地前承载组件 Demo。
- `/components` 当前作为组件 Demo 路由。
- 后续业务页面应按模块进入 `src/routes/<module>/`,再由统一路由入口注册。
- 管理后台页面默认使用项目基础布局,不在单个页面里重复实现侧边导航、顶部区域和基础内容容器。
## 6. 组件使用规则
- 页面优先使用 `packages/ui` 中已有组件。
- 页面不得为了单个场景临时堆一套与组件库重复的按钮、表单、表格、状态标签或反馈样式。
- 组件能力不足时,先记录缺口和业务场景,再判断是扩展组件 props、增加组合组件,还是只在页面层处理。
- 组件内部样式由组件负责,业务页面只通过 props、`className`、`style` 或 CSS 变量做受控扩展。
## 7. 状态与反馈规则
页面探索和实现时必须考虑以下状态:
- loading:列表、表单提交、异步开关、上传、外部同步。
- empty:无数据、筛选无结果、尚未配置。
- error:接口失败、权限失败、资源加载失败、字段校验失败。
- disabled:操作不可用时需要有明确视觉状态,复杂原因应提供说明。
- success:提交成功、保存成功、启停成功。
破坏性操作默认使用二次确认。表单字段错误显示在字段附近,非字段错误可使用全局反馈。
## 8. 测试与验证规则
修改本项目代码时,至少按影响范围运行:
```bash
npm run typecheck
npm test
npm run build
```
新增或修改页面交互时,应优先补充 Vitest + React Testing Library 测试。无法合理自动化覆盖的布局和关键交互,需要通过浏览器验证记录结果。
本文档本身只整理项目级规范,不改变页面功能代码。
# PC 管理后台整体框架与布局确认内容
更新时间:2026-05-19
## 文档定位
本文档记录「岗位Agent管理后台」PC 管理端的整体框架、布局骨架、菜单结构、路由规则和页面容器规则,便于后续 `web/` 管理后台前端开发对齐。
当前阶段只确认 PC 管理后台的通用框架与布局,不展开各业务页面内部的表格、表单、弹窗、抽屉字段细节。各页面具体需求仍以对应模块文档为准。
## 产品名称
管理后台产品名称统一为:`岗位Agent管理后台`。
后台为独立管理系统,登录后进入管理后台主框架。
## 登录后默认落点
管理员登录成功后默认进入:
```text
Agent管理 > Agent列表
```
Agent 列表页展示当前已经配置的 Agent。
未登录用户访问管理后台业务页面时,跳转登录页。登录成功后,如果存在原始访问路径,优先回到原访问路径;否则进入默认落点。
## 整体布局骨架
PC 管理后台采用经典后台布局:
```text
┌────────────────────────────────────────────────────────────────────────┐
│ [Logo] 岗位Agent管理后台 管理员 退出图标 │
├──────────────────┬─────────────────────────────────────────────────────┤
│ │ Agent管理 > Agent列表 │
│ Agent管理 ├─────────────────────────────────────────────────────┤
│ - Agent列表 │ │
│ - 岗位标签管理 │ │
│ - Skill列表 │ │
│ │ 内容区域 │
│ Agent群管理 │ │
│ - 渠道活码 │ │
│ │ │
│ 官网配置 │ │
│ - 岗位展示配置 │ │
│ - 方法论展示配置 │ │
└──────────────────┴─────────────────────────────────────────────────────┘
```
## 区域说明
| 区域 | 内容 |
|-|-|
| 顶栏 | 左侧展示 Logo 和系统名称「岗位Agent管理后台」;右侧展示当前登录用户「管理员」和退出登录图标 |
| 左侧菜单 | 展示一级菜单和二级菜单;本期不支持折叠 |
| 面包屑 | 展示当前路径,基础格式为「一级菜单名 > 二级菜单名」 |
| 内容区域 | 展示当前二级菜单或子页面对应内容,由各业务页面独立设计 |
## 顶栏规则
- 顶栏固定高度为 `56px`。
- 顶栏左侧展示 Logo 和系统名称「岗位Agent管理后台」。
- 系统名称不做全局居中,跟随左侧 Logo 区域展示。
- 顶栏右侧展示当前登录用户「管理员」。
- 「管理员」后展示退出登录图标。
- 点击退出登录后清除前端登录态并回到登录页。
## 左侧菜单规则
- 左侧菜单固定宽度为 `220px`。
- 本期暂不支持侧边栏折叠。
- 菜单按一级菜单和二级菜单展示。
- 一级菜单点击后只负责展开或收起其下二级菜单,不直接进入页面。
- 如果用户从 URL 直接访问一级菜单路径,系统重定向到该一级菜单下的第一个二级页面。
- 当前页面对应的二级菜单需要高亮。
- 深层子页面刷新后,需要根据当前 URL 还原左侧菜单展开状态和二级菜单高亮状态。
## 左侧菜单结构
| 一级菜单 | 二级菜单 | 说明 |
|-|-|-|
| Agent管理 | Agent列表 | Agent 增删改查、管家 Agent 固定展示、状态管理 |
| Agent管理 | 岗位标签管理 | 岗位标签的列表、新建、编辑、删除 |
| Agent管理 | Skill列表 | 所有可绑定 Skill 的只读列表展示 |
| Agent群管理 | 渠道活码 | 员工渠道活码的列表、新建、编辑、停用 |
| 官网配置 | 岗位展示配置 | 岗位 Tab 的新建、编辑、排序、下架,及对应 Agent 卡片的素材、话术、排序配置 |
| 官网配置 | 方法论展示配置 | 方法论独立展示页的内容配置 |
本期没有「群模板」概念,菜单中不展示「群模板」。
## 面包屑规则
- 面包屑位于顶栏下方、内容区顶部。
- 二级页面面包屑格式为:
```text
一级菜单名 > 二级菜单名
```
示例:
```text
Agent管理 > Agent列表
```
- 进入新建、编辑等独立子页面时,面包屑延伸到三级。
示例:
```text
Agent管理 > Agent列表 > 新建Agent
Agent管理 > Agent列表 > 编辑Agent
Agent群管理 > 渠道活码 > 新建渠道活码
官网配置 > 岗位展示配置 > 编辑岗位展示
```
- 详情以抽屉形式承载,不作为独立页面跳转;打开详情抽屉时,页面主面包屑保持当前列表页路径。
## 内容区域与页面容器
- 列表页内容区域使用满宽布局,适合承载搜索区、工具栏、表格和分页。
- 新建、编辑页面为独立页面,不在弹窗或抽屉中承载。
- 表单内容宽度建议控制在 `720px` 到 `960px`,避免表单行过长影响填写效率。
- 详情页面采用抽屉展示,便于在列表上下文中快速查看和切换不同记录详情。
- 抽屉打开后应保留列表当前筛选、分页和滚动上下文。
- 业务页面内部的工具栏、搜索区、表格、分页、空态、错误态、禁用态和成功反馈由各模块页面需求继续细化。
## 路由与刷新规则
后台支持客户端深层路由刷新。
用户在列表、新建、编辑等页面刷新浏览器时,应保持当前页面、左侧菜单高亮和面包屑状态。
如果详情抽屉通过 URL 参数或子路由承载,刷新浏览器后也应还原当前列表页和已打开的详情抽屉状态。
未登录用户访问深层路由时,跳转登录页;登录成功后回到原访问路径。
不存在的路由进入 404 页面。
存在路由但业务资源不存在时,不进入 404 页面,而是在对应页面内展示「资源不存在」或「资源已删除」等业务提示。
一级菜单路径访问规则:
| 访问路径类型 | 处理规则 |
|-|-|
| 访问具体二级页面路径 | 展示对应页面 |
| 访问一级菜单路径 | 重定向到该一级菜单下第一个二级页面 |
| 访问不存在路径 | 展示 404 页面 |
| 未登录访问任意业务路径 | 跳转登录页,登录后回到原路径 |
## 异常页与权限页
- 本期需要提供 404 页面。
- 本期暂不做无权限页面。
- 当前权限模型按管理员单角色设计,不做多角色菜单差异化。
## PC 适配范围
管理后台以 PC 桌面端为主要使用场景。
本期不要求移动端后台适配;小屏访问时优先保证页面不崩溃,具体移动端后台体验不作为本期验收重点。
## 与业务模块文档的关系
本文档只定义管理后台全局框架。
各业务模块的字段、状态、校验、列表操作、表单规则、弹窗确认、抽屉详情和埋点规则,继续以以下文档为准:
- `requirements-admin-login.md`
- `requirements-agent-management.md`
- `requirements-agent-group-management.md`
- `requirements-official-site-config.md`
# Mock 与接口契约协作规则
更新时间:2026-05-18
## 1. 文档定位
本文档说明 `workspace/agent-admin/web` 在业务探索阶段如何组织 mock 数据、页面字段和接口契约。
接口字段、枚举、请求响应和示例数据的主体内容继续维护在 `packages/contracts/frontend-api-contract.md`。本文档只描述协作规则。
## 2. 契约优先级
当前阶段以前端页面需要为起点:
1. 先从需求文档提炼页面字段、操作、状态和校验。
2. 再整理前端需要消费和提交的数据结构。
3. 最后与后端接口文档对齐路径、参数、响应和错误码。
本文档和 `packages/contracts` 不约束后端技术栈、数据表、队列、任务或运行时实现。
## 3. Mock 场景
每个列表、详情或表单模块至少准备以下 mock 场景:
- 正常数据。
- 空数据。
- 筛选无结果。
- 加载中。
- 接口失败。
- 字段缺失或为空。
- 长文本。
- 禁用或无可用操作。
- 分页边界。
涉及状态流转的页面,还需要准备每个关键状态下的操作可用性数据。
## 4. 错误展示
接口错误处理遵循以下顺序:
1. 字段级错误显示在字段附近。
2. 可恢复的业务错误显示在当前模块或弹窗内。
3. 提交结果和非字段错误可使用全局反馈。
4. 权限、登录过期、系统异常等跨页面错误需要单独定义展示策略。
接口返回 `trace_id` 时,前端可在调试信息或错误详情中展示,方便排查。
## 5. 字段命名与枚举
当前接口契约草案遵循:
- 接口前缀使用 `/api/v1`。
- 字段命名使用 snake_case。
- 分页参数使用 `page`、`page_size`。
- 成功响应使用 `code = 200`。
- 启停状态枚举使用 `enable`、`disable`。
如果后端接口文档采用不同约定,应在 `packages/contracts/frontend-api-contract.md` 中记录差异和最终对齐结果。
## 6. 与业务探索的关系
业务探索阶段不要直接跳到接口路径设计。应先回答:
- 页面上需要展示什么。
- 用户能执行什么操作。
- 操作需要哪些输入。
- 成功后页面如何变化。
- 失败后用户如何恢复。
- 哪些信息必须来自后端。
这些问题明确后,再更新接口契约草案。
# 页面模式草案
更新时间:2026-05-18
## 1. 文档定位
本文档沉淀岗位Agent管理后台常用页面模式,供业务需求探索、页面数据草案和后续 OpenSpec 编写使用。
这些模式只约束 `workspace/agent-admin/web` 当前项目,不作为全局页面规范定稿。
## 2. 列表页
列表页默认结构:
1. 页面标题和必要说明。
2. 搜索与筛选区。
3. 主操作区。
4. 表格。
5. 分页。
列表页探索时需要明确:
- 搜索字段。
- 筛选字段。
- 表格列。
- 状态展示。
- 行操作。
- 批量操作。
- 默认排序。
- 空数据和筛选无结果展示。
- 加载失败展示。
## 3. 表单页与弹窗表单
表单默认用于创建、编辑、配置类任务。信息量少且流程聚焦时,优先使用弹窗或抽屉;信息量大或需要分段时,再使用独立页面。
表单探索时需要明确:
- 字段名称、类型、默认值和占位文案。
- 必填、长度、格式、唯一性等校验。
- 字段是否只读、隐藏或由系统带入。
- 提交 payload。
- 保存成功后的跳转或停留策略。
- 取消时是否需要二次确认。
- 提交失败时的字段错误和全局错误展示。
## 4. 详情页
详情页默认用于查看复杂对象或操作结果。详情页不应堆成只读表单,应该按业务语义分组展示。
详情页探索时需要明确:
- 基础信息。
- 关联信息。
- 状态与历史记录。
- 可执行操作。
- 返回入口。
- 数据缺失时的展示。
## 5. 状态流转
涉及启用、停用、删除、上架、下架、审核、同步等流程时,需要先画清状态流转,再写页面。
状态流转探索时需要明确:
- 所有状态枚举。
- 初始状态。
- 终态。
- 每个状态下可见操作。
- 每个操作的确认方式。
- 成功和失败反馈。
- 哪些状态会阻塞其他操作。
## 6. 高影响操作
以下操作默认需要二次确认:
- 删除 Agent。
- 删除官网 Tab。
- 停用仍被展示链路引用的配置。
- 批量变更状态。
- 覆盖或清空配置。
确认弹窗需要说明操作后果。若后果来自接口返回,页面需要展示后端返回的影响项。
## 7. 文件与素材
文件上传类页面需要明确:
- 文件类型。
- 文件大小。
- 推荐尺寸或比例。
- 上传前校验。
- 上传进度。
- 失败重试。
- 预览方式。
- 删除或替换策略。
素材加载失败时,应展示占位状态,不应造成页面主要操作不可用。
...@@ -11,6 +11,6 @@ ...@@ -11,6 +11,6 @@
- 组件需要自带完整规范样式,使用 CSS Variables + CSS Modules / 普通 CSS。 - 组件需要自带完整规范样式,使用 CSS Variables + CSS Modules / 普通 CSS。
- 组件实现必须先有接口定义和失败测试,再补逻辑、样式和审核注释。 - 组件实现必须先有接口定义和失败测试,再补逻辑、样式和审核注释。
当前稳定导出入口为 `src/index.ts`,业务页面应从该入口消费组件。已建立的一期基础交互组件包括 `Button`、`Input`、`SearchInput`、`Checkbox`、`Radio` 和 `Switch`。 当前稳定导出入口为 `src/index.ts`,业务页面应从该入口消费组件。已建立的一期基础交互组件包括 `Button`、`Input`、`Textarea`、`SearchInput`、`Checkbox`、`Radio`、`Switch` 和 `Upload`。
`Upload` 组件规范尚未确认,暂不纳入当前组件库实现。 `Upload` 组件族提供文件拖拽上传和图片/视频媒体墙两种设计形态,只负责 UI 状态和回调,不内置真实上传传输、业务校验或预览弹层。
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import type { ReactNode } from 'react'; import type { CSSProperties, ReactNode } from 'react';
import { Button } from './Button'; import { Button } from './Button';
import { Icon } from './Icon'; import { Icon } from './Icon';
...@@ -159,11 +159,11 @@ export function Modal({ children, confirmLoading, footer, onCancel, onOk, open, ...@@ -159,11 +159,11 @@ export function Modal({ children, confirmLoading, footer, onCancel, onOk, open,
<button className={styles.plainButton} type="button" aria-label={`关闭${title}`} onClick={onCancel}>×</button> <button className={styles.plainButton} type="button" aria-label={`关闭${title}`} onClick={onCancel}>×</button>
</header> </header>
<div className={styles.section}>{children}</div> <div className={styles.section}>{children}</div>
<footer className={cx(styles.section, styles.row)}> <footer className={cx(styles.section, styles.row, styles.modalFooter)} data-testid="modal-footer">
{footer ?? ( {footer ?? (
<> <>
<Button onClick={onCancel}>取消</Button> <Button onClick={onCancel}>取消</Button>
<button className={styles.control} type="button" aria-busy={confirmLoading || undefined} onClick={onOk}>确定</button> <Button variant="primary" aria-busy={confirmLoading || undefined} onClick={onOk}>确定</Button>
</> </>
)} )}
</footer> </footer>
...@@ -177,21 +177,32 @@ export interface DrawerProps { ...@@ -177,21 +177,32 @@ export interface DrawerProps {
open?: boolean; open?: boolean;
title: ReactNode; title: ReactNode;
placement?: 'left' | 'right'; placement?: 'left' | 'right';
/** width 支持数字像素值或 CSS 宽度字符串,方便页面按场景控制 320px/480px/640px 等宽度。 */
width?: number | string;
footer?: ReactNode; footer?: ReactNode;
children?: ReactNode; children?: ReactNode;
onClose?: () => void; onClose?: () => void;
} }
export function Drawer({ children, footer, onClose, open, placement = 'right', title }: DrawerProps) { const formatDrawerWidth = (width: number | string) => (typeof width === 'number' ? `${width}px` : width);
export function Drawer({ children, footer, onClose, open, placement = 'right', title, width = '420px' }: DrawerProps) {
if (!open) return null; if (!open) return null;
const drawerStyle: CSSProperties = {
width: formatDrawerWidth(width),
...(placement === 'left' ? { left: 0, right: 'auto' } : undefined),
};
return ( return (
<aside className={styles.drawer} style={placement === 'left' ? { left: 0, right: 'auto' } : undefined} role="dialog" aria-label={String(title)}> <div className={styles.drawerOverlay} data-testid="drawer-overlay">
<header className={cx(styles.section, styles.between)}> <aside className={styles.drawer} style={drawerStyle} role="dialog" aria-modal="true" aria-label={String(title)}>
<strong>{title}</strong> <header className={cx(styles.section, styles.between)}>
<button className={styles.plainButton} type="button" aria-label={`关闭${title}`} onClick={onClose}>×</button> <strong>{title}</strong>
</header> <button className={styles.plainButton} type="button" aria-label={`关闭${title}`} onClick={onClose}>×</button>
<div className={styles.section}>{children}</div> </header>
{footer ? <footer className={styles.section}>{footer}</footer> : null} <div className={styles.section}>{children}</div>
</aside> {footer ? <footer className={styles.section}>{footer}</footer> : null}
</aside>
</div>
); );
} }
export type IconName = 'check-circle' | 'chevron-down' | 'chevron-left' | 'chevron-right' | 'close-circle' | 'info-circle' | 'search' | 'warning-circle'; export type IconName =
| 'check-circle'
| 'chevron-down'
| 'chevron-left'
| 'chevron-right'
| 'close-circle'
| 'download'
| 'eye'
| 'file'
| 'info-circle'
| 'play'
| 'plus'
| 'refresh'
| 'search'
| 'trash'
| 'upload'
| 'warning-circle';
export interface IconProps { export interface IconProps {
name: IconName; name: IconName;
...@@ -13,8 +29,16 @@ const paths: Record<IconName, string> = { ...@@ -13,8 +29,16 @@ const paths: Record<IconName, string> = {
'chevron-left': 'M15 6l-6 6 6 6', 'chevron-left': 'M15 6l-6 6 6 6',
'chevron-right': 'M9 6l6 6-6 6', 'chevron-right': 'M9 6l6 6-6 6',
'close-circle': 'M9 9l6 6 M15 9l-6 6 M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18', 'close-circle': 'M9 9l6 6 M15 9l-6 6 M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18',
download: 'M12 3v12 M7 10l5 5 5-5 M5 21h14',
eye: 'M2.5 12s3.5-6 9.5-6 9.5 6 9.5 6-3.5 6-9.5 6-9.5-6-9.5-6 M12 15a3 3 0 1 0 0-6 3 3 0 0 0 0 6',
file: 'M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8l-5-5z M14 3v5h5',
'info-circle': 'M12 10v6 M12 7h.01 M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18', 'info-circle': 'M12 10v6 M12 7h.01 M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18',
play: 'M8 5v14l11-7-11-7z',
plus: 'M12 5v14 M5 12h14',
refresh: 'M20 6v5h-5 M4 18v-5h5 M18.5 9A7 7 0 0 0 6.8 6.8L4 11 M5.5 15A7 7 0 0 0 17.2 17.2L20 13',
search: 'M10.5 17a6.5 6.5 0 1 1 4.6-1.9L20 20', search: 'M10.5 17a6.5 6.5 0 1 1 4.6-1.9L20 20',
trash: 'M4 7h16 M10 11v6 M14 11v6 M6 7l1 14h10l1-14 M9 7V4h6v3',
upload: 'M12 21V9 M7 14l5-5 5 5 M5 21h14',
'warning-circle': 'M12 8v5 M12 16h.01 M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18', 'warning-circle': 'M12 8v5 M12 16h.01 M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18',
}; };
......
...@@ -51,6 +51,13 @@ ...@@ -51,6 +51,13 @@
font-size: var(--gl-font-size-sm); font-size: var(--gl-font-size-sm);
} }
.counter {
flex: 0 0 auto;
color: var(--gl-color-text-secondary);
font-size: var(--gl-font-size-xs);
white-space: nowrap;
}
.input { .input {
width: 100%; width: 100%;
min-width: 0; min-width: 0;
......
...@@ -12,6 +12,8 @@ export interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, ...@@ -12,6 +12,8 @@ export interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>,
suffix?: ReactNode; suffix?: ReactNode;
/** 状态样式用于和 FormItem 校验信息协同展示。 */ /** 状态样式用于和 FormItem 校验信息协同展示。 */
status?: 'default' | 'success' | 'warning' | 'error'; status?: 'default' | 'success' | 'warning' | 'error';
/** 是否显示输入长度,默认使用简洁的当前值/上限格式。 */
showCount?: boolean;
/** 是否展示清空按钮,受控和非受控场景都通过字符串值回调给业务侧。 */ /** 是否展示清空按钮,受控和非受控场景都通过字符串值回调给业务侧。 */
allowClear?: boolean; allowClear?: boolean;
onChange?: (value: string) => void; onChange?: (value: string) => void;
...@@ -34,6 +36,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(function Input( ...@@ -34,6 +36,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
prefix, prefix,
status = 'default', status = 'default',
suffix, suffix,
showCount = false,
value, value,
...props ...props
}, },
...@@ -50,6 +53,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(function Input( ...@@ -50,6 +53,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
}; };
const clearLabel = props['aria-label'] ? `清空${props['aria-label']}` : '清空输入'; const clearLabel = props['aria-label'] ? `清空${props['aria-label']}` : '清空输入';
const countLabel = props.maxLength !== undefined ? `${currentValue.length}/${props.maxLength}` : String(currentValue.length);
return ( return (
<span <span
...@@ -72,6 +76,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(function Input( ...@@ -72,6 +76,7 @@ export const Input = forwardRef<HTMLInputElement, InputProps>(function Input(
aria-invalid={status === 'error' || undefined} aria-invalid={status === 'error' || undefined}
onChange={(event) => emitChange(event.target.value)} onChange={(event) => emitChange(event.target.value)}
/> />
{showCount ? <span className={styles.counter}>{countLabel}</span> : null}
{allowClear && currentValue ? ( {allowClear && currentValue ? (
<button <button
aria-label={clearLabel} aria-label={clearLabel}
......
...@@ -318,20 +318,23 @@ ...@@ -318,20 +318,23 @@
.form { .form {
display: grid; display: grid;
width: 100%;
gap: var(--gl-spacing-md); gap: var(--gl-spacing-md);
} }
.formColumnsOne { .formColumnsOne {
grid-template-columns: minmax(0, 1fr); grid-template-columns: minmax(0, 100%);
} }
.formColumnsTwo { .formColumnsTwo {
grid-template-columns: repeat(2, minmax(0, 1fr)); grid-template-columns: repeat(2, minmax(0, calc((100% - var(--gl-spacing-md)) / 2)));
} }
.formItem { .formItem {
display: grid; display: grid;
width: 100%;
align-items: start; align-items: start;
box-sizing: border-box;
gap: var(--gl-spacing-sm); gap: var(--gl-spacing-sm);
} }
...@@ -378,7 +381,7 @@ ...@@ -378,7 +381,7 @@
} }
.formTips { .formTips {
color: var(--gl-color-text-secondary); color: color-mix(in srgb, var(--gl-color-text-secondary) 64%, #fff);
font-size: var(--gl-font-size-sm); font-size: var(--gl-font-size-sm);
white-space: nowrap; white-space: nowrap;
} }
...@@ -567,13 +570,24 @@ ...@@ -567,13 +570,24 @@
box-shadow: 0 20px 48px rgb(16 24 40 / 22%); box-shadow: 0 20px 48px rgb(16 24 40 / 22%);
} }
.modalFooter {
justify-content: flex-end;
}
.drawerOverlay {
position: fixed;
inset: 0;
z-index: 100;
background: rgb(16 24 40 / 42%);
}
.drawer { .drawer {
position: fixed; position: fixed;
top: 0; top: 0;
right: 0; right: 0;
bottom: 0; bottom: 0;
z-index: 101; z-index: 101;
width: min(420px, 92vw); max-width: 92vw;
background: var(--gl-color-bg-container); background: var(--gl-color-bg-container);
box-shadow: -16px 0 40px rgb(16 24 40 / 18%); box-shadow: -16px 0 40px rgb(16 24 40 / 18%);
} }
......
.field {
display: flex;
width: 100%;
min-width: 0;
flex-direction: column;
gap: var(--gl-spacing-xs);
min-height: 96px;
padding: var(--gl-spacing-md);
border: 1px solid var(--gl-color-border-primary);
border-radius: var(--gl-radius-sm);
background: var(--gl-color-bg-container);
color: var(--gl-color-text-primary);
transition:
border-color 120ms ease,
box-shadow 120ms ease,
background-color 120ms ease;
}
.field:hover {
border-color: var(--gl-color-primary);
}
.field:focus-within {
border-color: var(--gl-color-primary);
box-shadow: 0 0 0 2px color-mix(in srgb, var(--gl-color-primary) 18%, transparent);
}
.fieldDisabled {
cursor: not-allowed;
background: var(--gl-color-fill-hover);
color: var(--gl-color-text-secondary);
}
.fieldError {
border-color: var(--gl-color-danger, #d92d20);
}
.fieldWarning {
border-color: var(--gl-color-warning, #dc6803);
}
.fieldSuccess {
border-color: var(--gl-color-success, #039855);
}
.textarea {
width: 100%;
min-width: 0;
flex: 1 1 auto;
resize: vertical;
border: 0;
outline: 0;
background: transparent;
color: inherit;
font: inherit;
font-size: var(--gl-font-size-sm);
line-height: 1.6;
}
.textarea::placeholder {
color: var(--gl-color-text-secondary);
}
.textarea:disabled {
cursor: not-allowed;
}
.footer {
align-self: flex-end;
color: var(--gl-color-text-secondary);
font-size: var(--gl-font-size-xs);
white-space: nowrap;
}
import { forwardRef, useState } from 'react';
import type { TextareaHTMLAttributes } from 'react';
import styles from './Textarea.module.css';
import { cx } from './utils';
export interface TextareaProps extends Omit<TextareaHTMLAttributes<HTMLTextAreaElement>, 'onChange' | 'size'> {
/** 状态样式用于和 FormItem 校验信息协同展示。 */
status?: 'default' | 'success' | 'warning' | 'error';
/** 是否显示输入长度,默认使用简洁的当前值/上限格式。 */
showCount?: boolean;
onChange?: (value: string) => void;
}
export const Textarea = forwardRef<HTMLTextAreaElement, TextareaProps>(function Textarea(
{
className,
defaultValue,
disabled,
onChange,
rows = 4,
showCount = false,
status = 'default',
value,
...props
},
ref,
) {
const [innerValue, setInnerValue] = useState(defaultValue?.toString() ?? '');
const currentValue = value === undefined ? innerValue : String(value);
const emitChange = (nextValue: string) => {
if (value === undefined) {
setInnerValue(nextValue);
}
onChange?.(nextValue);
};
// 多行输入的长度提示放在右下角,既不挤压正文,也能保持简洁可扫读。
const countLabel = props.maxLength !== undefined ? `${currentValue.length}/${props.maxLength}` : String(currentValue.length);
return (
<span
className={cx(
styles.field,
status === 'error' && styles.fieldError,
status === 'warning' && styles.fieldWarning,
status === 'success' && styles.fieldSuccess,
disabled && styles.fieldDisabled,
className,
)}
>
<textarea
{...props}
ref={ref}
className={styles.textarea}
disabled={disabled}
rows={rows}
value={currentValue}
aria-invalid={status === 'error' || undefined}
onChange={(event) => emitChange(event.target.value)}
/>
{showCount ? <span className={styles.footer}>{countLabel}</span> : null}
</span>
);
});
.root {
display: grid;
width: 100%;
max-width: 500px;
gap: var(--gl-spacing-lg);
}
.dragger {
display: flex;
width: 100%;
height: 208px;
box-sizing: border-box;
flex-direction: column;
align-items: center;
justify-content: center;
padding: var(--gl-spacing-xl);
border: 1px dashed var(--gl-color-border-primary);
border-radius: 12px;
background: var(--gl-color-bg-container);
color: var(--gl-color-text-primary);
cursor: pointer;
transition:
background-color 120ms ease,
border-color 120ms ease,
color 120ms ease,
opacity 120ms ease;
}
.dragger:hover:not(:disabled),
.draggerActive {
border-color: var(--gl-color-primary);
background: color-mix(in srgb, var(--gl-color-primary) 4%, #fff);
}
.dragger:focus-visible,
.mediaButton:focus-visible,
.mediaUpload:focus-visible,
.iconButton:focus-visible {
outline: 2px solid color-mix(in srgb, var(--gl-color-primary) 24%, transparent);
outline-offset: 2px;
}
.dragger:disabled,
.mediaUpload:disabled {
cursor: not-allowed;
opacity: 0.55;
}
.uploadIcon {
display: inline-flex;
width: 64px;
height: 64px;
align-items: center;
justify-content: center;
margin-bottom: var(--gl-spacing-lg);
border-radius: 999px;
background: color-mix(in srgb, var(--gl-color-primary) 10%, #fff);
color: var(--gl-color-primary);
}
.draggerTitle {
font-size: var(--gl-font-size-sm);
font-weight: 600;
line-height: var(--gl-line-height-md);
}
.draggerHelper {
margin-top: var(--gl-spacing-sm);
color: var(--gl-color-text-secondary);
font-size: var(--gl-font-size-xs);
line-height: var(--gl-line-height-sm);
}
.input {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
.fileList {
display: grid;
gap: var(--gl-spacing-sm);
padding: 0;
margin: 0;
list-style: none;
}
.fileItem {
display: grid;
min-height: 60px;
box-sizing: border-box;
grid-template-columns: minmax(0, 1fr) auto;
gap: var(--gl-spacing-md);
align-items: center;
padding: var(--gl-spacing-sm) var(--gl-spacing-md);
border: 1px solid var(--gl-color-border-primary);
border-radius: 10px;
background: var(--gl-color-bg-container);
}
.fileItemError {
border-color: color-mix(in srgb, var(--gl-color-danger, #d92d20) 38%, var(--gl-color-border-primary));
}
.fileMain {
display: flex;
min-width: 0;
align-items: center;
gap: var(--gl-spacing-md);
}
.fileIcon {
display: inline-flex;
width: 32px;
height: 32px;
flex: 0 0 32px;
align-items: center;
justify-content: center;
border-radius: var(--gl-radius-md);
background: color-mix(in srgb, var(--gl-color-primary) 8%, #fff);
color: var(--gl-color-primary);
}
.fileText {
display: grid;
min-width: 0;
gap: 2px;
}
.fileName {
overflow: hidden;
color: var(--gl-color-text-primary);
font-size: var(--gl-font-size-sm);
font-weight: 600;
line-height: var(--gl-line-height-md);
text-overflow: ellipsis;
white-space: nowrap;
}
.fileMeta,
.mediaHelper {
color: var(--gl-color-text-secondary);
font-size: var(--gl-font-size-xs);
line-height: var(--gl-line-height-sm);
}
.fileError {
color: var(--gl-color-danger, #d92d20);
font-size: var(--gl-font-size-xs);
line-height: var(--gl-line-height-sm);
}
.fileActions {
display: inline-flex;
align-items: center;
gap: var(--gl-spacing-xs);
}
.iconButton {
display: inline-flex;
width: 28px;
height: 28px;
align-items: center;
justify-content: center;
border: 0;
border-radius: var(--gl-radius-sm);
background: transparent;
color: var(--gl-color-text-secondary);
cursor: pointer;
}
.iconButton:hover {
background: var(--gl-color-fill-hover);
color: var(--gl-color-primary);
}
.iconButton[aria-label^='删除']:hover {
color: var(--gl-color-danger, #d92d20);
}
.progressTrack {
grid-column: 1 / -1;
height: 4px;
overflow: hidden;
border-radius: 999px;
background: var(--gl-color-border-secondary);
}
.progressFill {
display: block;
height: 100%;
border-radius: inherit;
background: var(--gl-color-primary);
}
.mediaRoot {
display: grid;
gap: var(--gl-spacing-sm);
}
.mediaGrid {
display: flex;
flex-wrap: wrap;
gap: var(--gl-spacing-md);
padding: 0;
margin: 0;
list-style: none;
}
.mediaCell {
width: 96px;
height: 96px;
}
.mediaButton,
.mediaUpload {
position: relative;
display: flex;
width: 96px;
height: 96px;
box-sizing: border-box;
align-items: center;
justify-content: center;
overflow: hidden;
border-radius: 8px;
cursor: pointer;
}
.mediaButton {
padding: 0;
border: 1px solid var(--gl-color-border-secondary);
background: var(--gl-color-bg-container);
}
.mediaThumb {
width: 100%;
height: 100%;
object-fit: cover;
}
.playBadge {
position: absolute;
inset: 0;
display: flex;
align-items: center;
justify-content: center;
color: #fff;
background: rgb(0 0 0 / 22%);
}
.playBadge svg {
width: 34px;
height: 34px;
padding: 7px;
border-radius: 999px;
background: rgb(0 0 0 / 38%);
fill: currentColor;
}
.mediaUpload {
flex-direction: column;
gap: var(--gl-spacing-xs);
border: 1px dashed var(--gl-color-border-primary);
background: var(--gl-color-bg-container);
color: var(--gl-color-text-secondary);
font-size: var(--gl-font-size-xs);
font-weight: 600;
}
.mediaUpload:hover:not(:disabled) {
border-color: var(--gl-color-primary);
color: var(--gl-color-primary);
background: color-mix(in srgb, var(--gl-color-primary) 4%, #fff);
}
.mediaPlus {
display: inline-flex;
width: 32px;
height: 32px;
align-items: center;
justify-content: center;
border-radius: 999px;
background: var(--gl-color-fill-hover);
}
.mediaHelper {
margin: 0;
}
.srOnly {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
import { useRef, useState, type CSSProperties } from 'react';
import { Icon } from './Icon';
import styles from './Upload.module.css';
import { cx } from './utils';
export type UploadFileStatus = 'uploading' | 'done' | 'error';
export interface UploadFileItem {
id: string;
name: string;
size: number;
status: UploadFileStatus;
progress?: number;
errorMessage?: string;
previewable?: boolean;
}
export interface UploadDraggerProps {
/** UploadDragger 只负责 UI 状态和操作意图,不执行真实校验、分片续传或接口上传。 */
files: UploadFileItem[];
title?: string;
helperText?: string;
accept?: string;
multiple?: boolean;
disabled?: boolean;
className?: string;
style?: CSSProperties;
onSelectFiles?: (files: File[]) => void;
onPreview?: (id: string) => void;
onDownload?: (id: string) => void;
onRemove?: (id: string) => void;
onRetry?: (id: string) => void;
onCancel?: (id: string) => void;
}
function formatSize(size: number) {
return `${(size / 1024 / 1024).toFixed(2)} MB`;
}
function clampProgress(progress = 0) {
return Math.min(100, Math.max(0, Math.round(progress)));
}
function IconButton({ label, name, onClick }: { label: string; name: Parameters<typeof Icon>[0]['name']; onClick?: () => void }) {
if (!onClick) return null;
return (
<button className={styles.iconButton} type="button" aria-label={label} onClick={onClick}>
<Icon name={name} size={16} />
</button>
);
}
function FileActions({
file,
onCancel,
onDownload,
onPreview,
onRemove,
onRetry,
}: {
file: UploadFileItem;
onCancel?: (id: string) => void;
onDownload?: (id: string) => void;
onPreview?: (id: string) => void;
onRemove?: (id: string) => void;
onRetry?: (id: string) => void;
}) {
if (file.status === 'uploading') {
return <IconButton label={`取消 ${file.name}`} name="close-circle" onClick={onCancel ? () => onCancel(file.id) : undefined} />;
}
if (file.status === 'error') {
return (
<>
<IconButton label={`重试 ${file.name}`} name="refresh" onClick={onRetry ? () => onRetry(file.id) : undefined} />
<IconButton label={`删除 ${file.name}`} name="trash" onClick={onRemove ? () => onRemove(file.id) : undefined} />
</>
);
}
return (
<>
{file.previewable ? <IconButton label={`预览 ${file.name}`} name="eye" onClick={onPreview ? () => onPreview(file.id) : undefined} /> : null}
<IconButton label={`下载 ${file.name}`} name="download" onClick={onDownload ? () => onDownload(file.id) : undefined} />
<IconButton label={`删除 ${file.name}`} name="trash" onClick={onRemove ? () => onRemove(file.id) : undefined} />
</>
);
}
export function UploadDragger({
accept,
className,
disabled = false,
files,
helperText = '支持分片断点续传,单文件上限 1GB',
multiple = true,
onCancel,
onDownload,
onPreview,
onRemove,
onRetry,
onSelectFiles,
style,
title = '点击或拖拽文件到此上传',
}: UploadDraggerProps) {
const inputRef = useRef<HTMLInputElement>(null);
const dragDepthRef = useRef(0);
const [dragActive, setDragActive] = useState(false);
const emitFiles = (selectedFiles: FileList | File[]) => {
const nextFiles = Array.from(selectedFiles);
if (!disabled && nextFiles.length > 0) onSelectFiles?.(nextFiles);
};
const resetDragState = () => {
dragDepthRef.current = 0;
setDragActive(false);
};
return (
<div className={cx(styles.root, className)} style={style}>
<button
className={cx(styles.dragger, dragActive && styles.draggerActive)}
data-testid="upload-dragger"
type="button"
disabled={disabled}
onClick={() => inputRef.current?.click()}
onDragEnter={(event) => {
event.preventDefault();
dragDepthRef.current += 1;
if (!disabled) setDragActive(true);
}}
onDragLeave={(event) => {
event.preventDefault();
dragDepthRef.current = Math.max(0, dragDepthRef.current - 1);
if (dragDepthRef.current === 0) setDragActive(false);
}}
onDragOver={(event) => {
event.preventDefault();
if (!disabled) event.dataTransfer.dropEffect = 'copy';
}}
onDrop={(event) => {
event.preventDefault();
resetDragState();
emitFiles(event.dataTransfer.files);
}}
>
<span className={styles.uploadIcon} aria-hidden="true">
<Icon name="upload" size={32} />
</span>
<span className={styles.draggerTitle}>{title}</span>
<span className={styles.draggerHelper}>{helperText}</span>
</button>
<input
ref={inputRef}
aria-label="选择上传文件"
className={styles.input}
type="file"
accept={accept}
multiple={multiple}
disabled={disabled}
onChange={(event) => {
if (event.target.files) emitFiles(event.target.files);
event.currentTarget.value = '';
}}
/>
{files.length > 0 ? (
<ul className={styles.fileList} aria-label="上传文件列表">
{files.map((file) => {
const progress = clampProgress(file.progress);
const statusText = file.status === 'done' ? '已完成' : file.status === 'error' ? '上传失败' : `上传中 ${progress}%`;
return (
<li key={file.id} className={cx(styles.fileItem, file.status === 'error' && styles.fileItemError)}>
<div className={styles.fileMain}>
<span className={styles.fileIcon} aria-hidden="true">
<Icon name="file" size={18} />
</span>
<div className={styles.fileText}>
<span className={styles.fileName}>{file.name}</span>
<span className={styles.fileMeta}>{formatSize(file.size)} · {statusText}</span>
{file.status === 'error' && file.errorMessage ? <span className={styles.fileError}>{file.errorMessage}</span> : null}
</div>
</div>
<div className={styles.fileActions}>
<FileActions file={file} onCancel={onCancel} onDownload={onDownload} onPreview={onPreview} onRemove={onRemove} onRetry={onRetry} />
</div>
{file.status === 'uploading' ? (
<div className={styles.progressTrack} role="progressbar" aria-label={`${file.name} 上传进度`} aria-valuemin={0} aria-valuemax={100} aria-valuenow={progress}>
<span className={styles.progressFill} style={{ width: `${progress}%` }} />
</div>
) : null}
</li>
);
})}
</ul>
) : null}
</div>
);
}
export interface MediaWallItem {
id: string;
type: 'image' | 'video';
src: string;
alt: string;
}
export interface MediaWallProps {
/** MediaWall 展示素材缩略图和预览意图;图片放大、视频播放和真实上传由业务侧组合实现。 */
items: MediaWallItem[];
helperText?: string;
accept?: string;
multiple?: boolean;
disabled?: boolean;
className?: string;
style?: CSSProperties;
onPreview?: (item: MediaWallItem) => void;
onSelectFiles?: (files: File[]) => void;
}
export function MediaWall({
accept = 'image/*,video/*',
className,
disabled = false,
helperText,
items,
multiple = true,
onPreview,
onSelectFiles,
style,
}: MediaWallProps) {
const inputRef = useRef<HTMLInputElement>(null);
return (
<div className={cx(styles.mediaRoot, className)} style={style}>
<ul className={styles.mediaGrid} data-testid="media-wall-grid" aria-label="媒体资源墙">
{items.map((item) => (
<li key={item.id} className={styles.mediaCell}>
<button className={styles.mediaButton} type="button" aria-label={`预览 ${item.alt}`} onClick={() => onPreview?.(item)}>
<img className={styles.mediaThumb} src={item.src} alt={item.alt} />
<span className={styles.srOnly}>{item.alt}</span>
{item.type === 'video' ? (
<span className={styles.playBadge} aria-label="视频">
<Icon name="play" size={20} />
</span>
) : null}
</button>
</li>
))}
<li className={styles.mediaCell}>
<button className={styles.mediaUpload} type="button" disabled={disabled} onClick={() => inputRef.current?.click()}>
<span className={styles.mediaPlus} aria-hidden="true">
<Icon name="plus" size={22} />
</span>
<span>图片/视频</span>
</button>
<input
ref={inputRef}
aria-label="选择图片或视频"
className={styles.input}
type="file"
accept={accept}
multiple={multiple}
disabled={disabled}
onChange={(event) => {
if (event.target.files) onSelectFiles?.(Array.from(event.target.files));
event.currentTarget.value = '';
}}
/>
</li>
</ul>
{helperText ? <p className={styles.mediaHelper}>{helperText}</p> : null}
</div>
);
}
...@@ -7,6 +7,7 @@ import { ...@@ -7,6 +7,7 @@ import {
Input, Input,
Radio, Radio,
SearchInput, SearchInput,
Textarea,
Switch, Switch,
} from '../index'; } from '../index';
...@@ -75,6 +76,23 @@ describe('shared UI basic controls', () => { ...@@ -75,6 +76,23 @@ describe('shared UI basic controls', () => {
expect(screen.getByText('元')).toBeInTheDocument(); expect(screen.getByText('元')).toBeInTheDocument();
}); });
it('renders concise Input and Textarea count display when showCount is enabled', () => {
const onTextareaChange = vi.fn();
render(
<>
<Input aria-label="字数输入" defaultValue="合同" maxLength={10} showCount />
<Textarea aria-label="备注" defaultValue="已填写" maxLength={20} showCount onChange={onTextareaChange} />
</>,
);
fireEvent.change(screen.getByLabelText('备注'), { target: { value: '已填写更多内容' } });
expect(screen.getByText('2/10')).toBeInTheDocument();
expect(screen.getByText('7/20')).toBeInTheDocument();
expect(onTextareaChange).toHaveBeenCalledWith('已填写更多内容');
});
it('triggers SearchInput search from enter, button click, and clear', () => { it('triggers SearchInput search from enter, button click, and clear', () => {
const onSearch = vi.fn(); const onSearch = vi.fn();
const onClear = vi.fn(); const onClear = vi.fn();
......
...@@ -19,6 +19,7 @@ import { ...@@ -19,6 +19,7 @@ import {
Timeline, Timeline,
Tooltip, Tooltip,
} from '../index'; } from '../index';
import buttonStyles from './Button.module.css';
import styles from './Shared.module.css'; import styles from './Shared.module.css';
describe('feedback and display components', () => { describe('feedback and display components', () => {
...@@ -235,7 +236,7 @@ describe('feedback and display components', () => { ...@@ -235,7 +236,7 @@ describe('feedback and display components', () => {
<Modal open title="编辑项目" confirmLoading onCancel={onModalClose} onOk={onModalOk}> <Modal open title="编辑项目" confirmLoading onCancel={onModalClose} onOk={onModalOk}>
表单内容 表单内容
</Modal> </Modal>
<Drawer open title="详情" placement="right" onClose={onDrawerClose} footer={<button type="button">保存</button>}> <Drawer open title="详情" placement="right" width="480px" onClose={onDrawerClose} footer={<button type="button">保存</button>}>
抽屉内容 抽屉内容
</Drawer> </Drawer>
</>, </>,
...@@ -246,8 +247,11 @@ describe('feedback and display components', () => { ...@@ -246,8 +247,11 @@ describe('feedback and display components', () => {
fireEvent.click(screen.getByRole('button', { name: '关闭详情' })); fireEvent.click(screen.getByRole('button', { name: '关闭详情' }));
expect(screen.getByRole('dialog', { name: '编辑项目' })).toBeInTheDocument(); expect(screen.getByRole('dialog', { name: '编辑项目' })).toBeInTheDocument();
expect(screen.getByRole('dialog', { name: '详情' })).toBeInTheDocument(); expect(screen.getByRole('dialog', { name: '详情' })).toHaveStyle({ width: '480px' });
expect(screen.getByRole('button', { name: '确定' })).toHaveClass(buttonStyles.primary);
expect(screen.getByRole('button', { name: '确定' })).toHaveAttribute('aria-busy', 'true'); expect(screen.getByRole('button', { name: '确定' })).toHaveAttribute('aria-busy', 'true');
expect(screen.getByTestId('modal-footer')).toHaveClass(styles.modalFooter);
expect(screen.getByTestId('drawer-overlay')).toHaveClass(styles.drawerOverlay);
expect(onModalClose).toHaveBeenCalledTimes(1); expect(onModalClose).toHaveBeenCalledTimes(1);
expect(onModalOk).toHaveBeenCalledTimes(1); expect(onModalOk).toHaveBeenCalledTimes(1);
expect(onDrawerClose).toHaveBeenCalledTimes(1); expect(onDrawerClose).toHaveBeenCalledTimes(1);
......
import { fireEvent, render, screen, within } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest';
import { MediaWall, UploadDragger } from '../index';
import styles from './Upload.module.css';
describe('Upload components', () => {
it('renders the 500 by 208 dragger with helper text and completed file actions', () => {
const onPreview = vi.fn();
const onDownload = vi.fn();
const onRemove = vi.fn();
render(
<UploadDragger
title="点击或拖拽业务资料到此上传"
helperText="支持分片断点续传,单文件上限 1GB"
files={[
{ id: 'design', name: 'product_design_v2.fig', size: 12.4 * 1024 * 1024, status: 'done', previewable: true },
]}
onPreview={onPreview}
onDownload={onDownload}
onRemove={onRemove}
/>,
);
expect(screen.getByTestId('upload-dragger')).toHaveClass(styles.dragger);
expect(screen.getByText('点击或拖拽业务资料到此上传')).toBeInTheDocument();
expect(screen.getByText('支持分片断点续传,单文件上限 1GB')).toBeInTheDocument();
expect(screen.getByText('product_design_v2.fig')).toBeInTheDocument();
expect(screen.getByText('12.40 MB · 已完成')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '预览 product_design_v2.fig' }));
fireEvent.click(screen.getByRole('button', { name: '下载 product_design_v2.fig' }));
fireEvent.click(screen.getByRole('button', { name: '删除 product_design_v2.fig' }));
expect(onPreview).toHaveBeenCalledWith('design');
expect(onDownload).toHaveBeenCalledWith('design');
expect(onRemove).toHaveBeenCalledWith('design');
});
it('renders uploading progress with cancel and failed files with retry plus delete', () => {
const onCancel = vi.fn();
const onRetry = vi.fn();
const onRemove = vi.fn();
render(
<UploadDragger
files={[
{ id: 'uploading', name: 'contract.pdf', size: 3 * 1024 * 1024, status: 'uploading', progress: 45 },
{ id: 'failed', name: 'archive.zip', size: 8 * 1024 * 1024, status: 'error', errorMessage: '网络异常,请重试' },
]}
onCancel={onCancel}
onRetry={onRetry}
onRemove={onRemove}
/>,
);
expect(screen.getByText('3.00 MB · 上传中 45%')).toBeInTheDocument();
expect(screen.getByRole('progressbar', { name: 'contract.pdf 上传进度' })).toHaveAttribute('aria-valuenow', '45');
expect(screen.getByText('8.00 MB · 上传失败')).toBeInTheDocument();
expect(screen.getByText('网络异常,请重试')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '取消 contract.pdf' }));
fireEvent.click(screen.getByRole('button', { name: '重试 archive.zip' }));
fireEvent.click(screen.getByRole('button', { name: '删除 archive.zip' }));
expect(onCancel).toHaveBeenCalledWith('uploading');
expect(onRetry).toHaveBeenCalledWith('failed');
expect(onRemove).toHaveBeenCalledWith('failed');
});
it('emits selected files without performing validation or transport', () => {
const onSelectFiles = vi.fn();
const file = new File(['demo'], 'demo.pdf', { type: 'application/pdf' });
render(<UploadDragger files={[]} onSelectFiles={onSelectFiles} />);
fireEvent.change(screen.getByLabelText('选择上传文件'), { target: { files: [file] } });
expect(onSelectFiles).toHaveBeenCalledWith([file]);
});
it('keeps the drag active style while moving over children inside the drop zone', () => {
render(<UploadDragger files={[]} />);
const dragger = screen.getByTestId('upload-dragger');
const title = screen.getByText('点击或拖拽文件到此上传');
fireEvent.dragEnter(dragger);
expect(dragger).toHaveClass(styles.draggerActive);
fireEvent.dragEnter(title);
fireEvent.dragLeave(title);
expect(dragger).toHaveClass(styles.draggerActive);
fireEvent.dragLeave(dragger);
expect(dragger).not.toHaveClass(styles.draggerActive);
});
it('renders media wall thumbnails, video play marker, helper text, and the upload tile last', () => {
const onPreview = vi.fn();
const onSelectFiles = vi.fn();
const image = { id: 'image', type: 'image' as const, src: '/cover.png', alt: '产品图片' };
const video = { id: 'video', type: 'video' as const, src: '/video-cover.png', alt: '演示视频' };
render(
<MediaWall
items={[image, video]}
helperText="支持 JPG、PNG、MP4、MOV,图片单张不超过 10MB,视频单个不超过 500MB"
onPreview={onPreview}
onSelectFiles={onSelectFiles}
/>,
);
const wall = screen.getByTestId('media-wall-grid');
const cells = within(wall).getAllByRole('listitem');
expect(cells[0]).toHaveTextContent('产品图片');
expect(cells[1]).toHaveTextContent('演示视频');
expect(cells[2]).toHaveTextContent('图片/视频');
expect(within(cells[1]).getByLabelText('视频')).toHaveClass(styles.playBadge);
expect(screen.getByText('支持 JPG、PNG、MP4、MOV,图片单张不超过 10MB,视频单个不超过 500MB')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '预览 产品图片' }));
fireEvent.click(screen.getByRole('button', { name: '预览 演示视频' }));
expect(onPreview).toHaveBeenNthCalledWith(1, image);
expect(onPreview).toHaveBeenNthCalledWith(2, video);
});
});
...@@ -14,6 +14,8 @@ export type { FormItemProps, FormProps, FormRule, FormValues } from './component ...@@ -14,6 +14,8 @@ export type { FormItemProps, FormProps, FormRule, FormValues } from './component
export { Form, FormItem } from './components/FormItem'; export { Form, FormItem } from './components/FormItem';
export type { InputProps, SearchInputProps } from './components/Input'; export type { InputProps, SearchInputProps } from './components/Input';
export { Input, SearchInput } from './components/Input'; export { Input, SearchInput } from './components/Input';
export type { TextareaProps } from './components/Textarea';
export { Textarea } from './components/Textarea';
export type { CollapseItem, CollapseProps, EmptyProps, StepsProps, TabsItem, TabsProps } from './components/Navigation'; 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 { Collapse, Empty, Skeleton, SkeletonAvatar, SkeletonButton, SkeletonInput, SkeletonParagraph, Steps, Tabs } from './components/Navigation';
export type { PaginationProps } from './components/Pagination'; export type { PaginationProps } from './components/Pagination';
...@@ -28,3 +30,5 @@ export type { TableColumn, TableProps } from './components/Table'; ...@@ -28,3 +30,5 @@ export type { TableColumn, TableProps } from './components/Table';
export { Table } from './components/Table'; export { Table } from './components/Table';
export type { TreeSelectNode, TreeSelectProps } from './components/TreeSelect'; export type { TreeSelectNode, TreeSelectProps } from './components/TreeSelect';
export { TreeSelect } from './components/TreeSelect'; export { TreeSelect } from './components/TreeSelect';
export type { MediaWallItem, MediaWallProps, UploadDraggerProps, UploadFileItem, UploadFileStatus } from './components/Upload';
export { MediaWall, UploadDragger } from './components/Upload';
...@@ -66,3 +66,9 @@ ...@@ -66,3 +66,9 @@
.formDemo { .formDemo {
min-width: 280px; min-width: 280px;
} }
.uploadDemo {
display: grid;
gap: var(--gl-spacing-xl);
align-items: start;
}
...@@ -5,7 +5,7 @@ import { ComponentsDemoPage } from './ComponentsDemoPage'; ...@@ -5,7 +5,7 @@ import { ComponentsDemoPage } from './ComponentsDemoPage';
import uiStyles from '../../../packages/ui/src/components/Shared.module.css'; import uiStyles from '../../../packages/ui/src/components/Shared.module.css';
describe('ComponentsDemoPage', () => { describe('ComponentsDemoPage', () => {
it('shows all phase-one component groups except Upload', () => { it('shows all phase-one component groups including Upload', () => {
render(<ComponentsDemoPage />); render(<ComponentsDemoPage />);
expect(screen.getByRole('heading', { name: '组件库 Demo' })).toBeInTheDocument(); expect(screen.getByRole('heading', { name: '组件库 Demo' })).toBeInTheDocument();
...@@ -16,9 +16,13 @@ describe('ComponentsDemoPage', () => { ...@@ -16,9 +16,13 @@ describe('ComponentsDemoPage', () => {
expect(screen.getByText('数据展示')).toBeInTheDocument(); expect(screen.getByText('数据展示')).toBeInTheDocument();
expect(screen.getByText('导航与占位')).toBeInTheDocument(); expect(screen.getByText('导航与占位')).toBeInTheDocument();
expect(screen.getByText('颜色能力')).toBeInTheDocument(); expect(screen.getByText('颜色能力')).toBeInTheDocument();
expect(screen.getByText('上传')).toBeInTheDocument();
expect(screen.getByText('暂无审批记录')).toBeInTheDocument(); expect(screen.getByText('暂无审批记录')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '新建审批' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '新建审批' })).toBeInTheDocument();
expect(screen.queryByText('Upload')).not.toBeInTheDocument(); expect(screen.getByText('点击或拖拽业务资料到此上传')).toBeInTheDocument();
expect(screen.getByText('图片/视频')).toBeInTheDocument();
expect(screen.getByText('4/20')).toBeInTheDocument();
expect(screen.getByText('4/120')).toBeInTheDocument();
}); });
it('keeps basic component demos interactive for manual review', () => { it('keeps basic component demos interactive for manual review', () => {
...@@ -61,13 +65,29 @@ describe('ComponentsDemoPage', () => { ...@@ -61,13 +65,29 @@ describe('ComponentsDemoPage', () => {
expect(screen.getByRole('img', { name: '错误提示' })).toBeInTheDocument(); expect(screen.getByRole('img', { name: '错误提示' })).toBeInTheDocument();
}); });
it('closes the feedback demo Modal when clicking cancel', () => {
render(<ComponentsDemoPage />);
fireEvent.click(screen.getByRole('button', { name: '取消' }));
expect(screen.queryByRole('dialog', { name: '编辑项目' })).not.toBeInTheDocument();
});
it('closes the feedback demo Modal when clicking the close button', () => {
render(<ComponentsDemoPage />);
fireEvent.click(screen.getByRole('button', { name: '关闭编辑项目' }));
expect(screen.queryByRole('dialog', { name: '编辑项目' })).not.toBeInTheDocument();
});
it('shows Form validation and horizontal FormItem layout in the feedback demo', () => { it('shows Form validation and horizontal FormItem layout in the feedback demo', () => {
render(<ComponentsDemoPage />); render(<ComponentsDemoPage />);
fireEvent.click(screen.getByRole('button', { name: '提交表单' })); fireEvent.click(screen.getByRole('button', { name: '提交表单' }));
expect(screen.getByRole('alert', { name: '请输入项目名称' })).toBeInTheDocument(); expect(screen.getByRole('alert', { name: '请输入项目名称' })).toBeInTheDocument();
expect(screen.getByTestId('form-root')).toHaveClass(uiStyles.formColumnsTwo); expect(screen.getByTestId('form-root')).toHaveClass(uiStyles.formColumnsOne);
expect(screen.getByTestId('form-item-项目名称')).toHaveClass(uiStyles.formItemHorizontal); expect(screen.getByTestId('form-item-项目名称')).toHaveClass(uiStyles.formItemHorizontal);
expect(screen.getByTestId('form-item-所属岗位')).toHaveClass(uiStyles.formItemSpanOne); expect(screen.getByTestId('form-item-所属岗位')).toHaveClass(uiStyles.formItemSpanOne);
expect(screen.getByTestId('form-item-备注')).toHaveClass(uiStyles.formItemSpanTwo); expect(screen.getByTestId('form-item-备注')).toHaveClass(uiStyles.formItemSpanTwo);
...@@ -82,4 +102,17 @@ describe('ComponentsDemoPage', () => { ...@@ -82,4 +102,17 @@ describe('ComponentsDemoPage', () => {
expect(screen.getByLabelText('张三')).toHaveClass(uiStyles.avatarCircle, uiStyles.avatarText); expect(screen.getByLabelText('张三')).toHaveClass(uiStyles.avatarCircle, uiStyles.avatarText);
expect(screen.getByTestId('progress-root')).toHaveClass(uiStyles.progressTopRight); expect(screen.getByTestId('progress-root')).toHaveClass(uiStyles.progressTopRight);
}); });
it('shows Upload file and media wall states in the demo', () => {
render(<ComponentsDemoPage />);
expect(screen.getByText('product_design_v2.fig')).toBeInTheDocument();
expect(screen.getByText('12.40 MB · 已完成')).toBeInTheDocument();
expect(screen.getByText('需求文档.pdf')).toBeInTheDocument();
expect(screen.getByText('3.20 MB · 上传中 42%')).toBeInTheDocument();
expect(screen.getByText('素材包.zip')).toBeInTheDocument();
expect(screen.getByText('网络异常,请重试')).toBeInTheDocument();
expect(screen.getByLabelText('视频')).toBeInTheDocument();
expect(screen.getByText('支持 JPG、PNG、MP4、MOV,图片单张不超过 10MB,视频单个不超过 500MB')).toBeInTheDocument();
});
}); });
...@@ -19,6 +19,7 @@ import { ...@@ -19,6 +19,7 @@ import {
FormItem, FormItem,
Input, Input,
Message, Message,
MediaWall,
Modal, Modal,
Pagination, Pagination,
Popconfirm, Popconfirm,
...@@ -35,6 +36,8 @@ import { ...@@ -35,6 +36,8 @@ import {
Timeline, Timeline,
Tooltip, Tooltip,
TreeSelect, TreeSelect,
Textarea,
UploadDragger,
} from '../../../packages/ui/src'; } from '../../../packages/ui/src';
import { Icon } from '../../../packages/ui/src/components/Icon'; import { Icon } from '../../../packages/ui/src/components/Icon';
import styles from './ComponentsDemoPage.module.css'; import styles from './ComponentsDemoPage.module.css';
...@@ -46,6 +49,11 @@ export function ComponentsDemoPage() { ...@@ -46,6 +49,11 @@ export function ComponentsDemoPage() {
const [treeValue, setTreeValue] = useState<string | undefined>(); const [treeValue, setTreeValue] = useState<string | undefined>();
const [dateValue, setDateValue] = useState('2026-05-16'); const [dateValue, setDateValue] = useState('2026-05-16');
const [showMessage, setShowMessage] = useState(false); const [showMessage, setShowMessage] = useState(false);
const [modalOpen, setModalOpen] = useState(true);
const mediaImage =
'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';
return ( return (
<section className={styles.page}> <section className={styles.page}>
...@@ -72,7 +80,8 @@ export function ComponentsDemoPage() { ...@@ -72,7 +80,8 @@ export function ComponentsDemoPage() {
<Button disabled>禁用按钮</Button> <Button disabled>禁用按钮</Button>
<Button loading>加载中</Button> <Button loading>加载中</Button>
</div> </div>
<Input aria-label="名称" defaultValue="项目名称" allowClear /> <Input aria-label="名称" defaultValue="项目名称" allowClear showCount maxLength={20} />
<Textarea aria-label="备注" defaultValue="补充说明" showCount maxLength={120} />
<SearchInput aria-label="搜索" defaultValue="合同" /> <SearchInput aria-label="搜索" defaultValue="合同" />
<Checkbox label="Demo 启用" checked={checkboxChecked} onChange={setCheckboxChecked} /> <Checkbox label="Demo 启用" checked={checkboxChecked} onChange={setCheckboxChecked} />
<Radio label="按项目" name="demo-radio" checked value="project" /> <Radio label="按项目" name="demo-radio" checked value="project" />
...@@ -112,7 +121,7 @@ export function ComponentsDemoPage() { ...@@ -112,7 +121,7 @@ export function ComponentsDemoPage() {
<section className={styles.group}> <section className={styles.group}>
<h3>反馈与浮层</h3> <h3>反馈与浮层</h3>
<div className={styles.grid}> <div className={styles.grid}>
<Form className={styles.formDemo} columns={2} initialValues={{ projectName: '', role: '驻店销售岗', remark: '' }}> <Form className={styles.formDemo} columns={1} initialValues={{ projectName: '', role: '驻店销售岗', remark: '' }}>
<FormItem <FormItem
label="项目名称" label="项目名称"
layout="horizontal" layout="horizontal"
...@@ -130,8 +139,8 @@ export function ComponentsDemoPage() { ...@@ -130,8 +139,8 @@ export function ComponentsDemoPage() {
</FormItem> </FormItem>
<Button type="submit" variant="primary">提交表单</Button> <Button type="submit" variant="primary">提交表单</Button>
</Form> </Form>
{/* <Alert type="info" title="提示">保存后立即生效</Alert> */} <Alert type="info" title="提示">保存后立即生效</Alert>
{/* <Button variant="primary" onClick={() => setShowMessage(true)}>展示消息提示</Button> */} <Button variant="primary" onClick={() => setShowMessage(true)}>展示消息提示</Button>
{showMessage ? ( {showMessage ? (
<Message <Message
items={[ items={[
...@@ -143,7 +152,7 @@ export function ComponentsDemoPage() { ...@@ -143,7 +152,7 @@ export function ComponentsDemoPage() {
) : null} ) : null}
<Tooltip content="补充说明"><Button>帮助</Button></Tooltip> <Tooltip content="补充说明"><Button>帮助</Button></Tooltip>
<Popconfirm title="确认删除?"><Button variant="danger">删除</Button></Popconfirm> <Popconfirm title="确认删除?"><Button variant="danger">删除</Button></Popconfirm>
<Modal open={false} title="编辑项目">内容</Modal> <Modal open={modalOpen} title="编辑项目" onCancel={() => setModalOpen(false)}>内容</Modal>
<Drawer open={false} title="详情">内容</Drawer> <Drawer open={false} title="详情">内容</Drawer>
</div> </div>
</section> </section>
...@@ -174,6 +183,33 @@ export function ComponentsDemoPage() { ...@@ -174,6 +183,33 @@ export function ComponentsDemoPage() {
<ColorInput aria-label="主题色" value="#2468f2" /> <ColorInput aria-label="主题色" value="#2468f2" />
</div> </div>
</section> </section>
<section className={styles.group}>
<h3>上传</h3>
<div className={styles.uploadDemo}>
<UploadDragger
title="点击或拖拽业务资料到此上传"
helperText="支持分片断点续传,单文件上限 1GB"
files={[
{ id: 'design', name: 'product_design_v2.fig', size: 12.4 * 1024 * 1024, status: 'done', previewable: true },
{ id: 'doc', name: '需求文档.pdf', size: 3.2 * 1024 * 1024, status: 'uploading', progress: 42 },
{ id: 'zip', name: '素材包.zip', size: 18.8 * 1024 * 1024, status: 'error', errorMessage: '网络异常,请重试' },
]}
onPreview={() => undefined}
onDownload={() => undefined}
onRemove={() => undefined}
onRetry={() => undefined}
onCancel={() => undefined}
/>
<MediaWall
items={[
{ id: 'image', type: 'image', src: mediaImage, alt: '宣传图' },
{ id: 'video', type: 'video', src: mediaVideo, alt: '演示视频' },
]}
helperText="支持 JPG、PNG、MP4、MOV,图片单张不超过 10MB,视频单个不超过 500MB"
onPreview={() => undefined}
/>
</div>
</section>
</section> </section>
); );
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!