Commit 991ffa5e by 胡悦

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

主要变更包括:
- 新增并归档全量后台表格与表单标准化OpenSpec规范、设计文档与任务清单
- 修复BusinessTable分页重复显示总数问题,精简空态与失败态展示
- 为多业务列表页的长文本列添加显式Tooltip悬浮提示
- 优化BusinessForm样式与输入限制,统一表单提示颜色规则
- 迁移多批后台编辑页到BusinessForm,覆盖Agent标签、渠道码、官网职位Tab等页面
- 调整官网Agent展示配置的状态文案与排序校验,统一业务口径
- 优化vite代理配置为测试环境地址,修复消息钩子无DOM环境报错问题
- 补充大量测试用例并修复现有测试断言
- 更新架构文档与组件使用规范
1 parent d4da367b
Showing 90 changed files with 2622 additions and 316 deletions
...@@ -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%;
} }
......
...@@ -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. 运行定向测试、类型检查和构建验证
# 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** 系统不为这些内容扩展新的配置协议
...@@ -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> {
......
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) => {
MessagePlugin[type]({ try {
content, MessagePlugin[type]({
duration: options?.duration ?? 3000, content,
closeBtn: options?.closable ?? false, duration: options?.duration ?? 3000,
placement: 'top-right', closeBtn: options?.closable ?? false,
}); 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(() => {
MessagePlugin.closeAll(); try {
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: '保存' }));
......
...@@ -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,9 +271,11 @@ describe('Channel code create page', () => { ...@@ -258,9 +271,11 @@ describe('Channel code create page', () => {
fireEvent.click(screen.getByRole('button', { name: '保存' })); fireEvent.click(screen.getByRole('button', { name: '保存' }));
expect(screen.getByText('请输入活码名称')).toBeInTheDocument(); await waitFor(() => {
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 () => {
...@@ -286,7 +301,9 @@ describe('Channel code create page', () => { ...@@ -286,7 +301,9 @@ 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: '保存' }));
expect(screen.getByText('活码描述最多200字')).toBeInTheDocument(); await waitFor(() => {
expect(screen.getByText('活码描述最多200字')).toBeInTheDocument();
});
}); });
it('validates welcome message max length', async () => { it('validates welcome message max length', async () => {
...@@ -312,7 +329,9 @@ describe('Channel code create page', () => { ...@@ -312,7 +329,9 @@ 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: '保存' }));
expect(screen.getByText('自动欢迎语最多500字')).toBeInTheDocument(); await waitFor(() => {
expect(screen.getByText('自动欢迎语最多500字')).toBeInTheDocument();
});
}); });
// TDD: 新增页不展示状态编辑项 // TDD: 新增页不展示状态编辑项
...@@ -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();
}); });
......
...@@ -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) => ({
...current,
<FormItem label="图标" labelAlign="left" requiredMark status={errors.icon_url || errors.upload_icon ? 'error' : undefined} tips={errors.icon_url || errors.upload_icon}> ...nextValues,
<MediaWall } as EditFormState))}
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,
sort_order: value === '' ? undefined as unknown as number : Number(value),
}))}
/>
</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,18 +124,22 @@ describe('OfficialSiteJobTabEditorPage', () => { ...@@ -124,18 +124,22 @@ 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: '保存' }));
expect(screen.getByText('请选择对应岗位')).toBeInTheDocument(); await waitFor(() => {
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: '保存' }));
expect(screen.getByText('Tab排序请输入0-99的整数')).toBeInTheDocument(); await waitFor(() => {
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 () => {
...@@ -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 { 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) => ({ errors={topErrors}
...current, labelAlign="left"
display_status: checked ? 'enable' : 'disable', fieldWidth="520px"
})); onChange={(nextValues, changedKey) => {
}} setNotice(null);
/> updateForm((current) => ({
</FormItem> ...current,
...(nextValues as MethodologyTopFormValues),
<FormItem label="主标题" labelAlign="left" requiredMark status={mainTitleError ? 'error' : undefined} tips={mainTitleError}> }));
<Input const changedFieldKey = typeof changedKey === 'string' ? changedKey : changedKey.key;
aria-label="主标题" if (changedFieldKey === 'main_title' || changedFieldKey === 'sub_title') {
className="w-full max-w-[520px]" setTopErrors((current) => {
maxlength={30} const next = { ...current };
allowInputOverMax delete next[changedFieldKey];
showLimitNumber return next;
value={form.main_title} });
onChange={(value) => { }
setMainTitleError(undefined); }}
updateForm((current) => ({ />
...current,
main_title: value,
}));
}}
/>
</FormItem>
<FormItem label="副标题" labelAlign="left" requiredMark status={subTitleError ? 'error' : undefined} tips={subTitleError}>
<Textarea
aria-label="副标题"
className="w-full max-w-[520px]"
maxlength={100}
allowInputOverMax
rows={4}
count
value={form.sub_title}
onChange={(value) => {
setSubTitleError(undefined);
updateForm((current) => ({
...current,
sub_title: value,
}));
}}
/>
</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!