Commit 991ffa5e by 胡悦

feat: 完成agent工作区后台管理系统表格与表单标准化全量落地

主要变更包括:
- 新增并归档全量后台表格与表单标准化OpenSpec规范、设计文档与任务清单
- 修复BusinessTable分页重复显示总数问题,精简空态与失败态展示
- 为多业务列表页的长文本列添加显式Tooltip悬浮提示
- 优化BusinessForm样式与输入限制,统一表单提示颜色规则
- 迁移多批后台编辑页到BusinessForm,覆盖Agent标签、渠道码、官网职位Tab等页面
- 调整官网Agent展示配置的状态文案与排序校验,统一业务口径
- 优化vite代理配置为测试环境地址,修复消息钩子无DOM环境报错问题
- 补充大量测试用例并修复现有测试断言
- 更新架构文档与组件使用规范
1 parent d4da367b
Showing 90 changed files with 4208 additions and 965 deletions
...@@ -39,11 +39,12 @@ ...@@ -39,11 +39,12 @@
- 已通过 `openspec status --change "official-site-job-tab-ai-intro" --json` 确认 proposal、design、specs、tasks 均完成,并通过 `openspec validate "official-site-job-tab-ai-intro" --strict`。 - 已通过 `openspec status --change "official-site-job-tab-ai-intro" --json` 确认 proposal、design、specs、tasks 均完成,并通过 `openspec validate "official-site-job-tab-ai-intro" --strict`。
- 已为 `workspace/agent-admin/web` 新建 OpenSpec change `official-site-agent-display-config`,覆盖官网配置下 `/official-site/job-tabs/:tabId/agents` 的 Agent 展示配置页,不修改 `official-site-job-tab-ai-intro` artifacts,且本轮未写业务代码。 - 已为 `workspace/agent-admin/web` 新建 OpenSpec change `official-site-agent-display-config`,覆盖官网配置下 `/official-site/job-tabs/:tabId/agents` 的 Agent 展示配置页,不修改 `official-site-job-tab-ai-intro` artifacts,且本轮未写业务代码。
- 已通过 `openspec status --change "official-site-agent-display-config" --json` 确认 proposal、design、specs、tasks 均完成,并通过 `openspec validate "official-site-agent-display-config" --strict`。 - 已通过 `openspec status --change "official-site-agent-display-config" --json` 确认 proposal、design、specs、tasks 均完成,并通过 `openspec validate "official-site-agent-display-config" --strict`。
- 已完成 `official-site-agent-display-config-sort-status` 的 OpenSpec 锁定与实现,官网 Agent 展示配置编辑弹窗已将 `disable` 文案改为 `不展示`,并补齐排序下限与回归测试;已通过 `npm test -- src/routes/official-site-agent-display-config/AgentDisplayConfigEditModal.test.tsx src/routes/official-site-agent-display-config/OfficialSiteAgentDisplayConfigEdit.test.tsx`、`npm run typecheck`、`npm run build` 和 `openspec validate "official-site-agent-display-config-sort-status" --strict`。
- 2026-05-30:已执行 `standardize-admin-shell-layout` 并补充全框架前端规则:独立新增/编辑页页头左侧保留 `返回`、右侧仅保留 `保存`、不展示右侧 `取消`,页面滚动时返回/保存操作区保持可见。该规则已写入全局 `web-desktop-ui-standard`、`component-guidelines.md` 和 `frontend-conventions.md`;`agent-admin` 的 Agent、岗位标签、渠道活码、官网岗位展示新增/编辑页已按规则调整。 - 2026-05-30:已执行 `standardize-admin-shell-layout` 并补充全框架前端规则:独立新增/编辑页页头左侧保留 `返回`、右侧仅保留 `保存`、不展示右侧 `取消`,页面滚动时返回/保存操作区保持可见。该规则已写入全局 `web-desktop-ui-standard`、`component-guidelines.md` 和 `frontend-conventions.md`;`agent-admin` 的 Agent、岗位标签、渠道活码、官网岗位展示新增/编辑页已按规则调整。
## 当前重点 ## 当前重点
在编写业务代码前,持续把新的业务页行为先落到 OpenSpec。当前 `official-site-agent-display-config` 已完成 OpenSpec 锁定,等待用户确认 artifacts;不应在确认前进入实现。 在编写业务代码前,持续把新的业务页行为先落到 OpenSpec。当前 `official-site-agent-display-config-sort-status` 已完成实现与验证;后续若继续调整官网 Agent 展示配置,只能先更新受影响的 OpenSpec artifacts 再改代码。
2026-06-03:`business-form-component` 已完成仓库级基线与目录结构占位,OpenSpec tasks 1.1-1.3 已勾选;本轮不推进测试或实现,后续只在 `packages/business-components/src/business-form/` 继续落地。 2026-06-03:`business-form-component` 已完成仓库级基线与目录结构占位,OpenSpec tasks 1.1-1.3 已勾选;本轮不推进测试或实现,后续只在 `packages/business-components/src/business-form/` 继续落地。
...@@ -67,13 +68,20 @@ ...@@ -67,13 +68,20 @@
## 下一步 ## 下一步
1. 等待用户确认 `official-site-agent-display-config` OpenSpec artifacts。 1. 若继续调整官网 Agent 展示配置,先更新对应 OpenSpec change 的 artifacts 和任务。
2. 若确认进入实现阶段,先按 tasks 编写前端契约、mock fixture 与页面测试,再实现路由页面、上下文展示、列表状态映射、编辑弹窗、上传校验和保存反馈。 2. 其他后台编辑页需求继续按“先 OpenSpec、后实现、再验证”的顺序推进。
3. 实现后运行 `npm run typecheck`、`npm test`、`npm run build`,并用浏览器验证 `/official-site/job-tabs/:tabId/agents` 的布局、返回列表、停用不可编辑、上传错误和保存反馈。 3. 已完成的 `official-site-agent-display-config-sort-status` 这类小修正,后续如再变更,仍需重新锁定文档后再动代码。
## 会话记录 ## 会话记录
- 2026-06-08:按用户要求将“表格超长文案列交互”提升为全局规范,而不是仅保留在 `agent-admin` 项目实现中。已更新 `architecture-spec/openspec/changes/standardize-backoffice-business-table-usage/`:描述、概述、说明、备注、内容等可能超长的业务文案列 SHALL 通过 `BusinessTable` 显式列配置开启单行省略和 TDesign `Tooltip`,Tooltip 宽度建议 200px 并自动换行;空值、空白字符串或占位符 `-` 只展示 `-`,不展示 Tooltip;名称、编码、状态、时间、数量等短文本或结构化字段不全局开启 Tooltip。同步更新 `architecture-spec/docs/architecture/component-guidelines.md` 和 `architecture-spec/docs/decisions/0003-backoffice-business-table-standard.md`,并通过 `openspec validate standardize-backoffice-business-table-usage --strict`。
- 2026-06-08:继续 `refine-business-components-tdesign-first`,按用户最新口径修正 `BusinessTable` tooltip 策略:默认不为普通文本列启用 Tooltip,必须由页面列配置显式声明 `ellipsisTooltip: true`;派生文本或数组拼接文本可通过 `tooltipValue` 提供展示内容。已在技能列表“说明”、官网 Agent 展示配置列表“Agent 概述”、岗位标签列表“标签描述”、渠道活码列表“关联 Agent”四类业务长文本列显式开启 TDesign `Tooltip`,悬浮内容宽度 200px 且换行。已更新既有 OpenSpec change `refine-business-components-tdesign-first` 的 proposal/design/spec/tasks,并通过 `BusinessTable`/`BusinessForm` 组件测试、四个相关列表页聚焦测试、`npm run typecheck`、`npm run build` 和 `openspec validate refine-business-components-tdesign-first --strict`;按用户要求未做浏览器验证。完整 `AgentTagManagement.test.tsx` 仍有与本次 tooltip 列无关的新建/编辑页断言失败,列表路由 tooltip 测试已单独通过。
- 2026-06-08:继续 `refine-business-components-tdesign-first`,按用户确认将“表格超长文本悬浮显示”落到通用 `BusinessTable`,不是只改单个业务页面:无自定义 `cell` 的普通文本/数字/布尔列默认单行省略,并使用 TDesign `Tooltip` 展示完整内容,悬浮内容宽度 200px 且换行;自定义 `cell` 保持不被覆盖。同步将无分页 `totalLabel` 收敛为 TDesign `Typography.Text`。`BusinessForm` 的 `input`/`textarea` 在配置 `maxLength` 后改为硬限制,值会在 `onChange` 层裁剪且继续展示 TDesign 字数;已清理已迁移页面中的常规 `allowInputOverMax: true`,官网 Agent 展示配置 `speech_content` 保持 100 字但不再允许输入第 101 字。已通过 `npm test -- --run src/business-components/BusinessForm.test.tsx src/business-components/business-table.test.tsx`、官网 Agent 展示配置相关测试、`npm run typecheck`、`npm run build`、`openspec validate refine-business-components-tdesign-first --strict`;按用户要求未做浏览器验证。
- 2026-06-08:继续 `migrate-editor-pages-to-business-form-phase-three`,按用户确认保留官网 Agent 展示配置编辑弹窗 `Agent 概述` 的 100 字校验,不改为 200 字,只补充 TDesign/BusinessForm 原生字数长度展示。实现为 `speech_content` 字段配置 `maxLength: 100` 与 `allowInputOverMax: true`,保存校验仍提示“Agent概述不能超过100字”。已补充页面集成测试覆盖 `101/100` 计数和超长校验,并通过官网 Agent 展示配置编辑测试、弹窗测试、BusinessForm 测试、`npm run typecheck`、`npm run build`、`openspec validate migrate-editor-pages-to-business-form-phase-three --strict`;按用户此前要求未做浏览器验证。
- 2026-06-08:完成 `migrate-editor-pages-to-business-form-phase-three` 实施:官网 Agent 展示配置编辑弹窗字段区已迁移到 `BusinessForm`,`Dialog`/`Button` 继续使用 TDesign,图标和展示素材通过 `BusinessForm` 自定义字段保留 `MediaWall` 上传、回显、删除和错误提示;相关弹窗与页面集成测试、BusinessForm 测试、`npm run typecheck`、`npm run build`、`openspec validate migrate-editor-pages-to-business-form-phase-three --strict` 均通过。按用户要求未做浏览器验证。
- 2026-06-05:继续 `business-form-component` 的 Demo 覆盖,按用户确认在 `BusinessForm` 示例中新增多选 Select 字段 `scenarios`(展示名“适用场景”),使用 `type: 'select'`、`multiple: true`,初始值为 `['approval', 'archive']`,用于在 `/components` 中对照单选 Select 验收 `select.multiple` 配置与数组值展示。同步更新 OpenSpec demo 覆盖范围和 task 7.14;Demo 测试新增多选字段断言,并将该测试的上传交互断言收窄为已有上传态展示,避免 JSDOM 中 TDesign Upload 隐藏 input 不稳定触发干扰。已通过 `npm run typecheck`、`npm test -- src/business-components/BusinessForm.test.tsx src/routes/components/ComponentsDemoPage.test.tsx`、`openspec validate business-form-component --strict` 和 `npm run build`;OpenSpec telemetry 仍有受限网络 PostHog flush 报错但退出码为 0。 - 2026-06-05:继续 `business-form-component` 的 Demo 覆盖,按用户确认在 `BusinessForm` 示例中新增多选 Select 字段 `scenarios`(展示名“适用场景”),使用 `type: 'select'`、`multiple: true`,初始值为 `['approval', 'archive']`,用于在 `/components` 中对照单选 Select 验收 `select.multiple` 配置与数组值展示。同步更新 OpenSpec demo 覆盖范围和 task 7.14;Demo 测试新增多选字段断言,并将该测试的上传交互断言收窄为已有上传态展示,避免 JSDOM 中 TDesign Upload 隐藏 input 不稳定触发干扰。已通过 `npm run typecheck`、`npm test -- src/business-components/BusinessForm.test.tsx src/routes/components/ComponentsDemoPage.test.tsx`、`openspec validate business-form-component --strict` 和 `npm run build`;OpenSpec telemetry 仍有受限网络 PostHog flush 报错但退出码为 0。
- 2026-06-08:继续 `official-site-agent-display-config-sort-status`,按用户补充将官网 Agent 展示配置列表页的 `展示状态` 同步为 `display_status = disable -> 不展示`,内部字段类型和值仍保持 `enable | disable` 不变。已更新列表页实现、列表页测试和该 change 的 OpenSpec artifacts/tasks;通过官网 Agent 展示配置相关测试、`npm run typecheck`、`npm run build` 和 `openspec validate official-site-agent-display-config-sort-status --strict`。按用户要求未做浏览器验证。
- 2026-06-08:继续 `official-site-agent-display-config-sort-status`,按用户反馈统一 `BusinessForm` 提示颜色:`errors[field.key]` 和内置校验错误使用红色,`helpText`/`helperText` 普通提示使用浅灰色。已在原 change 更新 proposal、design、spec 和 tasks,并按 TDD 补充 `BusinessForm.test.tsx`;实现中给 TDesign `FormItem help/tips` 分别传入带 `helpText`/`error` 样式的节点。已通过 BusinessForm 与官网 Agent 展示配置相关测试、`npm run typecheck`、`npm run build` 和 `openspec validate official-site-agent-display-config-sort-status --strict`;按用户要求未做浏览器验证。
- 2026-06-05:继续 `business-form-component` 的 TDesign Upload 收敛,按 TDD 增加上传字段 `maxCount` / `multiple` 配置。默认仍为单文件;配置 `maxCount > 1` 且 `multiple: true` 时,媒体上传支持多张图片/GIF/视频,值以 `BusinessFormUploadedFileValue[]` 写回;单文件已有值重新选择仍保持替换语义。图片/GIF 继续优先使用 TDesign `Upload theme="image"` 默认卡片,含视频列表仅做最小 `fileListDisplay` 适配以展示视频缩略图;文件名仍按现有 110px 卡片下方单行省略实现。Demo 的展示素材已配置为最多 3 个。已通过 `npm run typecheck`、`npm test -- src/business-components/BusinessForm.test.tsx src/routes/components/ComponentsDemoPage.test.tsx`、`npm run build`、`openspec validate business-form-component --strict`;未做浏览器验收,按用户要求由用户自行验收。 - 2026-06-05:继续 `business-form-component` 的 TDesign Upload 收敛,按 TDD 增加上传字段 `maxCount` / `multiple` 配置。默认仍为单文件;配置 `maxCount > 1` 且 `multiple: true` 时,媒体上传支持多张图片/GIF/视频,值以 `BusinessFormUploadedFileValue[]` 写回;单文件已有值重新选择仍保持替换语义。图片/GIF 继续优先使用 TDesign `Upload theme="image"` 默认卡片,含视频列表仅做最小 `fileListDisplay` 适配以展示视频缩略图;文件名仍按现有 110px 卡片下方单行省略实现。Demo 的展示素材已配置为最多 3 个。已通过 `npm run typecheck`、`npm test -- src/business-components/BusinessForm.test.tsx src/routes/components/ComponentsDemoPage.test.tsx`、`npm run build`、`openspec validate business-form-component --strict`;未做浏览器验收,按用户要求由用户自行验收。
- 2026-06-03:继续 `fix-business-table-duplicate-total`,用户确认后台列表首次加载使用骨架屏、后续分页/搜索/筛选/排序/刷新使用表格区域 loading。已把该规则写入全局 `architecture-spec/openspec/specs/web-desktop-ui-standard/spec.md` 与 `architecture-spec/docs/architecture/frontend-conventions.md`;`BusinessTable` 默认 loadingProps 调整为轻量小尺寸指示、浅色“加载中”文案和半透明蒙层,并允许调用方覆盖。已补充 `business-table.test.tsx` loading 回归,验证 loading 时保留表头且不展示空态;通过 `rtk npm test -- business-table.test.tsx`、`rtk npm run typecheck`、`rtk openspec validate fix-business-table-duplicate-total --strict` 和全局 `rtk openspec validate --specs --strict`。 - 2026-06-03:继续 `fix-business-table-duplicate-total`,用户确认后台列表首次加载使用骨架屏、后续分页/搜索/筛选/排序/刷新使用表格区域 loading。已把该规则写入全局 `architecture-spec/openspec/specs/web-desktop-ui-standard/spec.md` 与 `architecture-spec/docs/architecture/frontend-conventions.md`;`BusinessTable` 默认 loadingProps 调整为轻量小尺寸指示、浅色“加载中”文案和半透明蒙层,并允许调用方覆盖。已补充 `business-table.test.tsx` loading 回归,验证 loading 时保留表头且不展示空态;通过 `rtk npm test -- business-table.test.tsx`、`rtk npm run typecheck`、`rtk openspec validate fix-business-table-duplicate-total --strict` 和全局 `rtk openspec validate --specs --strict`。
- 2026-06-03:继续 `fix-business-table-duplicate-total` 的失败态收尾。用户指出列表失败态下方出现无文案蓝色按钮,定位为页面仍传 `errorState.onRetry`,而 `BusinessTable.createActionButton` 只判断回调、不判断按钮文案。已补充 OpenSpec 场景“不渲染无文案的状态区按钮”,更新 `business-table.test.tsx` 断言失败态不存在任何按钮,并修正 `createActionButton` 在没有 `label` 时返回 `undefined`;保留权限态“申请权限”按钮。已通过 `rtk npm test -- business-table.test.tsx`、`rtk npm run typecheck`、`rtk openspec validate fix-business-table-duplicate-total --strict`。 - 2026-06-03:继续 `fix-business-table-duplicate-total` 的失败态收尾。用户指出列表失败态下方出现无文案蓝色按钮,定位为页面仍传 `errorState.onRetry`,而 `BusinessTable.createActionButton` 只判断回调、不判断按钮文案。已补充 OpenSpec 场景“不渲染无文案的状态区按钮”,更新 `business-table.test.tsx` 断言失败态不存在任何按钮,并修正 `createActionButton` 在没有 `label` 时返回 `undefined`;保留权限态“申请权限”按钮。已通过 `rtk npm test -- business-table.test.tsx`、`rtk npm run typecheck`、`rtk openspec validate fix-business-table-duplicate-total --strict`。
...@@ -109,3 +117,12 @@ ...@@ -109,3 +117,12 @@
- 2026-06-01:按用户限定范围仅完成 `migrate-admin-ui-to-global-tdesign` 的 7.6,未推进 7.7。已通过 `openspec validate "migrate-admin-ui-to-global-tdesign" --strict`;命令退出码为 0,末尾仅出现 PostHog telemetry flush 网络超时提示,不影响 OpenSpec 校验结果;已只勾选 tasks 中的 7.6。 - 2026-06-01:按用户限定范围仅完成 `migrate-admin-ui-to-global-tdesign` 的 7.6,未推进 7.7。已通过 `openspec validate "migrate-admin-ui-to-global-tdesign" --strict`;命令退出码为 0,末尾仅出现 PostHog telemetry flush 网络超时提示,不影响 OpenSpec 校验结果;已只勾选 tasks 中的 7.6。
- 2026-06-01:按用户限定范围完成 `migrate-admin-ui-to-global-tdesign` 的 7.7。用 Playwright 浏览器验证主要列表页 `/agents`、`/agent-tags`、`/channel-codes`、`/skills`、`/official-site/job-tabs`,编辑页 `/agents/new`、`/agent-tags/new`、`/channel-codes/new`、`/official-site/job-tabs/new`、`/official-site/methodology`,官网 Agent 展示配置弹窗 `/official-site/job-tabs/301/agents`,以及 `/components` 的布局与关键交互。验证中发现并修复 TDesign `DateRangePicker` 空 range 值 console error:全局 `SearchFilter` 对空 range 传 `[]`,组件 Demo 的 `DateRangePicker` 改为受控空数组;已通过相关测试、`npm run typecheck`、`npm run build` 和完整浏览器复验,已只勾选 tasks 中的 7.7。 - 2026-06-01:按用户限定范围完成 `migrate-admin-ui-to-global-tdesign` 的 7.7。用 Playwright 浏览器验证主要列表页 `/agents`、`/agent-tags`、`/channel-codes`、`/skills`、`/official-site/job-tabs`,编辑页 `/agents/new`、`/agent-tags/new`、`/channel-codes/new`、`/official-site/job-tabs/new`、`/official-site/methodology`,官网 Agent 展示配置弹窗 `/official-site/job-tabs/301/agents`,以及 `/components` 的布局与关键交互。验证中发现并修复 TDesign `DateRangePicker` 空 range 值 console error:全局 `SearchFilter` 对空 range 传 `[]`,组件 Demo 的 `DateRangePicker` 改为受控空数组;已通过相关测试、`npm run typecheck`、`npm run build` 和完整浏览器复验,已只勾选 tasks 中的 7.7。
- 2026-06-01:继续 `extract-business-table-component` 的 3.1,仅迁移 `AgentListPage` 到 `BusinessTable`。页面现在用业务表格承接表格、筛选空态、加载失败态和分页,保留原有搜索和操作逻辑;同步把该页测试改成匹配新组件输出,去掉重复总数展示并按实际 DOM 断言失败态标题与重试按钮。已通过 `npm test -- src/routes/agents/AgentListPage.test.tsx` 和 `npm run typecheck`,已只勾选 tasks 中的 3.1。 - 2026-06-01:继续 `extract-business-table-component` 的 3.1,仅迁移 `AgentListPage` 到 `BusinessTable`。页面现在用业务表格承接表格、筛选空态、加载失败态和分页,保留原有搜索和操作逻辑;同步把该页测试改成匹配新组件输出,去掉重复总数展示并按实际 DOM 断言失败态标题与重试按钮。已通过 `npm test -- src/routes/agents/AgentListPage.test.tsx` 和 `npm run typecheck`,已只勾选 tasks 中的 3.1。
- 2026-06-08:继续 `refine-business-components-tdesign-first`,按用户反馈修正 `BusinessTable` 显式 tooltip 列的空内容行为:空字符串、空白字符串、`null`/`undefined` 和最终展示占位 `-` 的内容只显示 `-`,不渲染 TDesign `Tooltip`,避免空描述列出现无意义悬浮层;真实非空文本仍使用 `cellText` 单行省略和 200px 换行 Tooltip。已补充 OpenSpec business-table 场景、design 决策和 tasks,并完成实现与测试。验证通过 `npm test -- --run src/business-components/business-table.test.tsx`、`npm run typecheck`、`npm run build`、`openspec validate refine-business-components-tdesign-first --strict`;OpenSpec telemetry 仍因受限网络出现 PostHog flush 警告但退出码为 0,按用户要求未做浏览器验证。
- 2026-06-08:已核对并归档 `migrate-editor-pages-to-business-form-phase-three`。相关 `AgentDisplayConfigEditModal` / `OfficialSiteAgentDisplayConfigEdit` / `BusinessForm` 测试通过,`npm run typecheck`、`npm run build` 和 `openspec validate migrate-editor-pages-to-business-form-phase-three --strict` 均通过;OpenSpec archive 生成 `2026-06-08-migrate-editor-pages-to-business-form-phase-three`,并顺带更新了 `editor-page-form-composition` 规范。
- 2026-06-08:已核对并归档 `migrate-admin-ui-to-global-tdesign`。`workspace/agent-admin/web/src` 的运行时 import 守卫测试通过,`npm run typecheck` 通过,`openspec validate "migrate-admin-ui-to-global-tdesign" --strict` 通过;OpenSpec archive 生成 `2026-06-08-migrate-admin-ui-to-global-tdesign`,并更新了 `admin-ui-runtime-dependency` 规范。
- 2026-06-08:已核对并归档 `fix-business-table-duplicate-total`。`BusinessTable`、相关页面测试和 `business-table` 规范已对齐,`npm test -- --run src/business-components/business-table.test.tsx src/routes/components/ComponentsDemoPage.test.tsx src/routes/skills/SkillListPage.test.tsx src/routes/channel-codes/ChannelCodeListPage.test.tsx src/routes/agents/AgentListPage.test.tsx src/routes/agent-tags/AgentTagListPage.test.tsx src/routes/official-site-job-tabs/OfficialSiteJobTabListPage.test.tsx`、`npm run typecheck`、`openspec validate fix-business-table-duplicate-total --strict` 均通过;OpenSpec archive 生成 `2026-06-08-fix-business-table-duplicate-total`,并同步更新了 `business-table` 规范。
- 2026-06-08:已核对并归档 `align-components-demo-business-table-states`。`ComponentsDemoPage` 的表格状态示例已迁移为 `BusinessTable` 真实渲染,`ComponentsDemoPage.test.tsx` 覆盖了新旧文案与按钮差异;OpenSpec archive 生成 `2026-06-08-align-components-demo-business-table-states`,并同步更新了 `components-demo` 规范。
- 2026-06-08:按用户确认纠正 `official-site-agent-display-config-sort-status` 的文档归属:将误放在仓库根目录 `openspec/changes/` 的 active change 迁回 `workspace/agent-admin/web/openspec/changes/`,并将对应 Superpowers 设计文档从根目录 `docs/superpowers/specs/` 迁到 `workspace/agent-admin/web/docs/superpowers/specs/`。已在 `workspace/agent-admin/web` 下通过 `openspec validate official-site-agent-display-config-sort-status --strict`;当前 change 仍为 active,后续归档前需先处理/确认 tasks 2.5-2.8。
- 2026-06-08:复核 `official-site-agent-display-config-sort-status` 中官网 Agent 展示配置编辑弹窗颜色问题:当前 `AgentDisplayConfigEditModal` 字段区已迁移到 `BusinessForm`,不再直接维护 TDesign `FormItem` 的 `help/tips` 渲染,错误红色与普通说明浅灰色由 `BusinessForm` 统一保证。已更新该 change 的 proposal/design/spec/tasks,移除“弹窗直接 TDesign FormItem 需单独修复”的过时假设;通过 `npm test -- --run src/routes/official-site-agent-display-config/AgentDisplayConfigEditModal.test.tsx src/business-components/BusinessForm.test.tsx`、`npm run typecheck`、`npm run build`、`openspec validate official-site-agent-display-config-sort-status --strict`,`openspec status --change official-site-agent-display-config-sort-status --json` 显示 complete。
- 2026-06-08:已归档 `official-site-agent-display-config-sort-status`。归档前在 `workspace/agent-admin/web` 下确认 `openspec validate official-site-agent-display-config-sort-status --strict` 通过且 `openspec status --change official-site-agent-display-config-sort-status --json` 为 complete;`openspec archive official-site-agent-display-config-sort-status` 生成 `openspec/changes/archive/2026-06-08-official-site-agent-display-config-sort-status`,并创建项目级规范 `openspec/specs/official-site-agent-display-config-sort-status/spec.md`。归档后单独校验该 spec 通过;全量 `openspec validate --specs --strict` 仍有既有 `agent-tags-management` 与 `official-site-methodology-config` 失败,和本次归档 spec 无关。
- 2026-06-08:已归档工作区级规范 `standardize-backoffice-business-table-usage`。该 change 位于 `architecture-spec/openspec/changes/`,归档前确认 `openspec status --change standardize-backoffice-business-table-usage --json` 为 complete,且 `openspec validate standardize-backoffice-business-table-usage --strict` 通过;`openspec archive standardize-backoffice-business-table-usage` 生成 `openspec/changes/archive/2026-06-08-standardize-backoffice-business-table-usage`,并将后台表格默认使用 `BusinessTable`、长文案列显式 Tooltip 等规则合入 `openspec/specs/web-desktop-ui-standard/spec.md`。归档后 `openspec validate web-desktop-ui-standard --strict` 通过;OpenSpec telemetry 的 PostHog flush DNS 警告不影响退出码。
...@@ -120,6 +120,10 @@ ...@@ -120,6 +120,10 @@
`StatePlaceholder` 仅用于非表格区域的通用占位,例如页面级异常、卡片级缺省内容、引导区或其他不依赖表格结构的状态展示。若某个后台表格需要特殊状态或特殊动作,应优先扩展 `BusinessTable` 的受控配置,并通过 OpenSpec 更新规范,不在页面内临时拼装一套表格状态。 `StatePlaceholder` 仅用于非表格区域的通用占位,例如页面级异常、卡片级缺省内容、引导区或其他不依赖表格结构的状态展示。若某个后台表格需要特殊状态或特殊动作,应优先扩展 `BusinessTable` 的受控配置,并通过 OpenSpec 更新规范,不在页面内临时拼装一套表格状态。
描述、概述、说明、备注、内容等可能超长的业务文案列 SHALL 使用 `BusinessTable` 的受控列配置开启单行省略,并使用 TDesign `Tooltip` 在鼠标悬浮时展示完整内容。Tooltip 内容区域宽度 SHOULD 为 `200px`,内容自动换行。空值、空白字符串或占位符 `-` 只展示 `-`,不展示 Tooltip。
名称、编码、状态、时间、数量等短文本或结构化字段 SHOULD 保持默认文本展示,不为所有列全局开启 Tooltip。项目应按字段语义为可能超长文案列显式开启 Tooltip。
后台列表页 SHALL 以 `content` 列表页作为固定参考模式,统一采用以下结构: 后台列表页 SHALL 以 `content` 列表页作为固定参考模式,统一采用以下结构:
1. 页面标题区:展示页面标题、必要说明和主创建动作,主创建按钮放在右侧。 1. 页面标题区:展示页面标题、必要说明和主创建动作,主创建按钮放在右侧。
......
...@@ -17,12 +17,16 @@ ...@@ -17,12 +17,16 @@
- `BusinessTable` SHALL 承接后台表格本体、普通空态、筛选无结果、请求失败、权限受限、加载中和分页总数展示。 - `BusinessTable` SHALL 承接后台表格本体、普通空态、筛选无结果、请求失败、权限受限、加载中和分页总数展示。
- 页面仍 SHALL 负责搜索条件、请求参数、数据映射、业务弹窗、权限判断、行操作回调和埋点等业务逻辑。 - 页面仍 SHALL 负责搜索条件、请求参数、数据映射、业务弹窗、权限判断、行操作回调和埋点等业务逻辑。
- `StatePlaceholder` SHALL 仅用于非表格区域的通用占位,例如页面级异常、卡片级缺省内容、引导区或其他不依赖表格结构的状态展示。 - `StatePlaceholder` SHALL 仅用于非表格区域的通用占位,例如页面级异常、卡片级缺省内容、引导区或其他不依赖表格结构的状态展示。
- 当表格列展示描述、概述、说明、备注、内容等可能超长的业务文案时,项目 SHALL 使用 `BusinessTable` 的受控列配置开启单行省略,并使用 TDesign `Tooltip` 在鼠标悬浮时展示完整内容。
- Tooltip 内容区域宽度 SHOULD 为 `200px`,并支持自动换行;空值、空白字符串或占位符 `-` SHALL 只展示 `-`,不展示 Tooltip。
- 名称、编码、状态、时间、数量等短文本或结构化字段 SHOULD 保持默认文本展示,不为所有列全局开启 Tooltip。
- 如果后台表格需要特殊状态或特殊动作,项目 SHALL 优先扩展 `BusinessTable` 的受控配置,并同步更新工作区级规范和对应 OpenSpec,不在页面内临时拼装一套表格状态。 - 如果后台表格需要特殊状态或特殊动作,项目 SHALL 优先扩展 `BusinessTable` 的受控配置,并同步更新工作区级规范和对应 OpenSpec,不在页面内临时拼装一套表格状态。
- 历史页面若尚未使用 `BusinessTable`,SHOULD 通过独立 OpenSpec change 分批迁移,避免无规格的大范围重构。 - 历史页面若尚未使用 `BusinessTable`,SHOULD 通过独立 OpenSpec change 分批迁移,避免无规格的大范围重构。
## 影响 ## 影响
- `architecture-spec/docs/architecture/component-guidelines.md` 的表格使用规则需要明确 `BusinessTable` 是后台管理系统表格默认入口。 - `architecture-spec/docs/architecture/component-guidelines.md` 的表格使用规则需要明确 `BusinessTable` 是后台管理系统表格默认入口。
- 具体项目的表格列如展示超长文案,应继承省略和 TDesign Tooltip 的统一交互,而不是在页面内自定义悬浮层或默认给所有列加 Tooltip。
- 具体项目的 OpenSpec 如涉及后台表格、列表页或组件 demo,应继承该工作区级约束。 - 具体项目的 OpenSpec 如涉及后台表格、列表页或组件 demo,应继承该工作区级约束。
- `workspace/agent-admin/web` 的组件 demo 需要调整为通过 `BusinessTable` 展示表格状态,而不是在 `StatePlaceholder` demo 中展示表格状态集合。 - `workspace/agent-admin/web` 的组件 demo 需要调整为通过 `BusinessTable` 展示表格状态,而不是在 `StatePlaceholder` demo 中展示表格状态集合。
......
...@@ -24,6 +24,9 @@ ...@@ -24,6 +24,9 @@
- 替代方案:只写在 `agent-admin/web` 项目规范中。该方案无法覆盖 `agent` 下其他后台管理系统。 - 替代方案:只写在 `agent-admin/web` 项目规范中。该方案无法覆盖 `agent` 下其他后台管理系统。
- 页面不得直接拼装后台表格模式。 - 页面不得直接拼装后台表格模式。
- 原因:表格状态和分页规则应由 `BusinessTable` 统一承接,页面只负责业务数据和交互。 - 原因:表格状态和分页规则应由 `BusinessTable` 统一承接,页面只负责业务数据和交互。
- 表格超长文案列使用显式列配置开启省略和 TDesign Tooltip。
- 原因:描述、概述、说明、备注、内容等长文本字段需要保持列表可扫读,同时允许用户查看完整内容;但名称、编码、状态、时间、数量等短文本字段不应被全局 Tooltip 干扰。
- 交互:单元格单行省略,悬浮后用 TDesign `Tooltip` 展示完整内容;Tooltip 宽度建议为 `200px`,内容自动换行;空值、空白字符串和占位符 `-` 只展示 `-`,不展示 Tooltip。
- 历史迁移分批处理。 - 历史迁移分批处理。
- 原因:一次性迁移所有历史页面风险较高,且本次需求重点是锁定后续默认约束和 demo 展示。 - 原因:一次性迁移所有历史页面风险较高,且本次需求重点是锁定后续默认约束和 demo 展示。
...@@ -39,4 +42,5 @@ ...@@ -39,4 +42,5 @@
1. 写入工作区级 OpenSpec delta。 1. 写入工作区级 OpenSpec delta。
2. 校验 `standardize-backoffice-business-table-usage`。 2. 校验 `standardize-backoffice-business-table-usage`。
3. 后续项目或页面涉及后台表格时,按该规范默认使用 `BusinessTable`。 3. 后续项目或页面涉及后台表格时,按该规范默认使用 `BusinessTable`。
4. 既有页面如需迁移,另起 OpenSpec change。 4. 后续项目或页面涉及超长文案列时,按字段语义显式开启省略和 TDesign Tooltip。
5. 既有页面如需迁移,另起 OpenSpec change。
...@@ -22,6 +22,21 @@ ...@@ -22,6 +22,21 @@
- **THEN** 页面 SHALL 负责搜索条件、请求参数、数据映射、业务弹窗、权限判断、行操作回调和埋点 - **THEN** 页面 SHALL 负责搜索条件、请求参数、数据映射、业务弹窗、权限判断、行操作回调和埋点
- **AND** `BusinessTable` SHALL 负责表格结构、状态展示和分页总数展示 - **AND** `BusinessTable` SHALL 负责表格结构、状态展示和分页总数展示
#### Scenario: 超长文案列展示
- **WHEN** 任一后台管理系统前端项目的表格列展示描述、概述、说明、备注、内容或其他可能超长的业务文案
- **THEN** 该列 SHALL 使用 `BusinessTable` 的受控列配置开启单行省略展示
- **AND** 该列 SHALL 使用 TDesign `Tooltip` 在鼠标悬浮时展示完整内容
- **AND** Tooltip 内容区域宽度 SHOULD 为 `200px`,并支持自动换行
- **AND** 空值、空白字符串或占位符 `-` SHALL 只展示 `-`,不展示 Tooltip
#### Scenario: 普通短文本列展示
- **WHEN** 表格列展示名称、编码、状态、时间、数量或其他短文本/结构化字段
- **THEN** 该列 SHOULD 保持默认文本展示
- **AND** 页面 SHOULD NOT 为所有列全局开启 Tooltip
- **AND** 项目 SHALL 按字段语义为可能超长文案列显式开启 Tooltip
#### Scenario: 非表格占位 #### Scenario: 非表格占位
- **WHEN** 页面展示页面级异常、卡片级缺省内容、引导区或其他不依赖表格结构的通用占位 - **WHEN** 页面展示页面级异常、卡片级缺省内容、引导区或其他不依赖表格结构的通用占位
......
...@@ -4,13 +4,16 @@ ...@@ -4,13 +4,16 @@
- [x] 1.2 创建设计说明,明确约束范围覆盖 `agent` 下所有后台管理系统前端项目 - [x] 1.2 创建设计说明,明确约束范围覆盖 `agent` 下所有后台管理系统前端项目
- [x] 1.3 创建 `web-desktop-ui-standard` spec delta,写入后台表格默认使用 `BusinessTable` 的要求 - [x] 1.3 创建 `web-desktop-ui-standard` spec delta,写入后台表格默认使用 `BusinessTable` 的要求
- [x] 1.4 等待用户确认 OpenSpec 后进入具体项目 TDD - [x] 1.4 等待用户确认 OpenSpec 后进入具体项目 TDD
- [x] 1.5 补充跨项目表格超长文案列省略和 TDesign Tooltip 交互规范
## 2. 文档同步 ## 2. 文档同步
- [x] 2.1 在架构决策中记录后台管理系统统一使用 `BusinessTable` - [x] 2.1 在架构决策中记录后台管理系统统一使用 `BusinessTable`
- [x] 2.2 在组件使用规范中记录后台表格默认入口和 `StatePlaceholder` 边界 - [x] 2.2 在组件使用规范中记录后台表格默认入口和 `StatePlaceholder` 边界
- [x] 2.3 在组件使用规范和架构决策中记录超长文案列 Tooltip 规则
## 3. 验证 ## 3. 验证
- [x] 3.1 运行 `rtk openspec validate standardize-backoffice-business-table-usage --strict` - [x] 3.1 运行 `rtk openspec validate standardize-backoffice-business-table-usage --strict`
- [x] 3.2 在项目侧 demo OpenSpec 和实现中继承该约束 - [x] 3.2 在项目侧 demo OpenSpec 和实现中继承该约束
- [x] 3.3 重新运行 `rtk openspec validate standardize-backoffice-business-table-usage --strict`
...@@ -79,3 +79,59 @@ ...@@ -79,3 +79,59 @@
- **WHEN** 用户滚动独立页面中的表单或配置内容 - **WHEN** 用户滚动独立页面中的表单或配置内容
- **THEN** `返回` 和 `保存` 所在页头操作区保持在屏幕可见区域 - **THEN** `返回` 和 `保存` 所在页头操作区保持在屏幕可见区域
- **AND** sticky 页头具备不透明背景、边框和合理层级,避免内容滚动时穿透或覆盖页头 - **AND** sticky 页头具备不透明背景、边框和合理层级,避免内容滚动时穿透或覆盖页头
### Requirement: 后台管理系统表格必须默认使用 BusinessTable
`agent` 工作区下所有后台管理系统前端项目 SHALL 默认使用 `@gl/business-components` 的 `BusinessTable` 渲染后台列表表格,并由 `BusinessTable` 统一承接表格本体、普通空态、筛选无结果、请求失败、权限受限、加载中和分页总数展示。
#### Scenario: 新建后台列表页
- **WHEN** `agent` 工作区任一后台管理系统前端项目新增包含后台列表表格的页面
- **THEN** 页面 SHALL 使用 `BusinessTable` 渲染表格区域
- **AND** 页面 SHALL NOT 直接组合 TDesign `Table`、TDesign `Pagination`、TDesign `Empty`、`StatePlaceholder` 和按钮来替代 `BusinessTable` 的后台表格模式
#### Scenario: 新增 demo 或表格功能
- **WHEN** 后台管理系统项目新增组件 demo、业务模块或表格相关功能
- **THEN** 表格状态示例和表格运行态 SHALL 通过 `BusinessTable` 展示
- **AND** 系统 SHALL NOT 在页面内临时拼装另一套表格空态、失败态、权限态、loading 或分页总数展示规则
#### Scenario: 页面处理业务逻辑
- **WHEN** 页面使用 `BusinessTable` 渲染后台列表表格
- **THEN** 页面 SHALL 负责搜索条件、请求参数、数据映射、业务弹窗、权限判断、行操作回调和埋点
- **AND** `BusinessTable` SHALL 负责表格结构、状态展示和分页总数展示
#### Scenario: 超长文案列展示
- **WHEN** 任一后台管理系统前端项目的表格列展示描述、概述、说明、备注、内容或其他可能超长的业务文案
- **THEN** 该列 SHALL 使用 `BusinessTable` 的受控列配置开启单行省略展示
- **AND** 该列 SHALL 使用 TDesign `Tooltip` 在鼠标悬浮时展示完整内容
- **AND** Tooltip 内容区域宽度 SHOULD 为 `200px`,并支持自动换行
- **AND** 空值、空白字符串或占位符 `-` SHALL 只展示 `-`,不展示 Tooltip
#### Scenario: 普通短文本列展示
- **WHEN** 表格列展示名称、编码、状态、时间、数量或其他短文本/结构化字段
- **THEN** 该列 SHOULD 保持默认文本展示
- **AND** 页面 SHOULD NOT 为所有列全局开启 Tooltip
- **AND** 项目 SHALL 按字段语义为可能超长文案列显式开启 Tooltip
#### Scenario: 非表格占位
- **WHEN** 页面展示页面级异常、卡片级缺省内容、引导区或其他不依赖表格结构的通用占位
- **THEN** 页面 MAY 使用 `StatePlaceholder`
- **AND** 页面 SHALL NOT 使用 `StatePlaceholder` 替代后台表格状态区域
#### Scenario: 特殊表格例外
- **WHEN** 后台表格场景无法由当前 `BusinessTable` 承载
- **THEN** 项目 MUST 先通过 OpenSpec 说明例外原因、替代方案、状态规则和验证方式
- **AND** 项目 SHALL 优先评估扩展 `BusinessTable` 的受控配置
#### Scenario: 历史页面迁移
- **WHEN** 历史后台页面尚未使用 `BusinessTable`
- **THEN** 项目 SHOULD 通过独立 OpenSpec change 分批迁移
- **AND** 新页面、新 demo 和新增表格功能 SHALL NOT 继续扩散页面级自组装表格模式
.root { .root {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: 16px;
} }
.field { .field {
display: grid; min-width: 0;
grid-template-columns: 120px minmax(0, 1fr); }
column-gap: 16px;
align-items: start; .formItem {
margin-bottom: 0;
} }
.label { .label {
...@@ -29,12 +29,23 @@ ...@@ -29,12 +29,23 @@
} }
.controlHolder { .controlHolder {
width: 100%;
min-width: 0; min-width: 0;
} }
.controlHolder :global(.t-input),
.controlHolder :global(.t-input-number),
.controlHolder :global(.t-select),
.controlHolder :global(.t-textarea),
.controlHolder :global(.t-input__wrap),
.controlHolder :global(.t-select__wrap),
.controlHolder :global(.t-textarea__wrap) {
width: 100%;
}
.helpText { .helpText {
margin-top: 6px; margin-top: 6px;
color: #666; color: #a6a6a6;
font-size: 12px; font-size: 12px;
line-height: 1.5; line-height: 1.5;
} }
...@@ -50,6 +61,7 @@ ...@@ -50,6 +61,7 @@
display: inline-flex; display: inline-flex;
min-height: 32px; min-height: 32px;
align-items: center; align-items: center;
gap: 12px;
color: #1f1f1f; color: #1f1f1f;
} }
...@@ -108,6 +120,11 @@ ...@@ -108,6 +120,11 @@
display: inline-flex; display: inline-flex;
flex-direction: column; flex-direction: column;
gap: 8px; gap: 8px;
width: 160px;
max-width: 100%;
}
.uploadPreviewName {
max-width: 100%; max-width: 100%;
} }
......
import { useEffect, useMemo, useRef, useState } from 'react'; import { useEffect, useMemo, useRef, useState } from 'react';
import type { ReactNode } from 'react'; import type { CSSProperties, ReactNode } from 'react';
import { Button, InputNumber, Upload } from 'tdesign-react'; import { Button, Form, Image, Link, Typography, Upload } from 'tdesign-react';
import type { TdUploadProps, UploadFile } from 'tdesign-react'; import type { TdUploadProps, UploadFile } from 'tdesign-react';
import { BrowseIcon, DeleteIcon } from 'tdesign-icons-react'; import { BrowseIcon, DeleteIcon } from 'tdesign-icons-react';
...@@ -8,6 +8,12 @@ import { classNames } from '../shared/classNames'; ...@@ -8,6 +8,12 @@ import { classNames } from '../shared/classNames';
import { Input, Select, Switch, Textarea } from '../shared/TDesignAccessibleControls'; import { Input, Select, Switch, Textarea } from '../shared/TDesignAccessibleControls';
import styles from './BusinessForm.module.css'; import styles from './BusinessForm.module.css';
const { FormItem } = Form;
const { Text } = Typography;
const BUSINESS_FORM_ROW_GAP = '40px';
const BUSINESS_FORM_HELP_TEXT_COLOR = '#a6a6a6';
const BUSINESS_FORM_ERROR_TEXT_COLOR = '#d94841';
export type BusinessFormValue = export type BusinessFormValue =
| string | string
| number | number
...@@ -209,10 +215,59 @@ function resolveVisible( ...@@ -209,10 +215,59 @@ function resolveVisible(
} }
function formatFieldWidth(fieldWidth: number | string | undefined) { function formatFieldWidth(fieldWidth: number | string | undefined) {
if (fieldWidth === undefined) return '360px'; if (fieldWidth === undefined) return '360';
return typeof fieldWidth === 'number' ? `${fieldWidth}` : fieldWidth; return typeof fieldWidth === 'number' ? `${fieldWidth}` : fieldWidth;
} }
interface FieldWidthLayout {
dataWidth: string;
holderClassName?: string;
holderStyle?: CSSProperties;
controlStyle?: CSSProperties;
}
function resolveFieldWidthLayout(fieldWidth: number | string | undefined): FieldWidthLayout {
const dataWidth = formatFieldWidth(fieldWidth);
if (fieldWidth === undefined) {
return {
dataWidth,
holderStyle: { width: '100%', maxWidth: '360px' },
controlStyle: { width: '100%' },
};
}
if (typeof fieldWidth === 'number') {
return {
dataWidth,
holderStyle: { width: '100%', maxWidth: `${fieldWidth}px` },
controlStyle: { width: '100%' },
};
}
const trimmed = fieldWidth.trim();
const isCssLength =
/^(\d+(\.\d+)?(px|r?em|%|vw|vh|vmin|vmax|ch|ex|rem|cm|mm|in|pt|pc)|0)$/.test(trimmed) ||
trimmed.startsWith('calc(') ||
trimmed.startsWith('min(') ||
trimmed.startsWith('max(') ||
trimmed.startsWith('clamp(');
if (isCssLength) {
return {
dataWidth,
holderStyle: { width: '100%', maxWidth: trimmed },
controlStyle: { width: '100%' },
};
}
return {
dataWidth,
holderClassName: trimmed,
controlStyle: { width: '100%' },
};
}
function normalizeValue(value: BusinessFormValue) { function normalizeValue(value: BusinessFormValue) {
if (value === undefined || value === null) return ''; if (value === undefined || value === null) return '';
if (typeof value === 'string' || typeof value === 'number') return value; if (typeof value === 'string' || typeof value === 'number') return value;
...@@ -226,6 +281,11 @@ function stringifyValue(value: BusinessFormValue) { ...@@ -226,6 +281,11 @@ function stringifyValue(value: BusinessFormValue) {
return ''; return '';
} }
function capTextValue(field: BusinessFormInputField | BusinessFormTextareaField, value: string) {
if (typeof field.maxLength !== 'number' || field.maxLength < 0) return value;
return value.slice(0, field.maxLength);
}
function inferUploadKind(value: BusinessFormValue): BusinessFormUploadKind | undefined { function inferUploadKind(value: BusinessFormValue): BusinessFormUploadKind | undefined {
if (!value) return undefined; if (!value) return undefined;
if (typeof value === 'object' && 'kind' in value && value.kind) return value.kind; if (typeof value === 'object' && 'kind' in value && value.kind) return value.kind;
...@@ -401,6 +461,7 @@ function formatUploadError(reason: 'invalid-kind' | 'invalid-accept' | 'invalid- ...@@ -401,6 +461,7 @@ function formatUploadError(reason: 'invalid-kind' | 'invalid-accept' | 'invalid-
function resolveTextValue(value: BusinessFormValue) { function resolveTextValue(value: BusinessFormValue) {
if (value === undefined || value === null) return '-'; if (value === undefined || value === null) return '-';
if (Array.isArray(value)) return value.length > 0 ? value.join('、') : '-';
if (typeof value === 'boolean') return value ? '是' : '否'; if (typeof value === 'boolean') return value ? '是' : '否';
if (typeof value === 'object' && value && 'url' in value) { if (typeof value === 'object' && value && 'url' in value) {
return (value as BusinessFormUploadedFileValue).name ?? (value as BusinessFormUploadedFileValue).url; return (value as BusinessFormUploadedFileValue).name ?? (value as BusinessFormUploadedFileValue).url;
...@@ -408,6 +469,21 @@ function resolveTextValue(value: BusinessFormValue) { ...@@ -408,6 +469,21 @@ function resolveTextValue(value: BusinessFormValue) {
return String(value); return String(value);
} }
function renderSelectReadonlyValue(field: BusinessFormSelectField, value: BusinessFormValue): ReactNode {
const selectedValues = field.multiple ? (Array.isArray(value) ? value : []) : [value];
const labels = field.options
.filter((option) => selectedValues.includes(option.value))
.map((option) => option.label);
if (labels.length === 0) return resolveTextValue(value);
if (labels.length === 1) return labels[0];
return labels.reduce<ReactNode[]>((nodes, label, index) => {
if (index > 0) nodes.push('、');
nodes.push(label);
return nodes;
}, []);
}
function resolveUploadPreview(uploadedValues: BusinessFormUploadedFileValue[]) { function resolveUploadPreview(uploadedValues: BusinessFormUploadedFileValue[]) {
if (uploadedValues.length === 0) return null; if (uploadedValues.length === 0) return null;
...@@ -416,8 +492,10 @@ function resolveUploadPreview(uploadedValues: BusinessFormUploadedFileValue[]) { ...@@ -416,8 +492,10 @@ function resolveUploadPreview(uploadedValues: BusinessFormUploadedFileValue[]) {
if (kind === 'image' || kind === 'gif') { if (kind === 'image' || kind === 'gif') {
return ( return (
<div className={styles.uploadPreview} key={uploaded.url}> <div className={styles.uploadPreview} key={uploaded.url}>
<img className={styles.uploadImage} src={uploaded.url} alt={uploaded.name ?? uploaded.url} /> <Image className={styles.uploadImage} src={uploaded.url} alt={uploaded.name ?? uploaded.url} fit="cover" />
<span>{uploaded.name ?? uploaded.url}</span> <Text className={styles.uploadPreviewName} ellipsis>
{uploaded.name ?? uploaded.url}
</Text>
</div> </div>
); );
} }
...@@ -432,13 +510,23 @@ function resolveUploadPreview(uploadedValues: BusinessFormUploadedFileValue[]) { ...@@ -432,13 +510,23 @@ function resolveUploadPreview(uploadedValues: BusinessFormUploadedFileValue[]) {
playsInline playsInline
preload="metadata" preload="metadata"
/> />
<span>{uploaded.name ?? uploaded.url}</span> <Text className={styles.uploadPreviewName} ellipsis>
{uploaded.name ?? uploaded.url}
</Text>
</div> </div>
); );
} }
return ( return (
<div className={styles.uploadPreview} key={uploaded.url}> <div className={styles.uploadPreview} key={uploaded.url}>
<span>{uploaded.name ?? uploaded.url}</span> {uploaded.url ? (
<Link className={styles.uploadPreviewName} href={uploaded.url} target="_blank" {...({ rel: 'noreferrer' } as any)}>
{uploaded.name ?? uploaded.url}
</Link>
) : (
<Text className={styles.uploadPreviewName} ellipsis>
{uploaded.name ?? uploaded.url}
</Text>
)}
</div> </div>
); );
}); });
...@@ -454,10 +542,6 @@ function buildUploadFiles(uploadedValues: BusinessFormUploadedFileValue[]): Uplo ...@@ -454,10 +542,6 @@ function buildUploadFiles(uploadedValues: BusinessFormUploadedFileValue[]): Uplo
})); }));
} }
function resolveFieldWidthClass(fieldWidth: string) {
return fieldWidth;
}
function buildValidationMessage(field: BusinessFormField, value: BusinessFormValue, values: BusinessFormValues) { function buildValidationMessage(field: BusinessFormField, value: BusinessFormValue, values: BusinessFormValues) {
if (!resolveVisible(field.visible, values) || resolveBoolean(field.readonly, values) || field.type === 'displayText') { if (!resolveVisible(field.visible, values) || resolveBoolean(field.readonly, values) || field.type === 'displayText') {
return undefined; return undefined;
...@@ -495,23 +579,25 @@ async function runBusinessFormValidation(fields: BusinessFormField[], values: Bu ...@@ -495,23 +579,25 @@ async function runBusinessFormValidation(fields: BusinessFormField[], values: Bu
const errors: BusinessFormErrors = {}; const errors: BusinessFormErrors = {};
for (const field of fields) { for (const field of fields) {
const value = values[field.key];
const builtInError = buildValidationMessage(field, value, values);
if (builtInError) {
errors[field.key] = builtInError;
continue;
}
if (field.type === 'displayText' || !resolveVisible(field.visible, values) || resolveBoolean(field.readonly, values)) { if (field.type === 'displayText' || !resolveVisible(field.visible, values) || resolveBoolean(field.readonly, values)) {
continue; continue;
} }
const value = values[field.key];
if (field.validator) { if (field.validator) {
const customError = await field.validator(value, { values, field }); const customError = await field.validator(value, { values, field });
if (customError) { if (typeof customError === 'string') {
errors[field.key] = customError; errors[field.key] = customError;
continue;
}
} }
const builtInError = buildValidationMessage(field, value, values);
if (builtInError) {
errors[field.key] = builtInError;
continue;
} }
} }
return errors; return errors;
...@@ -523,6 +609,7 @@ export function BusinessForm({ ...@@ -523,6 +609,7 @@ export function BusinessForm({
errors, errors,
fieldWidth, fieldWidth,
fields, fields,
labelAlign = 'left',
values, values,
'data-testid': dataTestId = 'business-form', 'data-testid': dataTestId = 'business-form',
onChange, onChange,
...@@ -532,6 +619,7 @@ export function BusinessForm({ ...@@ -532,6 +619,7 @@ export function BusinessForm({
const draftValuesRef = useRef<BusinessFormValues>({ ...values }); const draftValuesRef = useRef<BusinessFormValues>({ ...values });
const changeValuesRef = useRef<BusinessFormValues>({ ...values }); const changeValuesRef = useRef<BusinessFormValues>({ ...values });
const resolvedWidth = formatFieldWidth(fieldWidth); const resolvedWidth = formatFieldWidth(fieldWidth);
const fieldWidthLayout = useMemo(() => resolveFieldWidthLayout(fieldWidth), [fieldWidth]);
const currentValues = draftValues; const currentValues = draftValues;
const mergedErrors = useMemo( const mergedErrors = useMemo(
...@@ -557,7 +645,13 @@ export function BusinessForm({ ...@@ -557,7 +645,13 @@ export function BusinessForm({
}; };
return ( return (
<div className={classNames(styles.root, className)} data-testid={dataTestId}> <Form
className={classNames(styles.root, className)}
colon={false}
labelAlign={labelAlign}
data-testid={dataTestId}
style={{ gap: BUSINESS_FORM_ROW_GAP }}
>
{fields.map((field) => { {fields.map((field) => {
const visible = resolveVisible(field.visible, currentValues); const visible = resolveVisible(field.visible, currentValues);
if (!visible) return null; if (!visible) return null;
...@@ -566,7 +660,7 @@ export function BusinessForm({ ...@@ -566,7 +660,7 @@ export function BusinessForm({
const readonly = resolveBoolean(field.readonly, currentValues); const readonly = resolveBoolean(field.readonly, currentValues);
const value = currentValues[field.key]; const value = currentValues[field.key];
const error = mergedErrors[field.key]; const error = mergedErrors[field.key];
const fieldWidthClass = resolveFieldWidthClass(resolvedWidth); const help = field.helperText ?? field.helpText;
const controlId = `business-form-control-${field.key}`; const controlId = `business-form-control-${field.key}`;
const labelId = `${controlId}-label`; const labelId = `${controlId}-label`;
const fieldState = { const fieldState = {
...@@ -591,22 +685,25 @@ export function BusinessForm({ ...@@ -591,22 +685,25 @@ export function BusinessForm({
key={field.key} key={field.key}
className={classNames(styles.field, field.className)} className={classNames(styles.field, field.className)}
data-testid={`business-form-field-${field.key}`} data-testid={`business-form-field-${field.key}`}
data-width={fieldWidthClass} data-width={resolvedWidth}
> >
<label <FormItem
className={styles.label} className={styles.formItem}
htmlFor={field.type === 'input' || field.type === 'numberInput' || field.type === 'textarea' ? controlId : undefined} help={help ? <div className={styles.helpText} style={{ color: BUSINESS_FORM_HELP_TEXT_COLOR }}>{help}</div> : undefined}
id={labelId} label={<span id={labelId}>{field.label}</span>}
requiredMark={field.required}
status={error ? 'error' : undefined}
tips={error ? <div className={styles.error} style={{ color: BUSINESS_FORM_ERROR_TEXT_COLOR }}>{error}</div> : undefined}
>
<div
className={classNames(styles.controlHolder, fieldWidthLayout.holderClassName)}
data-testid={`business-form-control-holder-${field.key}`}
style={fieldWidthLayout.holderStyle}
> >
{field.required ? <span className={styles.required}>*</span> : null}
<span>{field.label}</span>
</label>
<div className={styles.controlWrap}>
<div className={styles.controlHolder}>
{field.type === 'displayText' ? ( {field.type === 'displayText' ? (
<span className={styles.readonlyValue}> <Text className={styles.readonlyValue}>
{field.render?.(value, currentValues) ?? resolveTextValue(value)} {field.render?.(value, currentValues) ?? resolveTextValue(value)}
</span> </Text>
) : null} ) : null}
{field.type === 'custom' ? ( {field.type === 'custom' ? (
...@@ -622,59 +719,79 @@ export function BusinessForm({ ...@@ -622,59 +719,79 @@ export function BusinessForm({
) : null} ) : null}
{field.type === 'input' ? ( {field.type === 'input' ? (
readonly ? (
<Text className={styles.readonlyValue}>{resolveTextValue(value)}</Text>
) : (
<Input <Input
id={controlId} id={controlId}
aria-label={field.label} aria-label={field.label}
clearable={field.allowClear} clearable={field.allowClear}
disabled={disabled} disabled={disabled}
maxlength={field.maxLength} maxlength={field.maxLength}
allowInputOverMax={field.allowInputOverMax} allowInputOverMax={false}
placeholder={field.placeholder ?? `请输入${field.label}`} placeholder={field.placeholder ?? `请输入${field.label}`}
readOnly={readonly}
showLimitNumber={field.maxLength !== undefined} showLimitNumber={field.maxLength !== undefined}
type="text" type="text"
value={stringifyValue(normalizeValue(value))} value={stringifyValue(normalizeValue(value))}
style={fieldWidthLayout.controlStyle}
onChange={(nextValue) => { onChange={(nextValue) => {
applyFieldChange(field, String(nextValue ?? '')); applyFieldChange(field, capTextValue(field, String(nextValue ?? '')));
}} }}
/> />
)
) : null} ) : null}
{field.type === 'numberInput' ? ( {field.type === 'numberInput' ? (
<InputNumber readonly ? (
<Text className={styles.readonlyValue}>{resolveTextValue(value)}</Text>
) : (
<Input
id={controlId}
aria-label={field.label}
disabled={disabled} disabled={disabled}
max={field.max}
min={field.min}
placeholder={field.placeholder ?? `请输入${field.label}`} placeholder={field.placeholder ?? `请输入${field.label}`}
readOnly={readonly} type="number"
decimalPlaces={field.precision} value={value === undefined || value === null ? '' : String(value)}
value={value === undefined || value === null ? '' : (value as string | number)} style={fieldWidthLayout.controlStyle}
onChange={(nextValue) => { onChange={(nextValue) => {
applyFieldChange(field, nextValue === '' ? undefined : (nextValue as BusinessFormValue)); const text = String(nextValue ?? '').trim();
if (!text) {
applyFieldChange(field, undefined);
return;
}
const parsed = Number(text);
applyFieldChange(field, Number.isFinite(parsed) ? parsed : text);
}} }}
/> />
)
) : null} ) : null}
{field.type === 'select' ? ( {field.type === 'select' ? (
readonly ? (
<Text className={styles.readonlyValue}>{renderSelectReadonlyValue(field, value)}</Text>
) : (
<Select <Select
id={controlId} id={controlId}
aria-label={field.label} aria-label={field.label}
clearable={field.allowClear} clearable={field.allowClear}
disabled={disabled} disabled={disabled}
multiple={field.multiple} multiple={field.multiple}
inputProps={{ 'aria-label': field.label, role: 'combobox' } as never}
options={field.options} options={field.options}
placeholder={field.placeholder ?? `请选择${field.label}`} placeholder={field.placeholder ?? `请选择${field.label}`}
readOnly={readonly} style={fieldWidthLayout.controlStyle}
value={field.multiple ? (Array.isArray(value) ? value : []) : value ?? ''} value={field.multiple ? (Array.isArray(value) ? value : []) : value ?? ''}
onChange={(nextValue) => { onChange={(nextValue) => {
applyFieldChange(field, nextValue as BusinessFormValue); applyFieldChange(field, nextValue as BusinessFormValue);
}} }}
/> />
)
) : null} ) : null}
{field.type === 'switch' ? ( {field.type === 'switch' ? (
readonly ? ( readonly ? (
<span className={styles.readonlyValue}>{renderSwitchText(field, value)}</span> <Text className={styles.readonlyValue}>{renderSwitchText(field, value)}</Text>
) : ( ) : (
<Switch <Switch
aria-label={field.label} aria-label={field.label}
...@@ -690,25 +807,33 @@ export function BusinessForm({ ...@@ -690,25 +807,33 @@ export function BusinessForm({
) : null} ) : null}
{field.type === 'textarea' ? ( {field.type === 'textarea' ? (
readonly ? (
<Text className={styles.readonlyValue}>{resolveTextValue(value)}</Text>
) : (
<Textarea <Textarea
id={controlId} id={controlId}
aria-label={field.label} aria-label={field.label}
disabled={disabled} disabled={disabled}
maxlength={field.maxLength} maxlength={field.maxLength}
allowInputOverMax={field.allowInputOverMax} allowInputOverMax={false}
readOnly={readonly}
rows={field.rows ?? 4} rows={field.rows ?? 4}
count={field.maxLength !== undefined} count={field.maxLength !== undefined}
value={stringifyValue(value)} value={stringifyValue(value)}
style={fieldWidthLayout.controlStyle}
onChange={(nextValue) => { onChange={(nextValue) => {
applyFieldChange(field, String(nextValue ?? '')); applyFieldChange(field, capTextValue(field, String(nextValue ?? '')));
}} }}
/> />
)
) : null} ) : null}
{field.type === 'upload' ? ( {field.type === 'upload' ? (
readonly ? ( readonly ? (
<span className={styles.readonlyValue}>{resolveUploadPreview(uploadedValues) ?? field.placeholder ?? '未上传'}</span> <div className={styles.readonlyValue}>
{resolveUploadPreview(uploadedValues) ?? (
<Text>{field.placeholder ?? '未上传'}</Text>
)}
</div>
) : ( ) : (
<div className={styles.uploadWrap}> <div className={styles.uploadWrap}>
{(() => { {(() => {
...@@ -777,7 +902,7 @@ export function BusinessForm({ ...@@ -777,7 +902,7 @@ export function BusinessForm({
preload="metadata" preload="metadata"
/> />
) : ( ) : (
<img className={styles.uploadVideoCard} src={file.url} alt={file.name} /> <Image className={styles.uploadVideoCard} src={file.url} alt={file.name} fit="cover" />
)} )}
<div className="t-upload__card-mask"> <div className="t-upload__card-mask">
<div <div
...@@ -811,11 +936,13 @@ export function BusinessForm({ ...@@ -811,11 +936,13 @@ export function BusinessForm({
</div> </div>
{file.name ? ( {file.name ? (
file.url ? ( file.url ? (
<a className="t-upload__card-name" href={file.url} target="_blank" rel="noreferrer"> <Link className="t-upload__card-name" href={file.url} target="_blank" {...({ rel: 'noreferrer' } as any)}>
{file.name} {file.name}
</a> </Link>
) : ( ) : (
<span className="t-upload__card-name">{file.name}</span> <Text className="t-upload__card-name" ellipsis>
{file.name}
</Text>
) )
) : null} ) : null}
</li> </li>
...@@ -862,20 +989,11 @@ export function BusinessForm({ ...@@ -862,20 +989,11 @@ export function BusinessForm({
) )
) : null} ) : null}
</div> </div>
</FormItem>
{field.helperText ?? field.helpText ? (
<div className={styles.helpText}>{field.helperText ?? field.helpText}</div>
) : null}
{error ? (
<div className={styles.error} role="alert">
{error}
</div>
) : null}
</div>
</div> </div>
); );
})} })}
</div> </Form>
); );
} }
......
...@@ -64,6 +64,24 @@ ...@@ -64,6 +64,24 @@
font-size: var(--gl-font-size-sm); font-size: var(--gl-font-size-sm);
} }
.cellText {
display: inline-block;
max-width: 100%;
overflow: hidden;
text-overflow: ellipsis;
vertical-align: bottom;
white-space: nowrap;
}
.cellTooltipContent {
display: block;
width: 200px;
max-width: 200px;
white-space: normal;
word-break: break-word;
line-height: var(--gl-line-height-md);
}
.pagination { .pagination {
margin-left: auto; margin-left: auto;
} }
import { useMemo } from 'react';
import type { ReactElement, ReactNode } from 'react'; import type { ReactElement, ReactNode } from 'react';
import { CloseCircleIcon, SearchIcon } from 'tdesign-icons-react'; import { CloseCircleIcon, SearchIcon } from 'tdesign-icons-react';
import { Button, Empty, Pagination, Table, type EmptyProps, type PaginationProps, type PrimaryTableCol, type TableProps, type TableRowData } from 'tdesign-react'; import { Button, Empty, Pagination, Table, Tooltip, Typography, type EmptyProps, type PaginationProps, type PrimaryTableCol, type TableProps, type TableRowData } from 'tdesign-react';
import { classNames } from '../shared/classNames'; import { classNames } from '../shared/classNames';
import styles from './BusinessTable.module.css'; import styles from './BusinessTable.module.css';
export type BusinessTableColumn<T extends TableRowData> = PrimaryTableCol<T>; const { Text } = Typography;
export type BusinessTableColumn<T extends TableRowData> = PrimaryTableCol<T> & {
ellipsisTooltip?: boolean;
tooltipValue?: (row: T) => string | number | boolean | null | undefined;
};
export interface BusinessTableEmptyStateConfig { export interface BusinessTableEmptyStateConfig {
onAction?: () => void; onAction?: () => void;
...@@ -84,6 +90,55 @@ const defaultLoadingProps = { ...@@ -84,6 +90,55 @@ const defaultLoadingProps = {
text: '加载中', text: '加载中',
} satisfies TableProps<TableRowData>['loadingProps']; } satisfies TableProps<TableRowData>['loadingProps'];
function isPlainTextValue(value: unknown): value is string | number | boolean {
return ['string', 'number', 'boolean'].includes(typeof value);
}
function renderPlainTextCell<T extends TableRowData>(
row: T,
column: BusinessTableColumn<T>,
): ReactNode {
const value = column.tooltipValue
? column.tooltipValue(row)
: row[column.colKey as keyof T];
if (value === undefined || value === null) return '-';
if (!isPlainTextValue(value)) return value as ReactNode;
const text = String(value);
const normalizedText = text.trim();
if (!normalizedText || normalizedText === '-') return '-';
return (
<Tooltip
content={(
<span
className={styles.cellTooltipContent}
style={{ width: 200, maxWidth: 200, whiteSpace: 'normal' }}
>
{text}
</span>
)}
>
<span className={styles.cellText}>{text}</span>
</Tooltip>
);
}
function withPlainTextTooltipColumns<T extends TableRowData>(
columns: BusinessTableColumn<T>[],
): BusinessTableColumn<T>[] {
return columns.map((column) => {
if (!column.ellipsisTooltip || column.cell) return column;
const { ellipsisTooltip, tooltipValue, ...tableColumn } = column;
return {
...tableColumn,
cell: ({ row }) => renderPlainTextCell(row, column),
};
});
}
const errorStatePresets: Record<NonNullable<BusinessTableErrorStateConfig['kind']>, { const errorStatePresets: Record<NonNullable<BusinessTableErrorStateConfig['kind']>, {
actionText?: string; actionText?: string;
description?: string; description?: string;
...@@ -135,6 +190,7 @@ export function BusinessTable<T extends TableRowData>({ ...@@ -135,6 +190,7 @@ export function BusinessTable<T extends TableRowData>({
const isEmpty = data.length === 0; const isEmpty = data.length === 0;
const isLoading = Boolean(tableProps.loading); const isLoading = Boolean(tableProps.loading);
const displayColumns = useMemo(() => withPlainTextTooltipColumns(columns), [columns]);
const mergedLoadingProps = isLoading const mergedLoadingProps = isLoading
? { ? {
...defaultLoadingProps, ...defaultLoadingProps,
...@@ -160,7 +216,7 @@ export function BusinessTable<T extends TableRowData>({ ...@@ -160,7 +216,7 @@ export function BusinessTable<T extends TableRowData>({
<Table <Table
{...tableProps} {...tableProps}
className={classNames(styles.table, tableClassName)} className={classNames(styles.table, tableClassName)}
columns={columns} columns={displayColumns}
data={data} data={data}
empty={emptyNode} empty={emptyNode}
loadingProps={mergedLoadingProps} loadingProps={mergedLoadingProps}
...@@ -168,7 +224,7 @@ export function BusinessTable<T extends TableRowData>({ ...@@ -168,7 +224,7 @@ export function BusinessTable<T extends TableRowData>({
/> />
{pagination || totalLabel ? ( {pagination || totalLabel ? (
<div className={styles.footer}> <div className={styles.footer}>
{!pagination && totalLabel ? <div className={styles.totalLabel}>{totalLabel}</div> : <span />} {!pagination && totalLabel ? <Text className={styles.totalLabel}>{totalLabel}</Text> : <span />}
{pagination ? <Pagination className={styles.pagination} {...pagination} /> : null} {pagination ? <Pagination className={styles.pagination} {...pagination} /> : null}
</div> </div>
) : null} ) : null}
......
# BusinessForm 页面迁移实施计划
日期:2026-06-07
## 目标
把 `web/src/routes` 下第一批编辑页迁移到 `BusinessForm`,包括:
1. `AgentTagEditorPage`
2. `ChannelCodeEditorPage`
3. `OfficialSiteJobTabEditorPage`
要求保持现有页面行为、字段校验、保存 payload、加载/错误状态和保存反馈不变。
## 执行顺序
1. 先补测试,锁定迁移前后的关键行为和源代码边界。
2. 再逐页把表单区域替换成 `BusinessForm` 字段配置。
3. 复跑页面测试、类型检查、构建和 OpenSpec 校验。
4. 用浏览器验证三个页面的新建/编辑关键路径。
## TDD 关注点
1. `AgentTagEditorPage`:
- 新建/编辑模式下字段可见性。
- 标签编码在编辑态保持只读。
- 保存前校验和 payload 不变。
2. `ChannelCodeEditorPage`:
- 新建态岗位、员工联动。
- 编辑态只读信息展示。
- 描述和欢迎语校验不变。
3. `OfficialSiteJobTabEditorPage`:
- 岗位联动后带出只读信息。
- 标题、说明、排序、状态字段保持一致。
- 新建/编辑保存行为一致。
## 验证命令
1. `rtk npm test -- <相关页面测试>`
2. `rtk npm run typecheck`
3. `rtk npm run build`
4. `rtk openspec validate migrate-editor-pages-to-business-form --strict`
5. 浏览器中验证三个编辑页
## 风险
1. `BusinessForm` 字段映射后可能改变只读/禁用态表现。
2. `select` 联动和 displayText 回退可能遗漏一部分只读信息。
3. 页面源代码迁移后,测试可能需要兼顾行为断言和实现边界断言。
# 第三阶段编辑页迁移到 BusinessForm 实施计划
## 目标
将官网 Agent 展示配置编辑弹窗的标准字段迁移为 `BusinessForm` 配置渲染,同时保持弹窗外壳、上传处理、校验、保存 payload 和提示颜色语义不变。
## 步骤
1. 更新 OpenSpec proposal、design、spec 和 tasks,锁定第三阶段范围。
2. 按 TDD 调整 `AgentDisplayConfigEditModal.test.tsx` 和必要的页面集成测试,先覆盖迁移边界。
3. 将 `AgentDisplayConfigEditModal` 的字段区域替换为 `BusinessForm`,上传和无法标准表达的结构使用 `custom` 或 `upload` 字段承载。
4. 运行相关测试、`BusinessForm` 测试、类型检查、构建和 OpenSpec 校验。
5. 验证通过后更新 tasks 和项目记忆。
# 实施计划:官网 Agent 展示配置弹窗状态文案与排序下限调整
## 目标
把官网 Agent 展示配置编辑弹窗里的 `展示状态` 口径统一成 `不展示`,默认值仍然是 `disable`;同时让 `展示排序` 在 UI 和校验上都明确不接受小于 `0` 的值。
## 范围
- 仅修改 `workspace/agent-admin/web/src/routes/official-site-agent-display-config/AgentDisplayConfigEditModal.tsx`
- 同步更新该弹窗相关测试,以及外层编辑页的回归测试
- 不修改列表页的状态展示文案,不修改后端接口或枚举值
## 步骤
1. 调整编辑弹窗中 `display_status` 的选项文案,将 `disable` 映射为 `不展示`
2. 保持默认值仍为 `disable`,并在排序输入上补充 `min={0}` 约束
3. 更新相关测试,覆盖 `不展示` 文案、默认值和排序下限校验
4. 运行定向测试、类型检查和构建验证
# 业务组件 TDesign 优先改造设计
日期:2026-06-05
## 背景
`@gl/business-components` 中的 `BusinessForm` 和 `BusinessTable` 已经以 TDesign 为主要控件来源:表单输入、选择、开关、上传入口、表格、分页和状态空态都已经基于 `tdesign-react` 实现。但当前组件并不是“完全没有原生 HTML 和 CSS”。组件内部仍保留了表单布局、标签、帮助文案、错误文案、媒体预览和表格 footer 布局所需的原生结构与 CSS module。
用户希望后续按“能用 TDesign 就用 TDesign,TDesign 实现不了或不适合实现的再用原生”的原则收敛 `business-form` 和 `business-table`。本设计先评估哪些内容可以迁移到 TDesign,哪些需要保留原生实现,作为后续 OpenSpec change 的输入。
## 目标
- 明确 `BusinessForm` 和 `BusinessTable` 中 TDesign 可替代的原生实现范围。
- 明确需要谨慎评估的替换点,避免破坏既有受控值、上传语义和表单校验。
- 明确继续保留原生结构的合理边界,例如视频预览、必要布局容器和 TDesign slot 自定义。
- 为后续 OpenSpec change 提供可执行的改造范围、风险和验证策略。
## 非目标
- 本设计不直接修改业务代码。
- 不追求删除所有原生 `div`、`span`、`label` 或 CSS module;React 组件组合、布局容器和 TDesign 插槽内部仍可能需要少量原生结构。
- 不改变 `BusinessForm`、`BusinessTable` 的公开 API 和业务语义,除非后续 OpenSpec 明确确认。
- 不重写上传业务协议,不绑定固定上传接口。
- 不迁移具体业务页面。
## 现状观察
### BusinessForm
当前 `BusinessForm` 的基础输入控件主要来自 TDesign,包括 `Input`、`InputNumber`、`Select`、`Switch`、`Textarea`、`Upload` 和 `Button`。但外层表单项仍由组件自己渲染:
- 根表单、字段容器、标签、必填标记、帮助文案和错误文案使用原生结构与 CSS module。
- 只读文本和上传文件名使用原生文本节点或 `span`。
- 图片上传预览部分存在原生 `img`。
- 视频上传预览依赖原生 `video`。
- 自定义上传文件列表使用 TDesign `Upload.fileListDisplay`,内部为了渲染视频缩略图、文件名、删除和下载链接,仍使用原生结构。
### BusinessTable
当前 `BusinessTable` 的核心能力已经基于 TDesign:
- 表格使用 TDesign `Table`。
- 分页使用 TDesign `Pagination`。
- 空态和错误态使用 TDesign `Empty` 和 `Button`。
仍保留的原生结构主要是:
- 组件根容器。
- 错误态和空态的居中包裹容器。
- footer 布局容器。
- 无分页场景的 `totalLabel` 文本。
## 替换评估
### 可以优先迁移到 TDesign
1. 表单根结构与表单项语义
当前 `BusinessForm` 自己维护 label、required、help 和 error 展示。TDesign `Form` 与 `FormItem` 已提供 `label`、`requiredMark`、`help`、`tips`、`status`、`labelWidth` 和 `labelAlign` 等能力,可承接大部分表单项语义。
建议迁移方向:
- 用 TDesign `Form` 包裹字段列表。
- 用 TDesign `FormItem` 承接 label、必填标记、帮助文案和错误提示。
- 保留 `BusinessForm` 自己的配置驱动校验,不把页面保存流程交给 TDesign Form 实例。
- 优先采用已知兼容方案,避免 `FormItem` 因 `name` 或 child clone 行为覆盖受控值。
2. 只读文本、统计文本和文件名
`displayText`、上传文件名、表格无分页总数等文本展示可优先使用 TDesign `Typography.Text`,获得统一字号、颜色、省略和主题能力。
建议迁移方向:
- `BusinessForm` 的只读字段使用 `Typography.Text`。
- 上传卡片下方文件名使用 `Typography.Text` 的省略能力。
- `BusinessTable` 的无分页 `totalLabel` 使用 `Typography.Text`。
3. 图片预览
TDesign `Image` 可替代原生 `img`,用于图片、GIF、视频封面等静态预览。它提供统一的 `fit`、占位、错误态和样式接口。
建议迁移方向:
- 图片和 GIF 预览从 `img` 迁移到 `Image`。
- 视频封面如果是图片 URL,也可用 `Image` 渲染。
- 真实视频播放或首帧预览仍保留 `video`。
4. 文件链接
上传文件的下载或查看链接可用 TDesign `Link` 替代原生 `a`,但需要保留 `href`、`target`、`rel` 等浏览器语义。
建议迁移方向:
- 普通文件列表中的可访问文件链接使用 `Link`。
- 对外链安全属性继续保留。
5. 简单布局间距
部分横向按钮组或小块间距可用 TDesign `Space` 收敛,但不建议为了替换所有 `div` 而引入过多嵌套。
建议迁移方向:
- 上传操作按钮、文件操作区等局部按钮间距可评估 `Space`。
- 大范围表单布局仍以 `Form`、`FormItem` 和少量 CSS module 控制。
### 需要谨慎评估后迁移
1. 上传字段的更多状态能力
TDesign `Upload` 支持 `requestMethod`、`beforeUpload`、`sizeLimit`、`status`、`tips`、`showThumbnail`、`fileListDisplay`、`max` 和 `multiple` 等能力。理论上可继续减少组件内部自定义校验和状态渲染。
谨慎原因:
- `BusinessForm` 当前上传协议是业务侧传入 `upload(file, values)`,组件不绑定接口。
- 上传值支持字符串 URL、结构化文件值和多文件数组。
- 媒体上传需要同时覆盖图片、GIF 和视频。
- 现有错误文案和校验顺序需要保持稳定。
建议迁移方向:
- 第一阶段只把 TDesign 已有且不改变语义的能力接入,例如 `max`、`multiple`、`tips`、`status`。
- `requestMethod` 是否接管真实上传,需要单独验证与现有受控值协议是否冲突。
2. `FormItem` 全量替换
TDesign `FormItem` 可提升语义一致性,但项目记忆中已有 `FormItem` 在无 `name` 时 clone 子控件并覆盖受控值的历史风险。
建议迁移方向:
- 先做一个薄适配层或兼容写法,确保不会覆盖 `BusinessForm` 下发给控件的 `value` 与 `onChange`。
- 通过测试覆盖输入、选择、上传、只读和自定义字段。
3. 表格 footer 布局
`BusinessTable` footer 可尝试用 TDesign `Space` 或 `Row/Col`,但收益有限。
建议迁移方向:
- 仅替换文本为 `Typography.Text`。
- 保留必要 flex 容器,避免引入多余 DOM 或影响分页对齐。
### 建议继续保留原生实现
1. 视频预览
TDesign 没有通用视频播放组件。视频缩略图、预览和可播放片段应继续使用原生 `video`。
2. TDesign Upload 的自定义 `fileListDisplay`
当前视频上传列表需要展示视频缩略图、文件名、删除和链接等组合内容。`fileListDisplay` 本身就是 TDesign 提供的自定义出口,出口内部保留少量原生结构是合理的。
3. 必要布局容器
React 组件外层根容器、状态区居中容器、footer flex 容器和固定尺寸媒体卡片仍需要原生结构与 CSS module 承接布局。TDesign 不应被用来替代所有布局节点。
4. CSS module
组件仍需要 CSS module 管理业务组件的布局尺寸、对齐、媒体卡片尺寸、hover 蒙层和响应式约束。TDesign 组件负责控件语义和基础视觉,CSS module 负责业务组合布局。
## 推荐方案
采用“中等收敛”方案:优先把语义清晰、TDesign 能直接承接的部分迁移到 TDesign,同时保留媒体、slot 和布局层面的原生实现。
本方案的改造范围建议为:
- `BusinessForm` 引入 TDesign `Form` / `FormItem` 承接表单语义和字段提示。
- `BusinessForm` 使用 `Typography.Text` 承接只读文本、文件名和辅助文本中的普通文本展示。
- `BusinessForm` 使用 `Image` 替代图片/GIF 静态预览中的原生 `img`。
- `BusinessForm` 使用 `Link` 替代普通文件链接中的原生 `a`。
- `BusinessForm` 评估并接入 TDesign `Upload` 的低风险属性,例如 `max`、`multiple`、`status` 和 `tips`。
- `BusinessTable` 使用 `Typography.Text` 承接无分页 `totalLabel`。
- 保留 `video`、上传自定义列表内部必要结构、表格状态区布局和 CSS module。
不建议采用“极限替换”方案,即为了删除所有原生标签而强行使用 TDesign 布局组件包裹每一个节点。该方案会提高 DOM 复杂度,并可能削弱媒体上传和表格布局的可控性。
## 风险与权衡
- `FormItem` 迁移可能影响受控字段值,需要用测试覆盖所有字段类型,尤其是 `custom` 和 `upload`。
- 图片预览迁移到 `Image` 后,需要确认 GIF、跨域图片、错误图片和 object-fit 展示效果不回退。
- 文件链接换成 `Link` 后,需要确认下载、打开新窗口和可访问性属性不丢失。
- 上传状态继续接入 TDesign 能力时,需要确保既有 `upload(file, values)` 和多文件值结构不被改写。
- 保留部分原生结构可能无法达到“完全没有原生 HTML”的描述,但更符合 TDesign 组件库的真实使用方式。
## 测试策略
后续进入 OpenSpec 并实施时,建议新增或调整测试覆盖:
- `BusinessForm` 字段渲染后仍能输入、选择、切换、上传和只读展示。
- `FormItem` 迁移后错误提示、帮助文案、必填标记和 disabled/readonly 状态保持一致。
- 图片/GIF 预览使用 TDesign `Image` 后仍显示正确 alt、尺寸和移除操作。
- 视频预览继续使用原生 `video`,不被图片替换逻辑破坏。
- 普通文件链接使用 TDesign `Link` 后仍保留 `href`、`target` 和 `rel`。
- `BusinessTable` 无分页 `totalLabel` 正常展示;分页场景仍只展示 TDesign `Pagination` 默认总数。
- 运行 `npm run typecheck`、相关组件测试、构建和 `openspec validate <change-name> --strict`。
- 如修改 Demo 或可视区域,完成前用浏览器验证 `/components` 中 `BusinessForm` 和 `BusinessTable` 的布局与关键交互。
## 后续 OpenSpec 建议
建议创建 change:`refine-business-components-tdesign-first`。
建议影响规格:
- `business-form`
- `business-table`
建议 OpenSpec 任务拆分:
1. 更新 `business-form` 与 `business-table` 规格,明确 TDesign 优先原则和允许保留原生的边界。
2. 为 `BusinessForm` 的 `Form/FormItem`、`Typography.Text`、`Image`、`Link` 迁移补充测试。
3. 为 `BusinessTable` 的 `Typography.Text` 总数展示补充测试。
4. 实施低风险 TDesign 迁移。
5. 运行类型检查、组件测试、构建、OpenSpec 严格校验和必要浏览器验证。
## 待确认事项
- 是否按推荐的“中等收敛”方案创建 OpenSpec change:`refine-business-components-tdesign-first`。
- 是否将本次改造限制在 `@gl/business-components` 内,不迁移具体业务页面。
- 是否接受 `video`、TDesign `fileListDisplay` 内部结构和必要布局容器继续使用原生实现。
# Web 编辑页迁移到 BusinessForm 设计说明
日期:2026-06-07
## 背景
`BusinessForm` 组件已经具备常见后台表单字段承载能力。当前 `web/src/routes` 下仍有多处页面级表单直接组合 TDesign `Form`、`FormItem`、`Input`、`Select`、`Textarea` 等组件。用户希望在页面中优先使用 `BusinessForm`,只有 `BusinessForm` 暂时无法准确表达的复杂交互才继续使用页面原有实现或 `custom` 字段。
本设计只覆盖页面迁移,不修改 `BusinessForm` 组件能力边界,不归档既有组件 change。
## 目标
1. 第一批将低风险编辑页迁移到 `BusinessForm`。
2. 保持页面行为、路由、接口 payload、校验文案、保存成功/失败反馈不变。
3. 保持后台页面的信息密度和可扫读性,不引入营销页式布局。
4. 用测试和浏览器验证证明迁移前后关键交互一致。
## 非目标
1. 不一次性迁移所有 `web` 页面。
2. 不把动态数组、复杂上传编排、页面级加载错误块强行改成 `BusinessForm` 原生字段。
3. 不重构 API 客户端、路由结构、状态管理方式。
4. 不修改 `BusinessForm` 的公共 API;如果实施中发现必须增强组件,需要先补充对应组件 OpenSpec。
## 第一批范围
### AgentTagEditorPage
文件:
- `src/routes/agent-tags/AgentTagEditorPage.tsx`
迁移字段:
- 标签名称:`input`
- 标签编码:`input`,编辑态保持只读/禁用语义
- 标签描述:`textarea`
保留页面结构:
- 页面标题、返回按钮、加载状态、保存按钮区域
- 新建/编辑模式判断
- 现有校验和提交 payload
### ChannelCodeEditorPage
文件:
- `src/routes/channel-codes/ChannelCodeEditorPage.tsx`
迁移字段:
- 二维码名称:`input`
- 新建态岗位选择:`select`
- 已关联岗位信息:`displayText` 或 `custom`
- 关联员工选择:`select`
- 编辑态只读系统字段:`displayText`
- 描述:`textarea`
- 欢迎语:`textarea`
保留页面结构:
- 选项加载、错误提示、保存流程
- 新建/编辑态字段可见性
- 岗位与员工联动逻辑
### OfficialSiteJobTabEditorPage
文件:
- `src/routes/official-site-job-tabs/OfficialSiteJobTabEditorPage.tsx`
迁移字段:
- 岗位选择或岗位展示:`select` / `displayText`
- 岗位自动带出信息:`displayText` 或 `custom`
- 主标题、副标题:`input` / `textarea`
- 排序值:`numberInput`
- 展示状态:`switch` 或 `select`,以当前页面语义为准
保留页面结构:
- 页面分区标题、说明性块
- 岗位选择后的自动带出逻辑
- 保存、取消、加载和错误状态
## 暂缓范围
### AgentEditorPage
暂缓原因:
- 字段数量更多。
- 存在岗位、员工、技能选项加载错误展示。
- 存在负责人身份分支和多处条件渲染。
后续迁移策略:
- 先把普通字段迁入 `BusinessForm`。
- 加载失败、复杂提示和特殊选择区域用 `custom` 保留。
### AgentDisplayConfigEditModal
暂缓原因:
- 存在图标和媒体上传。
- 需要保持 `usage_type`、文件类型、大小限制、预览和删除行为完全一致。
后续迁移策略:
- 普通字段进入 `BusinessForm`。
- 上传字段若 `BusinessForm` upload 能完整承接则迁移,否则保留 `custom`。
### OfficialSiteMethodologyPage
暂缓原因:
- 页面包含动态步骤列表。
- 步骤支持新增、删除、排序和每步媒体上传。
后续迁移策略:
- 顶部基础配置可迁入 `BusinessForm`。
- 动态步骤列表继续保留原实现,直到组件层面支持动态字段数组或独立业务组件。
## 字段映射原则
1. 页面上已有的简单输入控件应迁移到 `BusinessFormField`:
- `Input` -> `type: "input"`
- `Textarea` -> `type: "textarea"`
- `Select` -> `type: "select"`
- 数字输入 -> `type: "numberInput"`
- 开关/状态 -> `type: "switch"` 或保持现有枚举选择
2. 只读信息优先使用 `displayText`。
3. `BusinessForm` 暂不能表达的复合节点使用 `custom`,并保持原有 TDesign 组件实现。
4. 不在页面中为了迁移而复制 `BusinessForm` 内部样式或校验逻辑。
5. 字段可见性、禁用态、只读态由字段配置表达;无法表达时使用 `custom`。
## 行为保持要求
1. 新建和编辑页面的初始值必须与现有实现一致。
2. 必填、长度、格式和业务校验文案必须与现有实现一致。
3. 提交 payload 字段名和值类型必须与现有实现一致。
4. 保存成功后的跳转、消息提示和缓存刷新必须与现有实现一致。
5. 加载中、加载失败、选项为空、提交失败状态必须与现有实现一致。
6. 页面测试不应依赖 `BusinessForm` 内部 DOM 结构,优先通过用户可见 label、按钮和反馈断言。
## 测试策略
1. 先补充或调整第一批页面的行为测试,覆盖迁移后必须保持的交互:
- 必填校验。
- 新建提交 payload。
- 编辑态初始值和禁用/只读字段。
- select 联动和展示字段。
- 保存成功/失败反馈。
2. 再迁移页面实现。
3. 保留 `BusinessForm` 自身单元测试,不把页面行为测试下沉到组件测试。
4. 完成后运行:
- 相关页面测试。
- `BusinessForm` 测试。
- 类型检查。
- 构建。
- 浏览器关键路径验证。
## 实施顺序
1. 创建 OpenSpec change:`migrate-editor-pages-to-business-form`。
2. 在 OpenSpec 中锁定第一批三页、非目标、验收要求和任务清单。
3. 为第一批页面补充失败的行为测试。
4. 迁移 `AgentTagEditorPage`。
5. 迁移 `ChannelCodeEditorPage`。
6. 迁移 `OfficialSiteJobTabEditorPage`。
7. 运行测试、类型检查、构建和浏览器验证。
8. 代码、测试、OpenSpec 对齐后再归档。
## 风险与应对
1. 风险:`BusinessForm` 的校验触发时机与现有页面不同。
- 应对:页面级测试锁定用户可见校验文案和提交阻断行为。
2. 风险:select 联动迁移后丢失只读展示或默认值。
- 应对:把新建态和编辑态分别覆盖到测试。
3. 风险:页面布局因统一组件包装后变松散。
- 应对:保留原页面容器和操作区,只迁字段区域。
4. 风险:迁移中发现 `BusinessForm` API 缺口。
- 应对:暂停对应页面迁移,先补充组件 OpenSpec,而不是在页面绕开公共能力。
# 第三阶段编辑页迁移到 BusinessForm 设计
## 背景
第一阶段已迁移智能体标签、渠道活码和官网职位 Tab 编辑页;第二阶段已迁移 Agent 编辑页和官网方法论顶部基础配置。第二阶段明确暂缓的官网 Agent 展示配置编辑弹窗仍直接组合 TDesign `FormItem/Input/Select` 与上传墙,需要继续评估并迁移可由 `BusinessForm` 表达的字段。
## 范围
本阶段只迁移 `AgentDisplayConfigEditModal`:
- `Agent 名称`:使用 `BusinessForm` 的 `displayText` 或禁用 `input` 字段,保持只读展示。
- `图标`:使用 `BusinessForm` 的 `upload` 字段承载单图上传入口,继续复用页面原有上传处理、删除和错误写入逻辑。
- `Agent 概述`:使用 `input` 字段,保持必填校验和原 placeholder。
- `展示素材`:使用 `upload` 字段承载图片/GIF/视频单文件入口,继续复用页面原有上传处理、删除和错误写入逻辑。
- `展示排序`:使用 `numberInput` 字段,保持 0-99 整数校验。
- `展示状态`:使用 `select` 字段,选项保持 `不展示`、`展示中`,默认值沿用页面当前状态。
## 保留
- 弹窗 `Dialog` 外壳、标题、取消/确定按钮和保存中状态。
- 详情加载、错误提示、保存请求、保存成功回调和失败反馈。
- 上传接口、`FormData` 组装、用途枚举、上传中状态、删除逻辑和错误提示文案。
- 普通帮助提示浅灰色、必填/校验错误红色的提示语义。
## 不迁移
- 官网方法论步骤动态数组、步骤图标上传和内容图上传。
- 列表页、搜索区、表格或组件 Demo。
- `BusinessForm` 公共 API 扩展;若现有字段能力不足,优先使用 `custom` 字段回退。
## 验证策略
- 先补充 `AgentDisplayConfigEditModal` 测试,锁定弹窗字段由 `BusinessForm` 承载、上传字段仍保留帮助提示、校验错误为红色、保存 payload 不变。
- 实现后运行该弹窗与官网展示配置编辑相关测试。
- 运行 `BusinessForm` 测试、类型检查、构建和 OpenSpec 严格校验。
- 浏览器验证继续按用户要求跳过。
## Context
官网 Agent 展示配置编辑弹窗需要一轮很小但明确的口径对齐:`展示状态` 的编辑态文案要从 `已下架` 改成 `不展示`,默认值也要同步显示成 `不展示`;`展示排序` 则要继续明确禁止小于 `0` 的值。
## Goals / Non-Goals
**Goals:**
- 让编辑弹窗里的展示状态文案更符合当前业务口径。
- 保持内部值不变,只改用户看到的文案和默认显示。
- 明确展示排序的下限,不允许负数提交。
**Non-Goals:**
- 不改列表页文案。
- 不改后端接口、枚举或保存 payload。
- 不扩展到其他页面。
## Decisions
- 编辑弹窗中的 `disable` 选项仅改显示文案为 `不展示`,不改 value。
- 默认值继续使用 `disable`,避免契约变化。
- `sort_order` 仍按整数校验处理,并明确下限为 `0`。
## Risks / Trade-offs
- 编辑页与列表页同一状态显示不同文案,可能让人一瞬间愣一下。我们把范围锁死在编辑弹窗,降低外溢风险。
- 只改文案不改 value,能够最大限度减少保存和兼容问题。
## Context
`@gl/business-components` 已提供 `BusinessForm`、`BusinessFormField`、`BusinessFormValues` 和 `validateBusinessForm` 等公共能力,支持 `input`、`textarea`、`select`、`numberInput`、`switch`、`displayText`、`custom`、`upload` 等字段类型。当前多个后台编辑页仍在页面内直接拼装 TDesign 表单控件,造成字段写法、校验和布局重复。
本次设计只覆盖页面迁移,不修改 `BusinessForm` API,也不归档仍未对齐的组件级 TDesign-first change。
## Goals / Non-Goals
**Goals:**
- 第一批迁移低风险编辑页,让页面主要通过 `BusinessForm` 配置表达表单字段。
- 保持页面原有行为不变,包括新增/编辑差异、字段校验、保存 payload、加载/错误/成功反馈和返回路径。
- 复杂信息展示优先使用 `displayText`,确实无法由标准字段表达时使用 `custom`。
- 用针对性测试证明迁移没有改变关键行为。
**Non-Goals:**
- 不一次性迁移 web 下所有表单页面。
- 不迁移上传、动态数组、复杂资源预览/删除或多分支大表单。
- 不改变 `BusinessForm` 公共字段协议。
- 不重构接口、路由、状态管理或页面数据模型。
## Decisions
### 第一批只迁移低风险编辑页
选择迁移 `AgentTagEditorPage`、`ChannelCodeEditorPage`、`OfficialSiteJobTabEditorPage`。这些页面以基础输入、文本域、选择器、数字输入、状态字段和少量只读展示为主,适合验证 `BusinessForm` 在真实页面中的落地方式。
备选方案是一次性迁移所有页面。该方案覆盖更完整,但会把上传、动态数组和复杂预览行为混入首批改造,验证成本和回归风险更高。
### 使用 `BusinessForm` 字段配置作为页面表单主入口
页面 SHALL 将可由 `BusinessFormField` 表达的字段整理成字段数组,并通过 `value/onChange/onSubmit` 等公共入口驱动。页面仍可保留加载、错误、标题、按钮区和业务数据组装逻辑。
备选方案是在页面中继续直接使用 TDesign `FormItem`,只抽取局部工具函数。该方案改动小,但无法真正复用业务组件,也无法沉淀统一表单组合方式。
### 复杂内容通过 `displayText/custom` 回退
职位联动后的只读说明、编辑模式下不可改字段等展示优先使用 `displayText`。若内容需要包含多段结构或已有业务节点,则使用 `custom` 承载,并只包裹不可避免的原生结构。
备选方案是为了迁移强行扩展 `BusinessForm` 字段类型。该方案会把页面个例推入组件 API,增加组件长期维护成本。
## Risks / Trade-offs
- 字段配置迁移可能改变校验触发或错误展示时机 → 通过页面测试覆盖必填、保存成功、保存失败和只读字段。
- `custom` 字段可能继续存在少量页面原生结构 → 只用于 `BusinessForm` 标准字段无法表达的复杂展示,避免扩大迁移范围。
- `ChannelCodeEditorPage` 有职位和员工联动逻辑 → 保留现有数据推导与副作用,只替换表单渲染入口。
- 数字和状态字段可能存在类型差异 → 测试保存 payload,确保提交前的数据形态与迁移前一致。
## Migration Plan
1. 为三个页面补充或调整测试,先锁定迁移前行为。
2. 逐页迁移字段配置,优先从 `AgentTagEditorPage` 开始,再处理联动更复杂的渠道二维码和官网职位 Tab。
3. 运行相关测试、类型检查、构建和 OpenSpec 校验。
4. 如浏览器环境可用,验证三个编辑页的新增/编辑关键交互和响应式布局。
回滚策略:每个页面迁移保持独立提交粒度,若某页风险超出预期,可只回退该页面的 `BusinessForm` 接入,不影响其他页面。
## Open Questions
- 暂无。上传、动态数组和大表单页面已明确延后到后续独立评估。
## Why
`BusinessForm` 已开发完成,但 web 下仍有多个编辑页直接组合 TDesign `Form/FormItem/Input/Select/Textarea`。现在需要把可由 `BusinessForm` 公共字段能力表达的页面字段迁移到业务组件,降低页面层重复实现,并继续遵守“能用 TDesign/业务组件就优先使用”的前端规则。
## What Changes
- 第一批迁移低风险编辑页:智能体标签编辑、渠道二维码编辑、官网职位 Tab 编辑。
- 将这些页面里可标准表达的输入、文本域、选择器、数字输入、状态开关/选择和只读展示迁移为 `BusinessForm` 字段配置。
- 保留既有新增/编辑模式、加载态、错误态、校验、保存 payload、路由返回和提示反馈。
- 对 `BusinessForm` 无法自然表达的复杂内容使用 `displayText` 或 `custom` 字段承载,不扩大 `BusinessForm` API。
- 暂不迁移上传、动态数组、复杂预览/删除和多分支大表单页面。
## Capabilities
### New Capabilities
- `editor-page-form-composition`: 约束后台编辑页如何优先使用 `BusinessForm` 组合可标准化表单字段,以及复杂字段的回退边界。
### Modified Capabilities
- 无。本次不修改既有业务接口、页面业务规则或 `BusinessForm` 公共 API。
## Impact
- 影响页面:
- `src/routes/agent-tags/AgentTagEditorPage.tsx`
- `src/routes/channel-codes/ChannelCodeEditorPage.tsx`
- `src/routes/official-site-job-tabs/OfficialSiteJobTabEditorPage.tsx`
- 影响测试:上述页面的编辑、校验、保存、只读字段、联动展示和错误态测试。
- 不引入新依赖,不修改后端 API,不修改路由结构。
- 后续大表单和上传/动态数组页面需要单独评估后再迁移。
## ADDED Requirements
### Requirement: 第一批编辑页应优先使用 BusinessForm 组合标准字段
系统 SHALL 在第一批迁移页面中使用 `BusinessForm` 承载可由其公共字段类型表达的编辑字段,并保留页面外层业务结构。
#### Scenario: 智能体标签编辑页使用 BusinessForm
- **WHEN** 用户进入智能体标签新增或编辑页
- **THEN** 标签名称、标签编码和描述字段 SHALL 由 `BusinessForm` 字段配置渲染
- **AND** 编辑模式下标签编码 SHALL 保持迁移前的只读或禁用行为
#### Scenario: 渠道二维码编辑页使用 BusinessForm
- **WHEN** 用户进入渠道二维码新增或编辑页
- **THEN** 二维码名称、新增模式职位选择、员工选择、描述和欢迎语字段 SHALL 由 `BusinessForm` 字段配置渲染
- **AND** 编辑模式下不可修改的职位、智能体编码和员工信息 SHALL 通过 `displayText` 或 `custom` 字段保持只读展示
#### Scenario: 官网职位 Tab 编辑页使用 BusinessForm
- **WHEN** 用户进入官网职位 Tab 新增或编辑页
- **THEN** 职位、主标题、副标题、排序和状态字段 SHALL 由 `BusinessForm` 字段配置渲染
- **AND** 职位联动产生的只读说明 SHALL 通过 `displayText` 或 `custom` 字段展示
### Requirement: 页面业务行为应在迁移后保持不变
系统 SHALL 在迁移到 `BusinessForm` 后保持第一批页面的业务行为、数据提交形态和用户反馈不变。
#### Scenario: 保存 payload 保持一致
- **WHEN** 用户在迁移后的页面填写有效表单并保存
- **THEN** 页面 SHALL 调用迁移前相同的创建或更新接口
- **AND** 提交 payload 的字段和值 SHALL 与迁移前等价
#### Scenario: 校验和反馈保持一致
- **WHEN** 用户提交缺少必填项或格式不合法的表单
- **THEN** 页面 SHALL 展示与迁移前等价的校验反馈
- **AND** 页面 SHALL NOT 调用创建或更新接口
#### Scenario: 加载和错误状态保持一致
- **WHEN** 页面加载详情、选项或保存请求失败
- **THEN** 页面 SHALL 保持迁移前等价的加载态、错误态和失败提示
### Requirement: 复杂字段应限定在明确回退边界内
系统 SHALL 只在 `BusinessForm` 标准字段无法表达页面内容时使用 `displayText` 或 `custom` 回退,不得为本次迁移扩展组件 API。
#### Scenario: 只读业务说明使用展示字段
- **WHEN** 页面需要展示由选项联动推导出的只读业务信息
- **THEN** 页面 SHALL 优先使用 `displayText` 字段
- **AND** 只有多段结构或已有业务节点无法标准表达时 SHALL 使用 `custom` 字段
#### Scenario: 延后页面不纳入首批迁移
- **WHEN** 页面包含上传、动态数组、复杂资源预览/删除或多分支大表单
- **THEN** 页面 SHALL NOT 在本次 change 中强制迁移
- **AND** 后续迁移 SHALL 通过独立评估和 OpenSpec change 锁定范围
## 1. OpenSpec 对齐
- [x] 1.1 创建并校验 `migrate-editor-pages-to-business-form` proposal/design/spec/tasks
- [x] 1.2 等待用户确认 OpenSpec 后进入实现
## 2. TDD 锁定行为
- [x] 2.1 补充或调整 `AgentTagEditorPage` 测试,覆盖新增/编辑、必填校验、编码只读和保存 payload
- [x] 2.2 补充或调整 `ChannelCodeEditorPage` 测试,覆盖新增/编辑字段、职位/员工联动、只读展示、校验和保存 payload
- [x] 2.3 补充或调整 `OfficialSiteJobTabEditorPage` 测试,覆盖职位联动、标题/排序/状态字段、校验和保存 payload
- [x] 2.4 运行相关页面测试,确认新增或调整的行为断言先能暴露当前直接表单实现与目标结构差异
## 3. 页面迁移实现
- [x] 3.1 将 `AgentTagEditorPage` 可标准表达字段迁移为 `BusinessForm`
- [x] 3.2 将 `ChannelCodeEditorPage` 可标准表达字段迁移为 `BusinessForm`,复杂只读信息使用 `displayText` 或 `custom`
- [x] 3.3 将 `OfficialSiteJobTabEditorPage` 可标准表达字段迁移为 `BusinessForm`,保留职位联动和状态行为
- [x] 3.4 清理迁移页面中不再需要的直接 TDesign Form 组合代码,保留必要的页面布局和业务状态
## 4. 验证
- [x] 4.1 运行三个页面相关测试并通过
- [x] 4.2 运行 `rtk npm run typecheck`
- [ ] 4.3 运行 `rtk npm run build`
- [ ] 4.4 运行 `rtk openspec validate migrate-editor-pages-to-business-form --strict`
- [x] 4.5 浏览器验证已按用户确认取消
...@@ -17,13 +17,15 @@ ...@@ -17,13 +17,15 @@
- 通过 `custom` 字段保留实际业务开发中的扩展空间。 - 通过 `custom` 字段保留实际业务开发中的扩展空间。
- 对所有内置字段优先使用 TDesign 已有属性和 API,避免在页面层保留原生控件兼容写法。 - 对所有内置字段优先使用 TDesign 已有属性和 API,避免在页面层保留原生控件兼容写法。
已确认迁移的页面需要遵守各自业务字段集合。官网岗位展示编辑页的编辑态字段集合为:`岗位标签`、`关联渠道活码`、`渠道编码`、`承接员工`、`岗位标题`、`岗位说明`、`Tab排序` 和 `展示状态`;即使详情接口返回 `employee_role_text`,编辑表单也不展示 `承接角色`。
**Non-Goals:** **Non-Goals:**
- 不接管页面保存按钮、提交接口、路由跳转、弹窗开关、埋点或全局消息提示。 - 不接管页面保存按钮、提交接口、路由跳转、弹窗开关、埋点或全局消息提示。
- 不绑定固定上传 API、固定 `FormData`、固定 `usage_type` 或固定文件返回结构。 - 不绑定固定上传 API、固定 `FormData`、固定 `usage_type` 或固定文件返回结构。
- 第一版不支持远程下拉搜索、异步联动请求、数组字段、嵌套对象字段、富文本、日期、多文件上传和复杂步骤表单。 - 第一版不支持远程下拉搜索、异步联动请求、数组字段、嵌套对象字段、富文本、日期、多文件上传和复杂步骤表单。
- 不替代 `SearchFilter`。 - 不替代 `SearchFilter`。
- 不强制一次性迁移现有编辑页和官网复杂配置页。 - 不强制一次性迁移所有编辑页和官网复杂配置页。
## Decisions ## Decisions
...@@ -61,6 +63,8 @@ ...@@ -61,6 +63,8 @@
`BusinessForm` 提供 `fieldWidth`,默认建议 `360px`,最大不超过 `450px`。`input`、`numberInput`、`select` 和 `textarea` 默认使用同一个宽度,并保持 label 后控件起点一致;`textarea` 只允许高度变化。 `BusinessForm` 提供 `fieldWidth`,默认建议 `360px`,最大不超过 `450px`。`input`、`numberInput`、`select` 和 `textarea` 默认使用同一个宽度,并保持 label 后控件起点一致;`textarea` 只允许高度变化。
表单项纵向间距统一为 `20px`,保证同一内容区内的字段分组有足够呼吸感,同时不破坏后台页面的信息密度。
`switch`、`upload`、`displayText` 和 `custom` 复用同一表单项外层布局。`custom` 可自行决定内部宽度,但建议遵守 `fieldWidth`。 `switch`、`upload`、`displayText` 和 `custom` 复用同一表单项外层布局。`custom` 可自行决定内部宽度,但建议遵守 `fieldWidth`。
`input` 和 `textarea` 的长度展示直接交给 `tdesign-react` 的 `showLimitNumber` / `count`,不再由 `BusinessForm` 额外渲染字数统计。 `input` 和 `textarea` 的长度展示直接交给 `tdesign-react` 的 `showLimitNumber` / `count`,不再由 `BusinessForm` 额外渲染字数统计。
......
...@@ -9,13 +9,14 @@ ...@@ -9,13 +9,14 @@
- 第一版内置 `input`、`numberInput`、`select`、`switch`、`textarea`、`upload`、`displayText` 字段,并直接使用 `tdesign-react` 基础控件实现可编辑态。 - 第一版内置 `input`、`numberInput`、`select`、`switch`、`textarea`、`upload`、`displayText` 字段,并直接使用 `tdesign-react` 基础控件实现可编辑态。
- 提供 `custom` 字段扩展口,用于内置字段无法覆盖的业务控件。 - 提供 `custom` 字段扩展口,用于内置字段无法覆盖的业务控件。
- 支持受控值、表单级 `onChange`、字段级 `onChange`、字段动态显示、动态禁用、动态只读和基础校验。 - 支持受控值、表单级 `onChange`、字段级 `onChange`、字段动态显示、动态禁用、动态只读和基础校验。
- `input`、`numberInput`、`select`、`textarea` 默认使用一致控件宽度,并支持通过 `fieldWidth` 统一控制。 - `input`、`numberInput`、`select`、`textarea` 默认使用一致控件宽度,控件列按可用容器宽度撑开,并支持通过 `fieldWidth` 统一控制最大宽度;表单行间距统一为 20px。
- `input` 和 `textarea` 支持 `allowInputOverMax`,并直接复用 `tdesign-react` 的 `showLimitNumber` 长度展示能力。 - `input` 和 `textarea` 支持 `allowInputOverMax`,并直接复用 `tdesign-react` 的 `showLimitNumber` 长度展示能力。
- `select`、`input`、`numberInput` 和 `textarea` 优先使用 `tdesign-react` 已有的 `disabled` / `readOnly` / 等价能力来表达字段级状态,不再保留页面侧原生控件写法。 - `select`、`input`、`numberInput` 和 `textarea` 优先使用 `tdesign-react` 已有的 `disabled` / `readOnly` / 等价能力来表达字段级状态,不再保留页面侧原生控件写法。
- `upload` 在第一版中分为媒体上传与普通文件上传两种展示路径,媒体上传统一支持图片、GIF 和视频,二者均使用 `tdesign-react` `Upload` 完成选择、预览和状态展示,并通过业务侧传入的 `upload(file, values)` 完成真实上传。 - `upload` 在第一版中分为媒体上传与普通文件上传两种展示路径,媒体上传统一支持图片、GIF 和视频,二者均使用 `tdesign-react` `Upload` 完成选择、预览和状态展示,并通过业务侧传入的 `upload(file, values)` 完成真实上传。
- 导出 `validateBusinessForm` 工具函数和必要类型。 - 导出 `validateBusinessForm` 工具函数和必要类型。
- 在组件 Demo 中展示内置字段、动态联动、上传校验和自定义字段。 - 在组件 Demo 中展示内置字段、动态联动、上传校验和自定义字段。
- 对已有实现中的兼容/适配路径做收敛,确保公开 API 以 TDesign 组件契约为准。 - 对已有实现中的兼容/适配路径做收敛,确保公开 API 以 TDesign 组件契约为准。
- 逐步迁移已确认的后台编辑页到 `BusinessForm`,并按页面业务确认的字段顺序和字段集合展示;官网岗位展示编辑页编辑态不展示 `承接角色`。
- 不绑定保存接口、上传 API、`usage_type`、路由、弹窗开关、全局消息或页面提交流程。 - 不绑定保存接口、上传 API、`usage_type`、路由、弹窗开关、全局消息或页面提交流程。
- 不在第一版支持远程下拉搜索、数组字段、嵌套对象字段、富文本、日期、多文件上传或复杂异步联动。 - 不在第一版支持远程下拉搜索、数组字段、嵌套对象字段、富文本、日期、多文件上传或复杂异步联动。
...@@ -34,5 +35,5 @@ ...@@ -34,5 +35,5 @@
- 全局组件包:`packages/business-components` 新增 `BusinessForm`、`validateBusinessForm`、样式和类型导出。 - 全局组件包:`packages/business-components` 新增 `BusinessForm`、`validateBusinessForm`、样式和类型导出。
- 组件 Demo:`workspace/agent-admin/web/src` 的 `/components` 增加业务表单示例。 - 组件 Demo:`workspace/agent-admin/web/src` 的 `/components` 增加业务表单示例。
- 测试:新增业务组件单元测试与 Demo 回归测试。 - 测试:新增业务组件单元测试与 Demo 回归测试。
- 现有页面:本 change 不要求一次性迁移现有编辑页;后续页面迁移需要单独确认或纳入后续任务。 - 现有页面:本 change 已纳入用户确认的部分编辑页迁移与回归修正;未确认页面不要求一次性迁移。
- 后端与接口:不影响后端 API、上传接口契约、保存接口和数据结构。 - 后端与接口:不影响后端 API、上传接口契约、保存接口和数据结构。
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
- **THEN** `BusinessForm` 通过表单级 `onChange` 抛出更新后的整表单值 - **THEN** `BusinessForm` 通过表单级 `onChange` 抛出更新后的整表单值
### Requirement: BusinessForm applies consistent field layout and widths ### Requirement: BusinessForm applies consistent field layout and widths
系统 MUST 统一基础输入控件的表单布局和宽度。 系统 MUST 统一基础输入控件的表单布局和宽度。`input`、`numberInput`、`select` 和 `textarea` 的控件列 MUST 使用可用容器宽度,并通过默认宽度或 `fieldWidth` 作为最大宽度约束,避免控件退回 TDesign 自身较窄的默认宽度。
#### Scenario: Default control width is consistent #### Scenario: Default control width is consistent
- **WHEN** 同一表单渲染 `input`、`numberInput`、`select` 和 `textarea` - **WHEN** 同一表单渲染 `input`、`numberInput`、`select` 和 `textarea`
...@@ -46,12 +46,35 @@ ...@@ -46,12 +46,35 @@
#### Scenario: fieldWidth applies to basic input controls #### Scenario: fieldWidth applies to basic input controls
- **WHEN** 页面传入 `fieldWidth` - **WHEN** 页面传入 `fieldWidth`
- **THEN** `input`、`numberInput`、`select` 和 `textarea` 同步应用该宽度 - **THEN** `input`、`numberInput`、`select` 和 `textarea` 同步应用该最大宽度
- **AND** 控件在该最大宽度内保持 `width: 100%`
#### Scenario: Editor page form fills the content column
- **WHEN** 编辑页在内容卡片中使用 `BusinessForm`
- **THEN** 表单控件列 SHALL 按内容卡片的可用宽度展示
- **AND** 页面 SHALL NOT 将 `BusinessForm` 的控件列再压缩到低于其 `fieldWidth` 最大宽度
#### Scenario: Textarea width remains consistent #### Scenario: Textarea width remains consistent
- **WHEN** `textarea` 因 `rows` 或内容交互改变高度 - **WHEN** `textarea` 因 `rows` 或内容交互改变高度
- **THEN** `textarea` 宽度仍与同表单内 `input`、`numberInput` 和 `select` 保持一致 - **THEN** `textarea` 宽度仍与同表单内 `input`、`numberInput` 和 `select` 保持一致
### Requirement: BusinessForm keeps 20px spacing between rows
系统 MUST 让 `BusinessForm` 的表单项之间保持统一的 20px 垂直间距,避免相邻行在内容区内显得过于拥挤。
#### Scenario: Form rows use 20px spacing
- **WHEN** `BusinessForm` 渲染多行字段
- **THEN** 任意相邻两行字段之间的垂直间距为 20px
- **AND** 该间距在 `input`、`numberInput`、`select`、`textarea`、`switch`、`upload`、`displayText` 和 `custom` 字段之间保持一致
### Requirement: Official site job tab editor uses the approved edit field set
系统 MUST 让已迁移到 `BusinessForm` 的官网岗位展示编辑页只渲染已确认的编辑字段,避免展示与当前编辑任务无关的详情字段。
#### Scenario: Edit page hides employee role text
- **WHEN** 用户进入官网岗位展示编辑页
- **AND** 详情接口返回 `employee_role_text`
- **THEN** 表单 SHALL NOT 展示 `承接角色` 字段
- **AND** 表单 SHALL 继续展示 `岗位标签`、`关联渠道活码`、`渠道编码`、`承接员工`、`岗位标题`、`岗位说明`、`Tab排序` 和 `展示状态`
### Requirement: BusinessForm supports text input limits and TDesign counts ### Requirement: BusinessForm supports text input limits and TDesign counts
系统 MUST 让 `input` 和 `textarea` 支持 `maxLength`、`allowInputOverMax`,并优先复用 `tdesign-react` 已有的长度展示能力和对应 API,而不是页面侧自绘计数逻辑。 系统 MUST 让 `input` 和 `textarea` 支持 `maxLength`、`allowInputOverMax`,并优先复用 `tdesign-react` 已有的长度展示能力和对应 API,而不是页面侧自绘计数逻辑。
...@@ -240,3 +263,34 @@ ...@@ -240,3 +263,34 @@
- **THEN** 示例中的媒体上传字段展示图片、GIF 和视频共用的卡片式上传入口与已有值预览态 - **THEN** 示例中的媒体上传字段展示图片、GIF 和视频共用的卡片式上传入口与已有值预览态
- **AND** 示例中的普通文件上传字段展示文件类上传入口与已有值信息态 - **AND** 示例中的普通文件上传字段展示文件类上传入口与已有值信息态
- **AND** 示例不得继续展示基于页面级原生文件输入控件的旧上传交互 - **AND** 示例不得继续展示基于页面级原生文件输入控件的旧上传交互
### Requirement: BusinessForm follows TDesign-first composition boundaries
系统 MUST 在 `BusinessForm` 中优先使用 TDesign 组件表达表单语义、文本、图片和链接,并明确保留 TDesign 无对应能力或 TDesign slot 内部所需的原生结构。
#### Scenario: Form items use TDesign form semantics
- **WHEN** `BusinessForm` 渲染字段 label、必填标记、helpText 或错误提示
- **THEN** 系统 MUST 优先使用 TDesign `Form`、`FormItem` 或其等价能力承接表单语义
- **AND** 系统 MUST 保持 `fields + values + onChange` 的受控配置协议不变
- **AND** 系统 MUST NOT 让 TDesign `FormItem` 覆盖内置控件、上传字段或 `custom` 字段的受控 `value` 与 `onChange`
#### Scenario: Text display uses TDesign typography
- **WHEN** `BusinessForm` 渲染 `displayText`、readonly 文案、上传文件名或普通辅助文本
- **THEN** 系统 MUST 优先使用 TDesign `Typography.Text` 或其等价文本能力
- **AND** 系统 MUST 保持空值默认展示 `-`、文件名单行省略和既有帮助文案展示语义
#### Scenario: Static image preview uses TDesign image
- **WHEN** 媒体上传字段展示图片、GIF 或图片形式的视频封面
- **THEN** 系统 MUST 优先使用 TDesign `Image` 或其等价图片能力展示静态预览
- **AND** 系统 MUST 保持媒体卡片尺寸、hover 操作蒙层、预览操作和删除操作语义不变
#### Scenario: File links use TDesign link
- **WHEN** 普通文件上传字段展示可打开或下载的文件链接
- **THEN** 系统 MUST 优先使用 TDesign `Link` 或其等价链接能力
- **AND** 系统 MUST 保留 `href`、`target`、`rel` 等浏览器链接语义和安全属性
#### Scenario: Native boundaries remain explicit
- **WHEN** TDesign 没有对应组件能力或组件 slot 内部需要组合媒体、操作按钮和布局结构
- **THEN** 系统 MAY 保留原生结构与 CSS module
- **AND** 视频预览 MAY 继续使用原生 `video`
- **AND** TDesign `Upload.fileListDisplay` 内部 MAY 继续使用必要原生结构展示视频缩略图、文件名、删除、预览和下载操作
- **AND** 系统 SHALL NOT 为了替换所有原生节点而破坏上传值结构、媒体预览、表单对齐或响应式布局
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
- [x] 6.3 运行 `npm run typecheck` - [x] 6.3 运行 `npm run typecheck`
- [x] 6.4 运行 `npm run build` - [x] 6.4 运行 `npm run build`
- [x] 6.5 运行 `openspec validate "business-form-component" --strict` - [x] 6.5 运行 `openspec validate "business-form-component" --strict`
- [ ] 6.6 由用户在浏览器中验收 `/components` 的 `BusinessForm` 布局、统一宽度、动态联动、上传形态和关键交互 - [x] 6.6 由用户在浏览器中验收 `/components` 的 `BusinessForm` 布局、统一宽度、动态联动、上传形态和关键交互
## 7. TDesign 迁移收敛 ## 7. TDesign 迁移收敛
...@@ -66,3 +66,31 @@ ...@@ -66,3 +66,31 @@
- [x] 7.12 将媒体上传文件名调整为单行省略,并把预览动作收敛到 TDesign `Upload` 的 `onPreview` 路径 - [x] 7.12 将媒体上传文件名调整为单行省略,并把预览动作收敛到 TDesign `Upload` 的 `onPreview` 路径
- [x] 7.13 为上传字段增加 `maxCount` 和 `multiple` 配置,默认单文件,媒体上传支持配置多张图片/GIF/视频并以数组值写回 - [x] 7.13 为上传字段增加 `maxCount` 和 `multiple` 配置,默认单文件,媒体上传支持配置多张图片/GIF/视频并以数组值写回
- [x] 7.14 在 `BusinessForm` Demo 中补充多选 Select 字段,展示 `select.multiple` 配置与数组值写回 - [x] 7.14 在 `BusinessForm` Demo 中补充多选 Select 字段,展示 `select.multiple` 配置与数组值写回
- [x] 7.15 将字段 label、必填标记、helpText 和错误提示优先收敛到 TDesign `Form` / `FormItem` 或等价表单语义,并验证不会覆盖受控 `value` / `onChange`
- [x] 7.16 将 `displayText`、readonly 文案、上传文件名和普通辅助文本优先收敛到 TDesign `Typography.Text` 或等价文本能力
- [x] 7.17 将图片/GIF/视频封面等静态预览优先收敛到 TDesign `Image` 或等价图片能力,视频播放继续保留原生 `video`
- [x] 7.18 将普通文件可打开或下载链接优先收敛到 TDesign `Link` 或等价链接能力,并保留 `href`、`target`、`rel`
- [x] 7.19 补充测试覆盖 TDesign-first 边界:FormItem 不覆盖受控值、文本展示、图片预览、视频保留、文件链接属性和 `fileListDisplay` 内部原生结构保留
- [x] 7.20 重新运行 `npm run typecheck`、相关测试、`npm run build` 和 `openspec validate "business-form-component" --strict`
## 8. 表单布局宽度修复
- [x] 8.1 补充 OpenSpec 约束:`BusinessForm` 基础控件列按容器宽度撑开,`fieldWidth` 作为最大宽约束
- [x] 8.2 先补充失败测试,覆盖默认宽度、数字 `fieldWidth` 和字符串宽度类名不会让控件退回窄宽
- [x] 8.3 修改 `BusinessForm` 布局实现,将宽度样式真实作用到控件容器与 TDesign 输入控件
- [x] 8.4 确认已迁移编辑页外层不再额外压缩 `BusinessForm` 的实际控件宽度,必要时仅保留内容卡片布局
- [x] 8.5 运行 `BusinessForm` 相关测试、涉及编辑页测试、`npm run typecheck`、`npm run build` 和 `openspec validate "business-form-component" --strict`
## 9. 表单行距调整
- [x] 9.1 补充 OpenSpec 约束:`BusinessForm` 相邻表单项的纵向间距统一为 20px
- [x] 9.2 先补充失败测试,覆盖多行字段渲染时相邻行间距为 20px
- [x] 9.3 调整 `BusinessForm` 顶层布局间距实现,确保各行之间保持 20px
- [x] 9.4 运行 `BusinessForm` 相关测试、涉及页面测试、`npm run typecheck`、`npm run build` 和 `openspec validate "business-form-component" --strict`
## 10. 岗位展示编辑页字段收敛
- [x] 10.1 补充 OpenSpec 约束:官网岗位展示编辑页不展示 `承接角色`
- [x] 10.2 先补充失败测试,覆盖详情接口返回 `employee_role_text` 时编辑页不出现 `承接角色`
- [x] 10.3 调整官网岗位展示编辑页的编辑态字段配置,移除 `employee_role_text` 展示项
- [x] 10.4 运行官网岗位展示编辑页相关测试、`npm run typecheck`、`npm run build` 和 `openspec validate "business-form-component" --strict`
...@@ -32,5 +32,5 @@ ...@@ -32,5 +32,5 @@
- [x] 3.7 运行 `rtk npm run typecheck` - [x] 3.7 运行 `rtk npm run typecheck`
- [x] 3.8 运行 `rtk openspec validate fix-business-table-duplicate-total --strict` - [x] 3.8 运行 `rtk openspec validate fix-business-table-duplicate-total --strict`
- [x] 3.9 运行 `rtk npm test -- business-table.test.tsx` - [x] 3.9 运行 `rtk npm test -- business-table.test.tsx`
- [ ] 3.10 运行 `rtk npm run typecheck`(当前失败:`packages/ui/src/components/business-form.test.tsx` 引用尚未导出的 `BusinessForm`/`validateBusinessForm` 等,与本次 loading 颜色调整无关) - [x] 3.10 运行 `rtk npm run typecheck`(之前曾因 `packages/ui/src/components/business-form.test.tsx` 引用未导出的 `BusinessForm`/`validateBusinessForm` 报错;本次复核已通过)
- [x] 3.11 运行 `rtk openspec validate fix-business-table-duplicate-total --strict` - [x] 3.11 运行 `rtk openspec validate fix-business-table-duplicate-total --strict`
# 第三阶段编辑页迁移到 BusinessForm 设计
## 范围选择
第三阶段延续前两阶段原则:页面外层业务结构保留,字段区域优先由 `BusinessForm` 承载。第二阶段已明确暂缓 `AgentDisplayConfigEditModal` 的图标和展示素材上传编排,本阶段只处理该弹窗,不扩大到官网方法论动态步骤。
## AgentDisplayConfigEditModal
迁移字段:
- `Agent 名称`:迁移为 `displayText` 或禁用 `input` 字段,继续只读展示当前 Agent 名称。
- `图标`:迁移为 `upload` 或 `custom` 字段承载,继续保留单图上传、删除、上传失败错误提示和帮助提示。
- `Agent 概述`:迁移为 `input` 字段,保留 placeholder、必填校验、最长 100 字校验、错误提示和字数长度展示。
- `展示素材`:迁移为 `upload` 或 `custom` 字段承载,继续保留图片/GIF/视频单文件上传、删除、上传失败错误提示和帮助提示。
- `展示排序`:迁移为 `numberInput` 字段,保留 0-99 整数校验和错误提示。
- `展示状态`:迁移为 `select` 字段,选项保持 `不展示` 和 `展示中`。
页面保留:
- `Dialog` 标题、footer 按钮、取消、保存、保存中禁用和关闭行为。
- 详情加载、加载中展示、页面级错误块和保存失败提示。
- 上传接口调用、`FormData` 字段、用途枚举、上传中状态和删除状态更新。
- 保存 payload 的字段名和值类型。
## 回退边界
- 如果 `BusinessForm` 标准 `upload` 字段无法完全表达当前 `MediaWall` 的展示素材预览或上传错误写入,使用 `custom` 字段包裹现有 `MediaWall`。
- 本阶段不扩展 `BusinessForm` API,不迁移动态数组,不改造弹窗外层状态机。
## 验证策略
- 先补充或调整弹窗测试,覆盖字段由 `BusinessForm` 承载、错误提示红色、普通帮助提示浅灰色和保存 payload 不变。
- 运行弹窗测试、官网展示配置编辑集成测试、`BusinessForm` 测试、类型检查、构建和 OpenSpec 校验。
- 浏览器验证按用户要求跳过。
# 第三阶段编辑页迁移到 BusinessForm
## 背景
第一阶段和第二阶段已完成多批编辑页字段迁移,后台仍有官网 Agent 展示配置编辑弹窗直接组合 TDesign `FormItem/Input/Select` 与上传墙。该弹窗字段结构稳定,且 `BusinessForm` 已具备 `input`、`select`、`numberInput`、`displayText`、`custom`、`upload` 等能力,适合作为第三阶段继续迁移。
## 目标
- 将 `AgentDisplayConfigEditModal` 的标准字段区域迁移为 `BusinessForm` 字段配置。
- 保持弹窗外壳、加载态、错误态、上传处理、校验文案、保存 payload、保存反馈和关闭行为不变。
- 保持普通帮助提示浅灰色、必填/校验错误红色。
- 不扩展 `BusinessForm` 公共 API;无法自然表达的内容使用 `custom` 回退。
## 非目标
- 不迁移官网方法论步骤动态数组、步骤图标上传、内容图上传和媒体预览/删除逻辑。
- 不迁移列表页、搜索区、表格或组件 Demo。
- 不重构 API、路由、状态管理或弹窗视觉框架。
## 影响范围
- `src/routes/official-site-agent-display-config/AgentDisplayConfigEditModal.tsx`
- `src/routes/official-site-agent-display-config/AgentDisplayConfigEditModal.test.tsx`
- 必要时调整 `OfficialSiteAgentDisplayConfigEdit.test.tsx`
- `editor-page-form-composition` 能力规范
## 风险
- 弹窗上传字段有独立上传中状态和错误写入逻辑,迁移时需要保留原有 `FormData`、用途枚举和删除语义。
- `BusinessForm` 上传字段与当前 `MediaWall` 展示结构可能不完全一致,必要时使用 `custom` 字段包裹现有上传节点,而不是扩展公共 API。
- 校验错误提示颜色不能因从 TDesign `FormItem tips` 切到 `BusinessForm` 后回退为普通提示色。
## ADDED Requirements
### Requirement: 第三阶段编辑弹窗应继续优先使用 BusinessForm 组合标准字段
系统 SHALL 在第三阶段迁移页面中使用 `BusinessForm` 承载可由其公共字段类型表达的编辑字段,并保留弹窗外层业务结构。
#### Scenario: 官网 Agent 展示配置编辑弹窗使用 BusinessForm
- **WHEN** 用户打开官网 Agent 展示配置编辑弹窗
- **THEN** `Agent 名称`、`图标`、`Agent 概述`、`展示素材`、`展示排序` 和 `展示状态` SHALL 由 `BusinessForm` 字段配置渲染
- **AND** `Agent 名称` SHALL 保持只读展示
- **AND** `图标` 与 `展示素材` SHALL 保持迁移前的上传、预览、删除、帮助提示和错误提示语义
- **AND** `Agent 概述` SHALL 保持必填校验和最长 100 字校验,并展示当前字数长度
- **AND** `展示排序` SHALL 保持 0-99 整数校验
### Requirement: 第三阶段迁移应保持弹窗业务行为不变
系统 SHALL 在第三阶段迁移到 `BusinessForm` 后保持弹窗业务行为、数据提交形态和用户反馈不变。
#### Scenario: 官网 Agent 展示配置保存行为保持一致
- **WHEN** 用户在迁移后的弹窗填写有效表单并保存
- **THEN** 页面 SHALL 调用迁移前相同的更新接口
- **AND** 提交 payload 的字段和值 SHALL 与迁移前等价
- **AND** 保存成功后的回调、关闭和列表刷新行为 SHALL 与迁移前等价
#### Scenario: 官网 Agent 展示配置校验和提示颜色保持一致
- **WHEN** 用户提交缺少必填项、排序不合法或上传缺失的表单
- **THEN** 弹窗 SHALL 展示与迁移前等价的校验反馈
- **AND** 必填/校验错误提示 SHALL 使用红色
- **AND** 普通上传帮助提示 SHALL 使用浅灰色
- **AND** 页面 SHALL NOT 调用更新接口
## 1. OpenSpec 对齐
- [x] 1.1 创建第三阶段 proposal/design/spec/tasks
- [x] 1.2 运行 `rtk openspec validate migrate-editor-pages-to-business-form-phase-three --strict`
- [x] 1.3 等待用户确认 OpenSpec 后进入实现
## 2. TDD 锁定行为
- [x] 2.1 补充或调整 `AgentDisplayConfigEditModal` 测试,覆盖字段由 `BusinessForm` 承载、上传帮助提示和错误提示颜色语义
- [x] 2.2 补充或调整官网 Agent 展示配置编辑集成测试,覆盖保存 payload 与弹窗关闭刷新行为不变
- [x] 2.3 运行相关测试,确认迁移目标有行为和结构边界保护
- [x] 2.4 调整官网 Agent 展示配置编辑集成测试,覆盖 `Agent 概述` 保持最长 100 字校验并展示字数长度
## 3. 弹窗迁移实现
- [x] 3.1 将 `AgentDisplayConfigEditModal` 字段区域迁移为 `BusinessForm`
- [x] 3.2 保留图标和展示素材上传、预览、删除、上传错误和普通帮助提示
- [x] 3.3 保留详情加载、页面级错误、保存请求、保存成功回调和取消关闭行为
- [x] 3.4 为 `Agent 概述` 补充字数长度展示,并保持最长 100 字校验不变
## 4. 验证
- [x] 4.1 运行 `rtk npm test -- --run src/routes/official-site-agent-display-config/AgentDisplayConfigEditModal.test.tsx src/routes/official-site-agent-display-config/OfficialSiteAgentDisplayConfigEdit.test.tsx`
- [x] 4.2 运行 `rtk npm test -- --run src/business-components/BusinessForm.test.tsx`
- [x] 4.3 运行 `rtk npm run typecheck`
- [x] 4.4 运行 `rtk npm run build`
- [x] 4.5 运行 `rtk openspec validate migrate-editor-pages-to-business-form-phase-three --strict`
- [x] 4.6 浏览器验证按用户要求跳过
- [x] 4.7 重新运行官网 Agent 展示配置编辑相关测试、类型检查、构建和 OpenSpec 校验
# 第二阶段编辑页迁移到 BusinessForm 设计
## 范围选择
第二阶段延续第一阶段原则:页面外层业务结构保留,字段区域优先由 `BusinessForm` 承载。`BusinessForm` 目前已支持 `input`、`textarea`、`select`、`numberInput`、`switch`、`displayText`、`custom`、`upload` 等字段类型,但本阶段不为个别页面扩展 API。
## AgentEditorPage
迁移字段:
- `Agent名称`:`input`,管家 Agent 下保持禁用。
- `所属岗位`:普通 Agent 使用 `select` 多选;管家 Agent 使用禁用 `input` 或展示字段显示 `系统调度`;岗位加载失败继续使用页面错误块。
- `托管企微员工`:普通 Agent 使用 `select`;管家 Agent 使用禁用 `input` 显示固定员工文案;员工加载失败继续使用页面错误块。
- `Agent描述`:`textarea`,保留最大长度和计数。
- `绑定Skill`:`select` 多选,管家 Agent 下保持非必填规则;Skill 加载失败继续使用页面错误块。
- `状态`:`switch`,管家 Agent 下保持启用且禁用。
页面保留:
- 详情、身份、岗位、员工、Skill 的加载和错误状态。
- 保存失败块、返回按钮、页面标题和保存按钮。
- 现有创建、编辑 payload 组装和保存后列表缓存更新。
## OfficialSiteMethodologyPage
迁移字段:
- `展示状态`:`switch`。
- `主标题`:`input`,保留 30 字限制和计数。
- `副标题`:`textarea`,保留 100 字限制和计数。
页面保留:
- 配置加载、保存提示和保存失败反馈。
- 方法论步骤动态列表。
- 步骤图标、内容图上传、预览、删除、校验和保存逻辑。
## 回退边界
- 选项加载失败重试块、动态步骤列表、上传预览和页面级提示可以继续用页面原结构实现。
- 如果某个字段需要多段业务节点或独立上传编排,使用 `custom` 或暂缓迁移,而不是扩展 `BusinessForm`。
## 验证策略
- 先补或调整页面测试,锁定必填校验、禁用态、选项联动、提交 payload 和上传保存不回归。
- 实现后运行相关页面测试、迁移依赖测试、`BusinessForm` 测试、类型检查、构建和 OpenSpec 校验。
- 浏览器验证按用户要求跳过。
# 第二阶段编辑页迁移到 BusinessForm
## 背景
第一批 `BusinessForm` 页面迁移已完成并验证通过,后台编辑页仍存在部分直接组合 TDesign `FormItem/Input/Select/Textarea/Switch` 的页面。需要继续把能由 `BusinessForm` 公共字段能力表达的字段迁入业务组件,同时保留复杂上传、动态列表和页面级错误块的现有实现。
## 目标
- 将 `AgentEditorPage` 的标准输入、选择、文本域和状态字段迁移为 `BusinessForm` 字段配置。
- 将 `OfficialSiteMethodologyPage` 顶部基础配置字段迁移为 `BusinessForm`,步骤动态列表和媒体上传保持页面原实现。
- 保持页面路由、加载态、错误态、校验文案、提交 payload、保存反馈和回跳行为不变。
- 不扩展 `BusinessForm` 公共 API;无法自然表达的内容使用 `custom` 回退或继续保留页面结构。
## 非目标
- 不迁移方法论步骤动态数组、步骤图标上传、内容图上传和媒体预览/删除逻辑。
- 不迁移 `AgentDisplayConfigEditModal` 的图标与展示素材上传编排;该弹窗留到后续阶段单独评估。
- 不重构 API、路由、状态管理或页面视觉框架。
## 影响范围
- `src/routes/agents/AgentEditorPage.tsx`
- `src/routes/official-site/OfficialSiteMethodologyPage.tsx`
- 两个页面的相关测试
- `editor-page-form-composition` 能力规范
## 风险
- `AgentEditorPage` 的岗位、员工、Skill 选项有加载失败重试块,迁移时需要通过 `custom` 保持原交互。
- 管家 Agent 的禁用字段和固定展示值不能因字段迁移丢失。
- 方法论页顶部基础配置和步骤列表共用同一份表单状态,迁移时不能破坏步骤上传保存链路。
## ADDED Requirements
### Requirement: 第二阶段编辑页应继续优先使用 BusinessForm 组合标准字段
系统 SHALL 在第二阶段迁移页面中使用 `BusinessForm` 承载可由其公共字段类型表达的编辑字段,并保留页面外层业务结构。
#### Scenario: Agent 编辑页使用 BusinessForm
- **WHEN** 用户进入 Agent 新增或编辑页
- **THEN** `Agent名称`、普通 Agent 的 `所属岗位`、普通 Agent 的 `托管企微员工`、`Agent描述`、`绑定Skill` 和 `状态` SHALL 由 `BusinessForm` 字段配置渲染
- **AND** 管家 Agent 的 `Agent名称`、`所属岗位`、`托管企微员工` 和 `状态` SHALL 保持迁移前的禁用或只读展示语义
- **AND** 岗位、员工或 Skill 选项加载失败时 SHALL 保持迁移前的错误提示和重试行为
#### Scenario: 官网方法论顶部基础配置使用 BusinessForm
- **WHEN** 用户进入官网方法论配置页
- **THEN** 顶部基础配置中的 `展示状态`、`主标题` 和 `副标题` SHALL 由 `BusinessForm` 字段配置渲染
- **AND** 方法论步骤动态列表、步骤图标上传、内容图上传、预览和删除 SHALL 保持页面原实现
### Requirement: 第二阶段迁移应保持页面业务行为不变
系统 SHALL 在第二阶段迁移到 `BusinessForm` 后保持页面业务行为、数据提交形态和用户反馈不变。
#### Scenario: Agent 保存行为保持一致
- **WHEN** 用户在迁移后的 Agent 页面填写有效表单并保存
- **THEN** 页面 SHALL 调用迁移前相同的创建或更新接口
- **AND** 提交 payload 的字段和值 SHALL 与迁移前等价
- **AND** 保存成功后的列表缓存更新和返回路径 SHALL 与迁移前等价
#### Scenario: 方法论保存行为保持一致
- **WHEN** 用户在迁移后的官网方法论配置页保存
- **THEN** 页面 SHALL 提交与迁移前等价的基础配置和步骤数据
- **AND** 上传、预览、删除和校验反馈 SHALL 与迁移前等价
#### Scenario: 第二阶段校验和错误状态保持一致
- **WHEN** 用户提交缺少必填项、长度超限或业务规则不合法的表单
- **THEN** 页面 SHALL 展示与迁移前等价的校验反馈
- **AND** 页面 SHALL NOT 调用创建或更新接口
## 1. OpenSpec 对齐
- [x] 1.1 创建第二阶段 proposal/design/spec/tasks
- [x] 1.2 运行 `rtk openspec validate migrate-editor-pages-to-business-form-phase-two --strict`
- [x] 1.3 等待用户确认 OpenSpec 后进入实现
## 2. TDD 锁定行为
- [x] 2.1 补充或调整 `AgentEditorPage` 测试,覆盖标准字段由 `BusinessForm` 承载、管家 Agent 禁用态、选项加载错误回退和保存 payload
- [x] 2.2 补充或调整 `OfficialSiteMethodologyPage` 测试,覆盖顶部基础配置由 `BusinessForm` 承载、标题校验、状态切换和步骤上传保存不回归
- [x] 2.3 运行相关测试,确认迁移目标有行为和结构边界保护
## 3. 页面迁移实现
- [x] 3.1 将 `AgentEditorPage` 可标准表达字段迁移为 `BusinessForm`
- [x] 3.2 保留 `AgentEditorPage` 选项加载失败块、管家 Agent 特殊展示和保存流程
- [x] 3.3 将 `OfficialSiteMethodologyPage` 顶部基础配置迁移为 `BusinessForm`
- [x] 3.4 保留方法论步骤动态列表、上传和预览删除逻辑
## 4. 验证
- [x] 4.1 运行 `rtk npm test -- --run src/routes/agents/AgentEditorFlow.test.tsx src/routes/official-site/OfficialSiteMethodologyPage.test.tsx src/routes/official-site/OfficialSiteMethodologyUploadSave.test.tsx`
- [x] 4.2 运行 `rtk npm test -- --run src/migrations/phase-five-editor-page-runtime-dependencies.test.ts src/business-components/BusinessForm.test.tsx`
- [x] 4.3 运行 `rtk npm run typecheck`
- [x] 4.4 运行 `rtk npm run build`
- [x] 4.5 运行 `rtk openspec validate migrate-editor-pages-to-business-form-phase-two --strict`
- [x] 4.6 浏览器验证按用户要求跳过
## Context
官网 Agent 展示配置页已经完成,当前需要对两个面向运营的细节进行对齐:`展示状态` 的 `disable` 文案需要从 `已下架` 改为 `不展示`,以及 `展示排序` 要明确不接受小于 `0` 的值。这个 change 调整编辑弹窗和列表页的前端展示口径,不改变后端枚举值。
## Goals / Non-Goals
**Goals:**
- 让编辑弹窗中的 `展示状态` 直接使用更贴近业务语义的 `不展示` 文案。
- 让列表页 `展示状态` 列同步使用 `不展示` 文案,避免同一字段在列表和编辑态口径不一致。
- 保持 `disable` 这个内部值不变,只改编辑态的呈现与默认选项。
- 让 `展示排序` 的校验明确覆盖小于 `0` 的输入,并在前端阻止提交。
- 让 `BusinessForm` 中由 `errors[field.key]` 产生的必填/校验错误提示使用红色,普通 `helpText`/`helperText` 说明使用浅灰色。
- 确认官网 Agent 展示配置编辑弹窗字段区已由 `BusinessForm` 承载,错误提示和普通说明复用 `BusinessForm` 的颜色语义,不再为弹窗内直接 TDesign `FormItem` 追加独立修复。
- 同步补齐测试,避免后续回归。
**Non-Goals:**
- 不修改接口枚举、保存 payload 或后端约定。
- 不扩展到其他官网配置页面。
## Decisions
### 1. 编辑弹窗和列表页统一 `disable` 的展示文案
编辑弹窗中把 `disable` 的标签改成 `不展示`,列表页的 `展示状态` 列也把可展示 Agent 的 `disable` 状态展示为 `不展示`,但内部值仍使用 `disable`。
**理由:** 这样能避免后端和页面状态语义分裂,也能让同一字段在列表和编辑态保持同一业务词。
**Alternatives considered:**
把后端枚举或接口字段一起改成新值。这个范围会影响保存契约和既有数据兼容,当前只需要前端展示口径调整。
### 2. 默认值保持 `disable`
未配置时仍默认选中 `disable`,只是界面上显示为 `不展示`。
**理由:** 默认语义没有变化,仍然表示“暂不对外展示”;改变默认内部值会引入不必要的保存语义变化。
**Alternatives considered:**
把默认值改成新枚举或空值。这样会破坏现有保存契约,也不利于和既有数据兼容。
### 3. `展示排序` 维持整数区间校验,明确下限为 `0`
继续使用前端字段校验拦截非法输入,并把 `0` 作为合法下限。
**理由:** 这符合当前页面已有的排序语义,也能最小化实现和测试改动。
**Alternatives considered:**
引入额外的格式化组件或后端再校验一层。当前范围里不需要新增复杂度。
### 4. `BusinessForm` 区分错误提示与普通提示颜色
`BusinessForm` 继续分别渲染字段错误和普通帮助提示:`errors[field.key]` 以及内置校验产生的错误提示使用错误态红色;`helpText`/`helperText` 这类非错误说明使用浅灰色。
**理由:** 必填错误需要被用户立即感知,普通说明只是辅助阅读,二者颜色语义应当清晰分离。
**Alternatives considered:**
完全交给 TDesign `FormItem` 的 `help`/`status` 渲染。当前组件已经封装了自有布局与帮助文案位置,直接固定组件样式能最小化页面迁移成本。
### 5. 编辑弹窗复用 `BusinessForm` 提示颜色语义
官网 Agent 展示配置编辑弹窗字段区已迁移到 `BusinessForm`,不再直接维护 TDesign `FormItem` 的字段 `help`/`tips` 渲染。图标、Agent 概述、展示素材、展示排序、展示状态等字段统一通过 `BusinessForm` 渲染,因此字段错误提示使用红色、普通说明使用浅灰色的规则由 `BusinessForm` 统一保证。
**理由:** 颜色问题来自旧实现中弹窗字段直接组合 TDesign `FormItem`,在字段区迁移到 `BusinessForm` 后,弹窗已经不再拥有独立的 `FormItem` 提示渲染路径。继续在弹窗层补丁会制造重复规则,统一复用 `BusinessForm` 更稳。
**Alternatives considered:**
继续在弹窗层为 TDesign `FormItem` 做显式错误包裹。该方案已不适用于当前代码,因为弹窗字段区已经迁移到 `BusinessForm`。
## Risks / Trade-offs
- `[Risk]` 编辑页与列表页对同一枚举值的文案不同。
`[Mitigation]` 同步更新列表页状态列,让 `disable` 在前端都展示为 `不展示`。
- `[Risk]` 规则描述容易和“已下架”旧口径混淆。
`[Mitigation]` 在 spec 和测试里同时固定默认值、选项文案和列表文案,保证代码和文档一致。
## Migration Plan
1. 更新编辑弹窗的 `display_status` 选项文案与默认选中态。
2. 更新列表页的 `display_status` 展示文案。
3. 保持 `sort_order` 校验下限为 `0`,补齐相关测试。
4. 更新 `BusinessForm` 字段提示样式,确保错误提示为红色、普通帮助提示为浅灰色。
5. 确认官网 Agent 展示配置编辑弹窗字段区复用 `BusinessForm`,无需保留独立 TDesign `FormItem` 颜色修复。
6. 运行类型检查、单测和构建验证。
7. 校验 OpenSpec 后再归档。
## Open Questions
- 暂无。当前变更只涉及前端文案与校验,不需要额外产品确认。
## Why
官网 Agent 展示配置中,`展示排序` 和 `展示状态` 的文案与默认值需要和当前业务口径对齐。现在 `display_status = disable` 在编辑态和列表态仍可能显示为 `已下架`,容易让运营把“是否展示”理解成别的状态词;同时 `展示排序` 需要明确禁止小于 `0` 的输入,避免出现不合法的展示顺序。
## What Changes
- 将官网 Agent 展示配置编辑弹窗中的 `展示状态` 选项文案从 `已下架` 调整为 `不展示`。
- 保持 `display_status = disable` 的语义不变,但编辑弹窗默认值改为 `不展示`。
- 将官网 Agent 展示配置列表中的 `display_status = disable` 展示文案同步调整为 `不展示`。
- 明确 `展示排序` 不允许小于 `0`,并保持提交校验拦截非法输入。
- 统一 `BusinessForm` 的提示颜色语义:必填/校验错误使用红色,普通帮助提示使用浅灰色。
- 确认官网 Agent 展示配置编辑弹窗字段区已由 `BusinessForm` 承载,字段提示颜色语义复用 `BusinessForm` 的错误红色与普通说明浅灰色规则。
- 同步更新相关测试,确保编辑态字段文案、默认值、列表态展示文案、校验规则和表单提示颜色一致。
## Capabilities
### New Capabilities
- `official-site-agent-display-config-sort-status`: 官网 Agent 展示配置编辑弹窗和列表页中排序校验与展示状态文案/默认值规则。
- `business-form-validation-hint-style`: `BusinessForm` 必填/校验错误与普通帮助提示的颜色语义。
### Modified Capabilities
- `official-site-agent-display-config`: 编辑弹窗和列表页的展示状态文案与排序校验细则发生变化。
## Impact
- 影响 `workspace/agent-admin/web/src/routes/official-site-agent-display-config/AgentDisplayConfigEditModal.tsx` 的表单字段文案、默认值和校验逻辑。
- 影响 `AgentDisplayConfigEditModal.tsx` 的字段承载方式判断:字段区已迁移到 `BusinessForm`,不再需要为弹窗内直接 TDesign `FormItem` 追加独立颜色修复。
- 影响 `workspace/agent-admin/web/src/routes/official-site-agent-display-config/OfficialSiteAgentDisplayConfigPage.tsx` 的列表状态展示文案。
- 影响 `packages/business-components/src/business-form/BusinessForm.tsx` 和 `BusinessForm.module.css` 的提示渲染与颜色样式。
- 影响对应测试用例对 `展示状态` 选项、默认值、列表状态列和 `展示排序` 校验的断言。
- 不涉及后端接口、保存 payload 或接口枚举值调整。
## ADDED Requirements
### Requirement: 官网 Agent 展示配置编辑弹窗的展示状态文案
Agent 展示配置编辑弹窗 SHALL 在 `展示状态` 字段中使用更贴近业务的文案,并保持内部状态值不变。
#### Scenario: 展示状态选项文案
- **WHEN** 用户打开官网 Agent 展示配置编辑弹窗
- **THEN** `display_status = disable` 的选项文案展示为 `不展示`
- **AND** `display_status = enable` 的选项文案继续展示为 `展示中`
#### Scenario: 默认展示状态
- **WHEN** 用户首次打开未配置的官网 Agent 展示配置编辑弹窗
- **THEN** `展示状态` 默认选中 `不展示`
- **AND** 页面提交时仍使用 `disable` 作为内部值
### Requirement: 官网 Agent 展示配置列表的展示状态文案
Agent 展示配置列表 SHALL 在 `展示状态` 列中使用和编辑弹窗一致的 `display_status` 展示文案,并保持内部状态值不变。
#### Scenario: 列表展示状态文案
- **WHEN** 用户查看官网 Agent 展示配置列表
- **AND** 某条可展示 Agent 记录的 `display_status = disable`
- **THEN** 该记录的 `展示状态` 列展示为 `不展示`
- **AND** `display_status = enable` 的记录继续展示为 `展示中`
### Requirement: 官网 Agent 展示配置编辑弹窗的展示排序校验
Agent 展示配置编辑弹窗 SHALL 阻止小于 `0` 的 `展示排序` 输入被提交。
#### Scenario: 展示排序下限校验
- **WHEN** 用户提交小于 `0` 的 `展示排序`
- **THEN** 页面在 `展示排序` 字段附近展示校验错误
- **AND** 页面不提交保存
#### Scenario: 展示排序合法范围
- **WHEN** 用户提交 `0` 或更大的整数 `展示排序`
- **THEN** 页面允许继续保存流程
### Requirement: BusinessForm 字段提示颜色语义
`BusinessForm` SHALL 区分字段错误提示与普通帮助提示的颜色语义。
#### Scenario: 必填或校验错误使用红色
- **WHEN** 字段存在 `errors[field.key]` 或内置校验产生的错误提示
- **THEN** `BusinessForm` 在字段下方展示错误提示
- **AND** 错误提示使用错误态红色
#### Scenario: 普通帮助提示使用浅灰色
- **WHEN** 字段配置了 `helpText` 或 `helperText`
- **AND** 该提示不是校验错误
- **THEN** `BusinessForm` 在字段下方展示普通帮助提示
- **AND** 普通帮助提示使用浅灰色
### Requirement: 官网 Agent 展示配置编辑弹窗字段提示颜色语义
官网 Agent 展示配置编辑弹窗 SHALL 通过 `BusinessForm` 承载字段区,并复用 `BusinessForm` 的字段错误提示与普通帮助说明颜色语义。
#### Scenario: 编辑弹窗校验错误使用红色
- **WHEN** 用户在官网 Agent 展示配置编辑弹窗提交缺失必填项或非法 `展示排序`
- **THEN** 页面在对应字段附近展示校验错误
- **AND** 校验错误使用错误态红色
- **AND** 错误提示由 `BusinessForm` 字段错误渲染路径承载
#### Scenario: 编辑弹窗普通说明使用浅灰色
- **WHEN** 官网 Agent 展示配置编辑弹窗展示图标或展示素材的上传说明
- **THEN** 普通上传说明使用浅灰色
- **AND** 普通上传说明不使用错误态红色
- **AND** 普通说明由 `BusinessForm` `helperText` 或 `helpText` 渲染路径承载
## 1. 编辑弹窗规则调整
- [x] 1.1 更新官网 Agent 展示配置编辑弹窗中 `展示状态` 的选项文案,将 `disable` 映射为 `不展示`
- [x] 1.2 保持 `展示状态` 默认值为 `disable`,并确保首次打开时显示为 `不展示`
- [x] 1.3 确认并固定 `展示排序` 的下限校验为 `0`
- [x] 1.4 更新官网 Agent 展示配置列表中 `展示状态` 列文案,将 `disable` 映射为 `不展示`
## 2. 测试与验证
- [x] 2.1 更新编辑弹窗相关测试,覆盖 `不展示` 文案、默认值和排序下限校验
- [x] 2.2 更新列表页相关测试,覆盖 `展示状态` 列的 `不展示` 文案
- [x] 2.3 更新 `BusinessForm` 相关测试,覆盖错误提示和普通帮助提示的颜色语义
- [x] 2.4 调整 `BusinessForm` 提示样式,确保必填/校验错误为红色、普通提示为浅灰色
- [x] 2.5 确认官网 Agent 展示配置编辑弹窗字段区已由 `BusinessForm` 承载,不再存在需要单独修复的直接 TDesign `FormItem` 提示渲染路径
- [x] 2.6 确认编辑弹窗字段提示颜色复用 `BusinessForm`:校验错误为红色、普通说明为浅灰色
- [x] 2.7 运行类型检查、单元测试和构建验证
- [x] 2.8 运行 `openspec validate "official-site-agent-display-config-sort-status" --strict`
## Context
`BusinessTable` 已经使用 TDesign `Table`、`Pagination`、`Empty` 和 `Button` 承接核心表格能力。当前需要补齐的 TDesign-first 收敛点集中在无分页场景的 `totalLabel` 文本表达、普通文本单元格按需开启的溢出展示,以及必要布局容器的保留边界。
`BusinessForm` 已具备 TDesign `Input` / `Textarea` 的 `maxLength` 和字数展示能力。当前用户确认“超过字段长度,应该不能再输入”,因此默认输入行为应回到硬限制:保留字数显示,但输入值不超过配置的最大长度。
## Goals / Non-Goals
**Goals:**
- 让 `BusinessTable` 无分页 `totalLabel` 使用 TDesign 文本组件或等价能力展示。
- 让 `BusinessTable` 默认不增加普通文本 Tooltip;当列配置显式要求时,普通文本单元格在内容超长时单行省略,悬浮后展示完整内容,提示宽度为 200px 且内容换行。
- 将已确认的业务长文本列迁移为显式开启 tooltip:技能列表“说明”、官网 Agent 展示配置列表“Agent 概述”、岗位标签列表“标签描述”、渠道活码列表“关联 Agent”。
- 明确 `BusinessTable` 的表格、分页、空态、按钮和统计文本优先使用 TDesign。
- 明确根容器、空态居中容器和 footer 对齐容器可继续使用必要原生结构与 CSS module。
- 让 `BusinessForm` 的 `input` / `textarea` 在配置 `maxLength` 后默认不能继续输入超长内容,同时保留 TDesign 字数统计。
- 保持分页、空态、错误态、footer 对齐和总数展示行为不变。
**Non-Goals:**
- 不改变既有 `BusinessTable` 调用语义;仅新增列级显式配置能力。
- 不改变 `BusinessForm` 公开 API。
- 不重构分页协议或 TDesign `Pagination` 的默认总数能力。
- 不为了删除所有原生节点而重写表格布局。
- 不为没有长文本诉求的表格列批量开启 Tooltip。
## Decisions
### 只收敛统计文本,不重构表格布局
无分页 `totalLabel` 属于纯文本语义,适合迁移到 TDesign `Typography.Text` 或等价 TDesign 文本能力。分页场景仍由 TDesign `Pagination` 默认总数展示承接,不在 `Pagination` 外额外渲染重复统计文本。
备选方案是引入 TDesign `Space`、`Row/Col` 等布局组件替换 footer 所有原生容器。该方案收益有限,并可能影响分页右对齐、空态视觉位置和已有 CSS 约束,因此不采用。
### 保留必要布局容器
表格根容器、空态居中容器和 footer 对齐容器属于业务组件组合布局,不是 TDesign 的语义控件缺口。它们可以继续使用原生结构与 CSS module,以维持现有布局密度、居中位置和响应式约束。
### 继续复用已有 TDesign 语义组件
表格主体、分页、空态和恢复操作按钮继续分别使用 TDesign `Table`、`Pagination`、`Empty` 和 `Button`。本 change 不引入新的组件库或封装层。
### 普通文本列按需开启省略与悬浮提示
`BusinessTable` 默认不为普通文本列增加 `Tooltip`,避免所有文本列在悬浮时都出现提示。需要完整内容悬浮展示的列必须显式开启列级配置。开启后,单元格可见内容单行省略,鼠标悬浮时使用 TDesign `Tooltip` 展示完整文本。Tooltip 内容宽度固定为 200px,并允许按内容自然换行。
显式开启 tooltip 的列仍需区分真实内容和空值。取值为空、只包含空白字符或最终展示为占位文案 `-` 时,单元格只展示 `-`,不渲染 TDesign `Tooltip`。这样可以避免空描述、空概述、空关联内容在悬浮时出现没有业务意义的提示层。
如果列已经提供自定义 `cell`,说明页面需要自定义按钮、状态标签、图片、组合内容或特殊交互,`BusinessTable` 不强行改写该列,避免破坏已有业务渲染。
对于业务列的数据源不是直接字符串字段的场景,列配置可以提供显式 tooltip 文本取值函数,由 `BusinessTable` 统一完成可见文本、省略样式和 TDesign `Tooltip` 渲染。页面不应为了普通长文本悬浮提示在业务列里重复手写 TDesign `Tooltip`。
本次确认接入的页面列如下:
- `SkillListPage`:`说明` / `description`
- `OfficialSiteAgentDisplayConfigPage`:`Agent 概述` / `speech_content`
- `AgentTagListPage`:`标签描述` / `description`
- `ChannelCodeListPage`:`关联 Agent` / `agent_names_preview`,展示值由数组拼接为普通文本
### 最大长度默认硬限制
`BusinessForm` 的 `input` 和 `textarea` 在配置 `maxLength` 时默认不允许继续输入超过最大长度的内容。组件继续传递 TDesign 的字数统计能力,用户可看到当前输入长度和最大长度;由于值不会超过最大长度,页面侧不需要再依赖“超长后保存校验”来阻止提交。
现有 `allowInputOverMax` 不作为页面常规配置继续使用。为了兼容历史类型,字段类型可暂时保留该属性,但组件默认行为以硬限制为准;已迁移页面应移除显式 `allowInputOverMax: true`。
## Risks / Trade-offs
- [Risk] 文本组件替换后总数样式或 DOM 查询变化影响测试 → 更新测试以断言用户可见行为和 TDesign 文本语义。
- [Risk] 页面误以为普通文本列会默认出现 Tooltip → 将行为定义为默认不启用,只有显式列配置才启用,并在已确认的业务长文本列逐列接入。
- [Risk] 长文本列原先使用自定义 `cell` 展示空值或派生文本 → 支持显式 tooltip 文本取值函数,页面改为配置数据来源而不是手写 Tooltip。
- [Risk] 去掉超长输入后原先依赖超长校验的测试失效 → 更新测试为“不能继续输入,仍展示最大长度计数”。
- [Risk] 误删必要布局容器导致空态或分页对齐回退 → 保留 CSS module 布局职责,并用测试/浏览器验证覆盖。
- [Risk] 分页场景再次出现重复总数 → 保持 `totalLabel` 只服务无分页场景,分页总数由 `Pagination` 承接。
## Migration Plan
1. 补充 `BusinessTable` 无分页 `totalLabel` 和分页总数回归测试。
2. 补充 `BusinessTable` 默认不展示 Tooltip、显式开启后展示 Tooltip 的测试。
3. 补充 `BusinessTable` tooltip 文本取值函数测试,覆盖数组或派生文本列。
4. 补充 `BusinessForm` 最大长度硬限制和字数展示测试。
5. 将无分页 `totalLabel` 渲染迁移到 TDesign `Typography.Text` 或等价文本组件。
6. 在 `BusinessTable` 内部仅对显式开启 tooltip 且无自定义 `cell` 的列使用单行省略和 TDesign Tooltip。
7. 为技能说明、Agent 概述、岗位标签描述、渠道活码关联 Agent 接入显式 tooltip 配置。
8. 调整 `BusinessForm` 输入字段配置和已迁移页面,移除常规 `allowInputOverMax: true`。
9. 保留必要布局容器,确认空态居中、footer 对齐和分页布局不变。
10. 运行类型检查、相关组件测试、构建和 OpenSpec 严格校验。
11. 如 Demo 视觉区域发生变化,在浏览器验证 `/components` 的表格展示;若用户明确免除浏览器验证,则记录跳过原因。
## Open Questions
- 无待确认问题。用户已确认“能用 TDesign 就用 TDesign,实现不了或不适合实现的用原生”的收敛方向。
## Why
`BusinessTable` 已经以 TDesign 为主要控件来源,但无分页统计文本、普通文本列按需溢出展示和必要布局边界还没有形成明确规格。需要把“能用 TDesign 就用 TDesign”的原则落到已归档的 `business-table` 能力上,同时避免默认给所有普通文本列增加悬浮提示。
`BusinessForm` 已经归档为公共能力。当前字段长度展示已使用 TDesign 字数能力,但默认仍可能通过 `allowInputOverMax` 允许超长输入后再校验。用户确认超出字段长度时不应继续输入,需要把该规则沉淀到 `business-form` 能力中。
## What Changes
- 对 `BusinessTable` 的无分页总数文案使用 TDesign 文本组件表达,表格、分页、空态和按钮继续使用已有 TDesign 组件。
- `BusinessTable` 默认不为普通文本单元格增加 Tooltip;需要完整内容悬浮展示的列,必须由列配置显式开启,并通过 TDesign `Tooltip` 展示完整内容,提示宽度为 200px 且内容换行。
- 为已确认的业务长文本列显式开启 `BusinessTable` tooltip:技能列表“说明”、官网 Agent 展示配置列表“Agent 概述”、岗位标签列表“标签描述”、渠道活码列表“关联 Agent”。
- 明确 `BusinessTable` 中根容器、空态居中容器和 footer 布局容器可保留必要原生结构。
- 对 `BusinessForm` 的 `input` 和 `textarea` 字段默认执行最大长度输入限制;保留 TDesign 字数显示,字段值不再超过 `maxLength`。
- 通过测试约束迁移后的行为保持不变,尤其是分页总数、无分页统计文本和空态布局。
## Capabilities
### New Capabilities
- 无。
### Modified Capabilities
- `business-table`:补充无分页总数文案的 TDesign-first 展示要求,补充普通文本列显式开启省略与悬浮提示的规则,并明确表格必要布局容器可保留原生实现。
- 业务页面列表:为技能说明、Agent 概述、岗位标签描述、渠道活码关联 Agent 等长文本列接入显式 tooltip 配置。
- `business-form`:补充字段最大长度的默认输入限制规则,并保留 TDesign 字数统计。
## Impact
- 影响 `packages/business-components/src/business-table/BusinessTable.tsx` 的无分页总数文案渲染。
- 影响 `packages/business-components/src/business-table/BusinessTable.tsx` 的普通文本单元格显式 tooltip 渲染配置。
- 影响技能列表、官网 Agent 展示配置列表、岗位标签列表和渠道活码列表中的长文本列展示配置。
- 影响 `packages/business-components/src/business-form/BusinessForm.tsx` 的 `input` / `textarea` 最大长度输入行为。
- 影响业务组件测试与组件 Demo 的视觉/行为回归验证。
- 不改变业务组件公开 API、分页协议或现有页面数据结构。
## MODIFIED Requirements
### Requirement: BusinessForm supports text input limits and TDesign counts
系统 MUST 让 `input` 和 `textarea` 支持 `maxLength`,并优先复用 `tdesign-react` 已有的长度展示能力和对应 API,而不是页面侧自绘计数逻辑。配置最大长度后,字段默认 SHALL NOT 继续输入超过最大长度的内容。
#### Scenario: Input count and max length hard limit
- **WHEN** `input` 字段配置 `maxLength`
- **THEN** 输入框 SHALL 展示 TDesign 提供的字数统计能力
- **AND** 用户输入达到最大长度后 SHALL NOT 继续写入更多字符
- **AND** 表单值 SHALL NOT 超过该 `maxLength`
#### Scenario: Textarea count and max length hard limit
- **WHEN** `textarea` 字段配置 `maxLength`
- **THEN** 文本域 SHALL 展示 TDesign 提供的字数统计能力
- **AND** 用户输入达到最大长度后 SHALL NOT 继续写入更多字符
- **AND** 表单值 SHALL NOT 超过该 `maxLength`
## MODIFIED Requirements
### Requirement: 可选分页和总数展示
系统 SHALL 支持在业务表格底部渲染可选分页或总数信息;分页场景 SHALL 由 TDesign `Pagination` 展示总数,无分页场景 SHALL 使用 TDesign 文本组件展示 `totalLabel`。
#### Scenario: 渲染分页
- **WHEN** 页面传入分页配置
- **THEN** 系统 SHALL 使用 TDesign `Pagination` 渲染当前页、页大小、总数和分页回调
#### Scenario: 禁用分页
- **WHEN** 页面传入 `pagination={false}`
- **THEN** 系统 SHALL NOT 渲染分页组件
#### Scenario: 展示总数文案
- **WHEN** 页面传入 `totalLabel`
- **THEN** 系统 SHALL 在表格底部使用 TDesign `Typography.Text` 或等价 TDesign 文本组件展示该总数文案
## ADDED Requirements
### Requirement: BusinessTable follows TDesign-first composition boundaries
系统 SHALL 在 `BusinessTable` 中优先使用 TDesign 组件表达表格、分页、空态、按钮和文本语义,并允许保留必要原生结构承载组件布局。
#### Scenario: Table semantic parts use TDesign
- **WHEN** `BusinessTable` 渲染表格、分页、空态、恢复操作或总数文本
- **THEN** 系统 SHALL 分别使用 TDesign `Table`、`Pagination`、`Empty`、`Button` 和 TDesign 文本组件或其等价能力
#### Scenario: Necessary layout containers remain native
- **WHEN** `BusinessTable` 需要根容器、空态居中容器或 footer 对齐容器
- **THEN** 系统 MAY 使用原生结构和 CSS module 承载布局
- **AND** 系统 SHALL NOT 为了替换布局容器而引入影响表格对齐、分页位置或空态视觉位置的额外组件层级
### Requirement: BusinessTable uses tooltip for text cells only when explicitly enabled
系统 SHALL 默认不为 `BusinessTable` 的普通文本单元格增加悬浮提示;当列配置显式开启普通文本悬浮提示时,系统 SHALL 使用单行省略展示超长内容,并在鼠标悬浮时通过 TDesign `Tooltip` 展示完整内容。
#### Scenario: Plain text cell does not opt in
- **WHEN** 列配置没有显式开启普通文本悬浮提示
- **THEN** 系统 SHALL NOT 默认为该单元格增加 TDesign `Tooltip`
#### Scenario: Text cell opts in to tooltip
- **WHEN** 列配置显式开启普通文本悬浮提示
- **AND** 列配置没有提供自定义 `cell`
- **AND** 单元格值为普通文本、数字、布尔值或由列配置显式提供的普通文本
- **THEN** 表格可见内容 SHALL 使用单行省略样式展示
- **AND** 鼠标悬浮该单元格内容时 SHALL 使用 TDesign `Tooltip` 展示完整内容
- **AND** Tooltip 宽度 SHALL 为 200px
- **AND** Tooltip 内容 SHALL 允许换行展示
#### Scenario: Empty text cell does not show tooltip
- **WHEN** 列配置显式开启普通文本悬浮提示
- **AND** 列配置没有提供自定义 `cell`
- **AND** 单元格取值为空、只包含空白字符或解析后为占位文案 `-`
- **THEN** 表格 SHALL 仅展示占位文案 `-`
- **AND** 系统 SHALL NOT 为该单元格渲染 TDesign `Tooltip`
#### Scenario: Text cell uses explicit tooltip value
- **WHEN** 列配置显式开启普通文本悬浮提示
- **AND** 列配置提供普通文本取值函数
- **THEN** 系统 SHALL 使用该取值函数结果作为单元格可见文本和 Tooltip 内容
- **AND** 页面 SHALL NOT 需要在业务列中手写 TDesign `Tooltip`
#### Scenario: Custom cell keeps page rendering
- **WHEN** 列配置已经提供自定义 `cell`
- **THEN** `BusinessTable` SHALL NOT 覆盖该列的单元格渲染
- **AND** 页面自定义的按钮、状态、图片或组合内容 SHALL 保持原样
### Requirement: Business long text columns opt in to tooltip
系统 SHALL 为已确认的业务长文本列表列显式开启 `BusinessTable` tooltip,以便文本超过列宽时单行省略并可悬浮查看完整内容。
#### Scenario: Confirmed business long text columns use explicit tooltip
- **WHEN** 技能列表渲染“说明”列
- **OR** 官网 Agent 展示配置列表渲染“Agent 概述”列
- **OR** 岗位标签列表渲染“标签描述”列
- **OR** 渠道活码列表渲染“关联 Agent”列
- **THEN** 对应列 SHALL 通过 `BusinessTable` 显式开启 TDesign Tooltip
- **AND** Tooltip 展示 SHALL 复用 `BusinessTable` 的 200px 宽度和换行规则
## 1. 测试优先
- [x] 1.1 为 `BusinessTable` 无分页 `totalLabel` 增加测试,断言总数文案通过 TDesign 文本能力展示
- [x] 1.2 为分页场景增加回归测试,断言 `Pagination` 继续负责总数展示且不额外渲染重复 `totalLabel`
- [x] 1.3 为必要布局容器保留增加回归覆盖,断言空态居中、footer 对齐和分页布局不回退
- [x] 1.4 为 `BusinessTable` 普通文本列增加测试,覆盖默认不展示 Tooltip、显式开启后单行省略、TDesign Tooltip、200px 悬浮宽度和换行展示
- [x] 1.6 为 `BusinessTable` 增加显式 tooltip 文本取值函数测试,覆盖派生文本或数组拼接文本
- [x] 1.7 为 `BusinessTable` 增加空值 tooltip 回归测试,覆盖空字符串、空白字符串和占位文案 `-` 仅展示占位且不渲染 Tooltip
- [x] 1.5 为 `BusinessForm` 增加测试,覆盖 `input` / `textarea` 达到 `maxLength` 后不能继续输入且仍展示字数长度
## 2. 组件实现
- [x] 2.1 将 `BusinessTable` 无分页 `totalLabel` 渲染收敛到 TDesign `Typography.Text` 或等价文本组件
- [x] 2.2 保留 `BusinessTable` 根容器、空态居中容器和 footer 对齐容器的必要原生结构与 CSS module
- [x] 2.3 确认表格、分页、空态、恢复操作按钮继续分别使用 TDesign `Table`、`Pagination`、`Empty` 和 `Button`
- [x] 2.4 在 `BusinessTable` 中仅为显式开启 tooltip 且无自定义 `cell` 的普通文本列提供省略和 TDesign Tooltip 包装
- [x] 2.8 调整 `BusinessTable` tooltip 包装逻辑,空值、空白值和占位 `-` 仅展示占位文本,不渲染 TDesign Tooltip
- [x] 2.7 为技能列表“说明”、官网 Agent 展示配置列表“Agent 概述”、岗位标签列表“标签描述”、渠道活码列表“关联 Agent”显式开启 `BusinessTable` tooltip
- [x] 2.5 调整 `BusinessForm` 的 `input` / `textarea` 最大长度处理,配置 `maxLength` 后默认不允许继续输入超长内容
- [x] 2.6 清理已迁移页面中的常规 `allowInputOverMax: true` 配置,保持页面值不超过最大长度
## 3. Demo 与验证
- [x] 3.1 检查 `/components` 中 `BusinessTable` 示例的分页和无分页总数展示,不引入重复总数
- [x] 3.2 运行 `npm run typecheck`
- [x] 3.3 运行相关 `BusinessTable` 和 `BusinessForm` 组件测试
- [x] 3.4 运行 `npm run build`
- [x] 3.5 运行 `openspec validate "refine-business-components-tdesign-first" --strict`
- [x] 3.7 重新运行 `BusinessTable` 相关测试、`npm run typecheck`、`npm run build` 和 OpenSpec 严格校验
- [x] 3.6 如 Demo 视觉区域发生变化,在浏览器验证 `/components` 的表格展示、空态位置和分页布局;若用户明确要求不用浏览器验证,则记录跳过原因:用户已明确要求“不用验证浏览器”,本次跳过浏览器验证。
# admin-ui-runtime-dependency Specification
## Purpose
TBD - created by archiving change migrate-admin-ui-to-global-tdesign. Update Purpose after archive.
## Requirements
### Requirement: 后台运行时代码不再依赖本地 UI 包
系统 MUST 让 `workspace/agent-admin/web/src` 中的运行时代码不再从 `workspace/agent-admin/web/packages/ui` 或其子路径引入组件、类型或工具。
#### Scenario: 扫描后台运行时 import
- **WHEN** 对 `workspace/agent-admin/web/src` 执行本地 UI 包依赖扫描
- **THEN** 扫描结果不包含指向 `packages/ui` 或 `packages/ui/src` 的运行时 import
### Requirement: 基础控件直接使用 TDesign
后台页面、布局、Hook 和组件 Demo MUST 直接使用 `tdesign-react` 提供的基础控件,并在需要图标时直接使用 `tdesign-icons-react`。
#### Scenario: 页面使用基础控件
- **WHEN** 后台页面渲染按钮、输入框、文本域、选择器、开关、表格、分页、弹窗、抽屉、标签或消息反馈
- **THEN** 对应基础能力来自 `tdesign-react`
#### Scenario: 页面使用图标
- **WHEN** 后台页面或组件 Demo 需要渲染 TDesign 已提供的图标
- **THEN** 图标来自 `tdesign-icons-react`
### Requirement: 业务组合组件通过全局组件包复用
系统 MUST 将 `SearchFilter`、`StatePlaceholder`、`MediaWall` 作为全局业务组合组件从 `@gl/business-components` 导出,并且这些组件内部 MUST 不依赖 `workspace/agent-admin/web/packages/ui`。
#### Scenario: 列表页复用搜索区
- **WHEN** 后台列表页渲染查询条件、查询按钮和重置按钮
- **THEN** 页面从 `@gl/business-components` 使用 `SearchFilter`
#### Scenario: 页面复用状态占位
- **WHEN** 后台页面展示加载态、空数据态或错误态
- **THEN** 页面从 `@gl/business-components` 使用 `StatePlaceholder`
#### Scenario: 官网配置复用媒体墙
- **WHEN** 官网配置页面展示媒体上传、预览或删除能力
- **THEN** 页面从 `@gl/business-components` 使用 `MediaWall`
### Requirement: UI 依赖迁移保持业务行为
系统 MUST 在迁移 UI 依赖后保持现有后台页面的查询、重置、分页、弹窗、抽屉、表单更新、表单提交、状态展示和媒体上传行为。
#### Scenario: 列表页交互保持一致
- **WHEN** 用户在迁移后的列表页执行查询、重置、分页或行操作
- **THEN** 页面行为与迁移前一致
#### Scenario: 编辑页交互保持一致
- **WHEN** 用户在迁移后的编辑页修改字段并提交表单
- **THEN** 字段状态、校验和提交行为与迁移前一致
#### Scenario: 媒体墙交互保持一致
- **WHEN** 用户在迁移后的媒体墙执行上传、预览或删除
- **THEN** 页面继续使用既有上传契约并正确回填状态
#### Scenario: 消息反馈在 React 19 下可用
- **WHEN** 用户操作触发成功、失败、警告或信息消息
- **THEN** TDesign 消息插件使用 React 19 兼容的渲染入口展示反馈
- **AND** 页面不抛出 `reactRender is not a function`
### Requirement: 组件 Demo 不再展示旧本地 UI 包
组件 Demo MUST 展示 TDesign 基础组件和全局业务组件,并且 MUST 不再从 `workspace/agent-admin/web/packages/ui` 引入运行时能力。
#### Scenario: 打开组件 Demo
- **WHEN** 用户访问 `/components`
- **THEN** 页面可展示并交互使用 TDesign 基础组件和全局业务组件
- **AND** 页面不依赖旧本地 UI 包
### Requirement: 旧本地 UI 包目录暂时保留
系统 MUST 在本轮迁移中保留 `workspace/agent-admin/web/packages/ui` 目录,不把旧源码删除作为零运行时依赖验收条件。
#### Scenario: 完成运行时依赖迁移
- **WHEN** `workspace/agent-admin/web/src` 已达到零本地 UI 包运行时依赖
- **THEN** `workspace/agent-admin/web/packages/ui` 目录仍可保留,等待后续独立清理
### Requirement: 本轮表单迁移保持页面级组合
系统 MUST 在本轮迁移中让编辑页直接使用 TDesign 表单能力,并且 MUST NOT 引入配置化表单渲染器或把复杂表单逻辑改写为配置协议。
#### Scenario: 迁移编辑页表单
- **WHEN** 后台编辑页替换本地 `FormItem`、输入控件或选择控件
- **THEN** 页面直接使用 TDesign `Form`、`FormItem` 和基础控件
- **AND** 页面继续保留既有字段状态、校验、联动、上传和提交逻辑
#### Scenario: 遇到复杂表单内容
- **WHEN** 编辑页包含上传、媒体墙、动态数组、多层级联动、复杂业务选择器或步骤表单
- **THEN** 本轮继续使用页面级组合
- **AND** 系统不为这些内容扩展新的配置协议
# business-form Specification
## Purpose
TBD - created by archiving change business-form-component. Update Purpose after archive.
## Requirements
### Requirement: BusinessForm provides a controlled configuration-driven form
系统 MUST 从 `@gl/business-components` 导出 `BusinessForm`,并通过 `fields`、`values` 和 `onChange` 渲染受控业务表单。
#### Scenario: Render configured fields
- **WHEN** 页面传入字段配置和当前表单值
- **THEN** `BusinessForm` 按字段顺序渲染表单项
- **AND** 字段变更后通过表单级 `onChange(nextValues, changedKey)` 抛出更新后的整表单值
#### Scenario: Export public types
- **WHEN** 业务页面从 `@gl/business-components` 引入业务表单能力
- **THEN** 包导出 `BusinessForm`、字段类型、值类型、错误类型和校验工具类型
### Requirement: BusinessForm supports first-version built-in field types
系统 MUST 支持 `input`、`numberInput`、`select`、`switch`、`textarea`、`upload` 和 `displayText` 七类第一版内置字段。
#### Scenario: Render built-in editable fields
- **WHEN** 字段配置包含 `input`、`numberInput`、`select`、`switch`、`textarea` 或 `upload`
- **THEN** `BusinessForm` 使用对应 `tdesign-react` 基础控件渲染可编辑表单项
#### Scenario: Render display text field
- **WHEN** 字段配置包含 `displayText`
- **THEN** `BusinessForm` 渲染只读展示内容
- **AND** 空值默认展示 `-`
### Requirement: BusinessForm supports custom fields
系统 MUST 支持 `custom` 字段,并把当前值、整表单值、错误、禁用、只读和更新函数传给自定义渲染函数。
#### Scenario: Render custom field
- **WHEN** 字段配置包含 `custom.render`
- **THEN** `BusinessForm` 复用表单项外层布局、label、必填标记、helpText 和错误提示
- **AND** 自定义渲染函数接收到 `value`、`values`、`error`、`disabled`、`readonly`、`setValue` 和 `setValues`
#### Scenario: Custom field updates value
- **WHEN** 自定义字段调用 `setValue` 或 `setValues`
- **THEN** `BusinessForm` 通过表单级 `onChange` 抛出更新后的整表单值
### Requirement: BusinessForm applies consistent field layout and widths
系统 MUST 统一基础输入控件的表单布局和宽度。`input`、`numberInput`、`select` 和 `textarea` 的控件列 MUST 使用可用容器宽度,并通过默认宽度或 `fieldWidth` 作为最大宽度约束,避免控件退回 TDesign 自身较窄的默认宽度。
#### Scenario: Default control width is consistent
- **WHEN** 同一表单渲染 `input`、`numberInput`、`select` 和 `textarea`
- **THEN** 这些控件使用一致的默认宽度
- **AND** 这些控件在 label 后的起点保持一致
#### Scenario: fieldWidth applies to basic input controls
- **WHEN** 页面传入 `fieldWidth`
- **THEN** `input`、`numberInput`、`select` 和 `textarea` 同步应用该最大宽度
- **AND** 控件在该最大宽度内保持 `width: 100%`
#### Scenario: Editor page form fills the content column
- **WHEN** 编辑页在内容卡片中使用 `BusinessForm`
- **THEN** 表单控件列 SHALL 按内容卡片的可用宽度展示
- **AND** 页面 SHALL NOT 将 `BusinessForm` 的控件列再压缩到低于其 `fieldWidth` 最大宽度
#### Scenario: Textarea width remains consistent
- **WHEN** `textarea` 因 `rows` 或内容交互改变高度
- **THEN** `textarea` 宽度仍与同表单内 `input`、`numberInput` 和 `select` 保持一致
### Requirement: BusinessForm keeps 20px spacing between rows
系统 MUST 让 `BusinessForm` 的表单项之间保持统一的 20px 垂直间距,避免相邻行在内容区内显得过于拥挤。
#### Scenario: Form rows use 20px spacing
- **WHEN** `BusinessForm` 渲染多行字段
- **THEN** 任意相邻两行字段之间的垂直间距为 20px
- **AND** 该间距在 `input`、`numberInput`、`select`、`textarea`、`switch`、`upload`、`displayText` 和 `custom` 字段之间保持一致
### Requirement: Official site job tab editor uses the approved edit field set
系统 MUST 让已迁移到 `BusinessForm` 的官网岗位展示编辑页只渲染已确认的编辑字段,避免展示与当前编辑任务无关的详情字段。
#### Scenario: Edit page hides employee role text
- **WHEN** 用户进入官网岗位展示编辑页
- **AND** 详情接口返回 `employee_role_text`
- **THEN** 表单 SHALL NOT 展示 `承接角色` 字段
- **AND** 表单 SHALL 继续展示 `岗位标签`、`关联渠道活码`、`渠道编码`、`承接员工`、`岗位标题`、`岗位说明`、`Tab排序` 和 `展示状态`
### Requirement: BusinessForm supports text input limits and TDesign counts
系统 MUST 让 `input` 和 `textarea` 支持 `maxLength`,并优先复用 `tdesign-react` 已有的长度展示能力和对应 API,而不是页面侧自绘计数逻辑。配置最大长度后,字段默认 SHALL NOT 继续输入超过最大长度的内容。
#### Scenario: Input count and max length hard limit
- **WHEN** `input` 字段配置 `maxLength`
- **THEN** 输入框 SHALL 展示 TDesign 提供的字数统计能力
- **AND** 用户输入达到最大长度后 SHALL NOT 继续写入更多字符
- **AND** 表单值 SHALL NOT 超过该 `maxLength`
#### Scenario: Textarea count and max length hard limit
- **WHEN** `textarea` 字段配置 `maxLength`
- **THEN** 文本域 SHALL 展示 TDesign 提供的字数统计能力
- **AND** 用户输入达到最大长度后 SHALL NOT 继续写入更多字符
- **AND** 表单值 SHALL NOT 超过该 `maxLength`
### Requirement: BusinessForm supports number input validation
系统 MUST 让 `numberInput` 支持数值输入和 `min`、`max`、`precision` 校验。
#### Scenario: Validate number range
- **WHEN** `numberInput` 字段配置 `min` 或 `max`
- **THEN** 低于最小值或高于最大值的值会产生字段错误
#### Scenario: Validate number precision
- **WHEN** `numberInput` 字段配置 `precision`
- **THEN** 超出允许小数位数的值会产生字段错误
### Requirement: BusinessForm uses TDesign-first disabled and readonly mapping for editable controls
系统 MUST 让 `input`、`numberInput`、`select` 和 `textarea` 优先使用 `tdesign-react` 已有的 `disabled` / `readOnly` 或等价 API 表达字段级禁用和只读,不再保留页面级原生控件兼容写法。
#### Scenario: Disabled select option cannot be selected
- **WHEN** `select.options` 中某个选项配置 `disabled: true`
- **THEN** 用户不能选择该选项
#### Scenario: Disabled editable field cannot be operated
- **WHEN** `input`、`numberInput`、`select` 或 `textarea` 字段的 `disabled` 计算结果为真
- **THEN** 下拉控件不可操作并呈现禁用状态
#### Scenario: Readonly editable field stays in TDesign render path
- **WHEN** `input`、`numberInput`、`select` 或 `textarea` 字段的 `readOnly` 计算结果为真
- **THEN** `BusinessForm` 直接使用 TDesign 对应属性或等价能力
- **AND** 不再切换为页面级原生控件或自绘兼容分支
### Requirement: BusinessForm supports switch value mapping
系统 MUST 让 `switch` 默认使用布尔值,并支持通过 `checkedValue` 和 `uncheckedValue` 映射业务值。
#### Scenario: Toggle boolean switch
- **WHEN** `switch` 字段未配置业务值映射
- **THEN** 开关切换产生 `true` 或 `false`
#### Scenario: Toggle mapped switch
- **WHEN** `switch` 字段配置 `checkedValue` 和 `uncheckedValue`
- **THEN** 开关切换产生对应业务值
#### Scenario: Readonly switch displays state
- **WHEN** `switch` 字段的 `readonly` 计算结果为真
- **THEN** 表单项展示当前状态文案
- **AND** 不展示可切换开关
### Requirement: BusinessForm supports dynamic field states
系统 MUST 让字段的 `visible`、`disabled` 和 `readonly` 支持布尔值或基于当前 `values` 的函数。
#### Scenario: Hide dynamic field
- **WHEN** 字段 `visible` 为 false 或函数返回 false
- **THEN** `BusinessForm` 不渲染该字段
- **AND** 该字段不参与校验
- **AND** 该字段错误不展示
#### Scenario: Enable field based on another field
- **WHEN** 字段 B 的 `disabled(values)` 依赖字段 A 的当前值
- **THEN** 字段 A 变更后字段 B 的禁用状态按最新 `values` 重新计算
#### Scenario: Show display text based on another field
- **WHEN** `displayText` 字段的 `visible(values)` 依赖字段 A 的当前值
- **THEN** 字段 A 变更后该展示字段按最新 `values` 显示或隐藏
### Requirement: BusinessForm supports field-level onChange patching
系统 MUST 支持字段级 `onChange(nextValue, context)`,用于同步联动更新其他字段。
#### Scenario: Field onChange patches related values
- **WHEN** 字段级 `onChange` 返回 `Partial<BusinessFormValues>`
- **THEN** `BusinessForm` 按 `{ ...values, [field.key]: nextValue, ...patch }` 合并整表单值
- **AND** 通过表单级 `onChange` 抛出合并后的值
#### Scenario: Field onChange only updates current field
- **WHEN** 字段级 `onChange` 不返回 patch
- **THEN** `BusinessForm` 只更新当前字段值
### Requirement: BusinessForm validates configured fields
系统 MUST 提供 `validateBusinessForm(fields, values)`,并按可见性、只读状态和字段规则生成校验结果。
#### Scenario: Validate required field
- **WHEN** 可编辑且可见字段配置 `required: true` 且值为空
- **THEN** `validateBusinessForm` 返回该字段错误
#### Scenario: Skip invisible and readonly fields
- **WHEN** 字段不可见或只读
- **THEN** `validateBusinessForm` 不校验该字段
#### Scenario: Skip display text field
- **WHEN** 字段类型为 `displayText`
- **THEN** `validateBusinessForm` 不对该字段执行必填或自定义校验
#### Scenario: Run custom validator
- **WHEN** 可编辑且可见字段配置 `validator`
- **THEN** `validateBusinessForm` 执行该 validator
- **AND** 使用 validator 返回的错误文案作为字段错误
### Requirement: BusinessForm supports media and regular file upload
系统 MUST 让 `upload` 字段在媒体上传和普通文件上传场景下使用不同展示路径,并且两条路径都基于 `tdesign-react` `Upload` 实现上传,不再使用页面级原生文件输入控件。媒体上传 MUST 统一支持图片、GIF 和视频。上传字段默认最多上传 1 个文件,并 MUST 支持通过字段配置调整最大数量和是否允许多选。
#### Scenario: Reject invalid media upload type
- **WHEN** 媒体上传场景下用户选择的图片、GIF 或视频不满足 `kinds` 或 `accept`
- **THEN** `BusinessForm` 展示类型错误
- **AND** 不调用业务传入的 `upload(file, values)`
#### Scenario: Reject invalid regular file upload type
- **WHEN** 普通文件上传场景下用户选择的文件不满足 `kinds` 或 `accept`
- **THEN** `BusinessForm` 展示类型错误
- **AND** 不调用业务传入的 `upload(file, values)`
#### Scenario: Reject oversized upload
- **WHEN** 用户选择的文件大小超过 `maxSize`
- **THEN** `BusinessForm` 展示大小错误
- **AND** 不调用业务传入的 `upload(file, values)`
#### Scenario: Upload valid media file
- **WHEN** 媒体上传场景下用户选择的图片、GIF 或视频满足 `kinds`、`accept` 和 `maxSize`
- **THEN** `BusinessForm` 调用业务传入的 `upload(file, values)`
- **AND** 上传成功后把 URL 或结构化文件值写入当前字段
#### Scenario: Upload multiple valid media files
- **WHEN** 媒体上传字段配置 `maxCount` 大于 `1` 或配置 `multiple: true`
- **AND** 用户选择的多个图片、GIF 或视频均满足 `kinds`、`accept` 和 `maxSize`
- **THEN** `BusinessForm` 按文件分别调用业务传入的 `upload(file, values)`
- **AND** 上传成功后把多个 URL 或结构化文件值以数组形式写入当前字段
- **AND** 当已上传数量达到 `maxCount` 时,TDesign `Upload` 不再继续展示新增入口或继续接收超过上限的文件
#### Scenario: Upload valid regular file
- **WHEN** 普通文件上传场景下用户选择的文件满足 `kinds`、`accept` 和 `maxSize`
- **THEN** `BusinessForm` 调用业务传入的 `upload(file, values)`
- **AND** 上传成功后把 URL 或结构化文件值写入当前字段
#### Scenario: Display uploaded media preview
- **WHEN** 媒体上传字段已有图片、GIF 或视频值
- **THEN** `BusinessForm` 使用媒体类 TDesign 图片卡片态展示缩略图、GIF 首帧或视频封面/首帧
- **AND** 已有值预览卡片尺寸固定为 `110px × 110px`
- **AND** 如果当前字段值为数组,则按数组顺序展示多个媒体卡片
- **AND** hover 或聚焦卡片时展示接近 TDesign 图片上传卡片的半透明操作蒙层,但蒙层颜色比默认深色遮罩更浅
- **AND** 蒙层中提供预览和删除操作
- **AND** 预览与删除操作之间展示竖向分隔线
- **AND** 预览操作优先复用 TDesign `Upload` 的 `onPreview` 能力,不在组件内重复实现独立预览入口
- **AND** 文件名按当前实现展示在卡片下方,并保持单行省略,不允许换行撑高布局
#### Scenario: Display media upload placeholder and helper text
- **WHEN** 媒体上传字段没有当前值
- **THEN** `BusinessForm` 展示 `110px × 110px` 的固定尺寸虚线卡片上传入口
- **AND** 卡片内部展示加号和字段配置 `placeholder`,未配置时默认展示 `点击上传`
- **AND** 如果字段配置 `helperText`,则在上传卡片下方展示该说明文案
#### Scenario: Restore media upload placeholder after deletion
- **WHEN** 用户删除媒体上传字段的已有图片、GIF 或视频
- **THEN** `BusinessForm` 从当前字段值中移除对应文件
- **AND** 当删除后字段值为空时,上传区域恢复到无值时的卡片占位态
- **AND** 当删除后字段值未空且未达到 `maxCount` 时,上传区域继续展示剩余卡片并允许继续新增
- **AND** 上传卡片下方继续展示字段配置传入的 `helperText`
#### Scenario: Display uploaded regular file preview
- **WHEN** 普通文件上传字段已有普通文件值
- **THEN** `BusinessForm` 使用文件类 TDesign 上传态展示文件信息
#### Scenario: Upload failure preserves previous value
- **WHEN** 业务传入的 `upload(file, values)` 失败
- **THEN** `BusinessForm` 展示上传失败错误
- **AND** 不改写当前字段已有值
### Requirement: BusinessForm demo covers first-version capabilities
系统 MUST 在组件 Demo 中展示 `BusinessForm` 第一版核心能力。
#### Scenario: Open components demo
- **WHEN** 用户访问 `/components`
- **THEN** 页面展示 `BusinessForm` 示例
- **AND** 示例覆盖内置字段、自定义字段、字段级联动、动态显示、动态禁用、动态只读、单选选择器、多选选择器、媒体上传、普通文件上传、上传校验和仅展示文字
#### Scenario: Demo reflects upload display paths
- **WHEN** 用户访问 `/components` 中的 `BusinessForm` 示例
- **THEN** 示例中的媒体上传字段展示图片、GIF 和视频共用的卡片式上传入口与已有值预览态
- **AND** 示例中的普通文件上传字段展示文件类上传入口与已有值信息态
- **AND** 示例不得继续展示基于页面级原生文件输入控件的旧上传交互
### Requirement: BusinessForm follows TDesign-first composition boundaries
系统 MUST 在 `BusinessForm` 中优先使用 TDesign 组件表达表单语义、文本、图片和链接,并明确保留 TDesign 无对应能力或 TDesign slot 内部所需的原生结构。
#### Scenario: Form items use TDesign form semantics
- **WHEN** `BusinessForm` 渲染字段 label、必填标记、helpText 或错误提示
- **THEN** 系统 MUST 优先使用 TDesign `Form`、`FormItem` 或其等价能力承接表单语义
- **AND** 系统 MUST 保持 `fields + values + onChange` 的受控配置协议不变
- **AND** 系统 MUST NOT 让 TDesign `FormItem` 覆盖内置控件、上传字段或 `custom` 字段的受控 `value` 与 `onChange`
#### Scenario: Text display uses TDesign typography
- **WHEN** `BusinessForm` 渲染 `displayText`、readonly 文案、上传文件名或普通辅助文本
- **THEN** 系统 MUST 优先使用 TDesign `Typography.Text` 或其等价文本能力
- **AND** 系统 MUST 保持空值默认展示 `-`、文件名单行省略和既有帮助文案展示语义
#### Scenario: Static image preview uses TDesign image
- **WHEN** 媒体上传字段展示图片、GIF 或图片形式的视频封面
- **THEN** 系统 MUST 优先使用 TDesign `Image` 或其等价图片能力展示静态预览
- **AND** 系统 MUST 保持媒体卡片尺寸、hover 操作蒙层、预览操作和删除操作语义不变
#### Scenario: File links use TDesign link
- **WHEN** 普通文件上传字段展示可打开或下载的文件链接
- **THEN** 系统 MUST 优先使用 TDesign `Link` 或其等价链接能力
- **AND** 系统 MUST 保留 `href`、`target`、`rel` 等浏览器链接语义和安全属性
#### Scenario: Native boundaries remain explicit
- **WHEN** TDesign 没有对应组件能力或组件 slot 内部需要组合媒体、操作按钮和布局结构
- **THEN** 系统 MAY 保留原生结构与 CSS module
- **AND** 视频预览 MAY 继续使用原生 `video`
- **AND** TDesign `Upload.fileListDisplay` 内部 MAY 继续使用必要原生结构展示视频缩略图、文件名、删除、预览和下载操作
- **AND** 系统 SHALL NOT 为了替换所有原生节点而破坏上传值结构、媒体预览、表单对齐或响应式布局
...@@ -32,54 +32,32 @@ TBD - created by archiving change extract-business-table-component. Update Purpo ...@@ -32,54 +32,32 @@ TBD - created by archiving change extract-business-table-component. Update Purpo
- **WHEN** 系统展示普通空态 - **WHEN** 系统展示普通空态
- **THEN** 系统 SHALL NOT 默认展示操作按钮 - **THEN** 系统 SHALL NOT 默认展示操作按钮
### Requirement: 筛选空态 ### Requirement: 精简筛选空态
系统 SHALL 在无错误、非加载、无数据且存在筛选条件时展示筛选空态。 系统 SHALL 在筛选无结果时使用精简状态块,仅展示图标和标题。
#### Scenario: 筛选无结果 #### Scenario: 筛选无结果
- **WHEN** `error` 不为 `true`、`loading` 不为 `true`、`data` 为空且 `hasFilter` 为 `true` - **WHEN** 表格无错误、非加载、无数据且存在筛选条件
- **THEN** 系统 SHALL 使用搜索语义图标展示标题“未找到匹配结果” - **THEN** 系统 SHALL 展示筛选无结果图标和标题“未找到匹配结果”
- **AND** 系统 SHALL 展示浅色说明文案“请调整搜索或筛选条件” - **AND** 系统 SHALL NOT 展示说明文案“请调整搜索或筛选条件”
- **AND** 系统 SHALL NOT 展示“暂无数据” - **AND** 系统 SHALL NOT 展示“清空筛选”按钮
#### Scenario: 清空筛选操作 ### Requirement: 精简列表失败态
- **WHEN** 筛选空态配置提供清空筛选回调 系统 SHALL 在列表加载失败时使用精简状态块,展示失败图标和标题“请求失败”。
- **THEN** 系统 SHALL 展示文案为“清空筛选”的 TDesign primary 实色按钮
#### Scenario: 触发清空筛选 #### Scenario: 列表加载失败
- **WHEN** 用户点击筛选空态中的“清空筛选”按钮 - **WHEN** 表格收到加载失败态配置
- **THEN** 系统 SHALL 调用筛选空态配置提供的清空筛选回调 - **THEN** 系统 SHALL 展示失败态图标和标题“请求失败”
- **AND** 系统 SHALL NOT 展示“重试”按钮
#### Scenario: 页面不传筛选空态文案 - **AND** 系统 SHALL NOT 渲染无文案的状态区按钮
- **WHEN** 页面使用 `BusinessTable` 展示筛选空态
- **THEN** 页面 SHALL 仅通过 `hasFilter` 表达筛选状态,并 MAY 通过 `filteredEmptyState.onAction` 提供清空筛选回调
- **AND** 页面 SHALL NOT 传入筛选空态的 `title`、`description` 或 `actionText`
### Requirement: 加载失败态 ### Requirement: 加载失败态
系统 SHALL 在表格加载失败或不可访问时展示错误状态块,并提供可恢复操作。 系统 SHALL 在表格加载失败或不可访问时展示错误状态块,并提供可恢复操作。
#### Scenario: 展示网络不可用
- **WHEN** `error` 为 `true`
- **THEN** 系统 SHALL 不渲染表格主体,并使用 TDesign 自带错误状态图标展示标题“网络不可用”
- **AND** 系统 SHALL 展示浅色说明文案“请检查网络连接后重试”
- **AND** 页面 SHALL NOT 传入加载失败态的 `title`、`description` 或 `retryText`
#### Scenario: 重试操作
- **WHEN** 网络不可用态配置提供重试回调
- **THEN** 系统 SHALL 展示文案为“重试”的 TDesign primary 实色按钮
#### Scenario: 触发重试
- **WHEN** 用户点击网络不可用态中的“重试”按钮
- **THEN** 系统 SHALL 调用加载失败态配置提供的重试回调
#### Scenario: 展示权限受限 #### Scenario: 展示权限受限
- **WHEN** `error` 为 `true` 且 `errorState.kind` 为 `forbidden` - **WHEN** `error` 为 `true` 且 `errorState.kind` 为 `forbidden`
...@@ -121,21 +99,27 @@ TBD - created by archiving change extract-business-table-component. Update Purpo ...@@ -121,21 +99,27 @@ TBD - created by archiving change extract-business-table-component. Update Purpo
### Requirement: 可选分页和总数展示 ### Requirement: 可选分页和总数展示
系统 SHALL 支持在业务表格底部渲染可选分页或总数信息。 系统 SHALL 支持在业务表格底部渲染可选分页或无分页总数信息,并在分页场景使用 TDesign `Pagination` 默认总数展示。
#### Scenario: 渲染分页 #### Scenario: 渲染分页
- **WHEN** 页面传入分页配置 - **WHEN** 页面传入分页配置
- **THEN** 系统 SHALL 使用 TDesign `Pagination` 渲染当前页、页大小、总数和分页回调 - **THEN** 系统 SHALL 使用 TDesign `Pagination` 渲染当前页、页大小、默认总数文案和分页回调
#### Scenario: 分页场景不渲染额外总数文案
- **WHEN** 页面传入分页配置
- **THEN** 系统 SHALL NOT 在 `Pagination` 外额外渲染 `totalLabel`
- **AND** 页面 SHALL 使用 TDesign `Pagination` 默认的 `totalContent` 展示总数
#### Scenario: 禁用分页 #### Scenario: 禁用分页
- **WHEN** 页面传入 `pagination={false}` - **WHEN** 页面传入 `pagination={false}`
- **THEN** 系统 SHALL NOT 渲染分页组件 - **THEN** 系统 SHALL NOT 渲染分页组件
#### Scenario: 展示总数文案 #### Scenario: 无分页时展示总数文案
- **WHEN** 页面传入 `totalLabel` - **WHEN** 页面未传入分页配置或传入 `pagination={false}`,且传入 `totalLabel`
- **THEN** 系统 SHALL 在表格底部展示该总数文案 - **THEN** 系统 SHALL 在表格底部展示该总数文案
### Requirement: 空态视觉位置 ### Requirement: 空态视觉位置
...@@ -147,6 +131,18 @@ TBD - created by archiving change extract-business-table-component. Update Purpo ...@@ -147,6 +131,18 @@ TBD - created by archiving change extract-business-table-component. Update Purpo
- **WHEN** `BusinessTable` 展示普通空态、筛选空态或加载失败态 - **WHEN** `BusinessTable` 展示普通空态、筛选空态或加载失败态
- **THEN** 系统 SHALL 使用足够的垂直空间和居中布局展示图标、标题、浅色说明和可选操作按钮,使其不显得贴近表头 - **THEN** 系统 SHALL 使用足够的垂直空间和居中布局展示图标、标题、浅色说明和可选操作按钮,使其不显得贴近表头
### Requirement: 表格刷新加载态
系统 SHALL 在 `BusinessTable` 收到加载态时使用表格区域局部 loading,并采用业务组件默认的轻量加载样式。
#### Scenario: 表格刷新中
- **WHEN** 页面向 `BusinessTable` 传入 `loading={true}`
- **THEN** 系统 SHALL 保留表格结构并展示表格区域 loading
- **AND** 系统 SHALL 使用小尺寸加载指示和当前主题主色提示文案
- **AND** 系统 SHALL 使用当前主题主色渲染加载指示器
- **AND** 系统 SHALL 允许调用方通过 TDesign `loadingProps` 覆盖默认加载配置
### Requirement: 后台列表页迁移 ### Requirement: 后台列表页迁移
系统 SHALL 将当前后台列表页迁移为使用 `BusinessTable` 渲染表格状态和分页区域。 系统 SHALL 将当前后台列表页迁移为使用 `BusinessTable` 渲染表格状态和分页区域。
...@@ -160,3 +156,72 @@ TBD - created by archiving change extract-business-table-component. Update Purpo ...@@ -160,3 +156,72 @@ TBD - created by archiving change extract-business-table-component. Update Purpo
- **WHEN** 页面迁移到 `BusinessTable` - **WHEN** 页面迁移到 `BusinessTable`
- **THEN** 系统 SHALL 保持现有查询、重置、分页、弹窗和行操作行为不变 - **THEN** 系统 SHALL 保持现有查询、重置、分页、弹窗和行操作行为不变
### Requirement: BusinessTable follows TDesign-first composition boundaries
系统 SHALL 在 `BusinessTable` 中优先使用 TDesign 组件表达表格、分页、空态、按钮和文本语义,并允许保留必要原生结构承载组件布局。
#### Scenario: Table semantic parts use TDesign
- **WHEN** `BusinessTable` 渲染表格、分页、空态、恢复操作或总数文本
- **THEN** 系统 SHALL 分别使用 TDesign `Table`、`Pagination`、`Empty`、`Button` 和 TDesign 文本组件或其等价能力
#### Scenario: Necessary layout containers remain native
- **WHEN** `BusinessTable` 需要根容器、空态居中容器或 footer 对齐容器
- **THEN** 系统 MAY 使用原生结构和 CSS module 承载布局
- **AND** 系统 SHALL NOT 为了替换布局容器而引入影响表格对齐、分页位置或空态视觉位置的额外组件层级
### Requirement: BusinessTable uses tooltip for text cells only when explicitly enabled
系统 SHALL 默认不为 `BusinessTable` 的普通文本单元格增加悬浮提示;当列配置显式开启普通文本悬浮提示时,系统 SHALL 使用单行省略展示超长内容,并在鼠标悬浮时通过 TDesign `Tooltip` 展示完整内容。
#### Scenario: Plain text cell does not opt in
- **WHEN** 列配置没有显式开启普通文本悬浮提示
- **THEN** 系统 SHALL NOT 默认为该单元格增加 TDesign `Tooltip`
#### Scenario: Text cell opts in to tooltip
- **WHEN** 列配置显式开启普通文本悬浮提示
- **AND** 列配置没有提供自定义 `cell`
- **AND** 单元格值为普通文本、数字、布尔值或由列配置显式提供的普通文本
- **THEN** 表格可见内容 SHALL 使用单行省略样式展示
- **AND** 鼠标悬浮该单元格内容时 SHALL 使用 TDesign `Tooltip` 展示完整内容
- **AND** Tooltip 宽度 SHALL 为 200px
- **AND** Tooltip 内容 SHALL 允许换行展示
#### Scenario: Empty text cell does not show tooltip
- **WHEN** 列配置显式开启普通文本悬浮提示
- **AND** 列配置没有提供自定义 `cell`
- **AND** 单元格取值为空、只包含空白字符或解析后为占位文案 `-`
- **THEN** 表格 SHALL 仅展示占位文案 `-`
- **AND** 系统 SHALL NOT 为该单元格渲染 TDesign `Tooltip`
#### Scenario: Text cell uses explicit tooltip value
- **WHEN** 列配置显式开启普通文本悬浮提示
- **AND** 列配置提供普通文本取值函数
- **THEN** 系统 SHALL 使用该取值函数结果作为单元格可见文本和 Tooltip 内容
- **AND** 页面 SHALL NOT 需要在业务列中手写 TDesign `Tooltip`
#### Scenario: Custom cell keeps page rendering
- **WHEN** 列配置已经提供自定义 `cell`
- **THEN** `BusinessTable` SHALL NOT 覆盖该列的单元格渲染
- **AND** 页面自定义的按钮、状态、图片或组合内容 SHALL 保持原样
### Requirement: Business long text columns opt in to tooltip
系统 SHALL 为已确认的业务长文本列表列显式开启 `BusinessTable` tooltip,以便文本超过列宽时单行省略并可悬浮查看完整内容。
#### Scenario: Confirmed business long text columns use explicit tooltip
- **WHEN** 技能列表渲染“说明”列
- **OR** 官网 Agent 展示配置列表渲染“Agent 概述”列
- **OR** 岗位标签列表渲染“标签描述”列
- **OR** 渠道活码列表渲染“关联 Agent”列
- **THEN** 对应列 SHALL 通过 `BusinessTable` 显式开启 TDesign Tooltip
- **AND** Tooltip 展示 SHALL 复用 `BusinessTable` 的 200px 宽度和换行规则
# components-demo Specification
## Purpose
TBD - created by archiving change align-components-demo-business-table-states. Update Purpose after archive.
## Requirements
### Requirement: 表格状态必须通过 BusinessTable 展示
组件 demo 页面 SHALL 在“表格与分页”区域通过 `BusinessTable` 展示表格相关状态,避免使用 `StatePlaceholder`、TDesign `Empty`、TDesign `Table` 和 TDesign `Pagination` 直接拼装表格状态示例。
#### Scenario: 展示表格状态集合
- **WHEN** 用户打开组件 demo 页面并查看“表格与分页”区域
- **THEN** 系统 SHALL 展示由 `BusinessTable` 渲染的有数据表格、普通空态、筛选无结果、请求失败、权限受限和加载中示例
#### Scenario: 普通空态示例
- **WHEN** demo 展示普通空态表格示例
- **THEN** 系统 SHALL 展示标题“暂无数据”
- **AND** 系统 SHALL NOT 展示说明文案“请先创建项目”
- **AND** 系统 SHALL NOT 展示空态操作按钮
#### Scenario: 筛选无结果示例
- **WHEN** demo 展示筛选无结果表格示例
- **THEN** 系统 SHALL 展示标题“未找到匹配结果”
- **AND** 系统 SHALL NOT 展示说明文案“请调整搜索或筛选条件”
- **AND** 系统 SHALL NOT 展示“清空筛选”按钮
#### Scenario: 请求失败示例
- **WHEN** demo 展示请求失败表格示例
- **THEN** 系统 SHALL 展示标题“请求失败”
- **AND** 系统 SHALL NOT 展示说明文案“列表请求失败,当前数据状态未知”
- **AND** 系统 SHALL NOT 展示“重试”按钮
#### Scenario: 权限受限示例
- **WHEN** demo 展示权限受限表格示例
- **THEN** 系统 SHALL 展示标题“权限受限”
- **AND** 系统 SHALL 展示说明文案“当前账号暂无访问权限”
- **AND** 系统 SHALL 展示“申请权限”按钮
#### Scenario: 导航与占位不展示表格状态集合
- **WHEN** 用户查看“导航与占位”区域
- **THEN** 系统 SHALL NOT 展示“网络不可用”“请检查网络连接后重试”或“重新连接”等表格网络失败示例
- **AND** 系统 SHALL NOT 展示旧表格状态集合
# editor-page-form-composition Specification
## Purpose
TBD - created by archiving change migrate-editor-pages-to-business-form. Update Purpose after archive.
## Requirements
### Requirement: 第一批编辑页应优先使用 BusinessForm 组合标准字段
系统 SHALL 在第一批迁移页面中使用 `BusinessForm` 承载可由其公共字段类型表达的编辑字段,并保留页面外层业务结构。
#### Scenario: 智能体标签编辑页使用 BusinessForm
- **WHEN** 用户进入智能体标签新增或编辑页
- **THEN** 标签名称、标签编码和描述字段 SHALL 由 `BusinessForm` 字段配置渲染
- **AND** 编辑模式下标签编码 SHALL 保持迁移前的只读或禁用行为
#### Scenario: 渠道二维码编辑页使用 BusinessForm
- **WHEN** 用户进入渠道二维码新增或编辑页
- **THEN** 二维码名称、新增模式职位选择、员工选择、描述和欢迎语字段 SHALL 由 `BusinessForm` 字段配置渲染
- **AND** 编辑模式下不可修改的职位、智能体编码和员工信息 SHALL 通过 `displayText` 或 `custom` 字段保持只读展示
- **AND** 编辑模式字段顺序 SHALL 按 `活码名称`、`对应岗位`、`渠道编码`、`承接员工`、`关联 Agent`、`活码描述`、`自动欢迎语` 展示
- **AND** 编辑模式 `对应岗位` SHALL 回显详情接口归一化后的 `position_name` 并保持禁用只读
- **AND** 当详情接口未直接返回 `position_name` 但返回岗位对象或岗位名称别名时,页面 SHALL 通过接口归一化结果回显岗位名称
#### Scenario: 官网职位 Tab 编辑页使用 BusinessForm
- **WHEN** 用户进入官网职位 Tab 新增或编辑页
- **THEN** 职位、主标题、副标题、排序和状态字段 SHALL 由 `BusinessForm` 字段配置渲染
- **AND** 职位联动产生的只读说明 SHALL 通过 `displayText` 或 `custom` 字段展示
### Requirement: 页面业务行为应在迁移后保持不变
系统 SHALL 在迁移到 `BusinessForm` 后保持第一批页面的业务行为、数据提交形态和用户反馈不变。
#### Scenario: 保存 payload 保持一致
- **WHEN** 用户在迁移后的页面填写有效表单并保存
- **THEN** 页面 SHALL 调用迁移前相同的创建或更新接口
- **AND** 提交 payload 的字段和值 SHALL 与迁移前等价
#### Scenario: 校验和反馈保持一致
- **WHEN** 用户提交缺少必填项或格式不合法的表单
- **THEN** 页面 SHALL 展示与迁移前等价的校验反馈
- **AND** 页面 SHALL NOT 调用创建或更新接口
#### Scenario: 加载和错误状态保持一致
- **WHEN** 页面加载详情、选项或保存请求失败
- **THEN** 页面 SHALL 保持迁移前等价的加载态、错误态和失败提示
### Requirement: 复杂字段应限定在明确回退边界内
系统 SHALL 只在 `BusinessForm` 标准字段无法表达页面内容时使用 `displayText` 或 `custom` 回退,不得为本次迁移扩展组件 API。
#### Scenario: 只读业务说明使用展示字段
- **WHEN** 页面需要展示由选项联动推导出的只读业务信息
- **THEN** 页面 SHALL 优先使用 `displayText` 字段
- **AND** 只有多段结构或已有业务节点无法标准表达时 SHALL 使用 `custom` 字段
#### Scenario: 延后页面不纳入首批迁移
- **WHEN** 页面包含上传、动态数组、复杂资源预览/删除或多分支大表单
- **THEN** 页面 SHALL NOT 在本次 change 中强制迁移
- **AND** 后续迁移 SHALL 通过独立评估和 OpenSpec change 锁定范围
### Requirement: 第二阶段编辑页应继续优先使用 BusinessForm 组合标准字段
系统 SHALL 在第二阶段迁移页面中使用 `BusinessForm` 承载可由其公共字段类型表达的编辑字段,并保留页面外层业务结构。
#### Scenario: Agent 编辑页使用 BusinessForm
- **WHEN** 用户进入 Agent 新增或编辑页
- **THEN** `Agent名称`、普通 Agent 的 `所属岗位`、普通 Agent 的 `托管企微员工`、`Agent描述`、`绑定Skill` 和 `状态` SHALL 由 `BusinessForm` 字段配置渲染
- **AND** 管家 Agent 的 `Agent名称`、`所属岗位`、`托管企微员工` 和 `状态` SHALL 保持迁移前的禁用或只读展示语义
- **AND** 岗位、员工或 Skill 选项加载失败时 SHALL 保持迁移前的错误提示和重试行为
#### Scenario: 官网方法论顶部基础配置使用 BusinessForm
- **WHEN** 用户进入官网方法论配置页
- **THEN** 顶部基础配置中的 `展示状态`、`主标题` 和 `副标题` SHALL 由 `BusinessForm` 字段配置渲染
- **AND** 方法论步骤动态列表、步骤图标上传、内容图上传、预览和删除 SHALL 保持页面原实现
### Requirement: 第二阶段迁移应保持页面业务行为不变
系统 SHALL 在第二阶段迁移到 `BusinessForm` 后保持页面业务行为、数据提交形态和用户反馈不变。
#### Scenario: Agent 保存行为保持一致
- **WHEN** 用户在迁移后的 Agent 页面填写有效表单并保存
- **THEN** 页面 SHALL 调用迁移前相同的创建或更新接口
- **AND** 提交 payload 的字段和值 SHALL 与迁移前等价
- **AND** 保存成功后的列表缓存更新和返回路径 SHALL 与迁移前等价
#### Scenario: 方法论保存行为保持一致
- **WHEN** 用户在迁移后的官网方法论配置页保存
- **THEN** 页面 SHALL 提交与迁移前等价的基础配置和步骤数据
- **AND** 上传、预览、删除和校验反馈 SHALL 与迁移前等价
#### Scenario: 第二阶段校验和错误状态保持一致
- **WHEN** 用户提交缺少必填项、长度超限或业务规则不合法的表单
- **THEN** 页面 SHALL 展示与迁移前等价的校验反馈
- **AND** 页面 SHALL NOT 调用创建或更新接口
### Requirement: 第三阶段编辑弹窗应继续优先使用 BusinessForm 组合标准字段
系统 SHALL 在第三阶段迁移页面中使用 `BusinessForm` 承载可由其公共字段类型表达的编辑字段,并保留弹窗外层业务结构。
#### Scenario: 官网 Agent 展示配置编辑弹窗使用 BusinessForm
- **WHEN** 用户打开官网 Agent 展示配置编辑弹窗
- **THEN** `Agent 名称`、`图标`、`Agent 概述`、`展示素材`、`展示排序` 和 `展示状态` SHALL 由 `BusinessForm` 字段配置渲染
- **AND** `Agent 名称` SHALL 保持只读展示
- **AND** `图标` 与 `展示素材` SHALL 保持迁移前的上传、预览、删除、帮助提示和错误提示语义
- **AND** `Agent 概述` SHALL 保持必填校验和最长 100 字校验,并展示当前字数长度
- **AND** `展示排序` SHALL 保持 0-99 整数校验
### Requirement: 第三阶段迁移应保持弹窗业务行为不变
系统 SHALL 在第三阶段迁移到 `BusinessForm` 后保持弹窗业务行为、数据提交形态和用户反馈不变。
#### Scenario: 官网 Agent 展示配置保存行为保持一致
- **WHEN** 用户在迁移后的弹窗填写有效表单并保存
- **THEN** 页面 SHALL 调用迁移前相同的更新接口
- **AND** 提交 payload 的字段和值 SHALL 与迁移前等价
- **AND** 保存成功后的回调、关闭和列表刷新行为 SHALL 与迁移前等价
#### Scenario: 官网 Agent 展示配置校验和提示颜色保持一致
- **WHEN** 用户提交缺少必填项、排序不合法或上传缺失的表单
- **THEN** 弹窗 SHALL 展示与迁移前等价的校验反馈
- **AND** 必填/校验错误提示 SHALL 使用红色
- **AND** 普通上传帮助提示 SHALL 使用浅灰色
- **AND** 页面 SHALL NOT 调用更新接口
# official-site-agent-display-config-sort-status Specification
## Purpose
TBD - created by archiving change official-site-agent-display-config-sort-status. Update Purpose after archive.
## Requirements
### Requirement: 官网 Agent 展示配置编辑弹窗的展示状态文案
Agent 展示配置编辑弹窗 SHALL 在 `展示状态` 字段中使用更贴近业务的文案,并保持内部状态值不变。
#### Scenario: 展示状态选项文案
- **WHEN** 用户打开官网 Agent 展示配置编辑弹窗
- **THEN** `display_status = disable` 的选项文案展示为 `不展示`
- **AND** `display_status = enable` 的选项文案继续展示为 `展示中`
#### Scenario: 默认展示状态
- **WHEN** 用户首次打开未配置的官网 Agent 展示配置编辑弹窗
- **THEN** `展示状态` 默认选中 `不展示`
- **AND** 页面提交时仍使用 `disable` 作为内部值
### Requirement: 官网 Agent 展示配置列表的展示状态文案
Agent 展示配置列表 SHALL 在 `展示状态` 列中使用和编辑弹窗一致的 `display_status` 展示文案,并保持内部状态值不变。
#### Scenario: 列表展示状态文案
- **WHEN** 用户查看官网 Agent 展示配置列表
- **AND** 某条可展示 Agent 记录的 `display_status = disable`
- **THEN** 该记录的 `展示状态` 列展示为 `不展示`
- **AND** `display_status = enable` 的记录继续展示为 `展示中`
### Requirement: 官网 Agent 展示配置编辑弹窗的展示排序校验
Agent 展示配置编辑弹窗 SHALL 阻止小于 `0` 的 `展示排序` 输入被提交。
#### Scenario: 展示排序下限校验
- **WHEN** 用户提交小于 `0` 的 `展示排序`
- **THEN** 页面在 `展示排序` 字段附近展示校验错误
- **AND** 页面不提交保存
#### Scenario: 展示排序合法范围
- **WHEN** 用户提交 `0` 或更大的整数 `展示排序`
- **THEN** 页面允许继续保存流程
### Requirement: BusinessForm 字段提示颜色语义
`BusinessForm` SHALL 区分字段错误提示与普通帮助提示的颜色语义。
#### Scenario: 必填或校验错误使用红色
- **WHEN** 字段存在 `errors[field.key]` 或内置校验产生的错误提示
- **THEN** `BusinessForm` 在字段下方展示错误提示
- **AND** 错误提示使用错误态红色
#### Scenario: 普通帮助提示使用浅灰色
- **WHEN** 字段配置了 `helpText` 或 `helperText`
- **AND** 该提示不是校验错误
- **THEN** `BusinessForm` 在字段下方展示普通帮助提示
- **AND** 普通帮助提示使用浅灰色
### Requirement: 官网 Agent 展示配置编辑弹窗字段提示颜色语义
官网 Agent 展示配置编辑弹窗 SHALL 通过 `BusinessForm` 承载字段区,并复用 `BusinessForm` 的字段错误提示与普通帮助说明颜色语义。
#### Scenario: 编辑弹窗校验错误使用红色
- **WHEN** 用户在官网 Agent 展示配置编辑弹窗提交缺失必填项或非法 `展示排序`
- **THEN** 页面在对应字段附近展示校验错误
- **AND** 校验错误使用错误态红色
- **AND** 错误提示由 `BusinessForm` 字段错误渲染路径承载
#### Scenario: 编辑弹窗普通说明使用浅灰色
- **WHEN** 官网 Agent 展示配置编辑弹窗展示图标或展示素材的上传说明
- **THEN** 普通上传说明使用浅灰色
- **AND** 普通上传说明不使用错误态红色
- **AND** 普通说明由 `BusinessForm` `helperText` 或 `helpText` 渲染路径承载
...@@ -136,6 +136,28 @@ describe('channelCode API', () => { ...@@ -136,6 +136,28 @@ describe('channelCode API', () => {
expect(result.qrcode_id).toBe(1); expect(result.qrcode_id).toBe(1);
expect(result.agent_ids).toEqual([101, 102]); expect(result.agent_ids).toEqual([101, 102]);
}); });
it('归一化岗位名称别名用于编辑页回显', async () => {
vi.mocked(apiClient.get).mockResolvedValueOnce({
qrcode_id: 1,
qrcode_name: '销售岗活码',
employee_id: 'emp_12345',
employee_name: '张三',
position_code: 'backend_engineer',
position: { name: '后端开发工程师' },
channel_code: 'position_b8b2e6',
qrcode_url: 'https://cdn.weixin.qq.com/qrcode/abc123.png',
agent_ids: [],
agent_names: [],
status: 'enable',
created_at: '2026-05-15T10:00:00Z',
created_by: 'admin',
});
const result = await getChannelQRCodeDetail(1);
expect(result.position_name).toBe('后端开发工程师');
});
}); });
describe('createChannelQRCode', () => { describe('createChannelQRCode', () => {
......
...@@ -215,6 +215,49 @@ function fillQRCodeListItem(item: Partial<ChannelQRCodeListItem>): ChannelQRCode ...@@ -215,6 +215,49 @@ function fillQRCodeListItem(item: Partial<ChannelQRCodeListItem>): ChannelQRCode
}; };
} }
function readString(value: unknown) {
return typeof value === 'string' ? value : '';
}
function readRecord(value: unknown) {
return value && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : {};
}
function resolveQRCodePositionName(item: Partial<ChannelQRCodeDetail>) {
const raw = item as Record<string, unknown>;
const position = readRecord(raw.position);
const positionTag = readRecord(raw.position_tag);
return readString(item.position_name)
|| readString(raw.positionName)
|| readString(raw.position_tag_name)
|| readString(position.name)
|| readString(position.position_name)
|| readString(positionTag.name)
|| readString(positionTag.position_name)
|| readString(item.position_code);
}
function fillQRCodeDetail(item: Partial<ChannelQRCodeDetail>): ChannelQRCodeDetail {
return {
qrcode_id: item.qrcode_id ?? 0,
employee_id: item.employee_id ?? '',
qrcode_name: item.qrcode_name ?? '',
employee_name: item.employee_name ?? '',
position_code: item.position_code ?? '',
position_name: resolveQRCodePositionName(item),
channel_code: item.channel_code ?? '',
qrcode_url: item.qrcode_url ?? '',
agent_ids: item.agent_ids ?? [],
agent_names: item.agent_names ?? [],
status: item.status ?? 'enable',
remark: item.remark,
welcome_message: item.welcome_message,
created_at: item.created_at ?? '',
created_by: item.created_by ?? '',
};
}
export async function getChannelQRCodeList(query: ChannelQRCodeListQuery): Promise<ChannelQRCodeListResponse> { export async function getChannelQRCodeList(query: ChannelQRCodeListQuery): Promise<ChannelQRCodeListResponse> {
const response = await apiClient.get<ChannelQRCodeListResponse>('/agent-group/qrcode/list', { params: query }); const response = await apiClient.get<ChannelQRCodeListResponse>('/agent-group/qrcode/list', { params: query });
return { return {
...@@ -224,7 +267,8 @@ export async function getChannelQRCodeList(query: ChannelQRCodeListQuery): Promi ...@@ -224,7 +267,8 @@ export async function getChannelQRCodeList(query: ChannelQRCodeListQuery): Promi
} }
export async function getChannelQRCodeDetail(qrcodeId: number): Promise<ChannelQRCodeDetail> { export async function getChannelQRCodeDetail(qrcodeId: number): Promise<ChannelQRCodeDetail> {
return apiClient.get<ChannelQRCodeDetail>(`/agent-group/qrcode/${qrcodeId}`); const response = await apiClient.get<ChannelQRCodeDetail>(`/agent-group/qrcode/${qrcodeId}`);
return fillQRCodeDetail(response);
} }
export async function createChannelQRCode(payload: CreateChannelQRCodePayload): Promise<CreateChannelQRCodeResponse> { export async function createChannelQRCode(payload: CreateChannelQRCodePayload): Promise<CreateChannelQRCodeResponse> {
......
...@@ -51,6 +51,14 @@ function getNumberInput(name: string) { ...@@ -51,6 +51,14 @@ function getNumberInput(name: string) {
return input as HTMLInputElement; return input as HTMLInputElement;
} }
function getControlHolder(name: string) {
const holder = screen.getByTestId(`business-form-control-holder-${name}`);
if (!holder) {
throw new Error(`Control holder ${name} was not found`);
}
return holder as HTMLElement;
}
function Harness({ function Harness({
fields, fields,
initialValues, initialValues,
...@@ -130,7 +138,7 @@ describe('BusinessForm', () => { ...@@ -130,7 +138,7 @@ describe('BusinessForm', () => {
); );
expect(screen.getByLabelText('名称')).toHaveValue('合同'); expect(screen.getByLabelText('名称')).toHaveValue('合同');
expect(getNumberInput('amount')).toHaveValue('2.00'); expect(getNumberInput('amount')).toHaveValue(2);
expect(getSelectTrigger('状态')).toHaveValue('启用'); expect(getSelectTrigger('状态')).toHaveValue('启用');
expect(screen.getByRole('switch', { name: '开关' })).toBeChecked(); expect(screen.getByRole('switch', { name: '开关' })).toBeChecked();
expect(screen.getByLabelText('备注')).toHaveValue('已填写'); expect(screen.getByLabelText('备注')).toHaveValue('已填写');
...@@ -141,6 +149,68 @@ describe('BusinessForm', () => { ...@@ -141,6 +149,68 @@ describe('BusinessForm', () => {
expect(screen.getByTestId('business-form-field-status')).toHaveAttribute('data-width', '360'); expect(screen.getByTestId('business-form-field-status')).toHaveAttribute('data-width', '360');
}); });
it('keeps controlled fields inside TDesign FormItem without overriding their values', () => {
const onChange = vi.fn();
render(
<Harness
fields={[
{ key: 'title', label: '名称', type: 'input', required: true, helpText: '请输入项目名称' },
{
key: 'status',
label: '状态',
type: 'select',
options: [{ label: '启用', value: 'enabled' }],
},
{
key: 'custom',
label: '自定义',
type: 'custom',
render: ({ value, setValue }) => (
<button type="button" onClick={() => setValue('custom-next')}>
{String(value)}
</button>
),
},
]}
initialValues={{ title: '合同', status: 'enabled', custom: 'custom-start' }}
errors={{ title: '名称错误' }}
onChange={onChange}
/>,
);
const titleField = screen.getByTestId('business-form-field-title');
expect(titleField.querySelector('.t-form__item')).toBeInTheDocument();
expect(within(titleField).getByText('请输入项目名称')).toBeInTheDocument();
expect(within(titleField).getByText('名称错误')).toBeInTheDocument();
fireEvent.change(screen.getByLabelText('名称'), { target: { value: '合同A' } });
fireEvent.click(screen.getByRole('button', { name: 'custom-start' }));
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ title: '合同A' }), 'title');
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ custom: 'custom-next' }), 'custom');
});
it('uses red validation text and light gray helper text', () => {
render(
<BusinessForm
fields={[{ key: 'title', label: '名称', type: 'input', required: true, helpText: '普通提示' }]}
values={{ title: '' }}
errors={{ title: '名称必填' }}
onChange={vi.fn()}
/>,
);
const titleField = screen.getByTestId('business-form-field-title');
const helperText = within(titleField).getByText('普通提示');
const errorText = within(titleField).getByText('名称必填');
expect(helperText.className).toContain('helpText');
expect(errorText.className).toContain('error');
expect(helperText).toHaveStyle({ color: '#a6a6a6' });
expect(errorText).toHaveStyle({ color: '#d94841' });
});
it('updates controlled values and emits form-level and field-level patch changes', () => { it('updates controlled values and emits form-level and field-level patch changes', () => {
const onChange = vi.fn(); const onChange = vi.fn();
const titleChange = vi.fn(); const titleChange = vi.fn();
...@@ -239,7 +309,8 @@ describe('BusinessForm', () => { ...@@ -239,7 +309,8 @@ describe('BusinessForm', () => {
expect(screen.getByLabelText('锁定项')).toBeDisabled(); expect(screen.getByLabelText('锁定项')).toBeDisabled();
fireEvent.change(screen.getByLabelText('模式'), { target: { value: 'read' } }); fireEvent.change(screen.getByLabelText('模式'), { target: { value: 'read' } });
expect(screen.getByLabelText('只读项')).toHaveAttribute('readonly'); expect(screen.queryByLabelText('只读项')).not.toBeInTheDocument();
expect(screen.getByText('只读值')).toBeInTheDocument();
}); });
it('validates required, max length, number range, precision, readonly, hidden and custom validator fields', async () => { it('validates required, max length, number range, precision, readonly, hidden and custom validator fields', async () => {
...@@ -278,7 +349,9 @@ describe('BusinessForm', () => { ...@@ -278,7 +349,9 @@ describe('BusinessForm', () => {
}); });
}); });
it('keeps allowInputOverMax editable and uses native length display for input and textarea', () => { it('caps input and textarea values at maxLength and uses native length display', () => {
const handleChange = vi.fn();
render( render(
<BusinessForm <BusinessForm
fields={[ fields={[
...@@ -286,15 +359,22 @@ describe('BusinessForm', () => { ...@@ -286,15 +359,22 @@ describe('BusinessForm', () => {
{ key: 'remark', label: '备注', type: 'textarea', maxLength: 5, allowInputOverMax: true }, { key: 'remark', label: '备注', type: 'textarea', maxLength: 5, allowInputOverMax: true },
]} ]}
values={{ title: '', remark: '' }} values={{ title: '', remark: '' }}
onChange={vi.fn()} onChange={handleChange}
/>, />,
); );
fireEvent.change(screen.getByLabelText('名称'), { target: { value: '超出长度啊' } }); fireEvent.change(screen.getByLabelText('名称'), { target: { value: '超出长度啊' } });
fireEvent.change(screen.getByLabelText('备注'), { target: { value: '超出长度内容啊' } }); fireEvent.change(screen.getByLabelText('备注'), { target: { value: '超出长度内容啊' } });
expect(screen.getByLabelText('名称')).toHaveValue('超出长度啊'); expect(screen.getByLabelText('名称')).toHaveValue('超出长度');
expect(screen.getByLabelText('备注')).toHaveValue('超出长度内容啊'); expect(screen.getByLabelText('备注')).toHaveValue('超出长度内');
expect(handleChange).toHaveBeenLastCalledWith(
{ title: '超出长度', remark: '超出长度内' },
expect.objectContaining({
key: 'remark',
value: '超出长度内',
}),
);
}); });
it('keeps input, numberInput, select and textarea at the same default width and syncs fieldWidth to all of them', () => { it('keeps input, numberInput, select and textarea at the same default width and syncs fieldWidth to all of them', () => {
...@@ -346,6 +426,49 @@ describe('BusinessForm', () => { ...@@ -346,6 +426,49 @@ describe('BusinessForm', () => {
expect(screen.getByTestId('business-form-field-amount')).toHaveAttribute('data-width', '420'); expect(screen.getByTestId('business-form-field-amount')).toHaveAttribute('data-width', '420');
expect(screen.getByTestId('business-form-field-status')).toHaveAttribute('data-width', '420'); expect(screen.getByTestId('business-form-field-status')).toHaveAttribute('data-width', '420');
expect(screen.getByTestId('business-form-field-remark')).toHaveAttribute('data-width', '420'); expect(screen.getByTestId('business-form-field-remark')).toHaveAttribute('data-width', '420');
expect(getControlHolder('title')).toHaveStyle({ width: '100%', maxWidth: '420px' });
expect(getControlHolder('amount')).toHaveStyle({ width: '100%', maxWidth: '420px' });
expect(getControlHolder('status')).toHaveStyle({ width: '100%', maxWidth: '420px' });
expect(getControlHolder('remark')).toHaveStyle({ width: '100%', maxWidth: '420px' });
rerender(
<BusinessForm
fields={[
{ key: 'title', label: '名称', type: 'input' },
{ key: 'amount', label: '数量', type: 'numberInput' },
{
key: 'status',
label: '状态',
type: 'select',
options: [{ label: '启用', value: 'enabled' }],
},
{ key: 'remark', label: '备注', type: 'textarea' },
]}
values={{ title: '', amount: 0, status: 'enabled', remark: '' }}
onChange={vi.fn()}
fieldWidth="w-full max-w-[450px]"
/>,
);
expect(getControlHolder('title')).toHaveClass('w-full', 'max-w-[450px]');
expect(getControlHolder('amount')).toHaveClass('w-full', 'max-w-[450px]');
expect(getControlHolder('status')).toHaveClass('w-full', 'max-w-[450px]');
expect(getControlHolder('remark')).toHaveClass('w-full', 'max-w-[450px]');
});
it('keeps 40px spacing between form rows', () => {
const { container } = render(
<BusinessForm
fields={[
{ key: 'title', label: '名称', type: 'input' },
{ key: 'amount', label: '数量', type: 'numberInput' },
]}
values={{ title: '', amount: 0 }}
onChange={vi.fn()}
/>,
);
expect(container.querySelector('form')).toHaveStyle({ gap: '40px' });
}); });
it('respects select option disabled, field disabled and readonly native props', () => { it('respects select option disabled, field disabled and readonly native props', () => {
...@@ -399,8 +522,8 @@ describe('BusinessForm', () => { ...@@ -399,8 +522,8 @@ describe('BusinessForm', () => {
expect(onChange).not.toHaveBeenCalled(); expect(onChange).not.toHaveBeenCalled();
expect(getSelectTrigger('状态')).toHaveValue('启用'); expect(getSelectTrigger('状态')).toHaveValue('启用');
expect(getSelectTrigger('禁用状态')).toBeDisabled(); expect(getSelectTrigger('禁用状态')).toBeDisabled();
expect(getSelectTrigger('只读状态')).toHaveValue('停用'); expect(screen.queryByLabelText('只读状态')).not.toBeInTheDocument();
expect(getSelectTrigger('只读状态')).toHaveAttribute('readonly'); expect(within(screen.getByTestId('business-form-field-readonlyStatus')).getByText('停用')).toBeInTheDocument();
}); });
it('supports boolean switch defaults, mapped values and readonly display', () => { it('supports boolean switch defaults, mapped values and readonly display', () => {
...@@ -433,6 +556,57 @@ describe('BusinessForm', () => { ...@@ -433,6 +556,57 @@ describe('BusinessForm', () => {
expect(screen.queryByRole('switch', { name: '只读开关' })).not.toBeInTheDocument(); expect(screen.queryByRole('switch', { name: '只读开关' })).not.toBeInTheDocument();
}); });
it('uses TDesign text, image and link primitives for readonly and static upload display', () => {
render(
<BusinessForm
fields={[
{ key: 'summary', label: '说明', type: 'displayText' },
{ key: 'readonlyNote', label: '只读说明', type: 'input', readonly: true },
{ key: 'readonlySwitch', label: '只读开关', type: 'switch', readonly: true },
{
key: 'readonlyMedia',
label: '只读素材',
type: 'upload',
uploadType: 'media',
readonly: true,
upload: vi.fn(),
},
{
key: 'readonlyFile',
label: '只读文件',
type: 'upload',
uploadType: 'file',
readonly: true,
upload: vi.fn(),
},
]}
values={{
summary: '展示内容',
readonlyNote: '只读内容',
readonlySwitch: true,
readonlyMedia: { name: 'cover.png', url: '/cover.png', kind: 'image' },
readonlyFile: { name: 'manual.pdf', url: '/manual.pdf', kind: 'file' },
}}
onChange={vi.fn()}
/>,
);
const summaryField = screen.getByTestId('business-form-field-summary');
const readonlyNoteField = screen.getByTestId('business-form-field-readonlyNote');
const readonlySwitchField = screen.getByTestId('business-form-field-readonlySwitch');
const readonlyMediaField = screen.getByTestId('business-form-field-readonlyMedia');
const readonlyFileField = screen.getByTestId('business-form-field-readonlyFile');
expect(within(summaryField).getByText('展示内容').tagName).toBe('SPAN');
expect(within(readonlyNoteField).getByText('只读内容').tagName).toBe('SPAN');
expect(within(readonlySwitchField).getByText('已开启').tagName).toBe('SPAN');
expect(readonlyMediaField.querySelector('.t-image')).toBeInTheDocument();
expect(within(readonlyMediaField).getByText('cover.png').tagName).toBe('SPAN');
expect(readonlyFileField.querySelector('.t-link')).toHaveAttribute('href', '/manual.pdf');
expect(readonlyFileField.querySelector('.t-link')).toHaveAttribute('target', '_blank');
expect(readonlyFileField.querySelector('.t-link')).toHaveAttribute('rel', 'noreferrer');
});
it('rejects invalid media uploads, uploads media and file values separately, and renders media cards', async () => { it('rejects invalid media uploads, uploads media and file values separately, and renders media cards', async () => {
const upload = vi.fn(async (file: File) => ({ url: `/uploaded/${file.name}` })); const upload = vi.fn(async (file: File) => ({ url: `/uploaded/${file.name}` }));
const failedUpload = vi.fn(async () => { const failedUpload = vi.fn(async () => {
......
import { fireEvent, render, screen, waitFor } from '@testing-library/react'; import { fireEvent, render, screen, waitFor } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest'; import { describe, expect, it, vi } from 'vitest';
import { BusinessTable } from '@gl/business-components'; import { BusinessTable, type BusinessTableColumn } from '@gl/business-components';
import type { PrimaryTableCol } from 'tdesign-react'; import type { PrimaryTableCol } from 'tdesign-react';
type DemoRow = { type DemoRow = {
...@@ -229,6 +229,122 @@ describe('BusinessTable', () => { ...@@ -229,6 +229,122 @@ describe('BusinessTable', () => {
expect(screen.getByText('示例一').closest('tr')).toHaveClass('demo-row'); expect(screen.getByText('示例一').closest('tr')).toHaveClass('demo-row');
}); });
it('does not add tooltip to plain text cells by default', () => {
const longName = '这是一段很长的表格文本内容,用来验证通用表格列的省略和悬浮展示';
const { container } = render(
<BusinessTable
rowKey="id"
columns={demoColumns}
data={[
{ id: 1, name: longName, status: '启用' },
]}
/>,
);
const textCell = screen.getByText(longName);
expect(textCell.className).not.toContain('cellText');
expect(container.querySelector('[class*="cellTooltipContent"]')).not.toBeInTheDocument();
});
it('truncates explicitly configured text cells and shows full content with TDesign Tooltip', async () => {
const longName = '这是一段很长的表格文本内容,用来验证通用表格列的省略和悬浮展示';
const columns: BusinessTableColumn<DemoRow>[] = [
{ title: '名称', colKey: 'name', ellipsisTooltip: true },
{
title: '状态',
colKey: 'status',
cell: ({ row }) => <span>{row.status}</span>,
},
];
const { container } = render(
<BusinessTable
rowKey="id"
columns={columns}
data={[
{ id: 1, name: longName, status: '启用' },
]}
/>,
);
const textCell = screen.getByText(longName);
expect(textCell.className).toContain('cellText');
expect(screen.getByText('启用').className).not.toContain('cellText');
fireEvent.mouseEnter(textCell);
await waitFor(() => {
const tooltipContent = document.body.querySelector('[class*="cellTooltipContent"]');
expect(tooltipContent).toBeInTheDocument();
if (!tooltipContent) throw new Error('Tooltip content should exist');
expect(tooltipContent).toHaveTextContent(longName);
expect(tooltipContent).toHaveStyle({
width: '200px',
maxWidth: '200px',
whiteSpace: 'normal',
});
expect(tooltipContent.className).toContain('cellTooltipContent');
});
expect(container.querySelector('.t-table')).toBeInTheDocument();
});
it('uses explicit tooltip value for derived plain text columns', async () => {
type AgentRow = {
id: number;
agents: string[];
};
const agentText = '小顾、设计助手、投放助手';
const columns: BusinessTableColumn<AgentRow>[] = [
{
title: '关联 Agent',
colKey: 'agents',
ellipsisTooltip: true,
tooltipValue: ({ agents }) => (agents.length > 0 ? agents.join('、') : '-'),
},
];
render(
<BusinessTable
rowKey="id"
columns={columns}
data={[{ id: 1, agents: ['小顾', '设计助手', '投放助手'] }]}
/>,
);
const textCell = screen.getByText(agentText);
expect(textCell.className).toContain('cellText');
fireEvent.mouseEnter(textCell);
await waitFor(() => {
const tooltipContent = document.body.querySelector('[class*="cellTooltipContent"]');
expect(tooltipContent).toBeInTheDocument();
expect(tooltipContent).toHaveTextContent(agentText);
});
});
it('does not render tooltip for explicitly configured empty text cells', () => {
const columns: BusinessTableColumn<DemoRow>[] = [
{ title: '名称', colKey: 'name', ellipsisTooltip: true },
];
const { container } = render(
<BusinessTable
rowKey="id"
columns={columns}
data={[
{ id: 1, name: '', status: '启用' },
{ id: 2, name: ' ', status: '启用' },
{ id: 3, name: '-', status: '启用' },
{ id: 4, name: '实际说明', status: '启用' },
]}
/>,
);
expect(screen.getAllByText('-')).toHaveLength(3);
expect(screen.getByText('实际说明').className).toContain('cellText');
expect(container.querySelectorAll('[class*="cellText"]')).toHaveLength(1);
expect(container.querySelector('[class*="cellTooltipContent"]')).not.toBeInTheDocument();
});
it('renders pagination, honors totalLabel and can disable pagination', () => { it('renders pagination, honors totalLabel and can disable pagination', () => {
const { container, rerender } = render( const { container, rerender } = render(
<BusinessTable <BusinessTable
...@@ -259,6 +375,6 @@ describe('BusinessTable', () => { ...@@ -259,6 +375,6 @@ describe('BusinessTable', () => {
); );
expect(container.querySelector('.t-pagination')).not.toBeInTheDocument(); expect(container.querySelector('.t-pagination')).not.toBeInTheDocument();
expect(screen.getByText('共 35 条')).toBeInTheDocument(); expect(screen.getByText('共 35 条').tagName).toBe('SPAN');
}); });
}); });
...@@ -34,12 +34,16 @@ const MessageContext = createContext<MessageContextValue | null>(null); ...@@ -34,12 +34,16 @@ const MessageContext = createContext<MessageContextValue | null>(null);
export function MessageProvider({ children }: { children: ReactNode }) { export function MessageProvider({ children }: { children: ReactNode }) {
const addMessage = useCallback((type: FlashState['type'], content: string, options?: MessageOptions) => { const addMessage = useCallback((type: FlashState['type'], content: string, options?: MessageOptions) => {
try {
MessagePlugin[type]({ MessagePlugin[type]({
content, content,
duration: options?.duration ?? 3000, duration: options?.duration ?? 3000,
closeBtn: options?.closable ?? false, closeBtn: options?.closable ?? false,
placement: 'top-right', placement: 'top-right',
}); });
} catch {
// 消息插件在测试或无 DOM 环境下可能不可用,忽略即可。
}
}, []); }, []);
const success = useCallback((content: string, options?: MessageOptions) => { const success = useCallback((content: string, options?: MessageOptions) => {
...@@ -59,7 +63,11 @@ export function MessageProvider({ children }: { children: ReactNode }) { ...@@ -59,7 +63,11 @@ export function MessageProvider({ children }: { children: ReactNode }) {
}, [addMessage]); }, [addMessage]);
const clear = useCallback(() => { const clear = useCallback(() => {
try {
MessagePlugin.closeAll(); MessagePlugin.closeAll();
} catch {
// 忽略消息插件关闭失败。
}
}, []); }, []);
return ( return (
......
...@@ -22,4 +22,13 @@ describe('phase five editor page local ui runtime dependencies', () => { ...@@ -22,4 +22,13 @@ describe('phase five editor page local ui runtime dependencies', () => {
it.each(editorPageRuntimeFiles)('%s no longer imports packages/ui', (_, source) => { it.each(editorPageRuntimeFiles)('%s no longer imports packages/ui', (_, source) => {
expect(source).not.toContain('packages/ui'); expect(source).not.toContain('packages/ui');
}); });
it.each([
['AgentTagEditorPage.tsx', agentTagEditorPageSource],
['ChannelCodeEditorPage.tsx', channelCodeEditorPageSource],
['OfficialSiteJobTabEditorPage.tsx', officialSiteJobTabEditorPageSource],
])('%s uses BusinessForm instead of direct TDesign form controls', (_, source) => {
expect(source).toContain('BusinessForm');
expect(source).not.toContain('TDesignAccessibleControls');
});
}); });
import { useState } from 'react'; import { useState } from 'react';
import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom'; import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom';
import { StatePlaceholder } from '@gl/business-components'; import {
BusinessForm,
StatePlaceholder,
validateBusinessForm,
type BusinessFormErrors,
type BusinessFormField,
type BusinessFormValues,
} from '@gl/business-components';
import { Button } from 'tdesign-react'; import { Button } from 'tdesign-react';
import { FormItem, Input, Textarea } from '../../components/TDesignAccessibleControls';
import { import {
getPositionTagList, getPositionTagList,
createPositionTag, createPositionTag,
...@@ -14,14 +20,10 @@ import { trackCustomEvent } from '../../api/tracking'; ...@@ -14,14 +20,10 @@ import { trackCustomEvent } from '../../api/tracking';
import { useDeferredEffect } from '../../hooks/useDeferredEffect'; import { useDeferredEffect } from '../../hooks/useDeferredEffect';
import { buildAgentTagListSearch, readAgentTagListRouteState } from './agentTagRouteState'; import { buildAgentTagListSearch, readAgentTagListRouteState } from './agentTagRouteState';
interface TagFormState { interface TagFormState extends BusinessFormValues {
name: string; name: string;
description: string; description: string;
} code?: string;
interface TagFormErrors {
name?: string;
description?: string;
} }
interface SaveNotice { interface SaveNotice {
...@@ -33,6 +35,7 @@ function buildInitialFormState(tag?: PositionTagListItem): TagFormState { ...@@ -33,6 +35,7 @@ function buildInitialFormState(tag?: PositionTagListItem): TagFormState {
return { return {
name: tag?.name ?? '', name: tag?.name ?? '',
description: tag?.description ?? '', description: tag?.description ?? '',
code: tag?.code ?? '',
}; };
} }
...@@ -47,10 +50,10 @@ export function AgentTagEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -47,10 +50,10 @@ export function AgentTagEditorPage({ mode }: { mode: 'create' | 'edit' }) {
const [loadError, setLoadError] = useState(false); const [loadError, setLoadError] = useState(false);
const [currentTag, setCurrentTag] = useState<PositionTagListItem | undefined>(() => routeTag); const [currentTag, setCurrentTag] = useState<PositionTagListItem | undefined>(() => routeTag);
const [form, setForm] = useState<TagFormState>(() => buildInitialFormState(currentTag)); const [form, setForm] = useState<TagFormState>(() => buildInitialFormState(currentTag));
const [errors, setErrors] = useState<TagFormErrors>({}); const [errors, setErrors] = useState<BusinessFormErrors>({});
const [notice, setNotice] = useState<SaveNotice | null>(null); const [notice, setNotice] = useState<SaveNotice | null>(null);
const [saving, setSaving] = useState(false); const [saving, setSaving] = useState(false);
const fieldWidthClassName = 'w-full max-w-[450px]'; const fieldWidth = 450;
useDeferredEffect(() => { useDeferredEffect(() => {
if (mode === 'edit' && !routeTag && params.tagId) { if (mode === 'edit' && !routeTag && params.tagId) {
...@@ -77,6 +80,30 @@ export function AgentTagEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -77,6 +80,30 @@ export function AgentTagEditorPage({ mode }: { mode: 'create' | 'edit' }) {
navigate(`/agent-tags${buildAgentTagListSearch(routeState)}`); navigate(`/agent-tags${buildAgentTagListSearch(routeState)}`);
}; };
const fields: BusinessFormField[] = [
{
key: 'name',
label: '标签名称',
type: 'input',
required: true,
maxLength: 20,
},
{
key: 'code',
label: '标签编码',
type: 'input',
readonly: true,
visible: mode === 'edit' && Boolean(currentTag?.code),
},
{
key: 'description',
label: '标签描述',
type: 'textarea',
maxLength: 100,
rows: 5,
},
];
if (loading) { if (loading) {
return ( return (
<section className="grid gap-6"> <section className="grid gap-6">
...@@ -85,7 +112,7 @@ export function AgentTagEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -85,7 +112,7 @@ export function AgentTagEditorPage({ mode }: { mode: 'create' | 'edit' }) {
); );
} }
if (mode === 'edit' && !currentTag) { if (loadError || (mode === 'edit' && !currentTag)) {
return ( return (
<StatePlaceholder <StatePlaceholder
state="error" state="error"
...@@ -96,28 +123,12 @@ export function AgentTagEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -96,28 +123,12 @@ export function AgentTagEditorPage({ mode }: { mode: 'create' | 'edit' }) {
); );
} }
const validate = () => {
const nextErrors: TagFormErrors = {};
const trimmedName = form.name.trim();
const trimmedDescription = form.description.trim();
if (!trimmedName) {
nextErrors.name = '请输入标签名称';
} else if (trimmedName.length > 20) {
nextErrors.name = '标签名称最多20字';
}
if (trimmedDescription.length > 100) {
nextErrors.description = '标签描述最多100字';
}
setErrors(nextErrors);
return Object.keys(nextErrors).length === 0;
};
const handleSave = async () => { const handleSave = async () => {
setNotice(null); setNotice(null);
if (!validate()) {
const validation = await validateBusinessForm(fields, form);
setErrors(validation);
if (Object.values(validation).some(Boolean)) {
return; return;
} }
...@@ -177,41 +188,14 @@ export function AgentTagEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -177,41 +188,14 @@ export function AgentTagEditorPage({ mode }: { mode: 'create' | 'edit' }) {
<div className="rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-10"> <div className="rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-10">
<div className="mx-auto grid max-w-[760px] gap-6"> <div className="mx-auto grid max-w-[760px] gap-6">
<FormItem label="标签名称" labelAlign="left" requiredMark status={errors.name ? 'error' : undefined} tips={errors.name}> <BusinessForm
<Input fields={fields}
aria-label="标签名称" values={form}
className={fieldWidthClassName} errors={errors}
maxlength={20} fieldWidth={fieldWidth}
allowInputOverMax labelAlign="left"
showLimitNumber onChange={(nextValues) => setForm(nextValues as TagFormState)}
value={form.name}
onChange={(value) => setForm((current) => ({ ...current, name: value }))}
/>
</FormItem>
{mode === 'edit' && currentTag?.code ? (
<FormItem label="标签编码" labelAlign="left">
<Input
aria-label="标签编码"
className={fieldWidthClassName}
disabled
value={currentTag.code}
/>
</FormItem>
) : null}
<FormItem label="标签描述" labelAlign="left" status={errors.description ? 'error' : undefined} tips={errors.description}>
<Textarea
aria-label="标签描述"
className={fieldWidthClassName}
maxlength={100}
allowInputOverMax
rows={5}
count
value={form.description}
onChange={(value) => setForm((current) => ({ ...current, description: value }))}
/> />
</FormItem>
</div> </div>
</div> </div>
</section> </section>
......
...@@ -133,7 +133,8 @@ export function AgentTagListPage() { ...@@ -133,7 +133,8 @@ export function AgentTagListPage() {
{ {
title: '标签描述', title: '标签描述',
colKey: 'description', colKey: 'description',
cell: ({ row }) => row.description?.trim() || '-', ellipsisTooltip: true,
tooltipValue: ({ description }) => description?.trim() || '-',
}, },
{ title: '绑定Agent数', colKey: 'agent_count' }, { title: '绑定Agent数', colKey: 'agent_count' },
{ title: '创建时间', colKey: 'created_at' }, { title: '创建时间', colKey: 'created_at' },
......
...@@ -172,6 +172,7 @@ describe('Agent tag routes and list page', () => { ...@@ -172,6 +172,7 @@ describe('Agent tag routes and list page', () => {
expect(screen.getAllByText('标签名称').length).toBeGreaterThan(0); expect(screen.getAllByText('标签名称').length).toBeGreaterThan(0);
expect(screen.getByText('标签编码')).toBeInTheDocument(); expect(screen.getByText('标签编码')).toBeInTheDocument();
expect(screen.getByText('标签描述')).toBeInTheDocument(); expect(screen.getByText('标签描述')).toBeInTheDocument();
expect(screen.getByText('驻店销售岗').className).toContain('cellText');
expect(screen.getByText('绑定Agent数')).toBeInTheDocument(); expect(screen.getByText('绑定Agent数')).toBeInTheDocument();
expect(screen.getByText('创建时间')).toBeInTheDocument(); expect(screen.getByText('创建时间')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '编辑店销顾问' })).toHaveClass('t-button--theme-primary', 't-button--variant-text'); expect(screen.getByRole('button', { name: '编辑店销顾问' })).toHaveClass('t-button--theme-primary', 't-button--variant-text');
...@@ -285,7 +286,7 @@ describe('Agent tag create and edit pages', () => { ...@@ -285,7 +286,7 @@ describe('Agent tag create and edit pages', () => {
// Validate that only name is required (code is auto-generated by backend) // Validate that only name is required (code is auto-generated by backend)
fireEvent.click(screen.getByRole('button', { name: '保存' })); fireEvent.click(screen.getByRole('button', { name: '保存' }));
await screen.findByText('请输入标签名称'); await screen.findByText('请输入必填项');
expect(screen.queryByText('请输入标签编码')).not.toBeInTheDocument(); expect(screen.queryByText('请输入标签编码')).not.toBeInTheDocument();
expect(screen.queryByLabelText('标签编码')).not.toBeInTheDocument(); expect(screen.queryByLabelText('标签编码')).not.toBeInTheDocument();
...@@ -317,9 +318,9 @@ describe('Agent tag create and edit pages', () => { ...@@ -317,9 +318,9 @@ describe('Agent tag create and edit pages', () => {
await screen.findByRole('heading', { name: '编辑岗位标签' }); await screen.findByRole('heading', { name: '编辑岗位标签' });
await waitFor(() => { await waitFor(() => {
expect(screen.getByLabelText('标签名称')).toHaveValue('售后客服'); expect(screen.getByLabelText('标签名称')).toHaveValue('售后客服');
expect(screen.getByLabelText('标签编码')).toHaveValue('after_sales_service'); expect(screen.getByText('after_sales_service')).toBeInTheDocument();
}); });
expect(screen.getByLabelText('标签编码')).toBeDisabled(); expect(screen.queryByRole('textbox', { name: '标签编码' })).not.toBeInTheDocument();
fireEvent.change(screen.getByLabelText('标签名称'), { target: { value: '售后服务' } }); fireEvent.change(screen.getByLabelText('标签名称'), { target: { value: '售后服务' } });
fireEvent.click(screen.getByRole('button', { name: '保存' })); fireEvent.click(screen.getByRole('button', { name: '保存' }));
......
import { useState } from 'react'; import { useState } from 'react';
import { useNavigate, useParams, useSearchParams } from 'react-router-dom'; import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
import { StatePlaceholder } from '@gl/business-components'; import {
BusinessForm,
StatePlaceholder,
type BusinessFormErrors,
type BusinessFormField,
type BusinessFormValues,
} from '@gl/business-components';
import { Button } from 'tdesign-react'; import { Button } from 'tdesign-react';
import { FormItem, Input, Select, Switch, Textarea } from '../../components/TDesignAccessibleControls'; import { Input, Select } from '../../components/TDesignAccessibleControls';
import { getPositionTagList, type PositionTagListItem } from '../../api/positionTag'; import { getPositionTagList, type PositionTagListItem } from '../../api/positionTag';
import { getEmployeeMounts, getAgentDetail, getAgentList, createAgent, updateAgent, type EmployeeMountItem, type AgentDetail, type AgentStatus } from '../../api/agent'; import { getEmployeeMounts, getAgentDetail, getAgentList, createAgent, updateAgent, type EmployeeMountItem, type AgentDetail, type AgentStatus } from '../../api/agent';
import { getSkillList, type SkillSummary } from '../../api/skill'; import { getSkillList, type SkillSummary } from '../../api/skill';
...@@ -19,7 +25,7 @@ interface PositionOption { ...@@ -19,7 +25,7 @@ interface PositionOption {
name: string; name: string;
} }
interface AgentFormState { interface AgentFormState extends BusinessFormValues {
name: string; name: string;
positionIds: number[]; positionIds: number[];
managedUserId: number | string | undefined; managedUserId: number | string | undefined;
...@@ -30,7 +36,6 @@ interface AgentFormState { ...@@ -30,7 +36,6 @@ interface AgentFormState {
status: AgentStatus; status: AgentStatus;
} }
const STEWARD_AGENT_NAME = '管家Agent';
const STEWARD_POSITION_LABEL = '系统调度'; const STEWARD_POSITION_LABEL = '系统调度';
const STEWARD_MANAGED_USER_FALLBACK = '专用管家企微员工'; const STEWARD_MANAGED_USER_FALLBACK = '专用管家企微员工';
const AGENT_DESCRIPTION_MAX_LENGTH = 500; const AGENT_DESCRIPTION_MAX_LENGTH = 500;
...@@ -84,6 +89,10 @@ function canSelectEmployee(employee: EmployeeMountItem, mode: 'create' | 'edit', ...@@ -84,6 +89,10 @@ function canSelectEmployee(employee: EmployeeMountItem, mode: 'create' | 'edit',
return mountedByCurrentAgent; return mountedByCurrentAgent;
} }
function isArrayValue(value: unknown): value is Array<string | number> {
return Array.isArray(value);
}
export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) { export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) {
const navigate = useNavigate(); const navigate = useNavigate();
const params = useParams(); const params = useParams();
...@@ -100,18 +109,15 @@ export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -100,18 +109,15 @@ export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) {
const initialFormState = buildInitialFormState(); const initialFormState = buildInitialFormState();
const [form, setForm] = useState<AgentFormState>(initialFormState); const [form, setForm] = useState<AgentFormState>(initialFormState);
const [errors, setErrors] = useState<Partial<Record<keyof AgentFormState, string>>>({}); const [errors, setErrors] = useState<BusinessFormErrors>({});
const [positionTags, setPositionTags] = useState<PositionTagListItem[]>([]); const [positionTags, setPositionTags] = useState<PositionTagListItem[]>([]);
const [positionsLoading, setPositionsLoading] = useState(true);
const [positionsError, setPositionsError] = useState(false); const [positionsError, setPositionsError] = useState(false);
const [employees, setEmployees] = useState<EmployeeMountItem[]>([]); const [employees, setEmployees] = useState<EmployeeMountItem[]>([]);
const [employeesLoading, setEmployeesLoading] = useState(true);
const [employeesError, setEmployeesError] = useState(false); const [employeesError, setEmployeesError] = useState(false);
const [skills, setSkills] = useState<SkillSummary[]>([]); const [skills, setSkills] = useState<SkillSummary[]>([]);
const [skillsLoading, setSkillsLoading] = useState(true);
const [skillsError, setSkillsError] = useState(false); const [skillsError, setSkillsError] = useState(false);
const [saveLoading, setSaveLoading] = useState(false); const [saveLoading, setSaveLoading] = useState(false);
...@@ -122,6 +128,16 @@ export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -122,6 +128,16 @@ export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) {
const fieldWidthClassName = 'w-full max-w-[450px]'; const fieldWidthClassName = 'w-full max-w-[450px]';
const agentId = params.agentId ? Number(params.agentId) : undefined; const agentId = params.agentId ? Number(params.agentId) : undefined;
const fetchPositions = () => {
setPositionsError(false);
getPositionTagList({ page: 1, page_size: 100 })
.then((response) => {
setPositionTags(response.list);
})
.catch(() => {
setPositionsError(true);
});
};
// 编辑模式始终调用详情接口,不依赖本地缓存 // 编辑模式始终调用详情接口,不依赖本地缓存
useDeferredEffect(() => { useDeferredEffect(() => {
...@@ -200,44 +216,28 @@ export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -200,44 +216,28 @@ export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) {
}, [agentId, detail?.name, mode]); }, [agentId, detail?.name, mode]);
useDeferredEffect(() => { useDeferredEffect(() => {
setPositionsLoading(true); fetchPositions();
setPositionsError(false);
getPositionTagList({ page: 1, page_size: 100 })
.then((response) => {
setPositionTags(response.list);
setPositionsLoading(false);
})
.catch(() => {
setPositionsError(true);
setPositionsLoading(false);
});
}, []); }, []);
useDeferredEffect(() => { useDeferredEffect(() => {
setEmployeesLoading(true);
setEmployeesError(false); setEmployeesError(false);
getEmployeeMounts() getEmployeeMounts()
.then((response) => { .then((response) => {
setEmployees(response.employees); setEmployees(response.employees);
setEmployeesLoading(false);
}) })
.catch(() => { .catch(() => {
setEmployeesError(true); setEmployeesError(true);
setEmployeesLoading(false);
}); });
}, []); }, []);
useDeferredEffect(() => { useDeferredEffect(() => {
setSkillsLoading(true);
setSkillsError(false); setSkillsError(false);
getSkillList() getSkillList()
.then((response) => { .then((response) => {
setSkills(response.list); setSkills(response.list);
setSkillsLoading(false);
}) })
.catch(() => { .catch(() => {
setSkillsError(true); setSkillsError(true);
setSkillsLoading(false);
}); });
}, []); }, []);
...@@ -263,82 +263,6 @@ export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -263,82 +263,6 @@ export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) {
navigate(`/agents${nextSearch}`); navigate(`/agents${nextSearch}`);
}; };
const validate = () => {
const nextErrors: Partial<Record<keyof AgentFormState, string>> = {};
if (!isSteward && !form.name.trim()) nextErrors.name = '请输入 Agent 名称';
if (!isSteward && form.positionIds.length === 0) nextErrors.positionIds = '请选择所属岗位';
if (!isSteward && !form.managedEmployeeValue) nextErrors.managedUserId = '请选择托管企微员工';
const description = form.description.trim();
if (!description) nextErrors.description = '请输入 Agent 描述';
else if (description.length > AGENT_DESCRIPTION_MAX_LENGTH) nextErrors.description = 'Agent 描述最多 500 字';
if (!isSteward && form.skillIds.length === 0) nextErrors.skillIds = '请至少绑定一个 Skill';
setErrors(nextErrors);
return Object.keys(nextErrors).length === 0;
};
const handleSave = async () => {
if (!validate()) {
return;
}
setSaveLoading(true);
setSaveError(null);
try {
if (mode === 'create') {
const payload = {
name: form.name.trim(),
position_ids: form.positionIds,
managed_user_id: form.managedUserId!,
description: form.description.trim(),
skill_codes: form.skillIds,
status: form.status,
};
const createdAgent = await createAgent(payload);
trackCustomEvent({ event_type: 'save_success', event_data: { page: 'agent_detail', agent_id: createdAgent.agent_id, is_new: true, skill_count: form.skillIds.length } });
message.success('保存成功');
navigate(
`/agents${buildAgentListSearch({
...routeState,
refreshToken: String(Date.now()),
})}`,
);
} else {
const payload = isSteward
? {
name: form.name.trim(),
description: form.description.trim(),
skill_codes: form.skillIds,
}
: {
name: form.name.trim(),
position_ids: form.positionIds,
managed_user_id: form.managedUserId,
description: form.description.trim(),
skill_codes: form.skillIds,
status: form.status,
};
const updatedAgent = await updateAgent(agentId!, payload);
trackCustomEvent({ event_type: 'save_success', event_data: { page: 'agent_detail', agent_id: agentId!, is_new: false, skill_count: updatedAgent.skill_ids?.length ?? form.skillIds.length } });
upsertSavedAgent(updatedAgent);
message.success('保存成功');
navigate(
`/agents${buildAgentListSearch({
...routeState,
detail: routeState.detail ? String(agentId) : undefined,
refreshToken: String(Date.now()),
})}`,
);
}
} catch (error) {
const errorMessage = isApiError(error) ? error.message : '保存失败,请重试';
setSaveError(errorMessage);
message.error(errorMessage);
} finally {
setSaveLoading(false);
}
};
const title = mode === 'create' ? '新建Agent' : '编辑Agent'; const title = mode === 'create' ? '新建Agent' : '编辑Agent';
const stewardManagedUserLabel = detail?.managed_user?.user_name ?? form.managedUserName ?? STEWARD_MANAGED_USER_FALLBACK; const stewardManagedUserLabel = detail?.managed_user?.user_name ?? form.managedUserName ?? STEWARD_MANAGED_USER_FALLBACK;
const currentManagedOption = form.managedUserId != null && form.managedUserName const currentManagedOption = form.managedUserId != null && form.managedUserName
...@@ -357,16 +281,13 @@ export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -357,16 +281,13 @@ export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) {
]; ];
const fetchEmployees = () => { const fetchEmployees = () => {
setEmployeesLoading(true);
setEmployeesError(false); setEmployeesError(false);
getEmployeeMounts() getEmployeeMounts()
.then((response) => { .then((response) => {
setEmployees(response.employees); setEmployees(response.employees);
setEmployeesLoading(false);
}) })
.catch(() => { .catch(() => {
setEmployeesError(true); setEmployeesError(true);
setEmployeesLoading(false);
}); });
}; };
...@@ -376,199 +297,319 @@ export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -376,199 +297,319 @@ export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) {
})); }));
const fetchSkills = () => { const fetchSkills = () => {
setSkillsLoading(true);
setSkillsError(false); setSkillsError(false);
getSkillList() getSkillList()
.then((response) => { .then((response) => {
setSkills(response.list); setSkills(response.list);
setSkillsLoading(false);
}) })
.catch(() => { .catch(() => {
setSkillsError(true); setSkillsError(true);
setSkillsLoading(false);
}); });
}; };
const fields: BusinessFormField[] = [
{
key: 'name',
label: 'Agent名称',
type: 'input',
required: true,
disabled: isSteward,
maxLength: 50,
validator: (value) => {
if (isSteward) return undefined;
return String(value ?? '').trim() ? undefined : '请输入 Agent 名称';
},
},
{
key: 'positionIds',
label: '所属岗位',
type: 'custom',
required: !isSteward,
validator: (value) => {
if (isSteward) return undefined;
return isArrayValue(value) && value.length > 0 ? undefined : '请选择所属岗位';
},
render: ({ values, setValue }) => {
if (positionsError) {
return ( return (
<section className="grid gap-6">
<header className="sticky top-0 z-10 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 className="flex items-center gap-4">
<Button variant="outline" onClick={() => goBackToList(Boolean(routeState.detail && mode === 'edit'))}>返回</Button>
<div>
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">{title}</h2>
<p className="m-0 mt-1 text-sm text-[var(--gl-color-text-secondary)]">
{mode === 'create' ? '创建新的岗位 Agent 配置' : '编辑已存在的 Agent 配置'}
</p>
</div>
</div>
<Button theme="primary" loading={saveLoading} onClick={handleSave}>保存</Button>
</header>
{saveError ? (
<StatePlaceholder <StatePlaceholder
state="error" state="error"
title="保存失败" title="岗位选项加载失败"
description={saveError} description="请重试加载岗位选项"
primaryAction={<Button size="small" onClick={handleSave}>重试</Button>} primaryAction={<Button size="small" onClick={fetchPositions}>重试</Button>}
/> />
) : null} );
}
<div className="rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-10"> if (isSteward) {
<div className="mx-auto grid max-w-[760px] gap-6"> return (
<FormItem label="Agent名称" labelAlign="left" requiredMark status={errors.name ? 'error' : undefined} tips={errors.name}>
<span className="grid gap-2">
<Input
aria-label="Agent名称"
className={fieldWidthClassName}
disabled={isSteward}
maxlength={50}
allowInputOverMax
showLimitNumber
value={form.name}
onChange={(value) => setForm((current) => ({ ...current, name: value }))}
/>
</span>
</FormItem>
<FormItem label="所属岗位" labelAlign="left" requiredMark status={errors.positionIds ? 'error' : undefined} tips={errors.positionIds}>
<span className="grid gap-2">
{positionsError ? (
<StatePlaceholder state="error" title="岗位选项加载失败" description="请重试加载岗位选项" primaryAction={<Button size="small" onClick={() => {
setPositionsLoading(true);
setPositionsError(false);
getPositionTagList({ page: 1, page_size: 100 })
.then((response) => {
setPositionTags(response.list);
setPositionsLoading(false);
})
.catch(() => {
setPositionsError(true);
setPositionsLoading(false);
});
}}>重试</Button>} />
) : isSteward ? (
// 管家 Agent 固定显示 "系统调度",使用 Input 确保显示固定文案
<Input <Input
aria-label="所属岗位" aria-label="所属岗位"
className={fieldWidthClassName} className={fieldWidthClassName}
disabled disabled
value={STEWARD_POSITION_LABEL} value={STEWARD_POSITION_LABEL}
/> />
) : ( );
}
return (
<Select <Select
aria-label="所属岗位" aria-label="所属岗位"
className={fieldWidthClassName} className={fieldWidthClassName}
disabled={isSteward}
multiple multiple
options={positionOptions.map((position) => ({ label: position.name, value: position.id }))} options={positionOptions.map((position) => ({ label: position.name, value: position.id }))}
value={form.positionIds.map(String)} value={isArrayValue(values.positionIds) ? values.positionIds.map(String) : []}
onChange={(value) => { onChange={(value) => {
const nextValue = Array.isArray(value) ? value.map(Number) : []; const nextValue = Array.isArray(value) ? value.map(Number) : [];
setForm((current) => ({ ...current, positionIds: nextValue })); setValue(nextValue);
}} }}
/> />
)} );
</span> },
</FormItem> },
{
key: 'managedUserId',
label: '托管企微员工',
type: 'custom',
required: !isSteward,
validator: (value) => {
if (isSteward) return undefined;
return value ? undefined : '请选择托管企微员工';
},
render: ({ values, setValues }) => {
if (employeesError) {
return (
<StatePlaceholder
state="error"
title="托管企微员工加载失败"
description="请重试加载托管企微员工选项"
primaryAction={<Button size="small" onClick={fetchEmployees}>重试</Button>}
/>
);
}
<FormItem if (isSteward) {
label="托管企微员工" return (
labelAlign="left"
requiredMark
status={errors.managedUserId ? 'error' : undefined} tips={errors.managedUserId}
>
<span className="grid gap-2">
{employeesError ? (
<StatePlaceholder state="error" title="托管企微员工加载失败" description="请重试加载托管企微员工选项" primaryAction={<Button size="small" onClick={fetchEmployees}>重试</Button>} />
) : isSteward ? (
<Input <Input
aria-label="托管企微员工" aria-label="托管企微员工"
className={fieldWidthClassName} className={fieldWidthClassName}
disabled disabled
value={stewardManagedUserLabel} value={stewardManagedUserLabel}
/> />
) : ( );
}
return (
<Select <Select
aria-label="托管企微员工" aria-label="托管企微员工"
className={fieldWidthClassName} className={fieldWidthClassName}
disabled={isSteward}
options={employeeOptions} options={employeeOptions}
placeholder="请选择托管企微员工" placeholder="请选择托管企微员工"
value={form.managedEmployeeValue} value={values.managedEmployeeValue ?? undefined}
onChange={(value) => setForm((current) => { onChange={(value) => {
const selectedValue = String(value ?? ''); const selectedValue = String(value ?? '');
if (!selectedValue) { if (!selectedValue) {
return { setValues({
...current, ...values,
managedUserId: undefined, managedUserId: undefined,
managedEmployeeValue: undefined, managedEmployeeValue: undefined,
managedUserName: undefined, managedUserName: undefined,
}; }, 'managedUserId');
return;
} }
const currentDetailManagedUser = detail?.managed_user; const currentDetailManagedUser = detail?.managed_user;
if (currentDetailManagedUser && selectedValue === buildCurrentManagedEmployeeValue(currentDetailManagedUser.user_id)) { if (currentDetailManagedUser && selectedValue === buildCurrentManagedEmployeeValue(currentDetailManagedUser.user_id)) {
return { setValues({
...current, ...values,
managedUserId: currentDetailManagedUser.user_id, managedUserId: currentDetailManagedUser.user_id,
managedEmployeeValue: selectedValue, managedEmployeeValue: selectedValue,
managedUserName: currentDetailManagedUser.user_name, managedUserName: currentDetailManagedUser.user_name,
}; }, 'managedUserId');
return;
} }
const selectedEmployee = employees.find((employee) => buildEmployeeValue(employee) === selectedValue); const selectedEmployee = employees.find((employee) => buildEmployeeValue(employee) === selectedValue);
setValues({
return { ...values,
...current,
managedUserId: selectedEmployee?.employee_id, managedUserId: selectedEmployee?.employee_id,
managedEmployeeValue: selectedValue, managedEmployeeValue: selectedValue,
managedUserName: selectedEmployee?.employee_name, managedUserName: selectedEmployee?.employee_name,
}; }, 'managedUserId');
})} }}
/> />
)} );
</span> },
</FormItem> },
{
<FormItem label="Agent描述" labelAlign="left" requiredMark status={errors.description ? 'error' : undefined} tips={errors.description}> key: 'description',
<Textarea label: 'Agent描述',
aria-label="Agent描述" type: 'textarea',
className={fieldWidthClassName} required: true,
maxlength={AGENT_DESCRIPTION_MAX_LENGTH} maxLength: AGENT_DESCRIPTION_MAX_LENGTH,
allowInputOverMax rows: 5,
rows={5} validator: (value) => {
count const description = String(value ?? '').trim();
value={form.description} if (!description) return '请输入 Agent 描述';
onChange={(value) => setForm((current) => ({ ...current, description: value }))} if (description.length > AGENT_DESCRIPTION_MAX_LENGTH) return 'Agent 描述最多 500 字';
return undefined;
},
},
{
key: 'skillIds',
label: '绑定Skill',
type: 'custom',
required: !isSteward,
validator: (value) => {
if (isSteward) return undefined;
return isArrayValue(value) && value.length > 0 ? undefined : '请至少绑定一个 Skill';
},
render: ({ values, setValue }) => {
if (skillsError) {
return (
<StatePlaceholder
state="error"
title="Skill 选项加载失败"
description="请重试加载 Skill 选项"
primaryAction={<Button size="small" onClick={fetchSkills}>重试</Button>}
/> />
</FormItem> );
}
<FormItem label="绑定Skill" labelAlign="left" requiredMark={!isSteward} status={errors.skillIds ? 'error' : undefined} tips={errors.skillIds}> return (
<span className="grid gap-2">
{skillsError ? (
<StatePlaceholder state="error" title="Skill 选项加载失败" description="请重试加载 Skill 选项" primaryAction={<Button size="small" onClick={fetchSkills}>重试</Button>} />
) : (
<Select <Select
aria-label="绑定Skill" aria-label="绑定Skill"
className={fieldWidthClassName} className={fieldWidthClassName}
multiple multiple
options={skillOptions} options={skillOptions}
value={form.skillIds} value={isArrayValue(values.skillIds) ? values.skillIds : []}
onChange={(value) => setForm((current) => ({ ...current, skillIds: Array.isArray(value) ? value : [] }))} onChange={(value) => setValue(Array.isArray(value) ? value : [])}
/>
)}
</span>
</FormItem>
<FormItem label="状态" labelAlign="left" requiredMark>
<Switch
aria-label="状态"
value={isSteward ? true : form.status === 'enable'}
disabled={isSteward}
onChange={(checked) => setForm((current) => ({ ...current, status: checked ? 'enable' : 'disable' }))}
/> />
</FormItem> );
},
},
{
key: 'status',
label: '状态',
type: 'switch',
required: true,
disabled: isSteward,
checkedValue: 'enable',
uncheckedValue: 'disable',
},
];
const validate = () => {
const nextErrors: BusinessFormErrors = {};
if (!isSteward && !form.name.trim()) nextErrors.name = '请输入 Agent 名称';
if (!isSteward && (!Array.isArray(form.positionIds) || form.positionIds.length === 0)) nextErrors.positionIds = '请选择所属岗位';
if (!isSteward && !form.managedEmployeeValue) nextErrors.managedUserId = '请选择托管企微员工';
const description = form.description.trim();
if (!description) nextErrors.description = '请输入 Agent 描述';
else if (description.length > AGENT_DESCRIPTION_MAX_LENGTH) nextErrors.description = 'Agent 描述最多 500 字';
if (!isSteward && (!Array.isArray(form.skillIds) || form.skillIds.length === 0)) nextErrors.skillIds = '请至少绑定一个 Skill';
setErrors(nextErrors);
return Object.keys(nextErrors).length === 0;
};
const handleSave = async () => {
if (!validate()) {
return;
}
setSaveLoading(true);
setSaveError(null);
try {
if (mode === 'create') {
const payload = {
name: form.name.trim(),
position_ids: form.positionIds,
managed_user_id: form.managedUserId!,
description: form.description.trim(),
skill_codes: form.skillIds,
status: form.status,
};
const createdAgent = await createAgent(payload);
trackCustomEvent({ event_type: 'save_success', event_data: { page: 'agent_detail', agent_id: createdAgent.agent_id, is_new: true, skill_count: form.skillIds.length } });
message.success('保存成功');
navigate(
`/agents${buildAgentListSearch({
...routeState,
refreshToken: String(Date.now()),
})}`,
);
} else {
const payload = isSteward
? {
name: form.name.trim(),
description: form.description.trim(),
skill_codes: form.skillIds,
}
: {
name: form.name.trim(),
position_ids: form.positionIds,
managed_user_id: form.managedUserId,
description: form.description.trim(),
skill_codes: form.skillIds,
status: form.status,
};
const updatedAgent = await updateAgent(agentId!, payload);
trackCustomEvent({ event_type: 'save_success', event_data: { page: 'agent_detail', agent_id: agentId!, is_new: false, skill_count: updatedAgent.skill_ids?.length ?? form.skillIds.length } });
upsertSavedAgent(updatedAgent);
message.success('保存成功');
navigate(
`/agents${buildAgentListSearch({
...routeState,
detail: routeState.detail ? String(agentId) : undefined,
refreshToken: String(Date.now()),
})}`,
);
}
} catch (error) {
const errorMessage = isApiError(error) ? error.message : '保存失败,请重试';
setSaveError(errorMessage);
message.error(errorMessage);
} finally {
setSaveLoading(false);
}
};
return (
<section className="grid gap-6">
<header className="sticky top-0 z-10 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 className="flex items-center gap-4">
<Button variant="outline" onClick={() => goBackToList(Boolean(routeState.detail && mode === 'edit'))}>返回</Button>
<div>
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">{title}</h2>
<p className="m-0 mt-1 text-sm text-[var(--gl-color-text-secondary)]">
{mode === 'create' ? '创建新的岗位 Agent 配置' : '编辑已存在的 Agent 配置'}
</p>
</div>
</div> </div>
<Button theme="primary" loading={saveLoading} onClick={handleSave}>保存</Button>
</header>
{saveError ? (
<StatePlaceholder
state="error"
title="保存失败"
description={saveError}
primaryAction={<Button size="small" onClick={handleSave}>重试</Button>}
/>
) : null}
<div className="rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-10">
<BusinessForm
fields={fields}
values={form}
errors={errors}
labelAlign="left"
fieldWidth={fieldWidthClassName}
onChange={(nextValues) => {
setForm((current) => ({ ...current, ...nextValues } as AgentFormState));
}}
/>
</div> </div>
</section> </section>
); );
......
...@@ -61,6 +61,14 @@ function setupCreatePageMocks() { ...@@ -61,6 +61,14 @@ function setupCreatePageMocks() {
}); });
} }
function getControlHolder(name: string) {
const holder = screen.getByTestId(`business-form-control-holder-${name}`);
if (!holder) {
throw new Error(`Control holder ${name} was not found`);
}
return holder as HTMLElement;
}
describe('Channel code create page', () => { describe('Channel code create page', () => {
beforeEach(() => { beforeEach(() => {
window.localStorage.clear(); window.localStorage.clear();
...@@ -234,6 +242,11 @@ describe('Channel code create page', () => { ...@@ -234,6 +242,11 @@ describe('Channel code create page', () => {
expect(screen.getByRole('combobox', { name: '对应岗位' })).toBeInTheDocument(); expect(screen.getByRole('combobox', { name: '对应岗位' })).toBeInTheDocument();
expect(screen.getByLabelText('活码描述')).toBeInTheDocument(); expect(screen.getByLabelText('活码描述')).toBeInTheDocument();
expect(screen.getByLabelText('自动欢迎语')).toBeInTheDocument(); expect(screen.getByLabelText('自动欢迎语')).toBeInTheDocument();
expect(getControlHolder('qrcode_name')).toHaveStyle({ width: '100%', maxWidth: '450px' });
expect(getControlHolder('position_code')).toHaveStyle({ width: '100%', maxWidth: '450px' });
expect(getControlHolder('employee_id')).toHaveStyle({ width: '100%', maxWidth: '450px' });
expect(getControlHolder('description')).toHaveStyle({ width: '100%', maxWidth: '450px' });
expect(getControlHolder('welcome_message')).toHaveStyle({ width: '100%', maxWidth: '450px' });
// 状态编辑控件不再渲染 // 状态编辑控件不再渲染
expect(screen.queryByRole('switch', { name: '状态' })).not.toBeInTheDocument(); expect(screen.queryByRole('switch', { name: '状态' })).not.toBeInTheDocument();
}); });
...@@ -258,10 +271,12 @@ describe('Channel code create page', () => { ...@@ -258,10 +271,12 @@ describe('Channel code create page', () => {
fireEvent.click(screen.getByRole('button', { name: '保存' })); fireEvent.click(screen.getByRole('button', { name: '保存' }));
await waitFor(() => {
expect(screen.getByText('请输入活码名称')).toBeInTheDocument(); expect(screen.getByText('请输入活码名称')).toBeInTheDocument();
expect(screen.getByText('请对应岗位')).toBeInTheDocument(); expect(screen.getByText('请对应岗位')).toBeInTheDocument();
expect(screen.getByText('请选择承接员工')).toBeInTheDocument(); expect(screen.getByText('请选择承接员工')).toBeInTheDocument();
}); });
});
it('validates description max length', async () => { it('validates description max length', async () => {
vi.mocked(getPositionTagList).mockResolvedValueOnce({ vi.mocked(getPositionTagList).mockResolvedValueOnce({
...@@ -286,8 +301,10 @@ describe('Channel code create page', () => { ...@@ -286,8 +301,10 @@ describe('Channel code create page', () => {
fireEvent.change(screen.getByLabelText('活码描述'), { target: { value: longDescription } }); fireEvent.change(screen.getByLabelText('活码描述'), { target: { value: longDescription } });
fireEvent.click(screen.getByRole('button', { name: '保存' })); fireEvent.click(screen.getByRole('button', { name: '保存' }));
await waitFor(() => {
expect(screen.getByText('活码描述最多200字')).toBeInTheDocument(); expect(screen.getByText('活码描述最多200字')).toBeInTheDocument();
}); });
});
it('validates welcome message max length', async () => { it('validates welcome message max length', async () => {
vi.mocked(getPositionTagList).mockResolvedValueOnce({ vi.mocked(getPositionTagList).mockResolvedValueOnce({
...@@ -312,8 +329,10 @@ describe('Channel code create page', () => { ...@@ -312,8 +329,10 @@ describe('Channel code create page', () => {
fireEvent.change(screen.getByLabelText('自动欢迎语'), { target: { value: longMessage } }); fireEvent.change(screen.getByLabelText('自动欢迎语'), { target: { value: longMessage } });
fireEvent.click(screen.getByRole('button', { name: '保存' })); fireEvent.click(screen.getByRole('button', { name: '保存' }));
await waitFor(() => {
expect(screen.getByText('自动欢迎语最多500字')).toBeInTheDocument(); expect(screen.getByText('自动欢迎语最多500字')).toBeInTheDocument();
}); });
});
// TDD: 新增页不展示状态编辑项 // TDD: 新增页不展示状态编辑项
it('create page does NOT show status switch field', async () => { it('create page does NOT show status switch field', async () => {
...@@ -1276,6 +1295,80 @@ describe('Channel code edit page', () => { ...@@ -1276,6 +1295,80 @@ describe('Channel code edit page', () => {
expect(screen.getByRole('heading', { name: '编辑员工渠道活码' })).toBeInTheDocument(); expect(screen.getByRole('heading', { name: '编辑员工渠道活码' })).toBeInTheDocument();
}); });
await waitFor(() => expect(screen.getByLabelText('活码名称')).toHaveValue('店销顾问渠道活码')); await waitFor(() => expect(screen.getByLabelText('活码名称')).toHaveValue('店销顾问渠道活码'));
expect(screen.getByLabelText('对应岗位')).toHaveValue('驻店销售岗');
expect(screen.getByLabelText('对应岗位')).toBeDisabled();
expect(screen.getByText('DSC-QR-001')).toBeInTheDocument();
expect(screen.getByText('张小萌')).toBeInTheDocument();
expect(screen.getByText('店销助手Agent、管家Agent')).toBeInTheDocument();
});
it('echoes position object name in the disabled edit field', async () => {
vi.mocked(getChannelQRCodeDetail).mockResolvedValueOnce({
qrcode_id: 1,
employee_id: 'emp_001',
qrcode_name: '研发使用活码',
employee_name: '杨同学',
position_code: 'position_b8b2e6',
position: { name: '后端开发工程师' },
channel_code: 'position_b8b2e6',
qrcode_url: 'https://cdn.weixin.qq.com/qrcode/test.png',
agent_ids: [1],
agent_names: ['管家 Agent'],
status: 'enable',
remark: '',
welcome_message: '杨同学欢迎你!',
created_at: '2026-05-15T10:00:00Z',
created_by: 'admin',
} as any);
renderChannelCodes('/channel-codes/1/edit');
await waitFor(() => {
expect(screen.getByLabelText('对应岗位')).toHaveValue('后端开发工程师');
});
expect(screen.getByLabelText('对应岗位')).toBeDisabled();
});
it('orders edit fields to match the design reference', async () => {
vi.mocked(getChannelQRCodeDetail).mockResolvedValueOnce({
qrcode_id: 1,
employee_id: 'emp_001',
qrcode_name: '店销顾问渠道活码',
employee_name: '张小萌',
position_code: 'store_sales',
position_name: '驻店销售岗',
channel_code: 'DSC-QR-001',
qrcode_url: 'https://cdn.weixin.qq.com/qrcode/test.png',
agent_ids: [1, 2],
agent_names: ['店销助手Agent', '管家Agent'],
status: 'enable',
remark: '备注',
welcome_message: '欢迎',
created_at: '2026-05-15T10:00:00Z',
created_by: 'admin',
});
renderChannelCodes('/channel-codes/1/edit');
await waitFor(() => {
expect(screen.getByLabelText('活码名称')).toBeInTheDocument();
});
const orderedNodes = [
screen.getByLabelText('活码名称'),
screen.getByLabelText('对应岗位'),
screen.getByText('DSC-QR-001'),
screen.getByText('张小萌'),
screen.getByText('店销助手Agent、管家Agent'),
screen.getByLabelText('活码描述'),
screen.getByLabelText('自动欢迎语'),
];
for (let index = 0; index < orderedNodes.length - 1; index += 1) {
expect(
orderedNodes[index].compareDocumentPosition(orderedNodes[index + 1]) & Node.DOCUMENT_POSITION_FOLLOWING,
).toBeTruthy();
}
}); });
it('always fetches detail when entering edit page even if route state already has code data', async () => { it('always fetches detail when entering edit page even if route state already has code data', async () => {
...@@ -1353,6 +1446,7 @@ describe('Channel code edit page', () => { ...@@ -1353,6 +1446,7 @@ describe('Channel code edit page', () => {
}); });
expect(screen.getByLabelText('对应岗位')).toBeDisabled(); expect(screen.getByLabelText('对应岗位')).toBeDisabled();
expect(screen.getByLabelText('对应岗位')).toHaveValue('驻店销售岗');
expect(screen.getByText('DSC-QR-001')).toBeInTheDocument(); expect(screen.getByText('DSC-QR-001')).toBeInTheDocument();
}); });
......
import { useState } from 'react'; import { useState } from 'react';
import { flushSync } from 'react-dom';
import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom'; import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom';
import { StatePlaceholder } from '@gl/business-components'; import {
BusinessForm,
StatePlaceholder,
validateBusinessForm,
type BusinessFormErrors,
type BusinessFormField,
type BusinessFormValues,
} from '@gl/business-components';
import { Button } from 'tdesign-react'; import { Button } from 'tdesign-react';
import { FormItem, Input, Select, Textarea } from '../../components/TDesignAccessibleControls';
import { import {
getChannelQRCodeDetail, getChannelQRCodeDetail,
createChannelQRCode, createChannelQRCode,
...@@ -12,16 +19,14 @@ import { ...@@ -12,16 +19,14 @@ import {
type ChannelQRCodeDetail, type ChannelQRCodeDetail,
type ChannelQRCodeStatus, type ChannelQRCodeStatus,
type EmployeeMountsResponse, type EmployeeMountsResponse,
type EmployeeMountItem,
} from '../../api/channelCode'; } from '../../api/channelCode';
import { import {
getPositionTagList, getPositionTagList,
type PositionTagListItem, type PositionTagListItem,
} from '../../api/positionTag'; } from '../../api/positionTag';
import { useMessage } from '../../hooks/useMessage';
import { useDeferredEffect } from '../../hooks/useDeferredEffect'; import { useDeferredEffect } from '../../hooks/useDeferredEffect';
interface ChannelCodeFormState { interface ChannelCodeFormState extends BusinessFormValues {
qrcode_name: string; qrcode_name: string;
position_code: string; position_code: string;
employee_id: string; employee_id: string;
...@@ -30,32 +35,50 @@ interface ChannelCodeFormState { ...@@ -30,32 +35,50 @@ interface ChannelCodeFormState {
description: string; description: string;
welcome_message: string; welcome_message: string;
status: ChannelQRCodeStatus; status: ChannelQRCodeStatus;
} position_name?: string;
interface ChannelCodeFormErrors {
qrcode_name?: string;
position_code?: string;
employee_id?: string;
description?: string;
welcome_message?: string;
} }
interface SaveNotice { interface SaveNotice {
type: 'error'; type: 'error' | 'success';
message: string; message: string;
} }
function readString(value: unknown) {
return typeof value === 'string' ? value : '';
}
function readRecord(value: unknown) {
return value && typeof value === 'object' && !Array.isArray(value) ? value as Record<string, unknown> : {};
}
function resolvePositionName(code?: ChannelQRCodeDetail) {
if (!code) return '';
const position = readRecord(code.position);
const positionTag = readRecord(code.position_tag);
return readString(code.position_name)
|| readString(code.positionName)
|| readString(code.position_tag_name)
|| readString(position.name)
|| readString(position.position_name)
|| readString(positionTag.name)
|| readString(positionTag.position_name)
|| readString(code.position_code);
}
function buildInitialFormState(code?: ChannelQRCodeDetail): ChannelCodeFormState { function buildInitialFormState(code?: ChannelQRCodeDetail): ChannelCodeFormState {
return { return {
qrcode_name: code?.qrcode_name ?? '', qrcode_name: code?.qrcode_name ?? '',
position_code: '', position_code: code?.position_code ?? '',
employee_id: '', employee_id: code?.employee_id ?? '',
employee_name: '', employee_name: code?.employee_name ?? '',
wechat_user_id: '', wechat_user_id: '',
description: code?.remark ?? '', description: code?.remark ?? '',
welcome_message: code?.welcome_message ?? '', welcome_message: code?.welcome_message ?? '',
// 新增和编辑都使用启用状态,不提供停用入口 // 新增和编辑都使用启用状态,不提供停用入口
status: 'enable', status: 'enable',
position_name: resolvePositionName(code),
}; };
} }
...@@ -101,35 +124,30 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -101,35 +124,30 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) {
const location = useLocation(); const location = useLocation();
const params = useParams(); const params = useParams();
const [searchParams] = useSearchParams(); const [searchParams] = useSearchParams();
const message = useMessage();
const routeState = readChannelCodeListRouteState(searchParams); const routeState = readChannelCodeListRouteState(searchParams);
const routeCode = (location.state as { code?: ChannelQRCodeDetail } | null)?.code; const routeCode = (location.state as { code?: ChannelQRCodeDetail } | null)?.code;
const [loading, setLoading] = useState(mode === 'edit' && !routeCode); const [loading, setLoading] = useState(mode === 'edit' && !routeCode);
const [loadError, setLoadError] = useState(false); const [loadError, setLoadError] = useState(false);
const [currentCode, setCurrentCode] = useState<ChannelQRCodeDetail | undefined>(() => routeCode as ChannelQRCodeDetail | undefined); const [currentCode, setCurrentCode] = useState<ChannelQRCodeDetail | undefined>(() => routeCode as ChannelQRCodeDetail | undefined);
const [form, setForm] = useState<ChannelCodeFormState>(() => buildInitialFormState(currentCode)); const [form, setForm] = useState<ChannelCodeFormState>(() => buildInitialFormState(currentCode));
const [errors, setErrors] = useState<ChannelCodeFormErrors>({}); const [errors, setErrors] = useState<BusinessFormErrors>({});
const [notice, setNotice] = useState<SaveNotice | null>(null); const [notice, setNotice] = useState<SaveNotice | null>(null);
const [saving, setSaving] = useState(false); const [saving, setSaving] = useState(false);
const fieldWidthClassName = 'w-full max-w-[450px]'; const fieldWidth = 450;
// For create mode: position and employee selection // For create mode: position and employee selection
const [positions, setPositions] = useState<PositionTagListItem[]>([]); const [positions, setPositions] = useState<PositionTagListItem[]>([]);
const [positionsLoading, setPositionsLoading] = useState(false);
const [employeeMounts, setEmployeeMounts] = useState<EmployeeMountsResponse | null>(null); const [employeeMounts, setEmployeeMounts] = useState<EmployeeMountsResponse | null>(null);
const [employeeMountsLoading, setEmployeeMountsLoading] = useState(false);
// Load position list for create mode // Load position list for create mode
useDeferredEffect(() => { useDeferredEffect(() => {
if (mode === 'create') { if (mode === 'create') {
setPositionsLoading(true);
getPositionTagList({ page: 1, page_size: 100 }) getPositionTagList({ page: 1, page_size: 100 })
.then((response) => { .then((response) => {
setPositions(response.list); setPositions(response.list);
setPositionsLoading(false);
}) })
.catch(() => { .catch(() => {
setPositionsLoading(false); setPositions([]);
}); });
} }
}, [mode]); }, [mode]);
...@@ -137,14 +155,12 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -137,14 +155,12 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) {
// Load employees mounts for create mode // Load employees mounts for create mode
useDeferredEffect(() => { useDeferredEffect(() => {
if (mode === 'create') { if (mode === 'create') {
setEmployeeMountsLoading(true);
getEmployeeMounts() getEmployeeMounts()
.then((response) => { .then((response) => {
setEmployeeMounts(response); setEmployeeMounts(response);
setEmployeeMountsLoading(false);
}) })
.catch(() => { .catch(() => {
setEmployeeMountsLoading(false); setEmployeeMounts(null);
}); });
} }
}, [mode]); }, [mode]);
...@@ -170,6 +186,159 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -170,6 +186,159 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) {
navigate(`/channel-codes${buildChannelCodeListSearch(routeState)}`); navigate(`/channel-codes${buildChannelCodeListSearch(routeState)}`);
}; };
const createFields: BusinessFormField[] = [
{
key: 'qrcode_name',
label: '活码名称',
type: 'input',
required: true,
maxLength: 50,
validator: (value) => {
const text = typeof value === 'string' ? value : '';
if (!text) return '请输入活码名称';
return undefined;
},
},
{
key: 'position_code',
label: '对应岗位',
type: 'select',
required: true,
options: positions.map((p) => ({
value: p.code,
label: (p.qrcode_channel_count ?? 0) > 0 ? `${p.name}(该岗位已绑定活码)` : p.name,
disabled: (p.qrcode_channel_count ?? 0) > 0,
})),
placeholder: '请选择岗位',
validator: (value) => (value ? undefined : '请对应岗位'),
onChange: (value, context) => {
const selectedPosition = positions.find((p) => p.code === value);
return {
...context.values,
position_code: String(value ?? ''),
employee_id: '',
employee_name: '',
wechat_user_id: '',
position_name: selectedPosition?.name ?? '',
};
},
},
{
key: 'channel_code',
label: '渠道编码',
type: 'displayText',
visible: (values) => Boolean(values.position_code),
render: (_, values) => (typeof values.position_code === 'string' && values.position_code ? values.position_code : '-'),
},
{
key: 'agent_names',
label: '关联 Agent',
type: 'displayText',
visible: (values) => Boolean(values.position_code),
render: (_, values) => {
const agentNames = (positions.find((p) => p.code === values.position_code)?.agents ?? []).map((a) => a.name).join('、');
return agentNames || '-';
},
},
{
key: 'employee_id',
label: '承接员工',
type: 'select',
required: true,
validator: (value) => (value ? undefined : '请选择承接员工'),
options: (employeeMounts?.employees ?? []).map((e) => ({
value: e.employee_id,
label: e.qrcode_count > 0 ? `${e.employee_name}(该员工已绑定活码)` : e.employee_name,
disabled: e.qrcode_count > 0,
})),
placeholder: '请选择承接员工',
onChange: (value, context) => {
const selected = (employeeMounts?.employees ?? []).find((e) => e.employee_id === value);
return {
...context.values,
employee_id: String(value ?? ''),
employee_name: selected?.employee_name ?? '',
wechat_user_id: selected?.wechat_user_id ?? '',
position_code: selected?.position_code ?? String(context.values.position_code ?? ''),
};
},
},
{
key: 'description',
label: '活码描述',
type: 'textarea',
maxLength: 200,
rows: 3,
validator: (value) => {
const text = typeof value === 'string' ? value : '';
if (text.length > 200) return '活码描述最多200字';
return undefined;
},
},
{
key: 'welcome_message',
label: '自动欢迎语',
type: 'textarea',
maxLength: 500,
rows: 3,
validator: (value) => {
const text = typeof value === 'string' ? value : '';
if (text.length > 500) return '自动欢迎语最多500字';
return undefined;
},
},
];
const editFields: BusinessFormField[] = [
{
key: 'qrcode_name',
label: '活码名称',
type: 'input',
required: true,
maxLength: 50,
},
{
key: 'position_name',
label: '对应岗位',
type: 'input',
disabled: true,
},
{
key: 'channel_code',
label: '渠道编码',
type: 'displayText',
render: () => currentCode?.channel_code ?? '-',
},
{
key: 'employee_name',
label: '承接员工',
type: 'displayText',
render: () => currentCode?.employee_name ?? '-',
},
{
key: 'agent_names',
label: '关联 Agent',
type: 'displayText',
render: () => (currentCode?.agent_names ?? []).join('、') || '-',
},
{
key: 'description',
label: '活码描述',
type: 'textarea',
maxLength: 200,
rows: 3,
},
{
key: 'welcome_message',
label: '自动欢迎语',
type: 'textarea',
maxLength: 500,
rows: 3,
},
];
const fields = mode === 'create' ? createFields : editFields;
if (loading) { if (loading) {
return ( return (
<section className="grid gap-6"> <section className="grid gap-6">
...@@ -178,7 +347,7 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -178,7 +347,7 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) {
); );
} }
if (mode === 'edit' && !currentCode) { if (loadError || (mode === 'edit' && !currentCode)) {
return ( return (
<StatePlaceholder <StatePlaceholder
state="error" state="error"
...@@ -189,41 +358,12 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -189,41 +358,12 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) {
); );
} }
const validate = () => {
const nextErrors: ChannelCodeFormErrors = {};
const trimmedName = form.qrcode_name.trim();
const trimmedDescription = form.description.trim();
const trimmedWelcomeMessage = form.welcome_message.trim();
if (!trimmedName) {
nextErrors.qrcode_name = '请输入活码名称';
} else if (trimmedName.length > 50) {
nextErrors.qrcode_name = '活码名称最多50字';
}
if (mode === 'create' && !form.position_code) {
nextErrors.position_code = '请对应岗位';
}
if (mode === 'create' && !form.employee_id) {
nextErrors.employee_id = '请选择承接员工';
}
if (trimmedDescription.length > 200) {
nextErrors.description = '活码描述最多200字';
}
if (trimmedWelcomeMessage.length > 500) {
nextErrors.welcome_message = '自动欢迎语最多500字';
}
setErrors(nextErrors);
return Object.keys(nextErrors).length === 0;
};
const handleSave = async () => { const handleSave = async () => {
setNotice(null); setNotice(null);
if (!validate()) {
const validation = await validateBusinessForm(fields, form);
setErrors(validation);
if (Object.values(validation).some(Boolean)) {
return; return;
} }
...@@ -247,7 +387,9 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -247,7 +387,9 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) {
remark: form.description || undefined, remark: form.description || undefined,
welcome_message: form.welcome_message || undefined, welcome_message: form.welcome_message || undefined,
}); });
message.success('保存成功'); flushSync(() => {
setNotice({ type: 'success', message: '保存成功' });
});
} }
// Ensure at least 2 seconds stay on page after create success // Ensure at least 2 seconds stay on page after create success
...@@ -289,7 +431,11 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -289,7 +431,11 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) {
{notice ? ( {notice ? (
<div <div
className="rounded-[var(--gl-radius-sm)] border border-[var(--gl-color-danger-border)] bg-[var(--gl-color-danger-bg)] px-4 py-3 text-sm text-[var(--gl-color-danger-text)]" className={
notice.type === 'success'
? 'rounded-[var(--gl-radius-sm)] border border-[var(--gl-color-success-border)] bg-[var(--gl-color-success-bg)] px-4 py-3 text-sm text-[var(--gl-color-success-text)]'
: 'rounded-[var(--gl-radius-sm)] border border-[var(--gl-color-danger-border)] bg-[var(--gl-color-danger-bg)] px-4 py-3 text-sm text-[var(--gl-color-danger-text)]'
}
role="alert" role="alert"
aria-label={notice.message} aria-label={notice.message}
> >
...@@ -299,143 +445,14 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -299,143 +445,14 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) {
<div className="rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-10"> <div className="rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-10">
<div className="mx-auto grid max-w-[760px] gap-6"> <div className="mx-auto grid max-w-[760px] gap-6">
<FormItem label="活码名称" labelAlign="left" requiredMark status={errors.qrcode_name ? 'error' : undefined} tips={errors.qrcode_name}> <BusinessForm
<Input fields={fields}
aria-label="活码名称" values={form}
className={fieldWidthClassName} errors={errors}
maxlength={50} fieldWidth={fieldWidth}
allowInputOverMax labelAlign="left"
showLimitNumber onChange={(nextValues) => setForm(nextValues as ChannelCodeFormState)}
value={form.qrcode_name}
onChange={(value) => setForm((current) => ({ ...current, qrcode_name: value }))}
/>
</FormItem>
{mode === 'create' ? (
<>
<FormItem label="对应岗位" labelAlign="left" requiredMark status={errors.position_code ? 'error' : undefined} tips={errors.position_code}>
<Select
aria-label="对应岗位"
className={fieldWidthClassName}
options={positions.map((p) => ({
value: p.code,
label: (p.qrcode_channel_count ?? 0) > 0 ? `${p.name}(该岗位已绑定活码)` : p.name,
disabled: (p.qrcode_channel_count ?? 0) > 0,
}))}
placeholder="请选择岗位"
value={form.position_code}
onChange={(value) => {
const selectedPosition = positions.find((p) => p.code === value);
setForm((current) => ({
...current,
position_code: String(value ?? ''),
employee_id: '',
employee_name: '',
wechat_user_id: '',
}));
}}
/>
</FormItem>
{form.position_code ? (
<>
<FormItem label="渠道编码" labelAlign="left">
<div className={fieldWidthClassName}>
{form.position_code}
</div>
</FormItem>
<FormItem label="关联 Agent" labelAlign="left">
<div className={fieldWidthClassName}>
{(positions.find((p) => p.code === form.position_code)?.agents ?? []).map((a) => a.name).join('、') || '-'}
</div>
</FormItem>
</>
) : null}
<FormItem label="承接员工" labelAlign="left" requiredMark status={errors.employee_id ? 'error' : undefined} tips={errors.employee_id}>
<Select
aria-label="承接员工"
className={fieldWidthClassName}
options={(employeeMounts?.employees ?? []).map((e) => ({
value: e.employee_id,
label: e.qrcode_count > 0 ? `${e.employee_name}(该员工已绑定活码)` : e.employee_name,
disabled: e.qrcode_count > 0,
}))}
placeholder="请选择承接员工"
value={form.employee_id}
onChange={(value) => {
const selected = (employeeMounts?.employees ?? []).find((e) => e.employee_id === value);
setForm((current) => ({
...current,
employee_id: String(value ?? ''),
employee_name: selected?.employee_name ?? '',
wechat_user_id: selected?.wechat_user_id ?? '',
position_code: selected?.position_code ?? current.position_code,
}));
}}
/>
</FormItem>
</>
) : null}
{currentCode ? (
<>
<FormItem label="对应岗位" labelAlign="left">
<Input
aria-label="对应岗位"
className={fieldWidthClassName}
disabled
value={currentCode.position_name ?? ''}
/>
</FormItem>
<FormItem label="渠道编码" labelAlign="left">
<div className={fieldWidthClassName}>
{currentCode.channel_code ?? ''}
</div>
</FormItem>
<FormItem label="承接员工" labelAlign="left">
<div className={fieldWidthClassName}>
{currentCode.employee_name ?? ''}
</div>
</FormItem>
<FormItem label="关联 Agent" labelAlign="left">
<div className={fieldWidthClassName}>
{(currentCode.agent_names ?? []).join('、') || '-'}
</div>
</FormItem>
</>
) : null}
<FormItem label="活码描述" labelAlign="left" status={errors.description ? 'error' : undefined} tips={errors.description}>
<Textarea
aria-label="活码描述"
className={fieldWidthClassName}
maxlength={200}
allowInputOverMax
rows={3}
count
value={form.description}
onChange={(value) => setForm((current) => ({ ...current, description: value }))}
/>
</FormItem>
<FormItem label="自动欢迎语" labelAlign="left" status={errors.welcome_message ? 'error' : undefined} tips={errors.welcome_message}>
<Textarea
aria-label="自动欢迎语"
className={fieldWidthClassName}
maxlength={500}
allowInputOverMax
rows={3}
count
value={form.welcome_message}
onChange={(value) => setForm((current) => ({ ...current, welcome_message: value }))}
/> />
</FormItem>
{/* 状态编辑控件已移除,新增和编辑都默认使用启用状态 */}
</div> </div>
</div> </div>
</section> </section>
......
...@@ -164,6 +164,7 @@ describe('Channel code list page', () => { ...@@ -164,6 +164,7 @@ describe('Channel code list page', () => {
expect(within(firstRow).getByText('店销顾问渠道活码')).toBeInTheDocument(); expect(within(firstRow).getByText('店销顾问渠道活码')).toBeInTheDocument();
// 承接员工应该读取 employee_name 字段 // 承接员工应该读取 employee_name 字段
expect(within(firstRow).getByText('张小萌')).toBeInTheDocument(); expect(within(firstRow).getByText('张小萌')).toBeInTheDocument();
expect(within(firstRow).getByText('店销助手Agent、管家Agent').className).toContain('cellText');
const statusTag = within(firstRow).getByText('启用'); const statusTag = within(firstRow).getByText('启用');
// 状态应该使用 Tag 标签组件 // 状态应该使用 Tag 标签组件
......
...@@ -145,8 +145,9 @@ export function ChannelCodeListPage() { ...@@ -145,8 +145,9 @@ export function ChannelCodeListPage() {
{ {
title: '关联 Agent', title: '关联 Agent',
colKey: 'agent_names_preview', colKey: 'agent_names_preview',
cell: ({ row }) => { ellipsisTooltip: true,
const agents = row.agent_names_preview ?? []; tooltipValue: ({ agent_names_preview }) => {
const agents = agent_names_preview ?? [];
return agents.length > 0 ? agents.join('、') : '-'; return agents.length > 0 ? agents.join('、') : '-';
}, },
}, },
......
...@@ -137,7 +137,8 @@ describe('ComponentsDemoPage', () => { ...@@ -137,7 +137,8 @@ describe('ComponentsDemoPage', () => {
expect(scoped.getByLabelText('锁定项')).toBeDisabled(); expect(scoped.getByLabelText('锁定项')).toBeDisabled();
fireEvent.change(scoped.getByLabelText('展示模式'), { target: { value: 'read' } }); fireEvent.change(scoped.getByLabelText('展示模式'), { target: { value: 'read' } });
expect(scoped.getByLabelText('只读项')).toHaveAttribute('readonly'); expect(scoped.queryByLabelText('只读项')).not.toBeInTheDocument();
expect(scoped.getByText('只读内容')).toBeInTheDocument();
fireEvent.click(scoped.getByRole('button', { name: '填充摘要' })); fireEvent.click(scoped.getByRole('button', { name: '填充摘要' }));
expect(scoped.getByText('摘要:新合同')).toBeInTheDocument(); expect(scoped.getByText('摘要:新合同')).toBeInTheDocument();
......
...@@ -57,6 +57,31 @@ describe('AgentDisplayConfigEditModal', () => { ...@@ -57,6 +57,31 @@ describe('AgentDisplayConfigEditModal', () => {
}); });
describe('图标回显', () => { describe('图标回显', () => {
it('字段区域由 BusinessForm 承载', async () => {
const { getAgentDisplayDetail } = await import('../../api/officialSiteAgentDisplay');
vi.mocked(getAgentDisplayDetail).mockResolvedValueOnce(mockDisplayDetail);
render(
<AgentDisplayConfigEditModal
open={true}
displayId={1}
onCancel={() => {}}
onSaveSuccess={() => {}}
/>
);
await waitFor(() => {
expect(screen.getByTestId('business-form-field-agent_name')).toBeInTheDocument();
});
expect(screen.getByTestId('business-form-field-agent_name').closest('form')).toBeInTheDocument();
expect(screen.getByTestId('business-form-field-icon_url')).toBeInTheDocument();
expect(screen.getByTestId('business-form-field-speech_content')).toBeInTheDocument();
expect(screen.getByTestId('business-form-field-media_url')).toBeInTheDocument();
expect(screen.getByTestId('business-form-field-sort_order')).toBeInTheDocument();
expect(screen.getByTestId('business-form-field-display_status')).toBeInTheDocument();
});
it('已有 icon_url 时图标字段不展示必填错误', async () => { it('已有 icon_url 时图标字段不展示必填错误', async () => {
const { getAgentDisplayDetail } = await import('../../api/officialSiteAgentDisplay'); const { getAgentDisplayDetail } = await import('../../api/officialSiteAgentDisplay');
vi.mocked(getAgentDisplayDetail).mockResolvedValueOnce(mockDisplayDetail); vi.mocked(getAgentDisplayDetail).mockResolvedValueOnce(mockDisplayDetail);
...@@ -509,4 +534,85 @@ describe('AgentDisplayConfigEditModal', () => { ...@@ -509,4 +534,85 @@ describe('AgentDisplayConfigEditModal', () => {
}); });
}); });
}); });
describe('展示状态与排序校验', () => {
it('默认展示状态显示为不展示', async () => {
const { getAgentDisplayDetail } = await import('../../api/officialSiteAgentDisplay');
vi.mocked(getAgentDisplayDetail).mockResolvedValueOnce(mockDisplayDetailWithoutIcon);
render(
<AgentDisplayConfigEditModal
open={true}
displayId={2}
onCancel={() => {}}
onSaveSuccess={() => {}}
/>
);
await waitFor(() => {
expect(screen.getByText(/编辑展示配置 - 助手 Agent/)).toBeInTheDocument();
});
const statusInput = screen.getByRole('combobox', { name: '展示状态' });
expect(statusInput).toHaveAttribute('value', '不展示');
});
it('展示状态选项使用不展示和展示中', async () => {
const user = userEvent.setup();
const { getAgentDisplayDetail } = await import('../../api/officialSiteAgentDisplay');
vi.mocked(getAgentDisplayDetail).mockResolvedValueOnce(mockDisplayDetail);
render(
<AgentDisplayConfigEditModal
open={true}
displayId={1}
onCancel={() => {}}
onSaveSuccess={() => {}}
/>
);
await waitFor(() => {
expect(screen.getByText(/编辑展示配置 - 复盘 Agent/)).toBeInTheDocument();
});
await user.click(screen.getByRole('combobox', { name: '展示状态' }));
await waitFor(() => {
expect(screen.getByText('不展示')).toBeInTheDocument();
expect(screen.getByText('展示中')).toBeInTheDocument();
});
});
it('展示排序不允许小于0', async () => {
const user = userEvent.setup();
const { getAgentDisplayDetail, updateAgentDisplayConfig } = await import('../../api/officialSiteAgentDisplay');
vi.mocked(getAgentDisplayDetail).mockResolvedValueOnce(mockDisplayDetailWithoutIcon);
render(
<AgentDisplayConfigEditModal
open={true}
displayId={2}
onCancel={() => {}}
onSaveSuccess={() => {}}
/>
);
await waitFor(() => {
expect(screen.getByText(/编辑展示配置 - 助手 Agent/)).toBeInTheDocument();
});
const sortInput = screen.getByRole('spinbutton', { name: '展示排序' });
await user.clear(sortInput);
await user.type(sortInput, '-1');
const saveButton = screen.getByRole('button', { name: '确定' });
await user.click(saveButton);
await waitFor(() => {
expect(screen.getByText('排序请输入0-99的整数')).toBeInTheDocument();
});
expect(updateAgentDisplayConfig).not.toHaveBeenCalled();
});
});
}); });
import { useState } from 'react'; import { useState } from 'react';
import { MediaWall } from '@gl/business-components'; import {
BusinessForm,
MediaWall,
type BusinessFormErrors,
type BusinessFormField,
type BusinessFormValues,
} from '@gl/business-components';
import { Button, Dialog } from 'tdesign-react'; import { Button, Dialog } from 'tdesign-react';
import { FormItem, Input, Select } from '../../components/TDesignAccessibleControls';
import { import {
getAgentDisplayDetail, getAgentDisplayDetail,
updateAgentDisplayConfig, updateAgentDisplayConfig,
...@@ -20,7 +25,7 @@ interface EditModalProps { ...@@ -20,7 +25,7 @@ interface EditModalProps {
onSaveSuccess: () => void; onSaveSuccess: () => void;
} }
interface EditFormState { interface EditFormState extends BusinessFormValues {
speech_title: string; speech_title: string;
speech_content: string; speech_content: string;
sort_order: number; sort_order: number;
...@@ -273,6 +278,83 @@ export function AgentDisplayConfigEditModal({ ...@@ -273,6 +278,83 @@ export function AgentDisplayConfigEditModal({
? [{ id: 'icon', type: 'image', src: form.icon_url, alt: 'Agent图标' }] ? [{ id: 'icon', type: 'image', src: form.icon_url, alt: 'Agent图标' }]
: []; : [];
const businessFormErrors: BusinessFormErrors = {
agent_name: errors.speech_title,
icon_url: errors.icon_url || errors.upload_icon,
speech_content: errors.speech_content,
media_url: errors.media_url || errors.upload_media,
sort_order: errors.sort_order,
};
const fields: BusinessFormField[] = [
{
key: 'agent_name',
label: 'Agent 名称',
type: 'input',
required: true,
disabled: true,
},
{
key: 'icon_url',
label: '图标',
type: 'custom',
required: true,
helperText: '支持图片,推荐 1:1,最大 2MB',
render: () => (
<MediaWall
accept={ICON_ACCEPT}
maxCount={1}
multiple={false}
items={iconItems}
onSelectFiles={handleUploadIcon}
onRemove={handleRemoveIcon}
/>
),
},
{
key: 'speech_content',
label: 'Agent 概述',
type: 'input',
required: true,
placeholder: '请输入Agent概述',
maxLength: 100,
},
{
key: 'media_url',
label: '展示素材',
type: 'custom',
required: true,
helperText: '支持图片、视频、GIF,推荐 1:1,最大 20MB',
render: () => (
<MediaWall
accept="image/png,image/jpeg,image/jpg,image/gif,image/webp,video/mp4,video/quicktime,video/x-msvideo,video/webm"
maxCount={1}
multiple={false}
items={mediaItems}
onSelectFiles={handleUploadMedia}
onRemove={handleRemoveMedia}
/>
),
},
{
key: 'sort_order',
label: '展示排序',
type: 'numberInput',
required: true,
placeholder: '请输入展示排序',
},
{
key: 'display_status',
label: '展示状态',
type: 'select',
required: true,
options: [
{ value: 'disable', label: '不展示' },
{ value: 'enable', label: '展示中' },
],
},
];
return ( return (
<Dialog <Dialog
visible={open} visible={open}
...@@ -301,80 +383,19 @@ export function AgentDisplayConfigEditModal({ ...@@ -301,80 +383,19 @@ export function AgentDisplayConfigEditModal({
加载中... 加载中...
</div> </div>
) : ( ) : (
<div className="grid gap-6 py-4"> <BusinessForm
<FormItem label="Agent 名称" labelAlign="left" requiredMark status={errors.speech_title ? 'error' : undefined} tips={errors.speech_title}> className="py-4"
<Input data-testid="agent-display-config-edit-form"
aria-label="Agent 名称" errors={businessFormErrors}
className="w-full max-w-[400px]" fieldWidth={400}
disabled fields={fields}
value={form.agent_name} labelAlign="left"
/> values={form}
</FormItem> onChange={(nextValues) => setForm((current) => ({
<FormItem label="图标" labelAlign="left" requiredMark status={errors.icon_url || errors.upload_icon ? 'error' : undefined} tips={errors.icon_url || errors.upload_icon}>
<MediaWall
accept={ICON_ACCEPT}
maxCount={1}
multiple={false}
items={iconItems}
helperText="支持图片,推荐 1:1,最大 2MB"
onSelectFiles={handleUploadIcon}
onRemove={handleRemoveIcon}
/>
</FormItem>
<FormItem label="Agent 概述" labelAlign="left" requiredMark status={errors.speech_content ? 'error' : undefined} tips={errors.speech_content}>
<Input
aria-label="Agent 概述"
className="w-full max-w-[400px]"
placeholder="请输入Agent概述"
value={form.speech_content}
onChange={(value) => setForm((current) => ({ ...current, speech_content: value }))}
/>
</FormItem>
<FormItem label="展示素材" labelAlign="left" requiredMark status={errors.media_url || errors.upload_media ? 'error' : undefined} tips={errors.media_url || errors.upload_media}>
<MediaWall
accept="image/png,image/jpeg,image/jpg,image/gif,image/webp,video/mp4,video/quicktime,video/x-msvideo,video/webm"
maxCount={1}
multiple={false}
items={mediaItems}
helperText="支持图片、视频、GIF,推荐 1:1,最大 20MB"
onSelectFiles={handleUploadMedia}
onRemove={handleRemoveMedia}
/>
</FormItem>
<FormItem label="展示排序" labelAlign="left" requiredMark status={errors.sort_order ? 'error' : undefined} tips={errors.sort_order}>
<Input
aria-label="展示排序"
className="w-full max-w-[400px]"
type="number"
placeholder="请输入展示排序"
value={form.sort_order === undefined || (typeof form.sort_order === 'number' && isNaN(form.sort_order)) ? '' : String(form.sort_order)}
onChange={(value) => setForm((current) => ({
...current, ...current,
sort_order: value === '' ? undefined as unknown as number : Number(value), ...nextValues,
}))} } as EditFormState))}
/> />
</FormItem>
<FormItem label="展示状态" labelAlign="left" requiredMark>
<Select
aria-label="展示状态"
className="w-full max-w-[400px]"
options={[
{ value: 'disable', label: '已下架' },
{ value: 'enable', label: '展示中' },
]}
value={form.display_status}
onChange={(value) => setForm((current) => ({
...current,
display_status: value as DisplayStatus,
}))}
/>
</FormItem>
</div>
)} )}
</Dialog> </Dialog>
); );
......
import { fireEvent, render, screen, within, waitFor } from '@testing-library/react'; import { fireEvent, render, screen, within, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { MemoryRouter } from 'react-router-dom'; import { MemoryRouter } from 'react-router-dom';
import { beforeEach, describe, expect, it, vi } from 'vitest'; import { beforeEach, describe, expect, it, vi } from 'vitest';
...@@ -325,7 +326,7 @@ describe('Agent display config edit modal', () => { ...@@ -325,7 +326,7 @@ describe('Agent display config edit modal', () => {
expect(within(modal).getByText('展示排序')).toBeInTheDocument(); expect(within(modal).getByText('展示排序')).toBeInTheDocument();
}); });
it('shows 展示状态 field with 已下架 and 展示中 options only', () => { it('shows 展示状态 field with 不展示 and 展示中 options only', () => {
const modal = screen.getByRole('dialog'); const modal = screen.getByRole('dialog');
expect(within(modal).getByText('展示状态')).toBeInTheDocument(); expect(within(modal).getByText('展示状态')).toBeInTheDocument();
expect(within(modal).queryByText('已停用')).not.toBeInTheDocument(); expect(within(modal).queryByText('已停用')).not.toBeInTheDocument();
...@@ -344,9 +345,9 @@ describe('Agent display config edit modal', () => { ...@@ -344,9 +345,9 @@ describe('Agent display config edit modal', () => {
}); });
}); });
it('shows default display_status as 已下架 for unconfigured agent', () => { it('shows default display_status as 不展示 for unconfigured agent', () => {
const modal = screen.getByRole('dialog'); const modal = screen.getByRole('dialog');
expect(within(modal).getByRole('combobox', { name: '展示状态' })).toHaveAttribute('value', '已下架'); expect(within(modal).getByRole('combobox', { name: '展示状态' })).toHaveAttribute('value', '不展示');
}); });
it('shows empty icon for unconfigured agent', () => { it('shows empty icon for unconfigured agent', () => {
...@@ -387,31 +388,33 @@ describe('Agent display config edit modal', () => { ...@@ -387,31 +388,33 @@ describe('Agent display config edit modal', () => {
); );
}); });
it('validates speech_content max 100 chars', async () => { it('validates speech_content max 100 chars and shows length count', async () => {
const user = userEvent.setup();
const modal = screen.getByRole('dialog'); const modal = screen.getByRole('dialog');
const contentInput = within(modal).getByPlaceholderText('请输入Agent概述'); const contentInput = within(modal).getByPlaceholderText('请输入Agent概述');
const longContent = '这是一段超过一百字的概述内容这是一段超过一百字的概述内容这是一段超过一百字的概述内容这是一段超过一百字的概述内容这是一段超过一百字的概述内容这是一段超过一百字的概述内容这是一段超过一百字的概述内容这是一段超过一百字的概述内容'; const longContent = '测'.repeat(101);
fireEvent.change(contentInput, { target: { value: longContent } }); await user.clear(contentInput);
fireEvent.click(within(modal).getByRole('button', { name: '确定' })); await user.type(contentInput, longContent);
await waitFor( expect(contentInput).toHaveValue('测'.repeat(100));
() => { expect(within(modal).getByText('100/100')).toBeInTheDocument();
expect(within(modal).getByText(/不能超过100字/)).toBeInTheDocument(); await user.click(within(modal).getByRole('button', { name: '确定' }));
}, expect(within(modal).queryByText(/不能超过100字/)).not.toBeInTheDocument();
{ timeout: 2000 },
);
}); });
it('validates sort_order 0-99', async () => { it('validates sort_order 0-99', async () => {
const user = userEvent.setup();
const modal = screen.getByRole('dialog'); const modal = screen.getByRole('dialog');
const inputs = within(modal).getAllByRole('spinbutton'); const inputs = within(modal).getAllByRole('spinbutton');
const sortInput = inputs[0]; const sortInput = inputs[0];
if (!sortInput) throw new Error('Sort input not found'); if (!sortInput) throw new Error('Sort input not found');
fireEvent.change(sortInput, { target: { value: '100' } }); await user.clear(sortInput);
await user.type(sortInput, '100');
const contentInput = within(modal).getByPlaceholderText('请输入Agent概述'); const contentInput = within(modal).getByPlaceholderText('请输入Agent概述');
fireEvent.change(contentInput, { target: { value: '测试概述' } }); await user.clear(contentInput);
fireEvent.click(within(modal).getByRole('button', { name: '确定' })); await user.type(contentInput, '测试概述');
await user.click(within(modal).getByRole('button', { name: '确定' }));
await waitFor( await waitFor(
() => { () => {
expect(within(modal).getByText(/0-99/)).toBeInTheDocument(); expect(within(modal).getByText(/0-99/)).toBeInTheDocument();
......
...@@ -184,6 +184,7 @@ describe('Agent display config list', () => { ...@@ -184,6 +184,7 @@ describe('Agent display config list', () => {
expect(screen.getByRole('columnheader', { name: 'Agent概述' })).toBeInTheDocument(); expect(screen.getByRole('columnheader', { name: 'Agent概述' })).toBeInTheDocument();
expect(screen.getByText('帮助店销顾问完成每日复盘,分析业绩数据和客户反馈')).toBeInTheDocument(); expect(screen.getByText('帮助店销顾问完成每日复盘,分析业绩数据和客户反馈')).toBeInTheDocument();
}); });
expect(screen.getByText('帮助店销顾问完成每日复盘,分析业绩数据和客户反馈').className).toContain('cellText');
}); });
it('shows icon column', async () => { it('shows icon column', async () => {
...@@ -215,7 +216,7 @@ describe('Agent display config list', () => { ...@@ -215,7 +216,7 @@ describe('Agent display config list', () => {
await waitFor(() => { await waitFor(() => {
expect(screen.getByRole('columnheader', { name: '展示状态' })).toBeInTheDocument(); expect(screen.getByRole('columnheader', { name: '展示状态' })).toBeInTheDocument();
expect(screen.getByText('展示中')).toBeInTheDocument(); expect(screen.getByText('展示中')).toBeInTheDocument();
expect(screen.getByText('已下架')).toBeInTheDocument(); expect(screen.getByText('不展示')).toBeInTheDocument();
}); });
}); });
...@@ -228,7 +229,7 @@ describe('Agent display config list', () => { ...@@ -228,7 +229,7 @@ describe('Agent display config list', () => {
}); });
describe('status mapping and operation permission', () => { describe('status mapping and operation permission', () => {
it('shows 展示中/已下架 for enabled agents', async () => { it('shows 展示中/不展示 for enabled agents', async () => {
renderApp(); renderApp();
await waitFor(() => { await waitFor(() => {
const rows = screen.getAllByRole('row'); const rows = screen.getAllByRole('row');
...@@ -238,7 +239,7 @@ describe('Agent display config list', () => { ...@@ -238,7 +239,7 @@ describe('Agent display config list', () => {
const row103 = rows.find((row) => within(row).queryByText('销售助手Agent')); const row103 = rows.find((row) => within(row).queryByText('销售助手Agent'));
expect(row103).toBeDefined(); expect(row103).toBeDefined();
expect(within(row103!).getByText('已下架')).toBeInTheDocument(); expect(within(row103!).getByText('不展示')).toBeInTheDocument();
}); });
}); });
......
...@@ -20,7 +20,7 @@ function mapAgentStatusToText(status: AgentStatus): string { ...@@ -20,7 +20,7 @@ function mapAgentStatusToText(status: AgentStatus): string {
function getDisplayStatusTextForList(agentStatus: AgentStatus, displayStatus: DisplayStatus): string { function getDisplayStatusTextForList(agentStatus: AgentStatus, displayStatus: DisplayStatus): string {
if (agentStatus === 'disable') return '-'; if (agentStatus === 'disable') return '-';
return displayStatus === 'enable' ? '展示中' : '已下架'; return displayStatus === 'enable' ? '展示中' : '不展示';
} }
export function OfficialSiteAgentDisplayConfigPage() { export function OfficialSiteAgentDisplayConfigPage() {
...@@ -97,9 +97,8 @@ export function OfficialSiteAgentDisplayConfigPage() { ...@@ -97,9 +97,8 @@ export function OfficialSiteAgentDisplayConfigPage() {
{ {
title: 'Agent概述', title: 'Agent概述',
colKey: 'speech_content', colKey: 'speech_content',
cell: ({ row }) => ( ellipsisTooltip: true,
<span className="max-w-[200px] truncate">{row.speech_content || '-'}</span> tooltipValue: ({ speech_content }) => speech_content || '-',
),
}, },
{ {
title: '图标', title: '图标',
......
...@@ -124,19 +124,23 @@ describe('OfficialSiteJobTabEditorPage', () => { ...@@ -124,19 +124,23 @@ describe('OfficialSiteJobTabEditorPage', () => {
expect(screen.getAllByText('选择岗位后自动展示')).toHaveLength(3); expect(screen.getAllByText('选择岗位后自动展示')).toHaveLength(3);
}); });
it('validates position is required on save', () => { it('validates position is required on save', async () => {
renderApp('/official-site/job-tabs/new'); renderApp('/official-site/job-tabs/new');
fireEvent.click(screen.getByRole('button', { name: '保存' })); fireEvent.click(screen.getByRole('button', { name: '保存' }));
await waitFor(() => {
expect(screen.getByText('请选择对应岗位')).toBeInTheDocument(); expect(screen.getByText('请选择对应岗位')).toBeInTheDocument();
}); });
});
it('validates tab order is 0-99 integer', () => { it('validates tab order is 0-99 integer', async () => {
renderApp('/official-site/job-tabs/new'); renderApp('/official-site/job-tabs/new');
const orderInput = screen.getByLabelText('Tab排序'); const orderInput = screen.getByLabelText('Tab排序');
fireEvent.change(orderInput, { target: { value: '100' } }); fireEvent.change(orderInput, { target: { value: '100' } });
fireEvent.click(screen.getByRole('button', { name: '保存' })); fireEvent.click(screen.getByRole('button', { name: '保存' }));
await waitFor(() => {
expect(screen.getByText('Tab排序请输入0-99的整数')).toBeInTheDocument(); expect(screen.getByText('Tab排序请输入0-99的整数')).toBeInTheDocument();
}); });
});
it('shows position select with available candidates (not duplicates)', async () => { it('shows position select with available candidates (not duplicates)', async () => {
renderApp('/official-site/job-tabs/new'); renderApp('/official-site/job-tabs/new');
...@@ -236,6 +240,13 @@ describe('OfficialSiteJobTabEditorPage', () => { ...@@ -236,6 +240,13 @@ describe('OfficialSiteJobTabEditorPage', () => {
}); });
}); });
it('does not show employee role text in edit mode', async () => {
renderApp('/official-site/job-tabs/1/edit');
await screen.findByRole('heading', { name: '编辑岗位展示' });
expect(screen.queryByText('承接角色')).not.toBeInTheDocument();
expect(screen.queryByText('店销主管')).not.toBeInTheDocument();
});
it('allows editing tab order and saves successfully', async () => { it('allows editing tab order and saves successfully', async () => {
renderApp('/official-site/job-tabs/1/edit'); renderApp('/official-site/job-tabs/1/edit');
// Find the number input and change its value // Find the number input and change its value
......
import { useState } from 'react'; import { useState } from 'react';
import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom'; import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom';
import { Button } from 'tdesign-react';
import { StatePlaceholder } from '@gl/business-components'; import {
import { FormItem, Input, Select, Textarea } from '../../components/TDesignAccessibleControls'; BusinessForm,
StatePlaceholder,
validateBusinessForm,
type BusinessFormErrors,
type BusinessFormField,
type BusinessFormValues,
} from '@gl/business-components';
import { Button } from 'tdesign-react';
import { import {
getOfficialSiteTabList, getOfficialSiteTabList,
getOfficialSiteTabDetail, getOfficialSiteTabDetail,
...@@ -18,7 +24,7 @@ import { ...@@ -18,7 +24,7 @@ import {
import { useDeferredEffect } from '../../hooks/useDeferredEffect'; import { useDeferredEffect } from '../../hooks/useDeferredEffect';
import { buildOfficialSiteJobTabListSearch, readOfficialSiteJobTabListRouteState } from './officialSiteJobTabRouteState'; import { buildOfficialSiteJobTabListSearch, readOfficialSiteJobTabListRouteState } from './officialSiteJobTabRouteState';
interface TabFormState { interface TabFormState extends BusinessFormValues {
position_code: string; position_code: string;
position_name: string; position_name: string;
qrcode_id: number; qrcode_id: number;
...@@ -32,13 +38,6 @@ interface TabFormState { ...@@ -32,13 +38,6 @@ interface TabFormState {
sub_title: string; sub_title: string;
} }
interface TabFormErrors {
position_code?: string;
tab_order?: string;
main_title?: string;
sub_title?: string;
}
interface SaveNotice { interface SaveNotice {
type: 'error' | 'success'; type: 'error' | 'success';
message: string; message: string;
...@@ -55,7 +54,7 @@ function buildInitialFormState(tab?: OfficialSiteTabEditorItem): TabFormState { ...@@ -55,7 +54,7 @@ function buildInitialFormState(tab?: OfficialSiteTabEditorItem): TabFormState {
channel_code: '', channel_code: '',
employee_name: '', employee_name: '',
employee_role_text: '', employee_role_text: '',
tab_order: tab?.sort_order ?? undefined as unknown as number, tab_order: tab?.sort_order ?? 0,
display_status: tab?.display_status ?? 'enable', display_status: tab?.display_status ?? 'enable',
main_title: tab?.main_title ?? '', main_title: tab?.main_title ?? '',
sub_title: tab?.sub_title ?? '', sub_title: tab?.sub_title ?? '',
...@@ -74,12 +73,11 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit' ...@@ -74,12 +73,11 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit'
const [loadError, setLoadError] = useState(false); const [loadError, setLoadError] = useState(false);
const [currentTab, setCurrentTab] = useState<OfficialSiteTabEditorItem | undefined>(() => routeTab); const [currentTab, setCurrentTab] = useState<OfficialSiteTabEditorItem | undefined>(() => routeTab);
const [form, setForm] = useState<TabFormState>(() => buildInitialFormState(currentTab)); const [form, setForm] = useState<TabFormState>(() => buildInitialFormState(currentTab));
const [errors, setErrors] = useState<TabFormErrors>({}); const [errors, setErrors] = useState<BusinessFormErrors>({});
const [notice, setNotice] = useState<SaveNotice | null>(null); const [notice, setNotice] = useState<SaveNotice | null>(null);
const [saving, setSaving] = useState(false); const [saving, setSaving] = useState(false);
const [availableQRCodes, setAvailableQRCodes] = useState<AvailableOfficialSiteQRCodeItem[]>([]); const [availableQRCodes, setAvailableQRCodes] = useState<AvailableOfficialSiteQRCodeItem[]>([]);
const [existingPositions, setExistingPositions] = useState<string[]>([]); const [existingPositions, setExistingPositions] = useState<string[]>([]);
const fieldWidthClassName = 'w-full max-w-[450px]';
useDeferredEffect(() => { useDeferredEffect(() => {
getAvailableQRCodes() getAvailableQRCodes()
...@@ -121,6 +119,200 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit' ...@@ -121,6 +119,200 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit'
navigate(`/official-site/job-tabs${buildOfficialSiteJobTabListSearch(routeState)}`); navigate(`/official-site/job-tabs${buildOfficialSiteJobTabListSearch(routeState)}`);
}; };
const currentTabDetail = currentTab as OfficialSiteTabDetail | undefined;
const availableQRCodeOptions = availableQRCodes.filter((qr) => {
if (mode === 'edit') return true;
return !existingPositions.includes(qr.position_name);
});
const createFields: BusinessFormField[] = [
{
key: 'position_code',
label: '对应岗位',
type: 'select',
required: true,
options: availableQRCodeOptions.map((qr) => ({
value: String(qr.qrcode_id),
label: qr.position_name,
disabled: existingPositions.includes(qr.position_name) || qr.status === 'disable',
})),
placeholder: '请选择对应岗位',
validator: (value) => (value ? undefined : '请选择对应岗位'),
onChange: (value, context) => {
const qr = availableQRCodes.find((item) => item.qrcode_id === Number(value));
return {
...context.values,
position_code: qr?.channel_code ?? '',
position_name: qr?.position_name ?? '',
qrcode_id: qr?.qrcode_id ?? 0,
qrcode_name: qr?.qrcode_name ?? '',
channel_code: qr?.channel_code ?? '',
employee_name: qr?.employee_name ?? '',
employee_role_text: '',
};
},
},
{
key: 'qrcode_name',
label: '关联渠道活码',
type: 'displayText',
emptyText: '选择岗位后自动展示',
render: () => form.qrcode_name || '选择岗位后自动展示',
},
{
key: 'channel_code',
label: '渠道编码',
type: 'displayText',
emptyText: '选择岗位后自动展示',
render: () => form.channel_code || '选择岗位后自动展示',
},
{
key: 'employee_name',
label: '承接员工',
type: 'displayText',
emptyText: '选择岗位后自动展示',
render: () => form.employee_name || '选择岗位后自动展示',
},
{
key: 'main_title',
label: '岗位标题',
type: 'input',
required: true,
maxLength: 30,
placeholder: '请输入岗位标题',
helpText: '展示在官网 Tab 名称下方,用一句话介绍 AI 如何赋能该岗位',
validator: (value) => {
const text = typeof value === 'string' ? value : '';
if (!text) return '请输入岗位标题';
if (text.length > 30) return '岗位标题最多30字';
return undefined;
},
},
{
key: 'sub_title',
label: '岗位说明',
type: 'textarea',
required: true,
maxLength: 200,
rows: 4,
placeholder: '请输入岗位说明',
helpText: '展示在官网 Tab 内容区,用于详细描述 AI 为该岗位带来的价值',
validator: (value) => {
const text = typeof value === 'string' ? value : '';
if (!text) return '请输入岗位说明';
if (text.length > 200) return '岗位说明最多200字';
return undefined;
},
},
{
key: 'tab_order',
label: 'Tab排序',
type: 'numberInput',
required: true,
precision: 0,
placeholder: '请输入Tab排序(0-99)',
validator: (value) => {
if (value === undefined || value === null || value === '') return 'Tab排序请输入0-99的整数';
if (typeof value !== 'number' || !Number.isInteger(value) || value < 0 || value > 99) {
return 'Tab排序请输入0-99的整数';
}
return undefined;
},
},
{
key: 'display_status',
label: '展示状态',
type: 'select',
options: [
{ value: 'enable', label: '展示中' },
{ value: 'disable', label: '已下架' },
],
},
];
const editFields: BusinessFormField[] = [
{
key: 'position_name',
label: '岗位标签',
type: 'input',
disabled: true,
},
{
key: 'qrcode_name',
label: '关联渠道活码',
type: 'displayText',
render: () => currentTabDetail?.qrcode_name ?? '-',
},
{
key: 'channel_code',
label: '渠道编码',
type: 'displayText',
render: () => currentTabDetail?.channel_code ?? '-',
},
{
key: 'employee_name',
label: '承接员工',
type: 'displayText',
render: () => currentTabDetail?.qrcode_employee_name || currentTabDetail?.employee_name || '-',
},
{
key: 'main_title',
label: '岗位标题',
type: 'input',
required: true,
maxLength: 30,
placeholder: '请输入岗位标题',
validator: (value) => {
const text = typeof value === 'string' ? value : '';
if (!text) return '请输入岗位标题';
if (text.length > 30) return '岗位标题最多30字';
return undefined;
},
},
{
key: 'sub_title',
label: '岗位说明',
type: 'textarea',
required: true,
maxLength: 200,
rows: 4,
placeholder: '请输入岗位说明',
validator: (value) => {
const text = typeof value === 'string' ? value : '';
if (!text) return '请输入岗位说明';
if (text.length > 200) return '岗位说明最多200字';
return undefined;
},
},
{
key: 'tab_order',
label: 'Tab排序',
type: 'numberInput',
required: true,
precision: 0,
placeholder: '请输入Tab排序(0-99)',
validator: (value) => {
if (value === undefined || value === null || value === '') return 'Tab排序请输入0-99的整数';
if (typeof value !== 'number' || !Number.isInteger(value) || value < 0 || value > 99) {
return 'Tab排序请输入0-99的整数';
}
return undefined;
},
},
{
key: 'display_status',
label: '展示状态',
type: 'select',
options: [
{ value: 'enable', label: '展示中' },
{ value: 'disable', label: '已下架' },
],
},
];
const fields = mode === 'create' ? createFields : editFields;
const sectionTitle = '岗位 AI 赋能介绍';
if (loading) { if (loading) {
return ( return (
<section className="grid gap-6"> <section className="grid gap-6">
...@@ -129,7 +321,7 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit' ...@@ -129,7 +321,7 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit'
); );
} }
if (mode === 'edit' && !currentTab) { if (loadError || (mode === 'edit' && !currentTab)) {
return ( return (
<StatePlaceholder <StatePlaceholder
state="error" state="error"
...@@ -140,40 +332,12 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit' ...@@ -140,40 +332,12 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit'
); );
} }
const selectedQRCode = availableQRCodes.find((qr) => qr.qrcode_id === form.qrcode_id);
const validate = () => {
const nextErrors: TabFormErrors = {};
const order = form.tab_order;
if (mode === 'create' && !form.position_code) {
nextErrors.position_code = '请选择对应岗位';
}
if (!Number.isInteger(order) || order < 0 || order > 99) {
nextErrors.tab_order = 'Tab排序请输入0-99的整数';
}
if (!form.main_title.trim()) {
nextErrors.main_title = '请输入岗位标题';
} else if (form.main_title.length > 30) {
nextErrors.main_title = '岗位标题最多30字';
}
if (!form.sub_title.trim()) {
nextErrors.sub_title = '请输入岗位说明';
} else if (form.sub_title.length > 200) {
nextErrors.sub_title = '岗位说明最多200字';
}
setErrors(nextErrors);
return Object.keys(nextErrors).length === 0;
};
const handleSave = async () => { const handleSave = async () => {
setNotice(null); setNotice(null);
if (!validate()) return; const validation = await validateBusinessForm(fields, form);
setErrors(validation);
if (Object.values(validation).some(Boolean)) return;
if (mode === 'create' && existingPositions.includes(form.position_code)) { if (mode === 'create' && existingPositions.includes(form.position_code)) {
setNotice({ type: 'error', message: '该岗位已存在官网岗位展示,请编辑原配置' }); setNotice({ type: 'error', message: '该岗位已存在官网岗位展示,请编辑原配置' });
...@@ -214,11 +378,6 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit' ...@@ -214,11 +378,6 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit'
} }
}; };
const availableQRCodeOptions = availableQRCodes.filter((qr) => {
if (mode === 'edit') return true;
return !existingPositions.includes(qr.position_name);
});
return ( return (
<section className="grid gap-6"> <section className="grid gap-6">
<header className="sticky top-0 z-10 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"> <header className="sticky top-0 z-10 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">
...@@ -252,125 +411,15 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit' ...@@ -252,125 +411,15 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit'
<div className="rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-10"> <div className="rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-10">
<div className="mx-auto grid max-w-[760px] gap-6"> <div className="mx-auto grid max-w-[760px] gap-6">
<FormItem label="对应岗位" labelAlign="left" requiredMark={mode === 'create'} status={errors.position_code ? 'error' : undefined} tips={errors.position_code}> <h3 className="m-0 text-base font-medium leading-[var(--gl-line-height-lg)]">{sectionTitle}</h3>
{mode === 'edit' ? ( <BusinessForm
<Input fields={fields}
aria-label="岗位标签" values={form}
className={fieldWidthClassName} errors={errors}
disabled fieldWidth={450}
value={currentTab?.position_name ?? ''} labelAlign="left"
/> onChange={(nextValues) => setForm(nextValues as TabFormState)}
) : (
<Select
aria-label="对应岗位"
className={fieldWidthClassName}
options={availableQRCodeOptions.map((qr) => ({
value: String(qr.qrcode_id),
label: qr.position_name,
disabled: existingPositions.includes(qr.position_name) || qr.status === 'disable',
}))}
placeholder="请选择对应岗位"
value={form.qrcode_id ? String(form.qrcode_id) : ''}
onChange={(value) => {
const qr = availableQRCodes.find((q) => q.qrcode_id === Number(value));
if (qr) {
setForm((current) => ({
...current,
position_code: qr.channel_code,
position_name: qr.position_name,
qrcode_id: qr.qrcode_id,
qrcode_name: qr.qrcode_name,
channel_code: qr.channel_code,
employee_name: qr.employee_name,
}));
}
}}
/>
)}
</FormItem>
<FormItem label="关联渠道活码" labelAlign="left">
<div className={fieldWidthClassName}>
{form.qrcode_name || currentTab?.qrcode_name || (mode === 'create' && !form.position_code ? (
<span className="text-sm text-[var(--gl-color-text-secondary)]">选择岗位后自动展示</span>
) : null)}
</div>
</FormItem>
<FormItem label="渠道编码" labelAlign="left">
<div className={fieldWidthClassName}>
{form.channel_code || currentTab?.channel_code || (mode === 'create' && !form.position_code ? (
<span className="text-sm text-[var(--gl-color-text-secondary)]">选择岗位后自动展示</span>
) : null)}
</div>
</FormItem>
<FormItem label="承接员工" labelAlign="left">
<div className={fieldWidthClassName}>
{form.employee_name || currentTab?.qrcode_employee_name || (mode === 'create' && !form.position_code ? (
<span className="text-sm text-[var(--gl-color-text-secondary)]">选择岗位后自动展示</span>
) : null)}
</div>
</FormItem>
<div className="border-t border-[var(--gl-color-border-secondary)]" />
<h3 className="m-0 text-lg font-semibold leading-[var(--gl-line-height-lg)]">岗位 AI 赋能介绍</h3>
<FormItem label="岗位标题" labelAlign="left" requiredMark status={errors.main_title ? 'error' : undefined} tips={errors.main_title}>
<div className={fieldWidthClassName}>
<Input
aria-label="岗位标题"
placeholder="请输入岗位标题"
maxlength={30}
allowInputOverMax
value={form.main_title}
onChange={(value) => setForm((current) => ({ ...current, main_title: value }))}
/>
<p className="m-0 mt-1 text-xs text-[var(--gl-color-text-secondary)]">展示在官网 Tab 名称下方,用一句话介绍 AI 如何赋能该岗位</p>
</div>
</FormItem>
<FormItem label="岗位说明" labelAlign="left" requiredMark status={errors.sub_title ? 'error' : undefined} tips={errors.sub_title}>
<div className={fieldWidthClassName}>
<Textarea
aria-label="岗位说明"
className="w-full"
placeholder="请输入岗位说明"
maxlength={200}
allowInputOverMax
count
rows={4}
value={form.sub_title}
onChange={(value) => setForm((current) => ({ ...current, sub_title: value }))}
/>
<p className="m-0 mt-1 text-xs text-[var(--gl-color-text-secondary)]">展示在官网 Tab 内容区,用于详细描述 AI 为该岗位带来的价值</p>
</div>
</FormItem>
<FormItem label="Tab 排序" labelAlign="left" requiredMark status={errors.tab_order ? 'error' : undefined} tips={errors.tab_order}>
<Input
aria-label="Tab排序"
className={fieldWidthClassName}
type="number"
placeholder="请输入Tab排序(0-99)"
value={form.tab_order === undefined || form.tab_order === null || (typeof form.tab_order === 'number' && isNaN(form.tab_order)) ? '' : String(form.tab_order)}
onChange={(value) => setForm((current) => ({ ...current, tab_order: value === '' ? undefined as unknown as number : Number(value) }))}
/>
</FormItem>
<FormItem label="展示状态" labelAlign="left" requiredMark>
<Select
aria-label="展示状态"
className={fieldWidthClassName}
options={[
{ value: 'enable', label: '展示中' },
{ value: 'disable', label: '已下架' },
]}
value={form.display_status}
onChange={(value) => setForm((current) => ({ ...current, display_status: value as OfficialSiteTabStatus }))}
/> />
</FormItem>
</div> </div>
</div> </div>
</section> </section>
......
import { useEffect, useState } from 'react'; import { useEffect, useState } from 'react';
import { MediaWall, StatePlaceholder } from '@gl/business-components'; import {
BusinessForm,
MediaWall,
StatePlaceholder,
type BusinessFormErrors,
type BusinessFormField,
} from '@gl/business-components';
import { Button } from 'tdesign-react'; import { Button } from 'tdesign-react';
import { FormItem, Input, Switch, Textarea } from '../../components/TDesignAccessibleControls'; import { FormItem, Input } from '../../components/TDesignAccessibleControls';
import { import {
getMethodologyConfig, getMethodologyConfig,
saveMethodologyConfig, saveMethodologyConfig,
...@@ -38,6 +44,8 @@ interface SaveNotice { ...@@ -38,6 +44,8 @@ interface SaveNotice {
message: string; message: string;
} }
type MethodologyTopFormValues = Pick<MethodologyFormState, 'display_status' | 'main_title' | 'sub_title'>;
const contentImageHelperText = '支持 PNG/JPG/JPEG,最大 10MB'; const contentImageHelperText = '支持 PNG/JPG/JPEG,最大 10MB';
const stepIconHelperText = '支持 PNG/JPG/JPEG,最大 2MB'; const stepIconHelperText = '支持 PNG/JPG/JPEG,最大 2MB';
...@@ -80,8 +88,7 @@ export function OfficialSiteMethodologyPage() { ...@@ -80,8 +88,7 @@ export function OfficialSiteMethodologyPage() {
const [loadError, setLoadError] = useState(false); const [loadError, setLoadError] = useState(false);
const [saving, setSaving] = useState(false); const [saving, setSaving] = useState(false);
const [notice, setNotice] = useState<SaveNotice | null>(null); const [notice, setNotice] = useState<SaveNotice | null>(null);
const [mainTitleError, setMainTitleError] = useState<string>(); const [topErrors, setTopErrors] = useState<BusinessFormErrors>({});
const [subTitleError, setSubTitleError] = useState<string>();
const [stepListError, setStepListError] = useState<string>(); const [stepListError, setStepListError] = useState<string>();
const [defaultIconUploading, setDefaultIconUploading] = useState<Set<string>>(new Set()); const [defaultIconUploading, setDefaultIconUploading] = useState<Set<string>>(new Set());
const [defaultIconUploadError, setDefaultIconUploadError] = useState<Map<string, string>>(new Map()); const [defaultIconUploadError, setDefaultIconUploadError] = useState<Map<string, string>>(new Map());
...@@ -95,8 +102,7 @@ export function OfficialSiteMethodologyPage() { ...@@ -95,8 +102,7 @@ export function OfficialSiteMethodologyPage() {
getMethodologyConfig() getMethodologyConfig()
.then((record) => { .then((record) => {
setForm(buildFormState(record)); setForm(buildFormState(record));
setMainTitleError(undefined); setTopErrors({});
setSubTitleError(undefined);
setStepListError(undefined); setStepListError(undefined);
setLoading(false); setLoading(false);
}) })
...@@ -117,32 +123,70 @@ export function OfficialSiteMethodologyPage() { ...@@ -117,32 +123,70 @@ export function OfficialSiteMethodologyPage() {
})); }));
}; };
const topFields: BusinessFormField[] = [
{
key: 'display_status',
label: '展示状态',
type: 'switch',
checkedValue: 'enable',
uncheckedValue: 'disable',
},
{
key: 'main_title',
label: '主标题',
type: 'input',
required: true,
maxLength: 30,
validator: (value) => {
const text = String(value ?? '').trim();
if (!text) return '请输入主标题';
if (text.length > 30) return '主标题不能超过 30 字';
return undefined;
},
},
{
key: 'sub_title',
label: '副标题',
type: 'textarea',
required: true,
maxLength: 100,
rows: 4,
validator: (value) => {
const text = String(value ?? '').trim();
if (!text) return '请输入副标题';
if (text.length > 100) return '副标题不能超过 100 字';
return undefined;
},
},
];
const validate = () => { const validate = () => {
if (!form) return false; if (!form) return false;
let valid = true; let valid = true;
setStepListError(undefined);
const nextTopErrors: BusinessFormErrors = {};
const trimmedMainTitle = form.main_title.trim(); const trimmedMainTitle = form.main_title.trim();
const trimmedSubTitle = form.sub_title.trim(); const trimmedSubTitle = form.sub_title.trim();
setMainTitleError(undefined);
setSubTitleError(undefined);
setStepListError(undefined);
if (!trimmedMainTitle) { if (!trimmedMainTitle) {
setMainTitleError('请输入主标题'); nextTopErrors.main_title = '请输入主标题';
valid = false; valid = false;
} else if (trimmedMainTitle.length > 30) { } else if (trimmedMainTitle.length > 30) {
setMainTitleError('主标题不能超过 30 字'); nextTopErrors.main_title = '主标题不能超过 30 字';
valid = false; valid = false;
} }
if (!trimmedSubTitle) { if (!trimmedSubTitle) {
setSubTitleError('请输入副标题'); nextTopErrors.sub_title = '请输入副标题';
valid = false; valid = false;
} else if (trimmedSubTitle.length > 100) { } else if (trimmedSubTitle.length > 100) {
setSubTitleError('副标题不能超过 100 字'); nextTopErrors.sub_title = '副标题不能超过 100 字';
valid = false; valid = false;
} }
setTopErrors(nextTopErrors);
if (form.display_status === 'enable' && form.steps.length === 0) { if (form.display_status === 'enable' && form.steps.length === 0) {
setStepListError('至少添加一个方法论步骤'); setStepListError('至少添加一个方法论步骤');
valid = false; valid = false;
...@@ -269,58 +313,32 @@ export function OfficialSiteMethodologyPage() { ...@@ -269,58 +313,32 @@ export function OfficialSiteMethodologyPage() {
) : null} ) : null}
<div className="rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-8"> <div className="rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-8">
<div className="grid gap-6"> <BusinessForm
<FormItem label="展示状态" labelAlign="left" requiredMark> fields={topFields}
<Switch values={{
aria-label="展示状态" display_status: form.display_status,
value={form.display_status === 'enable'} main_title: form.main_title,
onChange={(checked) => { sub_title: form.sub_title,
setNotice(null);
updateForm((current) => ({
...current,
display_status: checked ? 'enable' : 'disable',
}));
}}
/>
</FormItem>
<FormItem label="主标题" labelAlign="left" requiredMark status={mainTitleError ? 'error' : undefined} tips={mainTitleError}>
<Input
aria-label="主标题"
className="w-full max-w-[520px]"
maxlength={30}
allowInputOverMax
showLimitNumber
value={form.main_title}
onChange={(value) => {
setMainTitleError(undefined);
updateForm((current) => ({
...current,
main_title: value,
}));
}} }}
/> errors={topErrors}
</FormItem> labelAlign="left"
fieldWidth="520px"
<FormItem label="副标题" labelAlign="left" requiredMark status={subTitleError ? 'error' : undefined} tips={subTitleError}> onChange={(nextValues, changedKey) => {
<Textarea setNotice(null);
aria-label="副标题"
className="w-full max-w-[520px]"
maxlength={100}
allowInputOverMax
rows={4}
count
value={form.sub_title}
onChange={(value) => {
setSubTitleError(undefined);
updateForm((current) => ({ updateForm((current) => ({
...current, ...current,
sub_title: value, ...(nextValues as MethodologyTopFormValues),
})); }));
const changedFieldKey = typeof changedKey === 'string' ? changedKey : changedKey.key;
if (changedFieldKey === 'main_title' || changedFieldKey === 'sub_title') {
setTopErrors((current) => {
const next = { ...current };
delete next[changedFieldKey];
return next;
});
}
}} }}
/> />
</FormItem>
</div>
</div> </div>
<div className="rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-8"> <div className="rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-8">
......
...@@ -86,6 +86,7 @@ describe('SkillListPage', () => { ...@@ -86,6 +86,7 @@ describe('SkillListPage', () => {
await waitFor(() => { await waitFor(() => {
expect(screen.getByText('共 2 条')).toBeInTheDocument(); expect(screen.getByText('共 2 条')).toBeInTheDocument();
}); });
expect(screen.getByText('支持本地目标、浏览器检查和使用说明预览。').className).toContain('cellText');
expect(screen.getByRole('button', { name: '查看browser:browser详情' })).toHaveClass('t-button--theme-primary', 't-button--variant-text'); expect(screen.getByRole('button', { name: '查看browser:browser详情' })).toHaveClass('t-button--theme-primary', 't-button--variant-text');
expect(screen.queryByRole('button', { name: '新建Skill' })).not.toBeInTheDocument(); expect(screen.queryByRole('button', { name: '新建Skill' })).not.toBeInTheDocument();
expect(screen.queryByRole('button', { name: '编辑' })).not.toBeInTheDocument(); expect(screen.queryByRole('button', { name: '编辑' })).not.toBeInTheDocument();
......
...@@ -57,7 +57,7 @@ export function SkillListPage() { ...@@ -57,7 +57,7 @@ export function SkillListPage() {
const columns: BusinessTableColumn<SkillSummary>[] = [ const columns: BusinessTableColumn<SkillSummary>[] = [
{ title: 'Skill编码', colKey: 'skill_code' }, { title: 'Skill编码', colKey: 'skill_code' },
{ title: 'Skill名称', colKey: 'skill_name' }, { title: 'Skill名称', colKey: 'skill_name' },
{ title: '说明', colKey: 'description' }, { title: '说明', colKey: 'description', ellipsisTooltip: true },
{ {
title: '操作', title: '操作',
colKey: 'actions', colKey: 'actions',
......
...@@ -3,7 +3,8 @@ import { fileURLToPath, URL } from 'node:url'; ...@@ -3,7 +3,8 @@ import { fileURLToPath, URL } from 'node:url';
import { loadEnv } from 'vite'; import { loadEnv } from 'vite';
import { defineConfig } from 'vitest/config'; import { defineConfig } from 'vitest/config';
const DEFAULT_PROXY_TARGET = 'http://192.168.1.191:8000'; // const DEFAULT_PROXY_TARGET = 'http://192.168.1.191:8000';
const DEFAULT_PROXY_TARGET = 'http://agent-admin.test.glsx.com.cn/backend';
export default defineConfig(({ mode }) => { export default defineConfig(({ mode }) => {
const env = loadEnv(mode, process.cwd(), ''); const env = loadEnv(mode, process.cwd(), '');
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!