Commit 9d0c3115 by 胡悦

fix(web, h5): 修复官网Agent配置与H5展示的多个问题

- 重构官方站点Agent展示配置的API接口,优化接口路径与字段定义
- 优化MediaWall组件,支持视频素材预览,避免上传后额外渲染独立预览控件
- 修复后台管理端的可选链报错、删除按钮样式、渠道活码字段展示等问题
- 调整H5官网岗位能力区左侧布局,移除多余文案仅保留体验按钮
- 更新全量相关的测试用例与文档规范
1 parent 68e62299
Showing 32 changed files with 591 additions and 411 deletions
......@@ -6,7 +6,7 @@ H5 官网首页位于 `workspace/agent-admin/single-page`,当前页面已经
本次变更只处理 H5 首页真实接口接入。后端服务先使用用户指定的 `http://192.168.1.191:8000/` 进行开发联调,前端运行时仍保持同源 `/api/v1` 请求路径,避免把局域网地址写死进生产请求。
真实接口接入后,用户在浏览器验证发现三处 H5 展示边界需要同步锁定:Banner 背景图不能被接口返回图片覆盖,仍需使用前期给定的本地 Banner 素材;Banner 顶部胶囊标签需要展示“新一代智能协作平台”;方法论步骤图标需要显示在步骤名称前方,而不是只作为数据字段保留。
真实接口接入后,用户在浏览器验证发现四处 H5 展示边界需要同步锁定:Banner 背景图不能被接口返回图片覆盖,仍需使用前期给定的本地 Banner 素材;Banner 顶部胶囊标签需要展示“新一代智能协作平台”;岗位能力区左侧 Agent 素材下方不再展示标题、副标题或描述,仅保留体验按钮;方法论步骤图标需要显示在步骤名称前方,而不是只作为数据字段保留。
## Goals / Non-Goals
......@@ -17,6 +17,7 @@ H5 官网首页位于 `workspace/agent-admin/single-page`,当前页面已经
- 在开发环境通过 Vite proxy 默认转发 `/api` 到 `http://192.168.1.191:8000/`,并允许环境变量覆盖目标地址。
- 保持 Banner 背景图使用 H5 本地素材 `/banner.png` 与 `/banner-blur.png`,避免真实接口配置覆盖前期确认的视觉素材。
- 保证 Banner 胶囊标签展示“新一代智能协作平台”;接口未返回 `capsule_tag` 时使用该默认文案补齐。
- 岗位能力区左侧 Agent 素材下方仅保留“立即体验”按钮,不展示 `speech_title`、固定英文副标题或 `speech_content`。
- 在方法论步骤卡片的步骤名称前展示 `step_icon`,图标与名称保持同一标题行。
- 保留 mock 数据作为测试 fixture,避免删除前期页面测试资产。
- 补齐测试与验证,确保成功加载、失败展示、重试、响应映射和 mock 边界可回归。
......@@ -24,7 +25,7 @@ H5 官网首页位于 `workspace/agent-admin/single-page`,当前页面已经
**Non-Goals:**
- 不修改后端服务、接口路径、响应中间件或数据库。
- 不重做 H5 首页整体视觉样式、响应式布局和既有交互;仅修正本次浏览器验证发现的 Banner 素材、胶囊标签和方法论步骤标题图标展示。
- 不重做 H5 首页整体视觉样式、响应式布局和既有交互;仅修正本次浏览器验证发现的 Banner 素材、胶囊标签、岗位能力区左侧素材下方内容和方法论步骤标题图标展示。
- 不把 `http://192.168.1.191:8000/` 作为生产环境 API baseURL 写进业务运行时代码。
- 不接入认证、埋点、缓存刷新或其它 H5 页面。
- 不删除 `src/mocks` 下的 fixture。
......@@ -83,6 +84,12 @@ Banner 顶部胶囊标签优先使用接口返回的 `capsule_tag.text`;当接
备选方案是将 `step_icon` 用作卡片主图。该方案会与现有 `step_image` 职责冲突,并不能满足“步骤图标应该显示在步骤名称前面”的展示要求,因此不采用。
### 9. 岗位能力区左侧素材下方仅保留体验按钮
岗位能力区左侧 mockup 继续展示当前 Agent 的 `media_url` / `media_type` 素材,素材缺失时继续展示素材不可用状态;素材容器下方不再展示 Agent 标题、固定英文副标题 `/ Position Agent` 或 Agent 描述文案。左侧区域只保留“立即体验”按钮作为行动入口,二维码弹窗交互保持不变。
备选方案是保留标题并只隐藏描述。该方案仍会在无 Agent 或后端测试数据异常时展示兜底文案,不符合“素材下面的内容不要,只要保留按钮”的要求,因此不采用。
## Risks / Trade-offs
- 真实后端字段与当前 fixture 不完全一致 -> 在首页领域 API 或 response mapper 中集中处理字段映射,并用测试固定关键字段。
......@@ -92,6 +99,7 @@ Banner 顶部胶囊标签优先使用接口返回的 `capsule_tag.text`;当接
- mock fixture 继续存在可能被误用 -> 通过运行时 import 边界测试和 code review 约束,允许测试使用,禁止业务运行时使用。
- Banner 本地素材路径若缺失会导致背景降级 -> 保留现有 `/banner.png`、`/banner-blur.png` 并增加组件测试覆盖固定素材路径。
- 接口缺少 `capsule_tag` 可能导致品牌胶囊消失 -> 在 Banner 或页面组装层提供 `新一代智能协作平台` 默认文案。
- 左侧 Agent 标题/描述隐藏后,用户少一个文字解释入口 -> 右侧核心能力标题、说明和 Agent 卡片仍保留业务文字,左侧聚焦素材与体验按钮。
- `step_icon` 可能为空或加载失败 -> 方法论标题行只降级隐藏图标,步骤名称和说明继续展示。
## Migration Plan
......@@ -101,10 +109,11 @@ Banner 顶部胶囊标签优先使用接口返回的 `capsule_tag.text`;当接
3. 先补 API client 和首页数据 hook 测试,覆盖成功、失败、重试和 mock 边界。
4. 将 `useHomeData` 从 mock API 切换到真实首页 API 模块。
5. 调整 Banner 渲染:背景固定使用本地素材,胶囊标签提供默认文案。
6. 调整方法论卡片标题行:在步骤名称前渲染 `step_icon`。
7. 运行 H5 类型检查、单测、构建和 OpenSpec strict validate。
8. 启动 H5 dev server,使用默认代理目标联调 `GET /api/v1/official-site/home`,验证 PC 和移动端关键交互不回退。
9. 如联调目标不可用,可通过 `VITE_API_PROXY_TARGET=<other-backend>` 切换;代码层面不回退到 mock。
6. 调整岗位能力区左侧 mockup:素材下方移除标题、副标题和描述,仅保留“立即体验”按钮。
7. 调整方法论卡片标题行:在步骤名称前渲染 `step_icon`。
8. 运行 H5 类型检查、单测、构建和 OpenSpec strict validate。
9. 启动 H5 dev server,使用默认代理目标联调 `GET /api/v1/official-site/home`,验证 PC 和移动端关键交互不回退。
10. 如联调目标不可用,可通过 `VITE_API_PROXY_TARGET=<other-backend>` 切换;代码层面不回退到 mock。
## Open Questions
......
......@@ -12,10 +12,11 @@ H5 官网首页已经按真实聚合接口契约完成页面能力,但当前
- 更新 `useHomeData` 数据加载路径,使页面加载、重试和失败态基于真实接口结果,不再调用 `src/mocks/api` 的运行时模拟请求。
- Banner 背景图在真实接口接入后仍使用 H5 本地已提供素材(`/banner.png`、`/banner-blur.png`),不采用接口返回的 `background_image` / `background_blur_image` 作为页面背景。
- Banner 胶囊标签需稳定展示“新一代智能协作平台”样式内容;若接口未返回 `capsule_tag`,页面使用该默认文案补齐展示。
- 岗位能力区左侧 Agent 素材下方不再展示 Agent 标题、英文副标题或描述文案,仅保留“立即体验”按钮。
- 方法论步骤卡片需在步骤名称前展示接口返回的 `step_icon`,步骤图标与步骤名称作为同一标题行呈现。
- 保留现有 mock 数据和 fixture,用于单元测试、组件测试和契约样例;业务运行时代码不得依赖 mock 模块。
- 补充测试,覆盖 API client、首页聚合接口请求、响应映射、失败/重试行为、开发代理配置和“运行时代码不引用 mock API”的边界。
- 不改变 H5 首页整体视觉布局、交互状态和后端接口契约;本次仅修正真实接口接入后的 Banner 素材边界、胶囊标签展示和方法论步骤标题图标展示。
- 不改变 H5 首页整体视觉布局、交互状态和后端接口契约;本次仅修正真实接口接入后的 Banner 素材边界、胶囊标签展示、岗位能力区左侧素材下方内容展示和方法论步骤标题图标展示。
## Capabilities
......@@ -32,6 +33,6 @@ H5 官网首页已经按真实聚合接口契约完成页面能力,但当前
- 影响 H5 单页应用:`workspace/agent-admin/single-page`。
- 影响 H5 运行时数据源:从本地 mock API 切换为真实 HTTP 接口。
- 影响 H5 开发配置:`vite.config.ts` 增加 `/api` 代理,默认联调后端为 `http://192.168.1.191:8000/`。
- 影响 H5 Banner 与方法论模块渲染:真实接口数据仍驱动业务内容,但 Banner 背景素材使用本地图片,方法论步骤名称前展示步骤图标。
- 影响 H5 Banner、岗位能力区与方法论模块渲染:真实接口数据仍驱动业务内容,但 Banner 背景素材使用本地图片,岗位能力区左侧素材下方仅保留按钮,方法论步骤名称前展示步骤图标。
- 影响测试:新增或更新 API client、hooks、页面状态和 mock 边界相关测试。
- 不影响后台 Web 管理端、后端服务、数据库和官网 H5 首页布局需求。
......@@ -104,3 +104,20 @@ H5 方法论模块 SHALL 在每个步骤卡片的步骤名称前展示 `step_ico
- **WHEN** 方法论步骤的 `step_icon` 为空或图标加载失败
- **THEN** 步骤卡片隐藏该标题图标
- **AND** 步骤名称、步骤描述和卡片主图继续正常展示
### Requirement: H5 岗位能力区左侧素材下方内容隐藏
H5 岗位能力区左侧 mockup SHALL 在 Agent 素材下方仅展示体验按钮,不展示 Agent 标题、副标题或描述文案。
#### Scenario: 素材下方仅保留立即体验按钮
- **WHEN** 岗位能力区存在当前 Agent 且页面渲染左侧 mockup
- **THEN** 左侧 Agent 素材容器下方展示“立即体验”按钮
- **AND** 不展示 `speech_title`
- **AND** 不展示固定英文副标题 `/ Position Agent`
- **AND** 不展示 `speech_content`
#### Scenario: 当前岗位没有 Agent
- **WHEN** 当前岗位的 `agents` 为空
- **THEN** 左侧素材容器继续展示无素材状态
- **AND** 素材容器下方仍展示“立即体验”按钮
- **AND** 不展示“岗位智能体”兜底标题
- **AND** 不展示“为每个岗位配置专属 AI 助手,辅助决策,提升效率”兜底描述
## 1. 契约与 API 设计
- [ ] 1.1 确认 H5 首页真实接口路径为 `GET /api/v1/official-site/home`,请求端点在 H5 API 模块中以 `/official-site/home` 相对路径表达。
- [ ] 1.2 定义 H5 `ApiResponse<T>`、首页数据响应类型和统一 API 错误类型,确保与既有 H5 首页字段契约兼容。
- [ ] 1.3 明确 `VITE_API_BASE_URL`、`VITE_API_PROXY_TARGET` 的优先级和默认值,其中开发代理默认目标为 `http://192.168.1.191:8000/`。
- [x] 1.1 确认 H5 首页真实接口路径为 `GET /api/v1/official-site/home`,请求端点在 H5 API 模块中以 `/official-site/home` 相对路径表达。
- [x] 1.2 定义 H5 `ApiResponse<T>`、首页数据响应类型和统一 API 错误类型,确保与既有 H5 首页字段契约兼容。
- [x] 1.3 明确 `VITE_API_BASE_URL`、`VITE_API_PROXY_TARGET` 的优先级和默认值,其中开发代理默认目标为 `http://192.168.1.191:8000/`。
## 2. 测试先行
- [ ] 2.1 先编写 API client 测试,覆盖默认 `/api/v1`、`VITE_API_BASE_URL` 覆盖、`code === 200/201` 解包、业务失败、HTTP 失败和网络失败。
- [ ] 2.2 先编写首页 API 模块测试,验证请求 `GET /official-site/home` 并正确返回首页数据。
- [ ] 2.3 先编写 `useHomeData` 测试,覆盖真实接口成功加载、失败态、重试重新请求真实接口,以及失败时不展示 mock 兜底。
- [ ] 2.4 先编写 mock 边界测试或静态检查,验证 H5 运行时代码不 import `src/mocks/api`。
- [ ] 2.5 先编写 Vite proxy 配置测试或配置断言,覆盖默认代理目标 `http://192.168.1.191:8000/` 和 `VITE_API_PROXY_TARGET` 覆盖。
- [ ] 2.6 先更新 Banner 测试,验证真实接口返回背景图时仍使用本地 `/banner.png`、`/banner-blur.png`,并验证缺少 `capsule_tag` 时展示默认文案 `新一代智能协作平台`。
- [ ] 2.7 先更新方法论模块测试,验证 `step_icon` 显示在步骤名称前,且图标为空或加载失败时只隐藏图标、不影响步骤名称和描述展示。
- [x] 2.1 先编写 API client 测试,覆盖默认 `/api/v1`、`VITE_API_BASE_URL` 覆盖、`code === 200/201` 解包、业务失败、HTTP 失败和网络失败。
- [x] 2.2 先编写首页 API 模块测试,验证请求 `GET /official-site/home` 并正确返回首页数据。
- [x] 2.3 先编写 `useHomeData` 测试,覆盖真实接口成功加载、失败态、重试重新请求真实接口,以及失败时不展示 mock 兜底。
- [x] 2.4 先编写 mock 边界测试或静态检查,验证 H5 运行时代码不 import `src/mocks/api`。
- [x] 2.5 先编写 Vite proxy 配置测试或配置断言,覆盖默认代理目标 `http://192.168.1.191:8000/` 和 `VITE_API_PROXY_TARGET` 覆盖。
- [x] 2.6 先更新 Banner 测试,验证真实接口返回背景图时仍使用本地 `/banner.png`、`/banner-blur.png`,并验证缺少 `capsule_tag` 时展示默认文案 `新一代智能协作平台`。
- [x] 2.7 先更新方法论模块测试,验证 `step_icon` 显示在步骤名称前,且图标为空或加载失败时只隐藏图标、不影响步骤名称和描述展示。
- [x] 2.8 先更新岗位能力区测试,验证左侧素材下方只展示”立即体验”按钮,不展示 Agent 标题、`/ Position Agent`、Agent 描述或兜底标题/描述。
## 3. 实现真实接口接入
- [ ] 3.1 新增 H5 API client,统一处理 baseURL、响应解包和错误归一化。
- [ ] 3.2 新增首页 API 模块,封装 `GET /api/v1/official-site/home` 真实接口调用。
- [ ] 3.3 将 `useHomeData` 从 `src/mocks/api` 切换到首页 API 模块,并保留现有 loading、error、reload 状态模型。
- [ ] 3.4 更新 Vite 配置,开发环境 `/api` 代理默认转发到 `http://192.168.1.191:8000/`,并支持 `VITE_API_PROXY_TARGET` 覆盖。
- [ ] 3.5 保留 `src/mocks` 作为测试 fixture,清理业务运行时代码对 mock API 的依赖。
- [ ] 3.6 调整 Banner 渲染,使背景固定使用 H5 本地 `/banner.png` 与 `/banner-blur.png`,接口背景图字段不参与背景渲染。
- [ ] 3.7 调整 Banner 胶囊标签渲染,接口文案为空时展示默认 `新一代智能协作平台`,并保持截图所示星形图标、浅蓝圆角胶囊样式。
- [ ] 3.8 调整方法论步骤卡片标题行,在 `step_name` 前渲染 `step_icon`,并处理图标为空或加载失败的降级。
- [x] 3.1 新增 H5 API client,统一处理 baseURL、响应解包和错误归一化。
- [x] 3.2 新增首页 API 模块,封装 `GET /api/v1/official-site/home` 真实接口调用。
- [x] 3.3 将 `useHomeData` 从 `src/mocks/api` 切换到首页 API 模块,并保留现有 loading、error、reload 状态模型。
- [x] 3.4 更新 Vite 配置,开发环境 `/api` 代理默认转发到 `http://192.168.1.191:8000/`,并支持 `VITE_API_PROXY_TARGET` 覆盖。
- [x] 3.5 保留 `src/mocks` 作为测试 fixture,清理业务运行时代码对 mock API 的依赖。
- [x] 3.6 调整 Banner 渲染,使背景固定使用 H5 本地 `/banner.png` 与 `/banner-blur.png`,接口背景图字段不参与背景渲染。
- [x] 3.7 调整 Banner 胶囊标签渲染,接口文案为空时展示默认 `新一代智能协作平台`,并保持截图所示星形图标、浅蓝圆角胶囊样式。
- [x] 3.8 调整方法论步骤卡片标题行,在 `step_name` 前渲染 `step_icon`,并处理图标为空或加载失败的降级。
- [x] 3.9 调整岗位能力区左侧 mockup,移除素材下方的标题、副标题和描述渲染,仅保留”立即体验”按钮与二维码弹窗交互。
## 4. 联调与回归
- [ ] 4.1 运行 `openspec validate "h5-real-api-integration" --strict`。
- [ ] 4.2 在 `workspace/agent-admin/single-page` 运行类型检查。
- [ ] 4.3 在 `workspace/agent-admin/single-page` 运行相关单元测试。
- [ ] 4.4 在 `workspace/agent-admin/single-page` 运行构建。
- [ ] 4.1 运行 `openspec validate “h5-real-api-integration” --strict`。
- [x] 4.2 在 `workspace/agent-admin/single-page` 运行类型检查。
- [x] 4.3 在 `workspace/agent-admin/single-page` 运行相关单元测试。
- [x] 4.4 在 `workspace/agent-admin/single-page` 运行构建。
- [ ] 4.5 启动 H5 开发服务,使用默认代理目标 `http://192.168.1.191:8000/` 联调首页接口。
- [ ] 4.6 浏览器验证 PC 与移动端的首页加载、失败重试、岗位 Tab 切换、Agent 卡片选择、二维码弹窗和方法论切换,确认真实接口接入未破坏既有交互。
- [ ] 4.7 在浏览器验证 Banner 使用本地图片、胶囊标签展示“新一代智能协作平台”、方法论步骤图标位于步骤名称前方。
- [ ] 4.7 在浏览器验证 Banner 使用本地图片、胶囊标签展示”新一代智能协作平台”、方法论步骤图标位于步骤名称前方。
- [ ] 4.8 在浏览器验证岗位能力区左侧 Agent 素材下方不显示标题、英文副标题或描述,仅保留”立即体验”按钮。
......@@ -163,4 +163,108 @@ describe('岗位能力区测试', () => {
render(<PositionAbilityArea {...props} />);
expect(screen.getByText('素材不可用')).toBeInTheDocument();
});
describe('左侧素材下方不展示标题和描述', () => {
it('不展示 Agent 标题 speech_title', () => {
const agent = createMockAgent({ speech_title: 'Agent 标题' });
const tab = createMockPositionTab({ agents: [agent] });
const props = {
tab,
currentAgent: agent,
currentAgentIndex: 0,
onAgentSelect: vi.fn(),
onOpenQrcodeModal: vi.fn(),
qrcodeModalOpen: false,
onCloseQrcodeModal: vi.fn(),
};
render(<PositionAbilityArea {...props} />);
const leftMockup = screen.getByTestId('left-mockup');
expect(within(leftMockup).queryByText('Agent 标题')).not.toBeInTheDocument();
});
it('不展示英文副标题 / Position Agent', () => {
const agent = createMockAgent();
const tab = createMockPositionTab({ agents: [agent] });
const props = {
tab,
currentAgent: agent,
currentAgentIndex: 0,
onAgentSelect: vi.fn(),
onOpenQrcodeModal: vi.fn(),
qrcodeModalOpen: false,
onCloseQrcodeModal: vi.fn(),
};
render(<PositionAbilityArea {...props} />);
const leftMockup = screen.getByTestId('left-mockup');
expect(within(leftMockup).queryByText(/Position Agent/)).not.toBeInTheDocument();
});
it('不展示 Agent 描述 speech_content', () => {
const agent = createMockAgent({ speech_content: 'Agent 描述内容' });
const tab = createMockPositionTab({ agents: [agent] });
const props = {
tab,
currentAgent: agent,
currentAgentIndex: 0,
onAgentSelect: vi.fn(),
onOpenQrcodeModal: vi.fn(),
qrcodeModalOpen: false,
onCloseQrcodeModal: vi.fn(),
};
render(<PositionAbilityArea {...props} />);
const leftMockup = screen.getByTestId('left-mockup');
expect(within(leftMockup).queryByText('Agent 描述内容')).not.toBeInTheDocument();
});
it('不展示兜底标题 "岗位智能体"', () => {
const agent = createMockAgent({ speech_title: null });
const tab = createMockPositionTab({ agents: [agent] });
const props = {
tab,
currentAgent: agent,
currentAgentIndex: 0,
onAgentSelect: vi.fn(),
onOpenQrcodeModal: vi.fn(),
qrcodeModalOpen: false,
onCloseQrcodeModal: vi.fn(),
};
render(<PositionAbilityArea {...props} />);
const leftMockup = screen.getByTestId('left-mockup');
expect(within(leftMockup).queryByText('岗位智能体')).not.toBeInTheDocument();
});
it('不展示兜底描述', () => {
const agent = createMockAgent({ speech_content: null });
const tab = createMockPositionTab({ agents: [agent] });
const props = {
tab,
currentAgent: agent,
currentAgentIndex: 0,
onAgentSelect: vi.fn(),
onOpenQrcodeModal: vi.fn(),
qrcodeModalOpen: false,
onCloseQrcodeModal: vi.fn(),
};
render(<PositionAbilityArea {...props} />);
const leftMockup = screen.getByTestId('left-mockup');
expect(within(leftMockup).queryByText('为每个岗位配置专属 AI 助手')).not.toBeInTheDocument();
});
it('仅保留"立即体验"按钮', () => {
const agent = createMockAgent();
const tab = createMockPositionTab({ agents: [agent] });
const props = {
tab,
currentAgent: agent,
currentAgentIndex: 0,
onAgentSelect: vi.fn(),
onOpenQrcodeModal: vi.fn(),
qrcodeModalOpen: false,
onCloseQrcodeModal: vi.fn(),
};
render(<PositionAbilityArea {...props} />);
const leftMockup = screen.getByTestId('left-mockup');
expect(within(leftMockup).getByText('立即体验')).toBeInTheDocument();
});
});
});
\ No newline at end of file
......@@ -67,7 +67,10 @@ export function PositionAbilityArea({
<div className="max-w-container-max mx-auto px-margin-mobile tablet:px-margin-desktop">
<div className="grid grid-cols-1 tablet:grid-cols-2 gap-16 items-center">
{/* Left: Mockup UI */}
<div className="rounded-[32px] p-8 tablet:p-12 border border-outline-variant/30 bg-white/80 backdrop-blur-xl flex flex-col items-center text-center relative shadow-sm">
<div
data-testid="left-mockup"
className="rounded-[32px] p-8 tablet:p-12 border border-outline-variant/30 bg-white/80 backdrop-blur-xl flex flex-col items-center text-center relative shadow-sm"
>
<div className="absolute top-6 left-8 flex gap-2">
<div className="w-3 h-3 rounded-full bg-red-400/50" />
<div className="w-3 h-3 rounded-full bg-yellow-400/50" />
......@@ -87,14 +90,6 @@ export function PositionAbilityArea({
)}
</div>
<h3 className="text-headline-sm mb-2">
{currentAgent?.speech_title ?? '岗位智能体'}
<span className="text-on-surface-variant text-label-md font-normal ml-2">/ Position Agent</span>
</h3>
<p className="text-body-md text-on-surface-variant max-w-sm mb-8">
{currentAgent?.speech_content ?? '为每个岗位配置专属 AI 助手,辅助决策,提升效率'}
</p>
<button
onClick={onOpenQrcodeModal}
className="flex items-center gap-2 px-8 py-3 bg-primary-container text-white rounded-xl text-label-md transition-transform active:scale-95"
......
......@@ -58,6 +58,17 @@ Agent 展示配置页需要在进入 `/official-site/job-tabs/:tabId/agents` 后
- 页面测试固定 Agent 展示配置页加载时同时获取岗位 Tab 详情和 Agent 配置列表,详情失败时展示可恢复错误状态。
- 弹窗测试固定 `图标` 字段存在上传图片控件,上传成功后保存 payload 包含 `icon_url`。
- 弹窗测试固定缺少图标时展示字段附近校验错误,不用全局失败提示替代。
- 弹窗测试固定上传视频后只由 `MediaWall` 当前素材预览位承载展示,不在媒体墙外额外渲染独立 `<video>` 控件。
### 6. 展示素材视频预览由媒体墙统一承载
编辑配置弹窗的 `展示素材` 字段继续复用组件库 `MediaWall` 的媒体项能力。图片、GIF 和视频都应转成 `MediaWall` 的 `items` 数据,由组件内部按媒体类型展示缩略图或视频态图层。
上传视频成功后,页面只更新 `media_url`、`media_type` 和 `media_size`,不在 `MediaWall` 外层额外渲染独立 `<video>` 元素。这样可以保持上传入口、当前素材预览、删除操作和辅助文案处于同一组件布局中,避免出现左侧上传框/失败占位与右侧视频预览并排、字段宽度被撑开的样式回归。
视频类型判断仍集中在编辑弹窗数据转换处:`mp4`、`mov`、`avi`、`webm` 作为视频素材类型并将媒体墙 item 的 `type` 设置为 `video`;其他素材类型继续作为图片类预览处理。
`MediaWall` 内部不得把视频 URL 继续交给图片缩略图渲染。对于 `type=video` 的媒体项,组件应在上传卡片内部使用视频元素承载预览,避免 `.mov` 等真实视频 URL 被图片组件加载后展示“图片无法显示”占位。
## Risks / Trade-offs
......
......@@ -14,6 +14,7 @@
- `配置Agent` 跳转到 `/official-site/job-tabs/:tabId/agents` 后,页面标题只展示当前岗位名称与 `Agent展示配置页`。
- 页面加载时必须调用 `/api/v1/official-site/tabs/{tab_id}` 获取当前岗位 Tab 详情,并用详情中的 `qrcode_name` 展示关联渠道活码、`position_code` 展示渠道编码、`qrcode_employee_name` 展示承接员工。
- 编辑配置弹窗恢复 `图标` 上传图片能力,上传成功后写入 `icon_url`,保存 Agent 展示配置时提交图标字段。
- 编辑配置弹窗的 `展示素材` 上传视频后,仍使用媒体墙单一预览位展示当前素材;不得在媒体墙外额外并排渲染第二个视频预览,避免上传入口、失败占位和视频缩略图横向错位。
- 以失败优先测试覆盖详情接口调用、页面展示、图标上传、保存 payload 和异常状态。
## Capabilities
......
......@@ -101,3 +101,23 @@ Agent 编辑配置弹窗 SHALL 支持通过上传图片组件编辑图标,并
- **WHEN** 实施本修复
- **THEN** 测试 MUST 覆盖编辑弹窗的图标上传控件、图标必填校验、图标回显和上传失败状态
- **AND** 测试 MUST 覆盖保存 payload 包含 `icon_url`
### Requirement: 编辑配置弹窗展示素材视频预览布局
Agent 编辑配置弹窗 SHALL 使用单一媒体墙布局展示当前展示素材,上传视频后不得额外生成并排预览。
#### Scenario: 上传视频后保持单一预览位
- **WHEN** 用户在 `展示素材` 字段上传合法视频
- **THEN** 弹窗 SHALL 使用 `MediaWall` 当前素材预览位展示该视频素材
- **AND** `展示素材` 字段 SHALL NOT 在媒体墙外额外渲染第二个 `<video>` 控件
- **AND** 上传入口、当前素材预览、删除操作和辅助文案 SHALL 保持在同一媒体墙布局中
#### Scenario: 回显 mov 展示素材
- **WHEN** 编辑配置详情接口返回 `media_url` 指向 `.mov` 素材
- **AND** `media_type` 为 `mov`
- **THEN** 弹窗 SHALL 在 `展示素材` 字段将该素材作为视频预览回显
- **AND** 弹窗 SHALL NOT 将 `.mov` 素材作为图片加载并展示图片加载失败占位
#### Scenario: 保存视频素材类型
- **WHEN** 用户上传 `video/mp4`、`video/quicktime`、`video/x-msvideo` 或 `video/webm`
- **THEN** 表单 SHALL 将展示素材类型分别保存为 `mp4`、`mov`、`avi` 或 `webm`
- **AND** 保存 Agent 展示配置 payload MUST 包含对应 `media_type`
......@@ -7,6 +7,7 @@
- [ ] 1.5 为编辑配置弹窗增加测试:`图标` 字段使用上传图片组件,已有 `icon_url` 时回显预览。
- [ ] 1.6 为编辑配置弹窗增加测试:缺少 `icon_url` 保存时展示字段附近校验错误且不调用保存接口。
- [ ] 1.7 为编辑配置弹窗增加测试:图标上传成功后保存 payload 包含 `icon_url`,上传失败时允许重试。
- [ ] 1.8 为 `MediaWall` 与编辑配置弹窗增加测试:`media_type=mov` 的展示素材回显时使用视频预览,不作为图片加载。
## 2. API 与数据适配
......@@ -22,6 +23,8 @@
- [ ] 3.4 在编辑配置弹窗恢复 `图标` 上传图片字段,状态独立于展示素材字段。
- [ ] 3.5 实现图标上传、回显、删除、失败状态和必填校验。
- [ ] 3.6 保存 Agent 展示配置时提交 `icon_url`,保存成功后刷新列表并展示最新图标。
- [ ] 3.7 调整编辑配置弹窗的 `展示素材` 视频预览布局:上传视频后只保留 `MediaWall` 内部当前素材预览,不额外渲染媒体墙外的独立 `<video>` 控件。
- [ ] 3.8 调整 `MediaWall` 视频项渲染:`type=video` 的素材在上传卡片内部使用视频预览,避免 `.mov` URL 被图片缩略图加载失败。
## 4. 验证
......@@ -29,3 +32,5 @@
- [ ] 4.2 运行 `npm run typecheck`、`npm test`、`npm run build`,记录任何与本 change 无关的既有阻塞。
- [ ] 4.3 使用浏览器验证 `/official-site/job-tabs/:tabId/agents`:标题、关联渠道活码、渠道编码、承接员工、图标上传、保存和失败提示均符合规范。
- [ ] 4.4 运行 `openspec validate "fix-official-site-agent-config-detail" --strict`。
- [ ] 4.5 使用测试或浏览器验证展示素材上传视频后没有媒体墙外并排视频预览,字段辅助文案与预览布局保持稳定。
- [ ] 4.6 使用测试或浏览器验证详情接口返回 `.mov` / `media_type=mov` 时,编辑弹窗 `展示素材` 字段能回显视频预览。
......@@ -31,6 +31,7 @@ export interface AgentDetailRecord {
description: string;
skill_ids: string[];
status: AgentStatus;
is_manager: boolean;
}
export interface AgentEditorFixture {
......@@ -84,6 +85,7 @@ const detailRecords: Record<string, AgentDetailRecord> = {
description: '负责系统级调度与兜底回复。',
skill_ids: [],
status: 'enable',
is_manager: true,
},
'101': {
agent_id: 101,
......@@ -94,6 +96,7 @@ const detailRecords: Record<string, AgentDetailRecord> = {
description: '负责成交复盘与客户跟进建议。',
skill_ids: ['summary', 'lead'],
status: 'enable',
is_manager: false,
},
'102': {
agent_id: 102,
......@@ -104,6 +107,7 @@ const detailRecords: Record<string, AgentDetailRecord> = {
description: '负责会话质检与问题归因。',
skill_ids: ['quality'],
status: 'disable',
is_manager: false,
},
};
......@@ -166,5 +170,6 @@ export function createAgentRecord(payload: AgentDraftPayload, positionOptions?:
description: payload.description,
skill_ids: payload.skillIds,
status: payload.status,
is_manager: false,
} satisfies AgentDetailRecord;
}
......@@ -71,4 +71,11 @@
.mediaRoot {
display: grid;
gap: var(--gl-spacing-sm);
}
\ No newline at end of file
}
.mediaVideoPreview {
width: 100%;
height: 100%;
background: #000;
object-fit: cover;
}
......@@ -189,6 +189,7 @@ export function MediaWall({
// 判断是否需要自定义预览处理(有视频或有自定义 onPreview)
const hasVideo = items.some((item) => item.type === 'video');
const needCustomPreview = hasVideo || !!onPreview;
const itemById = new Map(items.map((item) => [item.id, item]));
const handleChange: UploadProps['onChange'] = (value, context) => {
const { trigger, file } = context;
......@@ -221,6 +222,62 @@ export function MediaWall({
onRemove?.(item);
};
const renderVideoFileList: UploadProps['fileListDisplay'] = ({ files }) => (
<div className="t-upload__card-container">
{files.map((file) => {
const item = itemById.get(file.uid || '') ?? {
id: file.uid || String(file.name),
type: file.type === 'video' ? 'video' : 'image',
src: file.url || '',
alt: file.name || '',
};
return (
<div className="t-upload__card-item" key={item.id}>
{item.type === 'video' ? (
<video
className={styles.mediaVideoPreview}
src={item.src}
aria-label={item.alt || '视频预览'}
muted
playsInline
preload="metadata"
/>
) : (
<img src={item.src} alt={item.alt} />
)}
<div className="t-upload__card-mask">
<button
type="button"
className="t-upload__card-mask-item"
aria-label="预览"
disabled={disabled}
onClick={(e) => {
e.stopPropagation();
onPreview?.(item);
}}
>
<span className="t-icon t-icon-browse" />
</button>
<button
type="button"
className="t-upload__card-mask-item"
aria-label="删除"
disabled={disabled}
onClick={(e) => {
e.stopPropagation();
onRemove?.(item);
}}
>
<span className="t-icon t-icon-delete" />
</button>
</div>
</div>
);
})}
</div>
);
return (
<div
className={cx(styles.mediaRoot, className)}
......@@ -240,7 +297,8 @@ export function MediaWall({
// 只有需要自定义预览时才传递 onPreview,否则让 TDesign 内置 ImageViewer 处理
onPreview={needCustomPreview ? handlePreview : undefined}
onRemove={handleRemove}
fileListDisplay={hasVideo ? renderVideoFileList : undefined}
/>
</div>
);
}
\ No newline at end of file
}
......@@ -125,14 +125,24 @@ describe('Upload components', () => {
}
});
it('calls onPreview for video items and also opens ImageViewer for thumbnail', () => {
it('renders video items with a video preview instead of an image thumbnail', () => {
const video = { id: 'video', type: 'video' as const, src: '/media.mov', alt: '演示视频' };
render(<MediaWall items={[video]} />);
const videoElement = document.querySelector(`video[src="${video.src}"]`);
expect(videoElement).toBeInTheDocument();
expect(document.querySelector(`img[src="${video.src}"]`)).not.toBeInTheDocument();
});
it('calls onPreview for video items', () => {
const onPreview = vi.fn();
const video = { id: 'video', type: 'video' as const, src: '/video-cover.png', alt: '演示视频' };
render(<MediaWall items={[video]} onPreview={onPreview} />);
const imgElement = document.querySelector(`img[src="${video.src}"]`);
expect(imgElement).toBeInTheDocument();
const videoElement = document.querySelector(`video[src="${video.src}"]`);
expect(videoElement).toBeInTheDocument();
// TDesign image-flow: browse icon is SVG inside card-mask-item
const maskItem = document.querySelector('.t-upload__card-mask-item') as HTMLElement;
......@@ -141,10 +151,6 @@ describe('Upload components', () => {
fireEvent.click(browseIcon);
expect(onPreview).toHaveBeenCalledWith(video);
}
// TDesign's ImageViewer opens for video thumbnail (video cover image)
// This is TDesign's built-in behavior - the callback can be used for additional actions like video playback
expect(document.querySelector('.t-image-viewer__modal-image')).toBeInTheDocument();
});
it('emits selected files when user selects a file', async () => {
......@@ -322,4 +328,4 @@ describe('Upload components', () => {
});
});
});
});
\ No newline at end of file
});
import { lazy, Suspense } from 'react';
import { Navigate, Route, Routes } from 'react-router-dom';
import { AdminShell } from './layouts/AdminShell';
import { RootLayout } from './layouts/RootLayout';
import { AgentEditorPage } from './routes/agents/AgentEditorPage';
import { AgentListPage } from './routes/agents/AgentListPage';
import { AgentTagEditorPage } from './routes/agent-tags/AgentTagEditorPage';
import { AgentTagListPage } from './routes/agent-tags/AgentTagListPage';
import { ChannelCodeEditorPage } from './routes/channel-codes/ChannelCodeEditorPage';
import { ChannelCodeListPage } from './routes/channel-codes/ChannelCodeListPage';
import { ComponentsDemoPage } from './routes/components/ComponentsDemoPage';
import { LoginPage } from './routes/login/LoginPage';
import { OfficialSiteMethodologyPage } from './routes/official-site/OfficialSiteMethodologyPage';
import { OfficialSiteAgentDisplayConfigPage } from './routes/official-site-agent-display-config/OfficialSiteAgentDisplayConfigPage';
import { OfficialSiteJobTabListPage } from './routes/official-site-job-tabs/OfficialSiteJobTabListPage';
import { OfficialSiteJobTabEditorPage } from './routes/official-site-job-tabs/OfficialSiteJobTabEditorPage';
import { ProtectedRoute } from './routes/ProtectedRoute';
import { SkillListPage } from './routes/skills/SkillListPage';
// 懒加载页面组件(命名导出需要转换)
const AgentEditorPage = lazy(() =>
import('./routes/agents/AgentEditorPage').then((m) => ({ default: m.AgentEditorPage }))
);
const AgentListPage = lazy(() =>
import('./routes/agents/AgentListPage').then((m) => ({ default: m.AgentListPage }))
);
const AgentTagEditorPage = lazy(() =>
import('./routes/agent-tags/AgentTagEditorPage').then((m) => ({ default: m.AgentTagEditorPage }))
);
const AgentTagListPage = lazy(() =>
import('./routes/agent-tags/AgentTagListPage').then((m) => ({ default: m.AgentTagListPage }))
);
const ChannelCodeEditorPage = lazy(() =>
import('./routes/channel-codes/ChannelCodeEditorPage').then((m) => ({ default: m.ChannelCodeEditorPage }))
);
const ChannelCodeListPage = lazy(() =>
import('./routes/channel-codes/ChannelCodeListPage').then((m) => ({ default: m.ChannelCodeListPage }))
);
const ComponentsDemoPage = lazy(() =>
import('./routes/components/ComponentsDemoPage').then((m) => ({ default: m.ComponentsDemoPage }))
);
const OfficialSiteMethodologyPage = lazy(() =>
import('./routes/official-site/OfficialSiteMethodologyPage').then((m) => ({ default: m.OfficialSiteMethodologyPage }))
);
const OfficialSiteAgentDisplayConfigPage = lazy(() =>
import('./routes/official-site-agent-display-config/OfficialSiteAgentDisplayConfigPage').then((m) => ({
default: m.OfficialSiteAgentDisplayConfigPage,
}))
);
const OfficialSiteJobTabListPage = lazy(() =>
import('./routes/official-site-job-tabs/OfficialSiteJobTabListPage').then((m) => ({
default: m.OfficialSiteJobTabListPage,
}))
);
const OfficialSiteJobTabEditorPage = lazy(() =>
import('./routes/official-site-job-tabs/OfficialSiteJobTabEditorPage').then((m) => ({
default: m.OfficialSiteJobTabEditorPage,
}))
);
const SkillListPage = lazy(() =>
import('./routes/skills/SkillListPage').then((m) => ({ default: m.SkillListPage }))
);
// 加载状态组件
function PageLoader() {
return (
<div className="flex h-64 items-center justify-center">
<div className="text-gray-500">加载中...</div>
</div>
);
}
export function App() {
return (
<Routes>
<Route path="login" element={<LoginPage />} />
<Route element={<ProtectedRoute />}>
<Route element={<AdminShell />}>
<Route index element={<Navigate to="/agents" replace />} />
<Route path="agents" element={<AgentListPage />} />
<Route path="agents/new" element={<AgentEditorPage mode="create" />} />
<Route path="agents/:agentId/edit" element={<AgentEditorPage mode="edit" />} />
<Route path="agent-tags" element={<AgentTagListPage />} />
<Route path="agent-tags/new" element={<AgentTagEditorPage mode="create" />} />
<Route path="agent-tags/:tagId/edit" element={<AgentTagEditorPage mode="edit" />} />
<Route path="channel-codes" element={<ChannelCodeListPage />} />
<Route path="channel-codes/new" element={<ChannelCodeEditorPage mode="create" />} />
<Route path="channel-codes/:codeId/edit" element={<ChannelCodeEditorPage mode="edit" />} />
<Route path="skills" element={<SkillListPage />} />
<Route path="official-site/methodology" element={<OfficialSiteMethodologyPage />} />
<Route path="official-site/job-tabs" element={<OfficialSiteJobTabListPage />} />
<Route path="official-site/job-tabs/new" element={<OfficialSiteJobTabEditorPage mode="create" />} />
<Route path="official-site/job-tabs/:tabId/edit" element={<OfficialSiteJobTabEditorPage mode="edit" />} />
<Route path="official-site/job-tabs/:tabId/agents" element={<OfficialSiteAgentDisplayConfigPage />} />
<Suspense fallback={<PageLoader />}>
<Routes>
<Route path="login" element={<LoginPage />} />
<Route element={<ProtectedRoute />}>
<Route element={<AdminShell />}>
<Route index element={<Navigate to="/agents" replace />} />
<Route path="agents" element={<AgentListPage />} />
<Route path="agents/new" element={<AgentEditorPage mode="create" />} />
<Route path="agents/:agentId/edit" element={<AgentEditorPage mode="edit" />} />
<Route path="agent-tags" element={<AgentTagListPage />} />
<Route path="agent-tags/new" element={<AgentTagEditorPage mode="create" />} />
<Route path="agent-tags/:tagId/edit" element={<AgentTagEditorPage mode="edit" />} />
<Route path="channel-codes" element={<ChannelCodeListPage />} />
<Route path="channel-codes/new" element={<ChannelCodeEditorPage mode="create" />} />
<Route path="channel-codes/:codeId/edit" element={<ChannelCodeEditorPage mode="edit" />} />
<Route path="skills" element={<SkillListPage />} />
<Route path="official-site/methodology" element={<OfficialSiteMethodologyPage />} />
<Route path="official-site/job-tabs" element={<OfficialSiteJobTabListPage />} />
<Route path="official-site/job-tabs/new" element={<OfficialSiteJobTabEditorPage mode="create" />} />
<Route path="official-site/job-tabs/:tabId/edit" element={<OfficialSiteJobTabEditorPage mode="edit" />} />
<Route path="official-site/job-tabs/:tabId/agents" element={<OfficialSiteAgentDisplayConfigPage />} />
</Route>
</Route>
<Route element={<RootLayout />}>
<Route path="components" element={<ComponentsDemoPage />} />
</Route>
</Route>
<Route element={<RootLayout />}>
<Route path="components" element={<ComponentsDemoPage />} />
</Route>
<Route path="*" element={<Navigate to="/agents" replace />} />
</Routes>
<Route path="*" element={<Navigate to="/agents" replace />} />
</Routes>
</Suspense>
);
}
......@@ -121,7 +121,7 @@ function inferAgentOperations(status: AgentStatus, isSteward: boolean): string[]
function fillAgentListItem(item: Partial<AgentListItem>): AgentListItem {
const status = item.status ?? 'enable';
const isSteward = item.is_steward ?? false;
const operations = item.operations?.length > 0 ? item.operations : inferAgentOperations(status, isSteward);
const operations = (item.operations && item.operations.length > 0) ? item.operations : inferAgentOperations(status, isSteward);
return {
agent_id: item.agent_id ?? 0,
name: item.name ?? '',
......@@ -136,7 +136,7 @@ function fillAgentListItem(item: Partial<AgentListItem>): AgentListItem {
status,
creator_name: item.creator_name ?? '',
created_at: item.created_at ?? '',
operations,
operations: operations as string[],
};
}
......
......@@ -32,11 +32,11 @@ export {
} from './officialSiteTab';
export type { OfficialSiteTabStatus as OfficialSiteTabStatusType } from './officialSiteTab';
export {
getAvailableAgents, saveAgentDisplayConfig, getConfiguredAgents, deleteAgentDisplayConfig, uploadOfficialSiteAsset,
getAvailableAgents, updateAgentDisplayConfig, uploadOfficialSiteAsset,
type OfficialSiteAvailableAgentsResponse, type SaveOfficialAgentDisplayPayload, type SaveOfficialAgentDisplayResponse,
type OfficialSiteConfiguredAgentsResponse, type DeleteOfficialAgentDisplayResponse, type UploadOfficialSiteAssetResponse,
type OfficialSiteAgentDisplayDetail, type DeleteOfficialAgentDisplayResponse, type UploadOfficialSiteAssetResponse,
} from './officialSiteAgentDisplay';
export type { MediaType as MediaTypeType, ImageType as ImageTypeType, DisplayStatus as DisplayStatusType, AgentStatus as AgentStatusType2 } from './officialSiteAgentDisplay';
export type { MediaType as MediaTypeType, DisplayStatus as DisplayStatusType, AgentStatus as AgentStatusType2, OfficialSiteAvailableAgent as OfficialSiteAvailableAgentType } from './officialSiteAgentDisplay';
export {
getMethodologyConfig, saveMethodologyConfig, uploadMethodologyAsset,
type MethodologyConfig, type SaveMethodologyPayload, type SaveMethodologyResponse, type UploadMethodologyAssetResponse,
......
import { describe, it, expect, vi, beforeEach } from 'vitest';
import {
getAvailableAgents,
saveAgentDisplayConfig,
getConfiguredAgents,
deleteAgentDisplayConfig,
updateAgentDisplayConfig,
uploadOfficialSiteAsset,
getAgentDisplayDetail,
} from './officialSiteAgentDisplay';
import { apiClient, ApiError } from './client';
......@@ -42,7 +41,7 @@ describe('officialSiteAgentDisplay API', () => {
position_name: '驻店销售岗',
qrcode_id: 5,
available_agents: [
{ agent_id: 101, agent_name: '复盘 Agent', agent_code: 'review', is_configured: false, is_steward: false },
{ display_id: 1, agent_id: 101, agent_name: '复盘 Agent', agent_code: 'review', is_configured: false, is_steward: false, display_status: 'disable', agent_status: 'enable' },
],
steward_agent: { agent_id: 100, agent_name: '管家 Agent', note: '管家 Agent 不参与官网展示' },
});
......@@ -53,11 +52,34 @@ describe('officialSiteAgentDisplay API', () => {
});
});
describe('saveAgentDisplayConfig', () => {
describe('getAgentDisplayDetail', () => {
it('调用正确的接口路径', async () => {
vi.mocked(apiClient.get).mockResolvedValueOnce({
display_id: 1,
agent_id: 101,
agent_name: '复盘 Agent',
agent_code: 'review',
media_url: 'https://cdn.example.com/media.gif',
media_type: 'gif',
media_size: 1000,
icon_url: 'https://cdn.example.com/icon.png',
speech_title: '标题',
speech_content: '内容',
sort_order: 1,
display_status: 'enable',
agent_status: 'enable',
});
await getAgentDisplayDetail(1);
expect(apiClient.get).toHaveBeenCalledWith('/official-site/agent-displays/1');
});
});
describe('updateAgentDisplayConfig', () => {
it('调用正确的接口路径和方法', async () => {
vi.mocked(apiClient.post).mockResolvedValueOnce({ media_url: 'url', speech_title: '标题' });
await saveAgentDisplayConfig(1, 101, {
await updateAgentDisplayConfig(1, {
media_url: 'url',
media_type: 'gif',
media_size: 1000,
......@@ -67,7 +89,7 @@ describe('officialSiteAgentDisplay API', () => {
sort_order: 1,
icon_url: 'https://cdn.example.com/icon.png',
});
expect(apiClient.post).toHaveBeenCalledWith('/official-site/tabs/1/agents/101/config', {
expect(apiClient.post).toHaveBeenCalledWith('/official-site/agent-displays/1/config', {
media_url: 'url',
media_type: 'gif',
media_size: 1000,
......@@ -80,51 +102,6 @@ describe('officialSiteAgentDisplay API', () => {
});
});
describe('getConfiguredAgents', () => {
it('调用正确的接口路径', async () => {
vi.mocked(apiClient.get).mockResolvedValueOnce({
tab_id: '1',
position_name: '店销顾问',
qrcode_name: '店销顾问渠道活码',
channel_code: 'DSC-QR-001',
employee_name: '张小萌',
employee_role_text: '店销主管',
configured_agents: [],
});
await getConfiguredAgents(1);
expect(apiClient.get).toHaveBeenCalledWith('/official-site/tabs/1/agents/configured');
});
it('返回已配置 Agent 列表和上下文信息', async () => {
vi.mocked(apiClient.get).mockResolvedValueOnce({
tab_id: '1',
position_name: '店销顾问',
qrcode_name: '店销顾问渠道活码',
channel_code: 'DSC-QR-001',
employee_name: '张小萌',
employee_role_text: '店销主管',
configured_agents: [
{ config_id: 'c1', agent_id: '101', agent_name: '复盘 Agent', media_url: 'url', media_type: 'gif', speech_title: '标题', speech_content: '内容', display_status: 'enable', sort_order: 1, agent_status: 'enable' },
],
});
const result = await getConfiguredAgents(1);
expect(result.configured_agents).toHaveLength(1);
expect(result.position_name).toBe('店销顾问');
expect(result.qrcode_name).toBe('店销顾问渠道活码');
});
});
describe('deleteAgentDisplayConfig', () => {
it('调用正确的接口路径和方法', async () => {
vi.mocked(apiClient.delete).mockResolvedValueOnce({ success: true, deleted_at: '2026-05-16T17:00:00Z' });
await deleteAgentDisplayConfig(1, 101);
expect(apiClient.delete).toHaveBeenCalledWith('/official-site/tabs/1/agents/101/config', undefined);
});
});
describe('uploadOfficialSiteAsset', () => {
it('调用正确的接口路径和方法', async () => {
const formData = new FormData();
......@@ -134,7 +111,6 @@ describe('officialSiteAgentDisplay API', () => {
vi.mocked(apiClient.post).mockResolvedValueOnce({ file_id: 'file_123', file_url: 'url', file_type: 'gif', file_size: 1000 });
await uploadOfficialSiteAsset(formData);
// 使用相对路径,最终命中 /api/v1/official-site/upload
expect(apiClient.post).toHaveBeenCalledWith('/official-site/upload', formData);
});
......
import { apiClient } from './client';
export type DisplayStatus = 'enable' | 'disable';
export type MediaType = 'gif' | 'mp4';
export type ImageType = 'png' | 'jpg' | 'jpeg';
export type MediaType = 'jpg' | 'jpeg' | 'png' | 'webp' | 'gif' | 'mp4' | 'mov' | 'avi' | 'webm';
export type AgentStatus = 'enable' | 'disable';
export type OfficialSiteUploadUsageType = 'agent_media' | 'methodology_icon' | 'methodology_image';
export interface OfficialSiteAvailableAgent {
export interface OfficialSiteAvailableAgent extends Record<string, unknown> {
display_id: number;
agent_id: number;
agent_name: string;
agent_code: string;
is_configured: boolean;
configured_description?: string;
is_steward: boolean;
icon_url?: string;
media_url?: string;
media_type?: MediaType;
summary?: string;
speech_content?: string;
display_status: DisplayStatus;
agent_status: AgentStatus;
}
export interface OfficialSiteStewardAgentNote {
......@@ -38,6 +45,7 @@ export interface SaveOfficialAgentDisplayPayload {
display_status: DisplayStatus;
sort_order: number;
icon_url: string;
summary?: string;
}
export interface SaveOfficialAgentDisplayResponse {
......@@ -50,30 +58,6 @@ export interface SaveOfficialAgentDisplayResponse {
sort_order: number;
}
export interface OfficialSiteConfiguredAgent extends Record<string, unknown> {
config_id: string;
agent_id: string;
agent_name: string;
media_url: string;
media_type: MediaType;
speech_title: string;
speech_content: string;
display_status: DisplayStatus;
sort_order: number;
agent_status: AgentStatus;
icon_url?: string;
}
export interface OfficialSiteConfiguredAgentsResponse {
tab_id: string;
position_name: string;
qrcode_name: string;
channel_code: string;
employee_name: string;
employee_role_text: string;
configured_agents: OfficialSiteConfiguredAgent[];
}
export interface DeleteOfficialAgentDisplayResponse {
success: boolean;
deleted_at: string;
......@@ -82,7 +66,7 @@ export interface DeleteOfficialAgentDisplayResponse {
export interface UploadOfficialSiteAssetResponse {
file_id: string;
file_url: string;
file_type: MediaType | ImageType;
file_type: MediaType;
file_size: number;
extracted_text?: string;
session_id?: string;
......@@ -92,16 +76,29 @@ export async function getAvailableAgents(tabId: number): Promise<OfficialSiteAva
return apiClient.get<OfficialSiteAvailableAgentsResponse>(`/official-site/tabs/${tabId}/agents/available`);
}
export async function saveAgentDisplayConfig(tabId: number, agentId: number, payload: SaveOfficialAgentDisplayPayload): Promise<SaveOfficialAgentDisplayResponse> {
return apiClient.post<SaveOfficialAgentDisplayResponse>(`/official-site/tabs/${tabId}/agents/${agentId}/config`, payload);
export interface OfficialSiteAgentDisplayDetail {
display_id: number;
agent_id: number;
agent_name: string;
agent_code: string;
media_url?: string;
media_type?: MediaType;
media_size: number;
icon_url?: string;
speech_title?: string;
speech_content?: string;
summary?: string;
sort_order: number;
display_status: DisplayStatus;
agent_status: AgentStatus;
}
export async function getConfiguredAgents(tabId: number): Promise<OfficialSiteConfiguredAgentsResponse> {
return apiClient.get<OfficialSiteConfiguredAgentsResponse>(`/official-site/tabs/${tabId}/agents/configured`);
export async function getAgentDisplayDetail(displayId: number): Promise<OfficialSiteAgentDisplayDetail> {
return apiClient.get<OfficialSiteAgentDisplayDetail>(`/official-site/agent-displays/${displayId}`);
}
export async function deleteAgentDisplayConfig(tabId: number, agentId: number): Promise<DeleteOfficialAgentDisplayResponse> {
return apiClient.delete<DeleteOfficialAgentDisplayResponse>(`/official-site/tabs/${tabId}/agents/${agentId}/config`, undefined);
export async function updateAgentDisplayConfig(displayId: number, payload: SaveOfficialAgentDisplayPayload): Promise<SaveOfficialAgentDisplayResponse> {
return apiClient.post<SaveOfficialAgentDisplayResponse>(`/official-site/agent-displays/${displayId}/config`, payload);
}
export async function uploadOfficialSiteAsset(formData: FormData): Promise<UploadOfficialSiteAssetResponse> {
......
......@@ -47,7 +47,7 @@ describe('officialSiteTab API', () => {
it('为 enable 状态的 Tab 推断 operations 包含 disable', async () => {
vi.mocked(apiClient.get).mockResolvedValueOnce({
list: [{ tab_id: 1, display_status: 'enable' as const, position_code: '', position_name: '', main_title: '', sub_title: '', qrcode_id: 0, qrcode_name: '', qrcode_url: '', qrcode_status: 'enable', sort_order: 0, agent_count: 0, created_at: '' }],
list: [{ tab_id: 1, display_status: 'enable' as const, position_code: '', position_name: '', main_title: '', sub_title: '', qrcode_id: 0, qrcode_name: '', qrcode_url: '', qrcode_status: 'enable', channel_code: '', qrcode_employee_name: '', sort_order: 0, agent_count: 0, created_at: '' }],
total: 1,
});
......@@ -57,7 +57,7 @@ describe('officialSiteTab API', () => {
it('为 disable 状态的 Tab 推断 operations 包含 enable', async () => {
vi.mocked(apiClient.get).mockResolvedValueOnce({
list: [{ tab_id: 1, display_status: 'disable' as const, position_code: '', position_name: '', main_title: '', sub_title: '', qrcode_id: 0, qrcode_name: '', qrcode_url: '', qrcode_status: 'enable', sort_order: 0, agent_count: 0, created_at: '' }],
list: [{ tab_id: 1, display_status: 'disable' as const, position_code: '', position_name: '', main_title: '', sub_title: '', qrcode_id: 0, qrcode_name: '', qrcode_url: '', qrcode_status: 'enable', channel_code: '', qrcode_employee_name: '', sort_order: 0, agent_count: 0, created_at: '' }],
total: 1,
});
......@@ -67,7 +67,7 @@ describe('officialSiteTab API', () => {
it('当后端返回空数组 operations 时也根据状态推断', async () => {
vi.mocked(apiClient.get).mockResolvedValueOnce({
list: [{ tab_id: 1, display_status: 'enable' as const, operations: [], position_code: '', position_name: '', main_title: '', sub_title: '', qrcode_id: 0, qrcode_name: '', qrcode_url: '', qrcode_status: 'enable', sort_order: 0, agent_count: 0, created_at: '' }],
list: [{ tab_id: 1, display_status: 'enable' as const, operations: [], position_code: '', position_name: '', main_title: '', sub_title: '', qrcode_id: 0, qrcode_name: '', qrcode_url: '', qrcode_status: 'enable', channel_code: '', qrcode_employee_name: '', sort_order: 0, agent_count: 0, created_at: '' }],
total: 1,
});
......@@ -121,6 +121,7 @@ describe('officialSiteTab API', () => {
vi.mocked(apiClient.put).mockResolvedValueOnce({ success: true, updated_at: '2026-05-16T14:00:00Z' });
await updateOfficialSiteTab(1, {
position_code: 'store_sales',
position_name: '更新名称',
qrcode_id: '5',
main_title: '新标题',
......@@ -129,6 +130,7 @@ describe('officialSiteTab API', () => {
sort_order: 2,
});
expect(apiClient.put).toHaveBeenCalledWith('/official-site/tabs/1', {
position_code: 'store_sales',
position_name: '更新名称',
qrcode_id: '5',
main_title: '新标题',
......
......@@ -52,6 +52,7 @@ export interface CreateOfficialSiteTabResponse {
}
export interface UpdateOfficialSiteTabPayload {
position_code: string;
position_name: string;
qrcode_id: string;
main_title: string;
......@@ -88,6 +89,7 @@ export interface AvailableOfficialSiteQRCodeQuery {
export interface AvailableOfficialSiteQRCodeItem {
qrcode_id: number;
qrcode_name: string;
channel_code: string;
employee_name: string;
position_name: string;
......@@ -106,6 +108,7 @@ export interface OfficialSiteTabDetail {
qrcode_name: string;
channel_code: string;
employee_name: string;
qrcode_employee_name: string;
employee_role_text: string;
main_title: string;
sub_title: string;
......@@ -122,6 +125,7 @@ interface RawTabDetailResponse {
channel_qrcode_name?: string;
channel_code?: string;
employee_name?: string;
qrcode_employee_name?: string;
employee_role_text?: string;
steward_name?: string;
steward_role?: string;
......@@ -140,6 +144,7 @@ function adaptTabDetailResponse(raw: RawTabDetailResponse): OfficialSiteTabDetai
qrcode_name: raw.qrcode_name ?? raw.channel_qrcode_name ?? '',
channel_code: raw.channel_code ?? '',
employee_name: raw.employee_name ?? raw.steward_name ?? '',
qrcode_employee_name: raw.qrcode_employee_name ?? '',
employee_role_text: raw.employee_role_text ?? raw.steward_role ?? '',
main_title: raw.main_title ?? '',
sub_title: raw.sub_title ?? '',
......
......@@ -62,7 +62,7 @@ export function AgentDetailDrawer({ agentId, routeState }: { agentId?: string; r
<div className="grid grid-cols-[100px_1fr] gap-2 items-start">
<span className="text-[var(--gl-color-text-secondary)]">所属岗位</span>
<div className="flex flex-wrap gap-2">
{detail.positions.map((position) => <Tag key={position.id}>{position.name}</Tag>)}
{detail.positions?.map((position) => <Tag key={position.id}>{position.name}</Tag>)}
</div>
</div>
<div className="grid grid-cols-[100px_1fr] gap-2 items-start">
......
import type { AgentDetailRecord } from '../../../packages/contracts/agent-editor-mock';
import type { AgentListMockItem } from '../../../packages/contracts/agent-list-mock';
import type { AgentDetail } from '../../api/agent';
const storageKey = 'agent-admin-saved-agents';
......@@ -20,16 +21,39 @@ export function readSavedAgents() {
}
}
export function upsertSavedAgent(detail: AgentDetailRecord) {
export function upsertSavedAgent(detail: AgentDetail | AgentDetailRecord) {
if (!canUseStorage()) {
return;
}
const adaptedDetail = adaptDetailToRecord(detail);
const current = readSavedAgents();
const next = [...current.filter((item) => item.agent_id !== detail.agent_id), detail];
const next = [...current.filter((item) => item.agent_id !== adaptedDetail.agent_id), adaptedDetail];
window.localStorage.setItem(storageKey, JSON.stringify(next));
}
function adaptDetailToRecord(detail: AgentDetail | AgentDetailRecord): AgentDetailRecord {
const isManager = 'is_manager' in detail ? detail.is_manager : detail.code === 'steward';
const positions = (detail.positions ?? []).map((p) => ({
id: String(p.id),
name: p.name,
}));
const managedUser = detail.managed_user
? { user_id: typeof detail.managed_user.user_id === 'string' ? Number(detail.managed_user.user_id) : detail.managed_user.user_id, user_name: detail.managed_user.user_name }
: null;
return {
agent_id: detail.agent_id,
name: detail.name,
code: detail.code,
positions,
managed_user: managedUser,
description: detail.description,
skill_ids: detail.skill_ids,
status: detail.status,
is_manager: isManager,
};
}
export function findSavedAgent(agentId?: string) {
if (!agentId) {
return undefined;
......
......@@ -6,7 +6,7 @@ import { resetAgentDisplayConfigMockState } from '../../../packages/contracts/of
import { resetOfficialSiteJobTabMockState } from '../../../packages/contracts/official-site-job-tab-mock';
import { App } from '../../App';
import { getOfficialSiteTabDetail, getOfficialSiteTabList, type OfficialSiteTabDetail, type OfficialSiteTabListItem } from '../../api/officialSiteTab';
import { getConfiguredAgents, type OfficialSiteConfiguredAgentsResponse, type OfficialSiteConfiguredAgent } from '../../api/officialSiteAgentDisplay';
import { getAvailableAgents, type OfficialSiteAvailableAgentsResponse } from '../../api/officialSiteAgentDisplay';
vi.mock('../../api/officialSiteTab', () => ({
getOfficialSiteTabDetail: vi.fn(),
......@@ -19,10 +19,10 @@ vi.mock('../../api/officialSiteTab', () => ({
}));
vi.mock('../../api/officialSiteAgentDisplay', () => ({
getConfiguredAgents: vi.fn(),
saveAgentDisplayConfig: vi.fn(),
deleteAgentDisplayConfig: vi.fn(),
getAvailableAgents: vi.fn(),
updateAgentDisplayConfig: vi.fn(),
uploadOfficialSiteAsset: vi.fn(),
getAgentDisplayDetail: vi.fn(),
}));
const mockTabDetail: OfficialSiteTabDetail = {
......@@ -33,6 +33,7 @@ const mockTabDetail: OfficialSiteTabDetail = {
qrcode_name: '店销顾问渠道活码',
channel_code: 'DSC-QR-001',
employee_name: '张小萌',
qrcode_employee_name: '张小萌',
employee_role_text: '店销主管',
main_title: 'AI 智能助手提升店销效率',
sub_title: '通过 AI 智能问答帮助店销顾问快速响应客户需求',
......@@ -50,6 +51,8 @@ const mockTabListItem: OfficialSiteTabListItem = {
qrcode_name: '店销顾问渠道活码',
qrcode_url: 'https://cdn.example.com/qrcode.png',
qrcode_status: 'enable',
channel_code: 'DSC-QR-001',
qrcode_employee_name: '张小萌',
display_status: 'enable',
sort_order: 10,
agent_count: 3,
......@@ -57,48 +60,49 @@ const mockTabListItem: OfficialSiteTabListItem = {
operations: ['edit', 'disable', 'delete', 'configureAgent'],
};
const mockConfiguredAgents: OfficialSiteConfiguredAgent[] = [
{
config_id: 'c1',
agent_id: '101',
agent_name: '复盘Agent',
media_url: 'https://cdn.example.com/media.mp4',
media_type: 'mp4',
speech_title: '复盘Agent',
speech_content: '帮助店销顾问完成每日复盘,分析业绩数据和客户反馈',
display_status: 'enable',
sort_order: 10,
agent_status: 'enable',
icon_url: 'https://cdn.example.com/icons/review-agent.png',
},
{
config_id: 'c2',
agent_id: '102',
agent_name: '质检Agent',
media_url: '',
media_type: 'gif',
speech_title: '',
speech_content: '',
display_status: 'disable',
sort_order: 30,
agent_status: 'disable',
},
{
config_id: 'c3',
agent_id: '103',
agent_name: '销售助手Agent',
media_url: 'https://cdn.example.com/media/sales-assist.gif',
media_type: 'gif',
speech_title: '销售助手Agent',
speech_content: '智能推荐话术',
display_status: 'disable',
sort_order: 20,
agent_status: 'enable',
icon_url: 'https://cdn.example.com/icons/sales-assist.png',
},
];
const mockEmptyAgents: OfficialSiteConfiguredAgent[] = [];
const mockAvailableAgentsResponse: OfficialSiteAvailableAgentsResponse = {
tab_id: 1,
position_name: '店销顾问',
qrcode_id: 1,
available_agents: [
{
display_id: 1,
agent_id: 101,
agent_name: '复盘Agent',
agent_code: 'review',
is_configured: true,
is_steward: false,
icon_url: 'https://cdn.example.com/icons/review-agent.png',
media_url: 'https://cdn.example.com/media.mp4',
summary: '帮助店销顾问完成每日复盘,分析业绩数据和客户反馈',
display_status: 'enable',
agent_status: 'enable',
},
{
display_id: 2,
agent_id: 102,
agent_name: '质检Agent',
agent_code: 'quality',
is_configured: false,
is_steward: false,
display_status: 'disable',
agent_status: 'disable',
},
{
display_id: 3,
agent_id: 103,
agent_name: '销售助手Agent',
agent_code: 'sales-assist',
is_configured: true,
is_steward: false,
icon_url: 'https://cdn.example.com/icons/sales-assist.png',
media_url: 'https://cdn.example.com/media/sales-assist.gif',
summary: '智能推荐话术',
display_status: 'disable',
agent_status: 'enable',
},
],
};
function renderApp(path = '/official-site/job-tabs/1/agents') {
window.localStorage.setItem('agent-admin-local-login', 'true');
......@@ -126,19 +130,11 @@ describe('Agent display config list', () => {
page: 1,
page_size: 10,
});
vi.mocked(getConfiguredAgents).mockResolvedValue({
tab_id: '1',
position_name: '店销顾问',
qrcode_name: '店销顾问渠道活码',
channel_code: 'DSC-QR-001',
employee_name: '张小萌',
employee_role_text: '店销主管',
configured_agents: mockConfiguredAgents,
});
vi.mocked(getAvailableAgents).mockResolvedValue(mockAvailableAgentsResponse);
});
describe('list rendering', () => {
it('shows Agent name column (speech_title)', async () => {
it('shows Agent name column', async () => {
renderApp();
await waitFor(() => {
expect(screen.getByRole('columnheader', { name: 'Agent名称' })).toBeInTheDocument();
......@@ -146,7 +142,7 @@ describe('Agent display config list', () => {
});
});
it('shows Agent overview column (speech_content)', async () => {
it('shows Agent overview column', async () => {
renderApp();
await waitFor(() => {
expect(screen.getByRole('columnheader', { name: 'Agent概述' })).toBeInTheDocument();
......@@ -168,15 +164,7 @@ describe('Agent display config list', () => {
});
});
it('shows sort order column', async () => {
renderApp();
await waitFor(() => {
expect(screen.getByRole('columnheader', { name: '排序' })).toBeInTheDocument();
expect(screen.getByText('10')).toBeInTheDocument();
});
});
it('shows status column (agent_status)', async () => {
it('shows status column', async () => {
renderApp();
await waitFor(() => {
expect(screen.getByRole('columnheader', { name: '状态' })).toBeInTheDocument();
......@@ -206,13 +194,11 @@ describe('Agent display config list', () => {
it('shows 展示中/已下架 for enabled agents', async () => {
renderApp();
await waitFor(() => {
// Agent 101 is enabled with display_status=enable
const rows = screen.getAllByRole('row');
const row101 = rows.find((row) => within(row).queryByText('复盘Agent'));
expect(row101).toBeDefined();
expect(within(row101!).getByText('展示中')).toBeInTheDocument();
// Agent 103 is enabled with display_status=disable
const row103 = rows.find((row) => within(row).queryByText('销售助手Agent'));
expect(row103).toBeDefined();
expect(within(row103!).getByText('已下架')).toBeInTheDocument();
......@@ -222,7 +208,6 @@ describe('Agent display config list', () => {
it('shows - for disabled agent display status', async () => {
renderApp();
await waitFor(() => {
// Agent 102 is disabled - show '-' for speech_content and display_status
expect(screen.getAllByText('-').length).toBeGreaterThan(0);
});
});
......@@ -269,14 +254,11 @@ describe('Agent display config list', () => {
describe('empty states', () => {
it('shows empty state when no configurable agents', async () => {
vi.mocked(getConfiguredAgents).mockResolvedValueOnce({
tab_id: '3',
vi.mocked(getAvailableAgents).mockResolvedValueOnce({
tab_id: 3,
position_name: '客服岗',
qrcode_name: '客服渠道活码',
channel_code: 'CS-QR-003',
employee_name: '客服员工',
employee_role_text: '客服专员',
configured_agents: mockEmptyAgents,
qrcode_id: 3,
available_agents: [],
});
renderApp('/official-site/job-tabs/3/agents');
......@@ -303,24 +285,5 @@ describe('Agent display config list', () => {
expect(iconImg.getAttribute('src')).toContain('cdn.example.com');
});
});
it('shows media type indicator', async () => {
renderApp();
await waitFor(() => {
expect(screen.getByText('视频')).toBeInTheDocument(); // Agent 101 has video media
expect(screen.getByText('GIF')).toBeInTheDocument(); // Agent 103 has gif media
});
});
});
describe('sort order display', () => {
it('shows sort order as number', async () => {
renderApp();
await waitFor(() => {
// Agent 104 has sort_order 0 (in tab 3)
// Agent 101 has sort_order 10
expect(screen.getByText('10')).toBeInTheDocument();
});
});
});
});
\ No newline at end of file
......@@ -3,11 +3,10 @@ import { useNavigate, useParams } from 'react-router-dom';
import { Button, StatePlaceholder, Table } from '../../../packages/ui/src';
import {
getConfiguredAgents,
deleteAgentDisplayConfig,
type OfficialSiteConfiguredAgent,
type AgentStatus,
getAvailableAgents,
type OfficialSiteAvailableAgent,
type DisplayStatus,
type AgentStatus,
} from '../../api/officialSiteAgentDisplay';
import { getOfficialSiteTabDetail, type OfficialSiteTabDetail } from '../../api/officialSiteTab';
import { AgentDisplayConfigEditModal } from './AgentDisplayConfigEditModal';
......@@ -30,8 +29,8 @@ export function OfficialSiteAgentDisplayConfigPage() {
const [loading, setLoading] = useState(true);
const [loadError, setLoadError] = useState(false);
const [tabDetail, setTabDetail] = useState<OfficialSiteTabDetail | null>(null);
const [items, setItems] = useState<OfficialSiteConfiguredAgent[]>([]);
const [editingAgent, setEditingAgent] = useState<OfficialSiteConfiguredAgent | null>(null);
const [items, setItems] = useState<OfficialSiteAvailableAgent[]>([]);
const [editingDisplayId, setEditingDisplayId] = useState<number | null>(null);
const [notice, setNotice] = useState<{ type: 'success' | 'error'; message: string } | null>(null);
const fetchData = useCallback(async () => {
......@@ -39,14 +38,13 @@ export function OfficialSiteAgentDisplayConfigPage() {
setLoadError(false);
try {
// Fetch both tab detail and agent list in parallel
const [detail, agentsResponse] = await Promise.all([
getOfficialSiteTabDetail(tabId),
getConfiguredAgents(tabId),
getAvailableAgents(tabId),
]);
setTabDetail(detail);
setItems(agentsResponse.configured_agents);
setItems(agentsResponse.available_agents);
setLoading(false);
} catch {
setLoadError(true);
......@@ -62,19 +60,8 @@ export function OfficialSiteAgentDisplayConfigPage() {
navigate('/official-site/job-tabs');
};
const handleEditAgent = (agent: OfficialSiteConfiguredAgent) => {
setEditingAgent(agent);
};
const handleDeleteAgent = async (agent: OfficialSiteConfiguredAgent) => {
try {
await deleteAgentDisplayConfig(tabId, Number(agent.agent_id));
setNotice({ type: 'success', message: '删除成功' });
fetchData();
} catch (error) {
const message = error instanceof Error ? error.message : '删除失败,请重试';
setNotice({ type: 'error', message });
}
const handleEditAgent = (agent: OfficialSiteAvailableAgent) => {
setEditingDisplayId(agent.display_id);
};
// Loading state
......@@ -123,7 +110,7 @@ export function OfficialSiteAgentDisplayConfigPage() {
const columns = [
{
title: 'Agent名称',
dataIndex: 'speech_title' as const,
dataIndex: 'agent_name' as const,
render: (value: unknown) => <span className="font-medium">{value as string}</span>,
},
{
......@@ -136,9 +123,8 @@ export function OfficialSiteAgentDisplayConfigPage() {
{
title: '图标',
dataIndex: 'icon_url' as const,
render: (value: unknown, item: OfficialSiteConfiguredAgent) => {
// Use media_url as icon if icon_url not available
const url = (value as string) || item.media_url;
render: (value: unknown, item: OfficialSiteAvailableAgent) => {
const url = value as string;
if (!url) {
return <span className="text-[var(--gl-color-text-secondary)]">-</span>;
}
......@@ -146,7 +132,7 @@ export function OfficialSiteAgentDisplayConfigPage() {
<img
data-testid={`agent-icon-${item.agent_id}`}
src={url}
alt={item.speech_title}
alt={item.agent_name}
className="w-8 h-8 rounded object-cover"
/>
);
......@@ -155,48 +141,25 @@ export function OfficialSiteAgentDisplayConfigPage() {
{
title: '展示素材',
dataIndex: 'media_url' as const,
render: (value: unknown, item: OfficialSiteConfiguredAgent) => {
render: (value: unknown, item: OfficialSiteAvailableAgent) => {
const url = value as string;
if (!url) {
return <span className="text-[var(--gl-color-text-secondary)]">-</span>;
}
const typeLabels: Record<string, string> = {
'image': '图片',
'video': '视频',
'gif': 'GIF',
'png': '图片',
'jpg': '图片',
'jpeg': '图片',
'mp4': '视频',
};
const isVideo = ['mp4', 'mov', 'avi', 'webm'].includes(item.media_type || '');
if (isVideo) {
return <span className="text-xs text-[var(--gl-color-text-secondary)]">视频</span>;
}
return (
<div className="flex items-center gap-2">
{item.media_type === 'mp4' ? (
<video
src={url}
className="w-8 h-8 rounded object-cover"
muted
/>
) : (
<img
src={url}
alt={item.speech_title}
className="w-8 h-8 rounded object-cover"
/>
)}
<span className="text-xs text-[var(--gl-color-text-secondary)]">
{typeLabels[item.media_type] || '素材'}
</span>
</div>
<img
src={url}
alt={item.agent_name}
className="w-8 h-8 rounded object-cover"
/>
);
},
},
{
title: '排序',
dataIndex: 'sort_order' as const,
render: (value: unknown) => <span>{value as number}</span>,
},
{
title: '状态',
dataIndex: 'agent_status' as const,
render: (value: unknown) => {
......@@ -210,7 +173,7 @@ export function OfficialSiteAgentDisplayConfigPage() {
{
title: '展示状态',
key: 'display_status_display',
render: (_: unknown, item: OfficialSiteConfiguredAgent) => {
render: (_: unknown, item: OfficialSiteAvailableAgent) => {
const text = getDisplayStatusTextForList(item.agent_status, item.display_status);
if (text === '-') {
return <span className="text-[var(--gl-color-text-secondary)]">-</span>;
......@@ -223,30 +186,20 @@ export function OfficialSiteAgentDisplayConfigPage() {
{
title: '操作',
key: 'actions',
render: (_: unknown, item: OfficialSiteConfiguredAgent) => {
render: (_: unknown, item: OfficialSiteAvailableAgent) => {
if (item.agent_status !== 'enable') {
return null;
}
return (
<span className="flex flex-wrap gap-1">
<Button
aria-label={`编辑配置-${item.speech_title}`}
aria-label={`编辑配置-${item.agent_name}`}
size="small"
variant="text"
onClick={() => handleEditAgent(item)}
>
编辑配置
</Button>
{item.display_status === 'enable' ? (
<Button
aria-label={`删除配置-${item.speech_title}`}
size="small"
variant="danger"
onClick={() => handleDeleteAgent(item)}
>
删除配置
</Button>
) : null}
</span>
);
},
......@@ -293,11 +246,11 @@ export function OfficialSiteAgentDisplayConfigPage() {
</div>
<div className="flex items-center gap-2">
<span className="shrink-0 min-w-[80px] text-[var(--gl-color-text-secondary)]">渠道编码:</span>
<span>{tabDetail.channel_code || '-'}</span>
<span>{tabDetail.position_code || '-'}</span>
</div>
<div className="flex items-center gap-2">
<span className="shrink-0 min-w-[80px] text-[var(--gl-color-text-secondary)]">承接员工:</span>
<span>{tabDetail.employee_name || '-'}</span>
<span>{tabDetail.qrcode_employee_name || '-'}</span>
</div>
</div>
</div>
......@@ -321,12 +274,11 @@ export function OfficialSiteAgentDisplayConfigPage() {
{/* Edit modal */}
<AgentDisplayConfigEditModal
open={Boolean(editingAgent)}
agent={editingAgent}
tabId={tabId}
onCancel={() => setEditingAgent(null)}
open={Boolean(editingDisplayId)}
displayId={editingDisplayId}
onCancel={() => setEditingDisplayId(null)}
onSaveSuccess={() => {
setEditingAgent(null);
setEditingDisplayId(null);
setNotice({ type: 'success', message: '保存成功' });
fetchData();
}}
......
......@@ -4,7 +4,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest';
import { App } from '../../App';
import { getOfficialSiteTabDetail, getOfficialSiteTabList, type OfficialSiteTabDetail, type OfficialSiteTabListItem } from '../../api/officialSiteTab';
import { getConfiguredAgents, type OfficialSiteConfiguredAgentsResponse } from '../../api/officialSiteAgentDisplay';
import { getAvailableAgents, type OfficialSiteAvailableAgentsResponse } from '../../api/officialSiteAgentDisplay';
vi.mock('../../api/officialSiteTab', () => ({
getOfficialSiteTabDetail: vi.fn(),
......@@ -17,10 +17,10 @@ vi.mock('../../api/officialSiteTab', () => ({
}));
vi.mock('../../api/officialSiteAgentDisplay', () => ({
getConfiguredAgents: vi.fn(),
saveAgentDisplayConfig: vi.fn(),
deleteAgentDisplayConfig: vi.fn(),
getAvailableAgents: vi.fn(),
updateAgentDisplayConfig: vi.fn(),
uploadOfficialSiteAsset: vi.fn(),
getAgentDisplayDetail: vi.fn(),
}));
const mockTabDetail: OfficialSiteTabDetail = {
......@@ -31,6 +31,7 @@ const mockTabDetail: OfficialSiteTabDetail = {
qrcode_name: '店销顾问渠道活码',
channel_code: 'DSC-QR-001',
employee_name: '张小萌',
qrcode_employee_name: '张小萌',
employee_role_text: '店销主管',
main_title: 'AI 智能助手提升店销效率',
sub_title: '通过 AI 智能问答帮助店销顾问快速响应客户需求',
......@@ -48,6 +49,8 @@ const mockTabListItem: OfficialSiteTabListItem = {
qrcode_name: '店销顾问渠道活码',
qrcode_url: 'https://cdn.example.com/qrcode.png',
qrcode_status: 'enable',
channel_code: 'DSC-QR-001',
qrcode_employee_name: '张小萌',
display_status: 'enable',
sort_order: 10,
agent_count: 3,
......@@ -55,51 +58,23 @@ const mockTabListItem: OfficialSiteTabListItem = {
operations: ['edit', 'disable', 'delete', 'configureAgent'],
};
const mockConfiguredAgents: OfficialSiteConfiguredAgentsResponse = {
tab_id: '1',
const mockAvailableAgentsResponse: OfficialSiteAvailableAgentsResponse = {
tab_id: 1,
position_name: '店销顾问',
qrcode_name: '店销顾问渠道活码',
channel_code: 'DSC-QR-001',
employee_name: '张小萌',
employee_role_text: '店销主管',
configured_agents: [
qrcode_id: 1,
available_agents: [
{
config_id: 'c1',
agent_id: '101',
display_id: 1,
agent_id: 101,
agent_name: '复盘Agent',
agent_code: 'review',
is_configured: true,
is_steward: false,
icon_url: 'https://cdn.example.com/icon.png',
media_url: 'https://cdn.example.com/media.gif',
media_type: 'gif',
speech_title: '复盘Agent',
speech_content: '帮助店销顾问完成每日复盘',
summary: '帮助店销顾问完成每日复盘',
display_status: 'enable',
sort_order: 10,
agent_status: 'enable',
icon_url: 'https://cdn.example.com/icon.png',
},
{
config_id: 'c2',
agent_id: '102',
agent_name: '质检Agent',
media_url: '',
media_type: 'gif',
speech_title: '',
speech_content: '',
display_status: 'disable',
sort_order: 30,
agent_status: 'disable',
},
{
config_id: 'c3',
agent_id: '103',
agent_name: '销售助手Agent',
media_url: 'https://cdn.example.com/media2.gif',
media_type: 'gif',
speech_title: '销售助手Agent',
speech_content: '智能推荐话术',
display_status: 'disable',
sort_order: 20,
agent_status: 'enable',
icon_url: 'https://cdn.example.com/icon2.png',
},
],
};
......@@ -117,9 +92,8 @@ describe('official site agent display config routes and navigation', () => {
beforeEach(() => {
window.localStorage.clear();
vi.clearAllMocks();
// 默认 mock 成功响应
vi.mocked(getOfficialSiteTabDetail).mockResolvedValue(mockTabDetail);
vi.mocked(getConfiguredAgents).mockResolvedValue(mockConfiguredAgents);
vi.mocked(getAvailableAgents).mockResolvedValue(mockAvailableAgentsResponse);
vi.mocked(getOfficialSiteTabList).mockResolvedValue({
list: [mockTabListItem],
total: 1,
......@@ -130,7 +104,6 @@ describe('official site agent display config routes and navigation', () => {
it('renders the agent display config page at /official-site/job-tabs/:tabId/agents', async () => {
renderApp();
// 等待加载完成,标题只展示岗位名称,不拼接渠道活码名称
await waitFor(() => {
expect(screen.getByRole('heading', { name: '店销顾问 Agent展示配置页' })).toBeInTheDocument();
});
......@@ -158,7 +131,6 @@ describe('official site agent display config routes and navigation', () => {
it('shows position name in page title', async () => {
renderApp();
// 标题为 "{岗位名称} Agent展示配置页"
await waitFor(() => {
expect(screen.getByRole('heading', { name: '店销顾问 Agent展示配置页' })).toBeInTheDocument();
});
......
......@@ -192,6 +192,7 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit'
});
} else if (currentTab) {
await updateOfficialSiteTab(currentTab.tab_id, {
position_code: currentTab.position_code,
position_name: form.position_name,
qrcode_id: String(form.qrcode_id),
main_title: form.main_title,
......@@ -279,7 +280,7 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit'
position_code: qr.channel_code,
position_name: qr.position_name,
qrcode_id: qr.qrcode_id,
qrcode_name: qr.channel_code,
qrcode_name: qr.qrcode_name,
channel_code: qr.channel_code,
employee_name: qr.employee_name,
}));
......@@ -291,7 +292,7 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit'
<FormItem label="关联渠道活码" layout="horizontal">
<div className={fieldWidthClassName}>
{form.qrcode_name || selectedQRCode?.channel_code || currentTab?.qrcode_name || (mode === 'create' && !form.position_code ? (
{form.qrcode_name || currentTab?.qrcode_name || (mode === 'create' && !form.position_code ? (
<span className="text-sm text-[var(--gl-color-text-secondary)]">选择岗位后自动展示</span>
) : null)}
</div>
......
......@@ -39,6 +39,8 @@ describe('OfficialSiteJobTabListPage action visibility', () => {
qrcode_name: '直播运营渠道活码',
qrcode_url: 'https://picsum.photos/seed/offsite_no_ops/200/200',
qrcode_status: 'enable',
channel_code: 'LIVE-QR-001',
qrcode_employee_name: '直播员工',
display_status: 'enable',
sort_order: 10,
agent_count: 2,
......
......@@ -106,7 +106,7 @@ export function OfficialSiteJobTabListPage() {
<Button aria-label={`编辑${item.position_name}`} size="small" variant="text" onClick={() => navigate(`/official-site/job-tabs/${item.tab_id}/edit${routeSearch}`, { state: { tab: item } })}>编辑</Button>
{canEnable ? <Button aria-label={`上架${item.position_name}`} size="small" variant="text" onClick={() => setStatusTarget({ tab: item, action: 'enable' })}>上架</Button> : null}
{canDisable ? <Button aria-label={`下架${item.position_name}`} size="small" variant="text" onClick={() => setStatusTarget({ tab: item, action: 'disable' })}>下架</Button> : null}
<Button aria-label={`删除${item.position_name}`} size="small" variant="danger" onClick={() => setDeleteTarget(item)}>删除</Button>
<Button aria-label={`删除${item.position_name}`} size="small" variant="text" onClick={() => setDeleteTarget(item)}>删除</Button>
</span>
);
},
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!