Commit 7c16dd2a by 胡悦

feat(ui): 完成三项OpenSpec规范落地与UI优化

- 落地独立页面页头操作规范:将返回按钮从左侧移至右侧操作区,左侧仅保留页面标题与说明,更新全局与项目级OpenSpec、架构文档、相关页面测试与实现
- 优化搜索过滤器组件:修改按钮文案为“查询”,调整按钮顺序为查询、重置、展开/收起,改为流式响应式布局,支持最多两行默认展示与自然换行适配
- 调整方法论配置页步骤倒序展示,保持后端数据提交的正序契约
- 新增对应三项OpenSpec变更的归档文件、设计文档与验证脚本
1 parent cb3a316d
Showing 47 changed files with 1469 additions and 218 deletions
...@@ -160,9 +160,10 @@ ...@@ -160,9 +160,10 @@
新增、编辑等独立页面的页头操作区 SHALL 统一遵循: 新增、编辑等独立页面的页头操作区 SHALL 统一遵循:
- 左侧展示 `返回`、页面标题和必要说明。 - 左侧只展示页面标题和必要说明,不展示页面级按钮。
- 右侧只展示主操作 `保存`,不再提供 `取消` 按钮。 - 右侧统一展示 `返回` 与其他页面级操作;`返回` 位于右侧操作区左端,主操作(如 `保存`)位于右侧操作区右端。
- 离开当前独立页面由左侧 `返回` 承载。 - 不再提供 `取消` 按钮。
- 离开当前独立页面由右侧操作区的 `返回` 承载。
- 页头在内容滚动容器内使用 sticky 固定;滚动表单内容时,`返回` 和 `保存` 始终保持可见。 - 页头在内容滚动容器内使用 sticky 固定;滚动表单内容时,`返回` 和 `保存` 始终保持可见。
- sticky 页头必须具备不透明背景、边框和合理层级,避免表单内容穿透或覆盖页头。 - sticky 页头必须具备不透明背景、边框和合理层级,避免表单内容穿透或覆盖页头。
......
...@@ -47,7 +47,7 @@ ...@@ -47,7 +47,7 @@
导出默认放在表格工具栏右侧,表达对当前结果集的处理。若同时支持导出筛选结果和导出选中项,使用下拉菜单区分。批量操作默认放在表格工具栏左侧,并在已选择数据时展示 `已选择 N 项`。 导出默认放在表格工具栏右侧,表达对当前结果集的处理。若同时支持导出筛选结果和导出选中项,使用下拉菜单区分。批量操作默认放在表格工具栏左侧,并在已选择数据时展示 `已选择 N 项`。
新增、编辑等独立页面的页头左侧展示 `返回`、页面标题和必要说明,右侧只展示主操作 `保存`,不展示 `取消`。页面内容滚动时,页头操作区必须在内容滚动容器内 sticky 固定,确保 `返回` 和 `保存` 始终可见;sticky 页头需要有不透明背景、边框和合理层级,避免内容穿透。 新增、编辑等独立页面的页头左侧只展示页面标题和必要说明,右侧统一展示 `返回` 与其他页面级操作;右侧操作区内 `返回` 位于左端,主操作(如 `保存`)位于右端,不展示 `取消`。页面内容滚动时,页头操作区必须在内容滚动容器内 sticky 固定,确保 `返回` 和 `保存` 始终可见;sticky 页头需要有不透明背景、边框和合理层级,避免内容穿透。
后台管理页面要保持信息密度和可扫读性。避免营销式首屏、装饰性卡片和过大的标题字号。 后台管理页面要保持信息密度和可扫读性。避免营销式首屏、装饰性卡片和过大的标题字号。
......
## Context
全局 Web 桌面端规范当前把独立新增、编辑页定义为左侧 `返回`、标题和说明,右侧主操作 `保存`。该布局曾用于减少页面底部操作区分散,但现在新的统一要求是“所有独立页面,按钮全部放到右侧”,即页头左侧只承载页面识别信息,右侧集中承载 `返回` 和其他页面级操作。
本 change 是全局规范调整,不直接修改业务项目代码。`agent-admin/web` 会通过同名项目级 change 承接实现。
## Goals / Non-Goals
**Goals:**
- 将独立页面页头按钮位置统一为右侧操作区。
- 明确 `返回` 也是页面级操作按钮,必须位于右侧操作区。
- 保留主操作按钮在右侧,并使其通常位于最右侧。
- 保留 sticky 页头操作区规则。
- 同步更新长期架构文档,避免 OpenSpec 与文档口径不一致。
**Non-Goals:**
- 不定义具体业务页面的路由、保存逻辑、权限规则或数据结构。
- 不要求恢复或新增 `取消` 按钮。
- 不覆盖弹窗、抽屉、列表工具栏、表格行内操作和移动端布局。
- 不在全局 change 中直接修改业务项目实现。
## Decisions
### 决策 1:右侧操作区集中承载所有页面级按钮
独立页面页头左侧只展示页面标题、必要说明和状态摘要;右侧展示 `返回`、保存、提交、发布、刷新、更多操作等页面级按钮。
备选方案是只把新增/编辑页改为右侧集中操作,配置页和详情页另行定义。该方案会让“独立页面”的概念继续分裂,因此不采用。
### 决策 2:`返回` 在右侧操作区靠左,主操作靠右
右侧操作区内,`返回` 作为导航动作放在操作区最左侧;主操作如 `保存`、`提交`、`发布` 放在最右侧;其他次级操作位于二者之间,数量较多时可收敛到更多操作菜单。
备选方案是让 `返回` 放在右侧最右。该方案会让主操作位置不稳定,也不利于用户在编辑页快速识别保存动作,因此不采用。
### 决策 3:规范以全局原则为准,项目实现逐项落地
全局 `web-desktop-ui-standard` 只描述可复用规则;业务项目在自己的 OpenSpec 中列出受影响页面、测试和实现任务。
备选方案是在全局 OpenSpec 中列出所有项目页面。该方案会让全局规范承担项目清单维护职责,后续容易过期,因此不采用。
## Risks / Trade-offs
- [Risk] 长标题或说明可能挤压右侧按钮 → Mitigation:规范要求右侧操作区不可被压缩到不可见,项目实现需使用稳定的 flex/grid 约束。
- [Risk] 项目对“独立页面”的边界理解不一致 → Mitigation:全局规范定义“脱离列表上下文、拥有独立路由或独立配置流程的页面”为独立页面,项目 OpenSpec 再列出覆盖范围。
- [Risk] 旧规范与新规范在归档前并存 → Mitigation:本 change 修改全局 OpenSpec delta 与架构文档,并由项目级 change 同步落地。
## Migration Plan
1. 更新全局 OpenSpec delta,修改 `web-desktop-ui-standard` 的独立页面页头操作区要求。
2. 更新全局架构文档中的页面布局说明。
3. 在业务项目中通过项目级 OpenSpec 承接实现。
4. 项目实现完成并验证后,再分别归档全局与项目 change。
回滚方式:若规范确认需要恢复旧布局,新增反向 OpenSpec change,将独立页面页头规则改回左侧 `返回`、右侧主操作,并由项目按反向任务回滚实现。
## Open Questions
无。
## Why
当前全局 Web 桌面端规范要求独立新增、编辑页左侧展示 `返回`、右侧展示主操作,但新的交互要求是所有独立页面的按钮统一放在右侧。需要将全局规范调整为右侧集中操作,避免不同项目继续沿用左右分散的页头按钮布局。
## What Changes
- 调整独立页面页头布局规则:左侧只承载页面标题、说明和状态摘要等识别信息。
- 明确独立页面页头右侧承载 `返回` 和其他页面级操作按钮。
- 明确 `返回` 是独立页面右侧操作区的标准按钮,不再放在页头左侧。
- 明确主操作按钮继续保留在右侧操作区,且通常位于最右侧。
- 保持 sticky 页头操作区要求,确保长表单、长配置页滚动时仍可访问返回和主操作。
- 不恢复 `取消` 按钮,不改变按钮的业务含义、路由跳转、保存逻辑或权限规则。
## Capabilities
### New Capabilities
无。
### Modified Capabilities
- `web-desktop-ui-standard`: 调整独立页面页头操作区规范,从“左侧返回、右侧主操作”改为“左侧页面信息、右侧返回和其他页面级操作”。
## Impact
- 影响全局 OpenSpec:`openspec/specs/web-desktop-ui-standard/spec.md`。
- 影响全局架构文档:`docs/architecture/frontend-conventions.md`,必要时同步 `docs/architecture/component-guidelines.md`。
- 下游 Web 桌面端项目需要按新规范调整独立页面页头按钮位置。
- 本全局 change 不直接修改业务代码;具体项目实现由项目级 OpenSpec change 承接。
## MODIFIED Requirements
### Requirement: 独立新增编辑页必须固定页头操作区
后台新增、编辑、配置等独立页面 SHALL 在页面内容区顶部提供统一页头操作区。页头左侧只承载页面标题、说明和状态摘要等页面识别信息;页头右侧 MUST 承载 `返回` 和其他页面级操作按钮。页面滚动时页头必须在内容滚动容器内保持可见。
#### Scenario: 渲染独立新增编辑页
- **WHEN** 前端项目实现新增、编辑、配置等独立页面
- **THEN** 页头左侧展示页面标题和必要说明
- **AND** 页头左侧不展示 `返回` 或其他按钮
- **AND** 页头右侧展示 `返回`
- **AND** 页头右侧展示 `保存` 等主操作
- **AND** 页头右侧不展示 `取消`
#### Scenario: 排列右侧页面级操作
- **WHEN** 独立页面同时提供 `返回`、主操作和其他页面级操作
- **THEN** `返回` 位于右侧操作区内靠左位置
- **AND** 主操作位于右侧操作区内靠右位置
- **AND** 其他次级页面级操作位于 `返回` 和主操作之间,或收敛到更多操作菜单
#### Scenario: 滚动独立新增编辑页
- **WHEN** 用户滚动独立页面中的表单或配置内容
- **THEN** `返回` 和 `保存` 等页面级操作所在页头操作区保持在屏幕可见区域
- **AND** sticky 页头具备不透明背景、边框和合理层级,避免内容滚动时穿透或覆盖页头
- **AND** 页头右侧操作区不得被页面标题或说明挤压到不可见
## 1. 全局规范同步
- [x] 1.1 更新 `openspec/specs/web-desktop-ui-standard/spec.md`,将独立页面页头规则改为左侧页面信息、右侧返回和其他页面级操作。
- [x] 1.2 更新 `docs/architecture/frontend-conventions.md` 中独立页面布局说明。
- [x] 1.3 审查 `docs/architecture/component-guidelines.md` 是否存在旧版左侧返回规则,并按需同步。
## 2. 下游项目承接
- [x] 2.1 确认 `workspace/agent-admin/web` 同名项目级 OpenSpec change 已同步 `admin-shell` 规范。
- [x] 2.2 在项目实现完成后,复核全局规范与项目规范、测试和页面行为一致。
## 3. 验证与归档
- [x] 3.1 运行 `openspec validate standardize-independent-page-right-actions --strict` 验证全局 change。
- [x] 3.2 项目实现和验证完成后,再归档全局 change。
...@@ -67,18 +67,27 @@ ...@@ -67,18 +67,27 @@
- **AND** 如已有旧数据,刷新期间优先保留旧数据,避免列表内容跳空 - **AND** 如已有旧数据,刷新期间优先保留旧数据,避免列表内容跳空
### Requirement: 独立新增编辑页必须固定页头操作区 ### Requirement: 独立新增编辑页必须固定页头操作区
后台新增、编辑等独立页面 SHALL 在页面内容区顶部提供统一页头操作区。页头左侧承载 `返回`、标题和说明,右侧只承载主操作 `保存`;页面滚动时页头必须在内容滚动容器内保持可见。 后台新增、编辑、配置等独立页面 SHALL 在页面内容区顶部提供统一页头操作区。页头左侧只承载页面标题、说明和状态摘要等页面识别信息;页头右侧 MUST 承载 `返回` 和其他页面级操作按钮。页面滚动时页头必须在内容滚动容器内保持可见。
#### Scenario: 渲染独立新增编辑页 #### Scenario: 渲染独立新增编辑页
- **WHEN** 前端项目实现新增、编辑等独立页面 - **WHEN** 前端项目实现新增、编辑、配置等独立页面
- **THEN** 页头左侧展示 `返回` 和页面标题 - **THEN** 页头左侧展示页面标题和必要说明
- **AND** 页头右侧展示 `保存` - **AND** 页头左侧不展示 `返回` 或其他按钮
- **AND** 页头右侧展示 `返回`
- **AND** 页头右侧展示 `保存` 等主操作
- **AND** 页头右侧不展示 `取消` - **AND** 页头右侧不展示 `取消`
#### Scenario: 排列右侧页面级操作
- **WHEN** 独立页面同时提供 `返回`、主操作和其他页面级操作
- **THEN** `返回` 位于右侧操作区内靠左位置
- **AND** 主操作位于右侧操作区内靠右位置
- **AND** 其他次级页面级操作位于 `返回` 和主操作之间,或收敛到更多操作菜单
#### Scenario: 滚动独立新增编辑页 #### Scenario: 滚动独立新增编辑页
- **WHEN** 用户滚动独立页面中的表单或配置内容 - **WHEN** 用户滚动独立页面中的表单或配置内容
- **THEN** `返回` 和 `保存` 所在页头操作区保持在屏幕可见区域 - **THEN** `返回` 和 `保存` 等页面级操作所在页头操作区保持在屏幕可见区域
- **AND** sticky 页头具备不透明背景、边框和合理层级,避免内容滚动时穿透或覆盖页头 - **AND** sticky 页头具备不透明背景、边框和合理层级,避免内容滚动时穿透或覆盖页头
- **AND** 页头右侧操作区不得被页面标题或说明挤压到不可见
### Requirement: 后台管理系统表格必须默认使用 BusinessTable ### Requirement: 后台管理系统表格必须默认使用 BusinessTable
......
.root { .root {
display: grid; min-width: 0;
gap: var(--gl-spacing-md);
} }
.viewport { .viewport {
max-width: 100%;
overflow: hidden; overflow: hidden;
transition: max-height 240ms ease; transition: max-height 240ms ease;
} }
...@@ -13,18 +13,24 @@ ...@@ -13,18 +13,24 @@
flex-wrap: wrap; flex-wrap: wrap;
gap: var(--gl-spacing-md) var(--gl-spacing-lg); gap: var(--gl-spacing-md) var(--gl-spacing-lg);
align-items: flex-start; align-items: flex-start;
width: 100%;
max-width: 100%;
min-width: 0;
overflow-x: hidden;
} }
.item { .item {
display: flex; display: flex;
width: var(--gl-search-item-width, 284px); order: var(--search-filter-order, 0);
flex: 0 1 var(--gl-search-item-width, 284px);
max-width: 100%;
min-width: 0; min-width: 0;
align-items: center; align-items: center;
gap: var(--gl-spacing-sm); gap: var(--gl-spacing-sm);
} }
.itemWide { .itemWide {
width: var(--gl-search-item-wide-width, 484px); flex-basis: var(--gl-search-item-wide-width, 484px);
} }
.label { .label {
...@@ -38,13 +44,13 @@ ...@@ -38,13 +44,13 @@
} }
.control { .control {
width: var(--gl-search-control-width, 200px); width: 100%;
min-width: 0; min-width: 0;
} }
.inputLabel { .inputLabel {
display: block; display: block;
width: var(--gl-search-control-width, 200px); flex: 1 1 auto;
min-width: 0; min-width: 0;
} }
...@@ -61,23 +67,44 @@ ...@@ -61,23 +67,44 @@
} }
.controlWide { .controlWide {
width: var(--gl-search-control-wide-width, 400px); width: 100%;
min-width: 0;
} }
.footer { .actions {
display: flex; display: flex;
order: var(--search-filter-order, 0);
flex: 0 0 auto;
align-items: center; align-items: center;
justify-content: flex-end;
gap: var(--gl-spacing-sm); gap: var(--gl-spacing-sm);
max-width: 100%;
white-space: nowrap;
}
.collapsedBreak {
order: var(--search-filter-order, 2);
flex: 0 0 100%;
width: 100%;
height: 0;
} }
.toggleButton { .toggleButton {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
}
.toggleContent {
display: inline-flex;
align-items: center;
gap: var(--gl-spacing-xs); gap: var(--gl-spacing-xs);
line-height: 1;
} }
.toggleIcon { .toggleIcon {
display: block;
width: 1em;
height: 1em;
flex: 0 0 auto;
transition: transform 240ms ease; transition: transform 240ms ease;
} }
......
import { useEffect, useLayoutEffect, useMemo, useRef, useState, type ReactNode } from 'react'; import { useEffect, useLayoutEffect, useMemo, useRef, useState, type CSSProperties, type ReactNode } from 'react';
import { Button, DatePicker, DateRangePicker, Input, Select } from 'tdesign-react'; import { Button, DatePicker, DateRangePicker, Input, Select } from 'tdesign-react';
import { ChevronDownIcon, RefreshIcon, SearchIcon } from 'tdesign-icons-react'; import { ChevronDownIcon, RefreshIcon, SearchIcon } from 'tdesign-icons-react';
...@@ -99,6 +99,70 @@ function buildInitialValues(fields: SearchFilterField[]) { ...@@ -99,6 +99,70 @@ function buildInitialValues(fields: SearchFilterField[]) {
}, {}); }, {});
} }
const MIN_ROW_HEIGHT = 44;
const MAX_COLLAPSED_ROWS = 2;
const FALLBACK_CONTAINER_WIDTH = 920;
interface SearchFilterLayout {
collapsedHeight: number;
expandedHeight: number;
showToggle: boolean;
visibleFieldCount: number;
}
function parsePixelValue(value: string | undefined) {
const parsed = Number.parseFloat(value ?? '');
return Number.isFinite(parsed) ? parsed : 0;
}
function getElementWidth(element: HTMLElement | null, fallback: number) {
if (!element) return fallback;
return element.offsetWidth || element.getBoundingClientRect().width || fallback;
}
function countWrappedRows(widths: number[], containerWidth: number, columnGap: number) {
if (widths.length === 0) return 0;
if (containerWidth <= 0) return 1;
let rows = 1;
let currentRowWidth = 0;
widths.forEach((width) => {
const itemWidth = Math.min(width, containerWidth);
const nextWidth = currentRowWidth === 0 ? itemWidth : currentRowWidth + columnGap + itemWidth;
if (currentRowWidth > 0 && nextWidth > containerWidth) {
rows += 1;
currentRowWidth = itemWidth;
return;
}
currentRowWidth = nextWidth;
});
return rows;
}
function getVisibleFieldCount(fieldWidths: number[], actionsWidth: number, containerWidth: number, columnGap: number) {
let visibleCount = 0;
for (let index = 0; index <= fieldWidths.length; index += 1) {
const rows = countWrappedRows([...fieldWidths.slice(0, index), actionsWidth], containerWidth, columnGap);
if (rows <= MAX_COLLAPSED_ROWS) {
visibleCount = index;
} else {
break;
}
}
return visibleCount;
}
function getRowsHeight(rowCount: number, rowGap: number) {
if (rowCount <= 0) return MIN_ROW_HEIGHT;
return rowCount * MIN_ROW_HEIGHT + Math.max(rowCount - 1, 0) * rowGap;
}
function SearchFieldControl({ function SearchFieldControl({
field, field,
value, value,
...@@ -182,8 +246,14 @@ export function SearchFilter({ fields, className, 'data-testid': dataTestId, onR ...@@ -182,8 +246,14 @@ export function SearchFilter({ fields, className, 'data-testid': dataTestId, onR
const [innerValues, setInnerValues] = useState<SearchFilterValues>(() => buildInitialValues(fields)); const [innerValues, setInnerValues] = useState<SearchFilterValues>(() => buildInitialValues(fields));
const [expanded, setExpanded] = useState(false); const [expanded, setExpanded] = useState(false);
const viewportRef = useRef<HTMLDivElement>(null); const viewportRef = useRef<HTMLDivElement>(null);
const [viewportHeight, setViewportHeight] = useState(44); const flowRef = useRef<HTMLDivElement>(null);
const [collapsedHeight, setCollapsedHeight] = useState(44); const actionsRef = useRef<HTMLDivElement>(null);
const [layout, setLayout] = useState<SearchFilterLayout>({
collapsedHeight: MIN_ROW_HEIGHT,
expandedHeight: MIN_ROW_HEIGHT,
showToggle: false,
visibleFieldCount: fields.length,
});
const fieldSignature = useMemo( const fieldSignature = useMemo(
() => fields.map((field) => `${field.key}:${field.type}:${field.type === 'datePicker' && field.range ? 'range' : 'single'}`).join('|'), () => fields.map((field) => `${field.key}:${field.type}:${field.type === 'datePicker' && field.range ? 'range' : 'single'}`).join('|'),
[fields], [fields],
...@@ -203,17 +273,58 @@ export function SearchFilter({ fields, className, 'data-testid': dataTestId, onR ...@@ -203,17 +273,58 @@ export function SearchFilter({ fields, className, 'data-testid': dataTestId, onR
}, [fieldSignature]); }, [fieldSignature]);
useLayoutEffect(() => { useLayoutEffect(() => {
const updateHeight = () => { const updateLayout = () => {
const viewport = viewportRef.current; const viewport = viewportRef.current;
if (!viewport) return; const flow = flowRef.current;
const firstItem = viewport.querySelector('[data-field-key]') as HTMLElement | null; const actions = actionsRef.current;
setCollapsedHeight(Math.max(firstItem?.getBoundingClientRect().height ?? 44, 44)); if (!viewport || !flow || !actions) return;
setViewportHeight(viewport.scrollHeight);
const computedStyle = window.getComputedStyle(flow);
const columnGap = parsePixelValue(computedStyle.columnGap);
const rowGap = parsePixelValue(computedStyle.rowGap);
const containerWidth = flow.clientWidth || flow.getBoundingClientRect().width || FALLBACK_CONTAINER_WIDTH;
const fieldElements = Array.from(flow.querySelectorAll<HTMLElement>('[data-field-key]'));
const fieldWidths = fieldElements.map((element) => getElementWidth(element, 284));
const actionsWidth = getElementWidth(actions, 220);
const completeRows = countWrappedRows([...fieldWidths, actionsWidth], containerWidth, columnGap);
const showToggle = completeRows > MAX_COLLAPSED_ROWS;
const visibleFieldCount = showToggle
? getVisibleFieldCount(fieldWidths, actionsWidth, containerWidth, columnGap)
: fields.length;
const expandedHeight = Math.max(flow.scrollHeight, getRowsHeight(completeRows, rowGap));
const collapsedRows = showToggle ? MAX_COLLAPSED_ROWS : Math.max(completeRows, 1);
const collapsedHeight = Math.min(expandedHeight, getRowsHeight(collapsedRows, rowGap));
setLayout((current) => {
const next = { collapsedHeight, expandedHeight, showToggle, visibleFieldCount };
if (
current.collapsedHeight === next.collapsedHeight
&& current.expandedHeight === next.expandedHeight
&& current.showToggle === next.showToggle
&& current.visibleFieldCount === next.visibleFieldCount
) {
return current;
}
return next;
});
};
updateLayout();
const resizeObserver = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(updateLayout);
if (resizeObserver) {
resizeObserver.observe(flowRef.current as Element);
}
window.addEventListener('resize', updateLayout);
return () => {
resizeObserver?.disconnect();
window.removeEventListener('resize', updateLayout);
}; };
updateHeight(); }, [fieldSignature, fields.length, layout.showToggle]);
window.addEventListener('resize', updateHeight);
return () => window.removeEventListener('resize', updateHeight); useEffect(() => {
}, [expanded, fieldSignature]); if (!layout.showToggle && expanded) setExpanded(false);
}, [expanded, layout.showToggle]);
const values = fields.reduce<SearchFilterValues>((current, field) => { const values = fields.reduce<SearchFilterValues>((current, field) => {
current[field.key] = isControlledField(field) ? normalizeFieldValue(field, field.value) : innerValues[field.key]; current[field.key] = isControlledField(field) ? normalizeFieldValue(field, field.value) : innerValues[field.key];
...@@ -234,16 +345,23 @@ export function SearchFilter({ fields, className, 'data-testid': dataTestId, onR ...@@ -234,16 +345,23 @@ export function SearchFilter({ fields, className, 'data-testid': dataTestId, onR
fields.forEach((field) => field.onChange?.(nextValues[field.key] as never)); fields.forEach((field) => field.onChange?.(nextValues[field.key] as never));
onReset?.(); onReset?.();
}; };
const showToggle = fields.reduce((count, field) => count + (field.type === 'datePicker' && field.range ? 2 : 1), 0) > 3; const shouldFold = layout.showToggle && !expanded;
const viewportMaxHeight = expanded ? layout.expandedHeight : layout.collapsedHeight;
return ( return (
<div className={classNames(styles.root, className)} data-testid={dataTestId}> <div className={classNames(styles.root, className)} data-testid={dataTestId} role="search" aria-label="搜索过滤条件">
<div ref={viewportRef} className={styles.viewport} style={{ maxHeight: expanded ? viewportHeight : collapsedHeight }}> <div ref={viewportRef} className={styles.viewport} style={{ maxHeight: viewportMaxHeight }}>
<div className={styles.fields}> <div ref={flowRef} className={styles.fields} data-search-filter-flow="true">
{fields.map((field) => { {fields.map((field, index) => {
const isWide = field.type === 'datePicker' && field.range; const isWide = field.type === 'datePicker' && field.range;
const order = shouldFold && index >= layout.visibleFieldCount ? 3 : 0;
return ( return (
<div key={field.key} className={classNames(styles.item, isWide && styles.itemWide)} data-field-key={field.key}> <div
key={field.key}
className={classNames(styles.item, isWide && styles.itemWide)}
data-field-key={field.key}
style={{ '--search-filter-order': order } as CSSProperties}
>
<span className={styles.label} title={field.label}>{field.label}</span> <span className={styles.label} title={field.label}>{field.label}</span>
<SearchFieldControl <SearchFieldControl
field={field} field={field}
...@@ -254,18 +372,26 @@ export function SearchFilter({ fields, className, 'data-testid': dataTestId, onR ...@@ -254,18 +372,26 @@ export function SearchFilter({ fields, className, 'data-testid': dataTestId, onR
</div> </div>
); );
})} })}
<div
ref={actionsRef}
className={styles.actions}
data-search-filter-actions="true"
style={{ '--search-filter-order': shouldFold ? 1 : 0 } as CSSProperties}
>
<Button className={styles.actionButton} icon={<SearchIcon />} theme="primary" onClick={handleSearch}>查询</Button>
<Button className={styles.actionButton} icon={<RefreshIcon />} variant="outline" onClick={handleReset}>重置</Button>
{layout.showToggle ? (
<Button className={styles.toggleButton} variant="text" onClick={() => setExpanded((value) => !value)}>
<span className={styles.toggleContent}>
<span>{expanded ? '收起' : '展开'}</span>
<ChevronDownIcon className={classNames(styles.toggleIcon, expanded && styles.toggleIconExpanded)} />
</span>
</Button>
) : null}
</div>
{shouldFold ? <div className={styles.collapsedBreak} style={{ '--search-filter-order': 2 } as CSSProperties} /> : null}
</div> </div>
</div> </div>
<div className={styles.footer}>
{showToggle ? (
<Button className={styles.toggleButton} variant="text" onClick={() => setExpanded((value) => !value)}>
{expanded ? '收起' : '展开'}
<ChevronDownIcon className={classNames(styles.toggleIcon, expanded && styles.toggleIconExpanded)} />
</Button>
) : null}
<Button className={styles.actionButton} icon={<RefreshIcon />} variant="outline" onClick={handleReset}>重置</Button>
<Button className={styles.actionButton} icon={<SearchIcon />} theme="primary" onClick={handleSearch}>搜索</Button>
</div>
</div> </div>
); );
} }
# 独立页面右侧操作区实施计划
## 目标
基于 OpenSpec change `standardize-independent-page-right-actions`,将全局 Web 桌面端规范与 `agent-admin/web` 项目独立页面同步到“左侧页面信息、右侧返回和其他页面级操作”的页头布局。
## 前置确认
- 全局 OpenSpec change:`architecture-spec/openspec/changes/standardize-independent-page-right-actions`
- 项目 OpenSpec change:`workspace/agent-admin/web/openspec/changes/standardize-independent-page-right-actions`
- 两侧 `openspec validate standardize-independent-page-right-actions --strict` 已通过。
- 进入代码前需由用户确认本轮 OpenSpec artifacts 与实施计划。
## 实施步骤
## 1. 全局规范落地
- 更新 `architecture-spec/openspec/specs/web-desktop-ui-standard/spec.md` 中独立页面页头操作区要求。
- 更新 `architecture-spec/docs/architecture/frontend-conventions.md` 的页面布局说明。
- 审查 `architecture-spec/docs/architecture/component-guidelines.md`,如存在旧口径则同步。
## 2. 项目规范落地
- 更新 `workspace/agent-admin/web/openspec/specs/admin-shell/spec.md` 中独立页面页头操作区要求。
- 确认项目规范不再出现左侧 `返回`、右侧 `保存` 的旧规则。
## 3. TDD 测试调整
- 先更新明确覆盖页面的测试,让旧布局下出现失败:
- Agent 新增/编辑页。
- Agent 标签新增/编辑页。
- 渠道码新增/编辑页。
- 官网岗位 Tab 新增/编辑页。
- 测试断言重点:
- 页头左侧标题区不包含 `返回` 按钮。
- 页头右侧操作区包含 `返回`。
- 页头右侧操作区包含主操作,例如 `保存`。
- 原有返回、保存、校验行为继续通过。
## 4. 页面实现
- 在现有页面局部页头中移动按钮,不新增通用页头组件。
- 右侧操作区顺序为:`返回`、其他次级操作、主操作。
- 标题区允许收缩或换行,右侧操作区保持不可被压缩到不可见。
- 保持 sticky 页头背景、边框和层级。
## 5. 边界审查
- 检查配置页、详情页中是否存在独立页面页头。
- 只迁移拥有独立路由且页头存在返回或页面级操作区的页面。
- 不迁移弹窗、抽屉、列表工具栏、表格行内操作或局部返回入口。
## 6. 验证
- 运行全局 OpenSpec 严格校验。
- 运行项目 OpenSpec 严格校验。
- 运行相关页面测试。
- 运行 `npm run typecheck`。
- 运行 `npm run build`。
- 启动本地页面并用浏览器验证桌面布局、sticky 页头和关键交互。
## 完成标准
- 全局规范、项目规范、页面实现和测试口径一致。
- 当前覆盖的独立页面页头右侧同时展示 `返回` 和主操作。
- 页头左侧不再展示按钮。
- 验证命令和浏览器验证均完成,未遗留未解释失败。
# 独立页面页头右侧操作规范设计
## 背景
当前全局 Web 桌面端规范与 `agent-admin/web` 项目规范要求独立新增、编辑页的页头左侧展示 `返回`、标题和说明,右侧展示主操作 `保存`。新需求要求所有独立页面的按钮统一放到右侧,右侧包含 `返回` 和其他操作按钮。
本设计按全局规范处理:先更新公司级 Web 桌面端规范,再同步 `agent-admin/web` 项目规范与当前页面实现。
## 目标
- 所有 Web 桌面端独立页面的页头左侧只承载页面识别信息,包括标题、说明或状态摘要。
- 页头右侧集中承载页面级按钮,包括 `返回` 和保存、提交、发布、刷新、更多操作等其他页面级操作。
- `返回` 作为独立页面的标准导航动作,必须出现在页头右侧操作区。
- 页面滚动时,页头操作区继续保持 sticky 可见,避免编辑表单或长页面中主操作丢失。
- `agent-admin/web` 当前已有独立新增、编辑、配置页面与新规范保持一致。
## 非目标
- 不改变按钮的业务含义、提交逻辑、路由跳转目标或权限规则。
- 不新增 `取消` 按钮,也不恢复此前已移除的取消动作。
- 不调整表单字段、列表工具栏、弹窗/抽屉内操作区或表格行内操作。
- 不改变移动端或非 Web 桌面端规范。
## 方案
采用“全局规范 + 项目同步 + 后续实现”的方案。
1. 全局规范层:更新 `architecture-spec/openspec` 中的 Web 桌面端 UI 标准,把独立页面页头操作区规则从“左侧返回、右侧保存”调整为“左侧标题信息、右侧返回与其他操作”。
2. 全局文档层:同步更新 `architecture-spec/docs/architecture/frontend-conventions.md` 和必要的组件/页面规则文档,确保长期架构说明与 OpenSpec 一致。
3. 项目规范层:更新 `workspace/agent-admin/web/openspec` 的 `admin-shell` 相关规范,明确当前项目独立页面遵循同一右侧操作规则。
4. 项目实现层:在 OpenSpec artifacts 确认后,用 TDD 调整现有独立页面页头布局,把返回按钮移入右侧操作区,并更新相关测试。
## 交互规则
独立页面页头建议结构:
- 左侧:页面标题、必要说明、状态摘要。
- 右侧:`返回` + 其他页面级操作按钮。
右侧按钮排序:
- `返回` 放在右侧操作区的最左侧。
- 主操作放在右侧操作区的最右侧,例如 `保存`、`提交`、`发布`。
- 其他次级操作放在 `返回` 和主操作之间,或收敛到更多操作菜单。
视觉与可用性:
- 页头操作区保持 sticky。
- `返回` 使用次级/描边按钮样式。
- 主操作保持主按钮样式。
- 按钮之间保持稳定间距,页面滚动、标题换行和说明展示不得造成操作区错位。
- 页面标题过长时,左侧信息区可以换行或截断,但不能挤压右侧按钮到不可见。
## 影响范围
全局规范:
- `architecture-spec/openspec/specs/web-desktop-ui-standard/spec.md`
- `architecture-spec/docs/architecture/frontend-conventions.md`
- 可能涉及 `architecture-spec/docs/architecture/component-guidelines.md`
`agent-admin/web` 项目规范:
- `workspace/agent-admin/web/openspec/specs/admin-shell/spec.md`
- 新增 OpenSpec change:`standardize-independent-page-right-actions`
`agent-admin/web` 当前页面候选:
- Agent 新增/编辑独立页
- Agent 标签新增/编辑独立页
- 渠道码新增/编辑独立页
- 官网岗位 Tab 新增/编辑独立页
- 其他被项目规范认定为独立页面的配置页或详情页
最终具体文件以 OpenSpec 任务和测试覆盖结果为准。
## 验收标准
- 全局 OpenSpec 明确要求独立页面页头按钮全部位于右侧,且右侧包含 `返回` 与其他页面级操作。
- `agent-admin/web` 项目 OpenSpec 与全局规范保持一致。
- 已有独立新增、编辑页面的返回按钮不再出现在页头左侧。
- 已有独立新增、编辑页面的右侧操作区同时包含 `返回` 和主操作按钮。
- 原有保存、返回、校验、权限和路由行为保持不变。
- 相关测试覆盖按钮位置规则。
- 完成实现后运行 OpenSpec 校验、类型检查、相关测试、构建,并完成浏览器布局验证。
## 风险与处理
- 部分页面是否属于“独立页面”可能存在边界。处理方式:OpenSpec tasks 中先列出明确覆盖页面,再把疑似页面作为审查项,不在未确认前扩大行为改动。
- 标题较长时可能挤压右侧按钮。处理方式:实现时使用稳定的 flex/grid 约束,确保右侧操作区不被压缩到不可用。
- 全局规范和项目规范可能产生重复描述。处理方式:全局规范定义原则,项目规范只说明 `agent-admin/web` 的落地要求和覆盖页面。
## 后续步骤
确认本设计后,使用 OpenSpec change name:`standardize-independent-page-right-actions`。
随后按顺序创建和确认:
1. 全局 OpenSpec change artifacts。
2. `agent-admin/web` 项目 OpenSpec change artifacts。
3. Superpowers 实施计划。
4. TDD 实现、验证和必要的规范归档。
# 搜索过滤器两行折叠与响应式布局设计
## 背景
`SearchFilter` 已作为全局业务组件沉淀在 `packages/business-components/src/search-filter/`,并由 `workspace/agent-admin/web` 通过 `@gl/business-components` 使用。当前组件采用“搜索条件区域 + 底部右侧操作区”的结构:条件项负责换行展示,展开/收起、重置、搜索按钮固定在底部操作区。
新的交互要求调整为:
- 默认最多展示两行搜索条件;内容只有一行时展示一行,内容正好两行时展示两行且不折叠。
- 查询按钮跟随在最后一个可见查询条件后面。
- 按钮顺序为:查询、重置、展开/收起。
- 当前宽屏一行可展示 3 个条件;屏幕变小时应随容器宽度响应式调整,通过自然换行适配,不出现横向滚动条。
## 目标
1. 将搜索条件与操作按钮放进同一个响应式流式布局中,按钮不再独立固定在底部右侧。
2. 默认态最多展示两行内容;当内容超过两行时折叠到两行,查询按钮位于默认可见区域最后一个可见条件之后。
3. 展开态展示全部搜索条件,操作按钮跟随在全部条件之后。
4. 展开/收起触发按钮只在实际存在第三行及后续内容被折叠隐藏时出现,不再按固定字段数量判断。
5. 布局随容器宽度变化重新计算,可在窄屏时自然换行,不保留固定“一行 3 个”的假设,且不产生横向滚动条。
## 非目标
- 不调整 `SearchFilter` 对外字段配置 API。
- 不改变查询、重置、草稿值更新、日期范围等业务语义。
- 不引入页面级搜索参数或后端接口变更。
- 不把全局组件改成某个页面的专用实现。
## 方案
采用方案 A:统一流式布局。
组件内部将条件项和操作按钮组渲染在同一个 flex 容器中:
- 普通条件项保留现有基础宽度约束。
- 范围类条件项保留更宽的展示宽度。
- 操作按钮组作为一个不可拆分的 flex item,内部顺序固定为“查询、重置、展开/收起”。
- 默认折叠态下,组件根据真实 DOM 布局测量前两行高度,并最多展示两行。
- 展开态下,组件展示完整内容高度。
- 当容器宽度变化、字段配置变化、展开状态变化时重新测量。
为保证默认态按钮可见,默认态会把前两行可容纳的条件项排在操作按钮前,其余条件项排在操作按钮之后并被两行高度裁切隐藏;展开态恢复为全部条件在前、按钮在最后。这样同时满足“默认最多两行”和“查询跟在最后一个可见查询条件后面”。
响应式策略只采用“自然换行”,不使用横向滚动条。容器变窄时,条件项和按钮组都应参与换行计算,并保持文本与控件不重叠。
## 交互细节
- 默认状态为折叠态,但默认可见高度为最多两行。
- 默认态展示前两行可容纳的条件项和操作按钮组。
- 若全部内容在一行或两行内即可展示,则不显示展开/收起按钮,也不裁切内容。
- 若实际布局存在第三行及后续被折叠隐藏的条件项,则显示“展开”。
- 点击“展开”后展示全部条件,按钮组跟随在最后一个条件后面,展开按钮文案变为“收起”。
- 点击“收起”后恢复最多两行的默认展示。
- 查询按钮文案统一为“查询”,保留原 `onSearch` 行为。
- 重置按钮文案仍为“重置”,保留原 `onReset` 行为。
- 搜索区容器不出现横向滚动条;当空间不足时,后续条件项进入下一行,超过两行的内容由默认态裁切或展开态完整展示。
## 实现影响
主要影响文件:
- `packages/business-components/src/search-filter/SearchFilter.tsx`
- `packages/business-components/src/search-filter/SearchFilter.module.css`
- `workspace/agent-admin/web/src/business-components/global-business-components.test.tsx`
- `workspace/agent-admin/web/src/routes/components/ComponentsDemoPage.test.tsx`
测试需要覆盖:
- 操作按钮顺序为“查询、重置、展开/收起”。
- 查询按钮仍触发原搜索回调。
- 重置按钮仍触发原重置逻辑。
- 实际存在第三行及后续内容被折叠隐藏时才显示展开/收起;只有一行或两行时不显示。
- 窄容器下布局可重新计算,默认态最多展示两行且按钮可见。
- 窄容器下不出现横向滚动条。
## 风险与处理
- DOM 测量在 jsdom 中不具备真实布局能力,单元测试需要用可控尺寸或抽象测量结果验证逻辑,真实布局通过浏览器验证补齐。
- 按钮组参与布局后,极窄宽度下可能单独占据第二行。CSS 需要保证按钮组不被拆分,同时容器不出现文本重叠。
- 需要避免使用固定总宽度或 `overflow-x: auto` 造成横向滚动。
- 现有规范中“默认最多两行”和“按钮固定右下角”的描述将与新需求冲突,OpenSpec 需要同步修改。
## 验证计划
1. 先补充或调整测试,体现新的按钮顺序、文案和折叠逻辑。
2. 实现组件布局与测量逻辑。
3. 运行相关单元测试。
4. 运行类型检查与构建。
5. 启动本地页面,在宽屏、较窄桌面宽度下用浏览器验证:
- 默认最多展示两行。
- 查询、重置、展开/收起顺序正确。
- 展开后全部条件可见。
- 窄屏时布局自然换行,无重叠。
## Context
`SearchFilter` 是后台列表页复用的全局搜索过滤组件,源码位于 `packages/business-components/src/search-filter/`,由 `agent-admin/web` 通过 `@gl/business-components` 使用。当前实现将搜索字段和底部操作区分离:字段区域负责换行和折叠,操作按钮固定在右下角,展开/收起按钮位于重置与搜索按钮左侧。
新交互要求把操作按钮放回搜索条件流中,按钮顺序调整为“查询、重置、展开/收起”,并按真实布局判断是否超过两行。容器变窄时只能自然换行,不能出现横向滚动条。
## Goals / Non-Goals
**Goals:**
- 搜索字段与操作按钮在同一个响应式布局中流动。
- 默认态最多展示两行;内容一行或两行内完整展示时不折叠。
- 只有实际出现第三行及后续隐藏内容时,才显示展开/收起。
- 查询按钮跟随默认可见区域最后一个查询条件,展开态跟随全部查询条件。
- 窄屏或容器变窄时自然换行,不产生横向滚动条。
**Non-Goals:**
- 不修改 `SearchFilter` 字段配置 API。
- 不修改查询、重置、字段变更的业务语义。
- 不调整列表页查询参数、分页重置或接口调用契约。
- 不引入新的 UI 依赖。
## Decisions
1. 统一流式布局
条件项和操作按钮组渲染在同一个 flex wrap 容器中。按钮组作为一个不可拆分的 flex item,内部顺序固定为“查询、重置、展开/收起”。相比继续保留底部操作区,这能让按钮真正跟随可见条件,并避免右下角固定区域与字段换行高度脱节。
2. 基于真实布局测量两行高度
组件通过 DOM 测量识别行位置,默认态计算前两行的可见高度,展开态使用完整内容高度。是否展示展开/收起不再依赖字段数量,而依赖真实布局是否存在第三行内容。
3. 默认态保证按钮可见
当字段超过两行时,默认态会把前两行可容纳的条件项排在操作按钮前,其余条件项排在按钮之后并由两行高度裁切。展开态恢复为全部条件在前、按钮在最后。这样能同时满足“最多两行默认展示”和“查询跟随最后一个可见条件”。
4. 响应式只允许换行
搜索区容器不使用 `overflow-x: auto`,字段项和按钮组在容器变窄时自然换行。普通字段与范围字段保留既有基础宽度,但需要通过 `max-width` 等约束避免小容器下撑出横向滚动。
## Risks / Trade-offs
- [Risk] jsdom 没有真实布局,无法完全覆盖 DOM 行高测量。 → Mitigation: 单元测试覆盖按钮顺序、回调和可控测量逻辑,浏览器验证覆盖真实宽度变化。
- [Risk] 极窄容器下按钮组可能占据单独一行。 → Mitigation: 保持按钮组不可拆分,但允许字段换行,并验证无文本重叠和横向滚动。
- [Risk] 默认态重排字段与展开态完整顺序存在差异。 → Mitigation: 仅在折叠且超过两行时为保证按钮可见进行排序;展开态恢复字段配置顺序。
## Migration Plan
1. 更新 `SearchFilter` 单元测试和 demo 测试,先表达新按钮文案、顺序与展开触发规则。
2. 调整组件结构和样式,移除独立右下角 footer。
3. 加入基于容器尺寸变化的重新测量逻辑。
4. 运行 OpenSpec 校验、类型检查、测试、构建和浏览器布局验证。
## Open Questions
无。
## Why
当前全局 `SearchFilter` 的操作按钮固定在搜索区右下角,且展开/收起按钮位于搜索与重置按钮左侧;这与新的后台搜索区交互要求不一致。搜索区需要在不同容器宽度下自然换行,默认最多展示两行,并让操作按钮跟随在当前可见查询条件之后。
## What Changes
- 将 `SearchFilter` 的搜索条件与操作按钮统一到同一个响应式流式布局中。
- 操作按钮顺序调整为“查询、重置、展开/收起”。
- 默认态最多展示两行;一行或两行即可完整展示时不显示展开/收起。
- 只有实际存在第三行及后续内容被折叠隐藏时,才显示展开/收起。
- 窄屏或容器变窄时通过自然换行适配,不出现横向滚动条。
- 查询按钮文案由“搜索”调整为“查询”,保持原搜索回调语义。
## Capabilities
### New Capabilities
- 无。
### Modified Capabilities
- `global-search-filter`: 调整全局搜索过滤器的操作按钮布局、按钮顺序、默认展示行数、展开/收起触发条件与响应式换行要求。
## Impact
- 影响全局业务组件 `packages/business-components/src/search-filter/SearchFilter.tsx` 与样式文件。
- 影响 `agent-admin/web` 中引用 `SearchFilter` 的组件 demo 与相关测试。
- 不改变 `SearchFilter` 的字段配置 API、搜索回调、重置回调和页面查询语义。
## ADDED Requirements
### Requirement: 操作按钮跟随搜索条件
系统 SHALL 将 `SearchFilter` 的查询、重置和展开/收起按钮作为搜索条件布局的一部分展示,并 SHALL 让操作按钮跟随在当前可见查询条件之后。
#### Scenario: 默认态展示操作按钮
- **WHEN** 搜索字段内容超过默认两行展示区域且组件处于默认折叠状态
- **THEN** 组件在默认可见区域内展示查询、重置和展开按钮
- **AND** 查询按钮位于最后一个可见查询条件之后
#### Scenario: 展开态展示操作按钮
- **WHEN** 用户展开搜索区域
- **THEN** 组件展示全部搜索字段
- **AND** 查询、重置和收起按钮跟随在最后一个搜索条件之后
#### Scenario: 触发查询和重置回调
- **WHEN** 用户点击查询或重置按钮
- **THEN** 组件分别调用传入的搜索或重置回调
### Requirement: 操作按钮顺序
系统 SHALL 按“查询、重置、展开/收起”的顺序展示 `SearchFilter` 操作按钮。
#### Scenario: 展示查询和重置按钮
- **WHEN** 组件渲染搜索区域
- **THEN** 操作按钮组先展示“查询”按钮
- **AND** 随后展示“重置”按钮
#### Scenario: 展示展开按钮
- **WHEN** 组件处于默认折叠状态且存在第三行及后续被隐藏内容
- **THEN** “展开”按钮展示在“查询”和“重置”按钮之后
#### Scenario: 展示收起按钮
- **WHEN** 用户展开搜索区域
- **THEN** “收起”按钮展示在“查询”和“重置”按钮之后
### Requirement: 响应式自然换行
系统 SHALL 在 `SearchFilter` 容器宽度变化时重新布局搜索条件与操作按钮,并 MUST 通过自然换行适配窄容器,且 MUST NOT 出现横向滚动条。
#### Scenario: 容器变窄
- **WHEN** `SearchFilter` 容器宽度不足以在一行展示原有数量的搜索条件
- **THEN** 搜索条件和操作按钮按容器宽度自然换行
- **AND** 搜索区不出现横向滚动条
#### Scenario: 容器宽度变化后重新判断折叠
- **WHEN** `SearchFilter` 容器宽度变化导致内容行数变化
- **THEN** 组件重新判断是否存在第三行及后续内容
- **AND** 组件按新的布局结果展示或隐藏展开/收起按钮
## MODIFIED Requirements
### Requirement: 最多两行默认展示
系统 SHALL 默认最多展示两行搜索区域内容,且 SHALL 将操作按钮所在区域计入两行展示高度。
#### Scenario: 字段在一行内完整展示
- **WHEN** 搜索字段与操作按钮在一行内可完整展示
- **THEN** 组件展示一行内容
- **AND** 组件不展示展开/收起按钮
#### Scenario: 字段在两行内完整展示
- **WHEN** 搜索字段与操作按钮在两行内可完整展示
- **THEN** 组件展示两行内容
- **AND** 组件不展示展开/收起按钮
#### Scenario: 字段超过两行
- **WHEN** 搜索字段与操作按钮超过默认两行可展示范围
- **THEN** 组件折叠状态仅展示前两行范围内内容
- **AND** 组件展示展开按钮
### Requirement: 展开收起交互
系统 SHALL 在搜索字段与操作按钮超过默认两行展示区域时提供展开/收起文字按钮,按钮 SHALL 位于查询与重置按钮之后,并 SHALL 使用文字与箭头表达当前操作。
#### Scenario: 折叠状态展示展开按钮
- **WHEN** 组件处于折叠状态且存在第三行及后续被隐藏内容
- **THEN** 操作按钮组在查询与重置按钮之后展示“展开”文字按钮和向下箭头
#### Scenario: 展开状态展示收起按钮
- **WHEN** 用户点击展开按钮后
- **THEN** 组件展示全部搜索字段
- **AND** 操作按钮组在查询与重置按钮之后展示“收起”文字按钮和向上箭头
#### Scenario: 展开收起具有动画
- **WHEN** 用户切换展开或收起状态
- **THEN** 搜索字段内容区域以平滑动画过渡到目标高度
## REMOVED Requirements
### Requirement: 操作按钮固定在右下角
**Reason**: 新交互要求操作按钮跟随搜索条件展示,固定右下角会导致按钮无法位于最后一个可见查询条件之后。
**Migration**: 使用新增的“操作按钮跟随搜索条件”和“操作按钮顺序”要求约束按钮布局与交互。
## 1. 测试先行
- [x] 1.1 更新 `SearchFilter` 相关单元测试,覆盖按钮文案“查询”、按钮顺序“查询、重置、展开/收起”和查询/重置回调。
- [x] 1.2 增加折叠判定测试,覆盖一行、两行不显示展开/收起,超过两行才显示展开/收起。
- [x] 1.3 更新组件 demo 测试,覆盖展开后展示“收起”、收起后恢复默认最多两行。
## 2. 组件实现
- [x] 2.1 调整 `SearchFilter` 结构,将搜索条件与操作按钮组放入同一个响应式流式布局。
- [x] 2.2 实现基于真实布局的两行高度测量和第三行溢出判断。
- [x] 2.3 在默认折叠态保证操作按钮位于前两行可见区域内,并在展开态恢复为全部条件之后。
- [x] 2.4 将操作按钮顺序调整为“查询、重置、展开/收起”,并将搜索按钮文案调整为“查询”。
- [x] 2.5 调整样式,确保窄容器自然换行、不出现横向滚动条、按钮组不被拆分且文本不重叠。
- [x] 2.6 修正展开/收起按钮内部文字与图标的垂直居中对齐。
## 3. 验证
- [x] 3.1 运行 `openspec validate refine-search-filter-single-row-responsive --strict`。
- [x] 3.2 运行相关单元测试。
- [x] 3.3 运行类型检查。
- [x] 3.4 运行构建。
- [x] 3.5 启动本地页面并在宽屏、较窄桌面宽度下验证默认最多两行、超过两行才展开、无横向滚动条。(用户确认自行浏览器验证)
## Context
方法论展示配置页当前使用 `form.steps` 作为页面渲染和保存 payload 的单一顺序来源。现有 `normalizeSteps` 会按数组索引将 `step_order` 归一为 `index + 1`;上移、下移、删除都会先调整数组,再调用 `normalizeSteps`。
用户澄清后的目标是:页面只改变展示顺序,展示为步骤三、步骤二、步骤一;但保存给后端的数据仍保持步骤一、步骤二、步骤三。也就是说,`form.steps` 应继续作为正序数据源,倒序只发生在渲染层。
当前「添加步骤」追加到 `form.steps` 末尾,这在数据层是正确的:新步骤应成为最大 `step_order` 的下一步。只要渲染层按倒序展示,新增步骤自然会出现在最上方。
## Decision
保持 `form.steps` 为正序业务顺序,不改变保存 payload 的数据来源。新增一个仅用于渲染的倒序视图,例如:
```ts
const visibleSteps = [...form.steps].reverse()
```
步骤卡片渲染使用 `visibleSteps`,但编辑、删除、上移、下移等操作仍回写到 `form.steps` 中对应的原始步骤。保存 payload 继续使用正序 `form.steps.map(...)`,无需新增字段或改变接口契约。
「添加步骤」继续追加到 `form.steps` 末尾:
```ts
steps: normalizeSteps([...current.steps, createEmptyStep(current.steps.length + 1)])
```
因为页面按倒序渲染,新增的最大 `step_order` 步骤会展示在最上方;保存时则仍位于 payload 的最后一个步骤,符合步骤一、步骤二、步骤三的后端数据顺序。
上移/下移按钮的可见语义需要跟倒序展示一致:用户在页面上点击「上移」时,卡片应向页面上方移动;由于数据层是正序,这等价于增大该步骤在 `form.steps` 中的索引。点击「下移」则等价于减小该步骤在 `form.steps` 中的索引。实现时应避免直接复用正序渲染下的相邻交换方向。
## Alternatives Considered
### 直接把 `form.steps` 改成倒序
可以在加载或新增时把 `form.steps` 直接倒序,这样渲染实现更简单。但保存 payload 会默认变成步骤三、步骤二、步骤一,违背后端数据仍保持正序的要求,因此不采用。
### 保存前再临时反转
可以让页面内部都使用倒序数组,保存前再按 `step_order` 排正序。该方案增加了更多状态约定,容易影响校验、删除、排序和上传回写。保持 `form.steps` 正序、只在渲染层倒序更清晰。
## Risks
- 既有测试可能默认第一张步骤卡始终是接口返回的第一步。需要补充或调整测试,明确第一张可见卡为最大 `step_order` 的步骤。
- 上移/下移在倒序展示下与数据数组方向相反,需要用测试覆盖可见移动语义和保存 payload 顺序。
## Why
方法论展示配置页当前按步骤一、步骤二、步骤三的正序展示步骤。运营配置时更关注最新或靠后的步骤,希望页面按步骤三、步骤二、步骤一的倒序展示,减少查看和编辑靠后步骤时的滚动成本。
后端接口和 H5 展示端仍以步骤一、步骤二、步骤三的业务顺序为准,因此本次只调整配置页的展示顺序,不改变保存给后端的数据顺序。
## What Changes
- 方法论展示配置页 SHALL 按 `step_order` 倒序展示步骤卡片,即步骤三、步骤二、步骤一。
- 点击「添加步骤」后,新建空步骤 SHALL 作为最大 `step_order` 的下一步,并展示在页面最上方。
- 保存时提交给后端的 `steps` SHALL 仍按 `step_order` 正序排列,即步骤一、步骤二、步骤三。
- 保留现有步骤编辑、删除、上移、下移、图标上传、内容图上传和保存校验行为。
## Capabilities
### New Capabilities
- 无。
### Modified Capabilities
- `official-site-methodology-config`: 调整方法论展示配置页步骤卡片的可见顺序,使配置页倒序展示步骤,同时保持后端保存 payload 的正序数据契约。
## Impact
- 影响页面:`/official-site/methodology` 方法论展示配置页。
- 影响代码:`workspace/agent-admin/web/src/routes/official-site/OfficialSiteMethodologyPage.tsx`。
- 影响测试:方法论展示配置页相关交互测试。
- 不修改后端接口、字段契约、上传规则或 H5 展示端渲染逻辑。
## MODIFIED Requirements
### Requirement: 步骤配置
系统 SHALL 支持方法论步骤的添加、删除、排序、倒序配置展示和步骤字段校验。
#### Scenario: 倒序展示步骤
- **WHEN** 后端返回步骤一、步骤二、步骤三的正序步骤数据
- **THEN** 方法论展示配置页 SHALL 按步骤三、步骤二、步骤一的倒序展示步骤卡片
- **AND** 系统 SHALL 保持内部保存数据仍为 `step_order` 正序
#### Scenario: 添加步骤
- **WHEN** 用户在方法论展示配置页点击「添加步骤」
- **THEN** 系统 SHALL 在正序数据末尾新增一个最大 `step_order` 的可编辑步骤
- **AND** 系统 SHALL 因倒序展示将新步骤显示在步骤列表最上方
- **AND** 新步骤 SHALL 可配置步骤图标、步骤名称和内容图
- **AND** 系统 SHALL 保持保存 payload 的 `steps` 仍按 `step_order` 正序排列
#### Scenario: 删除步骤
- **WHEN** 用户删除一个步骤
- **THEN** 系统 SHALL 从步骤列表移除该步骤
- **AND** 系统 SHALL 重新维护剩余步骤的排序序号
#### Scenario: 调整步骤排序
- **WHEN** 用户对步骤执行上移或下移
- **THEN** 系统 SHALL 按当前可见倒序列表的方向调整步骤位置
- **AND** 用户点击可见「上移」时对应步骤 SHALL 向页面上方移动
- **AND** 用户点击可见「下移」时对应步骤 SHALL 向页面下方移动
- **AND** 系统 SHALL 重新维护正序数据中的步骤排序序号
#### Scenario: 步骤名称校验
- **WHEN** 用户保存空步骤名称或超过 20 字的步骤名称
- **THEN** 系统 SHALL 阻止保存
- **AND** 系统 SHALL 在对应步骤名称字段附近展示校验错误
#### Scenario: 开启展示时步骤为空
- **WHEN** 展示状态为 `enable` 且步骤列表为空时用户保存
- **THEN** 系统 SHALL 阻止保存
- **AND** 系统 SHALL 提示至少添加一个方法论步骤
#### Scenario: 关闭展示时步骤为空
- **WHEN** 展示状态为 `disable` 且步骤列表为空时用户保存
- **THEN** 系统 SHALL 允许保存基础配置
- **AND** 系统 SHALL 不要求新增步骤
## 1. 测试先行
- [x] 1.1 为方法论展示配置页新增或调整交互测试:接口返回步骤一、步骤二、步骤三时,页面可见顺序为步骤三、步骤二、步骤一。
- [x] 1.2 覆盖点击「添加步骤」后,新步骤作为最大 `step_order` 展示在第一张步骤卡。
- [x] 1.3 覆盖保存 payload 的 `steps` 仍按 `step_order` 正序提交。
- [x] 1.4 覆盖倒序展示下的上移/下移按钮语义:点击可见「上移」时卡片向页面上方移动,点击可见「下移」时卡片向页面下方移动。
## 2. 页面实现
- [x] 2.1 保持 `form.steps` 为 `step_order` 正序数据源,用倒序派生列表渲染步骤卡片。
- [x] 2.2 保持「添加步骤」追加到正序 `form.steps` 末尾,使新步骤成为最大 `step_order`,并因倒序展示出现在顶部。
- [x] 2.3 调整编辑、删除、上传、上移和下移操作,使其在倒序可见列表中操作正确的原始步骤。
- [x] 2.4 保存 payload 前继续按 `step_order` 正序提交,避免改变后端数据契约。
## 3. 验证
- [x] 3.1 运行 `openspec validate reverse-methodology-step-display --strict`。
- [x] 3.2 运行方法论展示配置页相关测试。
- [x] 3.3 运行类型检查。
- [x] 3.4 按用户确认,本轮不启动浏览器;页面交互由用户自行验证。
## Context
`agent-admin/web` 当前已有多类独立新增、编辑页面,页头通常采用左侧 `返回`、标题和说明,右侧 `保存` 的布局。全局 Web 桌面端规范将调整为所有独立页面按钮集中放在右侧,因此项目需要同步 OpenSpec,并在实现中把返回按钮移入右侧操作区。
本 change 覆盖项目级规范与当前页面实现,保持业务逻辑不变。
## Goals / Non-Goals
**Goals:**
- 同步项目 `admin-shell` 规范,使独立页面页头左侧只展示标题、说明和状态摘要。
- 将当前独立页面页头中的 `返回` 按钮移动到右侧操作区。
- 使右侧操作区同时包含 `返回` 和 `保存` 等主操作按钮。
- 保持 sticky 页头、按钮样式、路由返回、保存校验和 loading 行为不变。
- 用测试覆盖右侧操作区布局约束。
**Non-Goals:**
- 不修改后端 API、mock 数据结构、路由路径或页面业务流程。
- 不新增 `取消` 按钮。
- 不调整表单字段、表单校验规则、列表页工具栏、表格行内操作、弹窗或抽屉操作区。
- 不处理 `single-page`。
## Decisions
### 决策 1:页面局部调整,暂不引入新的通用页头组件
本次优先在现有独立页面页头结构中移动按钮位置,并统一右侧操作区结构。原因是项目中独立页数量有限,且当前页头结构已稳定;引入新通用组件会扩大迁移范围,并可能与后续业务表单页组件化工作重叠。
备选方案是新增 `IndependentPageHeader` 组件并一次性迁移所有页面。该方案长期收益存在,但本次需求重点是规范与布局对齐,组件抽象可在重复度进一步上升时独立处理。
### 决策 2:覆盖明确的独立新增/编辑页面,审查配置页边界
本次明确覆盖 Agent 新增/编辑、Agent 标签新增/编辑、渠道码新增/编辑、官网岗位 Tab 新增/编辑页面。对于配置页或详情页,只有当页面拥有独立路由且页头存在返回或页面级操作区时,才纳入本 change。
备选方案是通过全文搜索把所有 `返回` 按钮都移动到右侧。该方案可能误伤详情内局部导航、空状态或非页头按钮,因此不采用。
### 决策 3:测试以结构约束为主,行为回归为辅
测试需要断言页头右侧操作区同时包含 `返回` 和主操作,且页头左侧不再包含按钮。已有保存、返回和校验行为测试继续保留,不因布局调整削弱。
备选方案是只更新快照或只做人工验收。该方案不能稳定防止后续页面回到旧布局,因此不采用。
## Risks / Trade-offs
- [Risk] 页面标题过长时挤压右侧按钮 → Mitigation:实现时让标题区允许收缩/换行,右侧操作区保持 `shrink-0` 或等效约束。
- [Risk] 测试难以识别“右侧操作区” → Mitigation:为页头左右区域使用稳定的语义结构或测试可识别容器,避免依赖脆弱的文本顺序。
- [Risk] 配置页边界扩大导致不必要改动 → Mitigation:先审查页面结构,只迁移符合独立页页头定义的页面。
## Migration Plan
1. 更新项目 OpenSpec delta,修改 `admin-shell` 的独立页面页头操作区要求。
2. 更新或新增测试,先让旧布局下测试失败。
3. 调整明确覆盖的独立页面页头布局。
4. 审查疑似配置页和详情页,按任务清单确认是否需要迁移。
5. 运行相关测试、类型检查、构建和浏览器布局验证。
回滚方式:若需要恢复旧布局,撤回页面页头结构修改,并通过反向 OpenSpec change 恢复项目规范。
## Open Questions
无。
## Why
全局 Web 桌面端规范将独立页面页头按钮调整为右侧集中放置,`agent-admin/web` 当前新增、编辑等独立页面仍沿用左侧 `返回`、右侧 `保存` 的旧布局。需要同步项目规范和实现,确保当前后台页面与全局规范一致。
## What Changes
- 调整 `agent-admin/web` 独立页面页头布局规则:左侧只展示页面标题、说明和状态摘要等识别信息。
- 将独立页面的 `返回` 按钮移动到页头右侧操作区。
- 右侧操作区同时承载 `返回` 与保存、提交、发布、刷新、更多操作等其他页面级按钮。
- 保持 `保存` 等主操作按钮的业务行为、禁用态、loading 态、校验逻辑和权限规则不变。
- 保持页头操作区 sticky 可见。
- 不新增 `取消` 按钮,不调整表单字段、列表工具栏、弹窗/抽屉操作区或表格行内操作。
## Capabilities
### New Capabilities
无。
### Modified Capabilities
- `admin-shell`: 调整项目独立页面页头操作区规范,从“左侧返回、右侧保存”改为“左侧页面信息、右侧返回和其他页面级操作”。
## Impact
- 影响项目 OpenSpec:`openspec/specs/admin-shell/spec.md`。
- 影响现有独立页面候选:Agent 新增/编辑页、Agent 标签新增/编辑页、渠道码新增/编辑页、官网岗位 Tab 新增/编辑页,以及经审查确认属于独立页面的配置页或详情页。
- 影响相关前端测试:需要覆盖 `返回` 和主操作按钮同属页头右侧操作区。
- 不影响后端 API、路由路径、数据结构和 `single-page`。
## MODIFIED Requirements
### Requirement: 独立页面页头操作区
岗位 Agent 管理后台 SHALL 为新增、编辑、配置等独立页面提供一致且滚动可见的页头操作区。页头左侧只展示页面标题、说明和状态摘要等页面识别信息;页头右侧 MUST 展示 `返回` 和其他页面级操作按钮。
#### Scenario: 独立页面右侧集中展示操作按钮
- **WHEN** 已登录用户打开新增、编辑、配置等独立页面
- **THEN** 独立页面页头左侧展示页面标题和必要说明
- **AND** 独立页面页头左侧不展示 `返回` 入口或其他按钮
- **AND** 独立页面页头右侧展示 `返回` 入口
- **AND** 独立页面页头右侧展示 `保存` 等主操作
- **AND** 独立页面页头右侧不展示 `取消` 按钮
#### Scenario: 右侧操作区按钮排序
- **WHEN** 独立页面页头右侧同时存在 `返回`、主操作和其他页面级操作
- **THEN** `返回` 位于右侧操作区内靠左位置
- **AND** 主操作位于右侧操作区内靠右位置
- **AND** 其他次级页面级操作位于 `返回` 和主操作之间,或收敛到更多操作菜单
#### Scenario: 滚动时保持页头操作区可见
- **WHEN** 已登录用户在新增、编辑、配置等独立页面向下滚动表单内容
- **THEN** 独立页面页头操作区保持在内容滚动容器顶部可见
- **AND** `返回` 和 `保存` 等页面级操作入口保持可点击
- **AND** 滚动内容不得覆盖页头操作区
- **AND** 页头右侧操作区不得被页面标题或说明挤压到不可见
## 1. 规范同步
- [x] 1.1 更新 `openspec/specs/admin-shell/spec.md`,将独立页面页头规则改为左侧页面信息、右侧返回和其他页面级操作。
- [x] 1.2 对照全局 `web-desktop-ui-standard`,确认项目规范没有保留左侧返回、右侧保存的旧口径。
## 2. 测试先行
- [x] 2.1 更新 Agent 新增/编辑页测试,断言页头右侧操作区包含 `返回` 和 `保存`,左侧标题区不包含按钮。
- [x] 2.2 更新 Agent 标签新增/编辑页测试,断言页头右侧操作区包含 `返回` 和 `保存`,左侧标题区不包含按钮。
- [x] 2.3 更新渠道码新增/编辑页测试,断言页头右侧操作区包含 `返回` 和 `保存`,左侧标题区不包含按钮。
- [x] 2.4 更新官网岗位 Tab 新增/编辑页测试,断言页头右侧操作区包含 `返回` 和 `保存`,左侧标题区不包含按钮。
- [x] 2.5 审查配置页和详情页中的页头 `返回` 或页面级操作,确认是否属于本 change 覆盖范围,并为纳入页面补充测试。
## 3. 页面实现
- [x] 3.1 调整 Agent 新增/编辑页页头,将 `返回` 移入右侧操作区并保持 `保存` 主操作行为不变。
- [x] 3.2 调整 Agent 标签新增/编辑页页头,将 `返回` 移入右侧操作区并保持 `保存` 主操作行为不变。
- [x] 3.3 调整渠道码新增/编辑页页头,将 `返回` 移入右侧操作区并保持 `保存` 主操作行为不变。
- [x] 3.4 调整官网岗位 Tab 新增/编辑页页头,将 `返回` 移入右侧操作区并保持 `保存` 主操作行为不变。
- [x] 3.5 对纳入范围的配置页或详情页同步调整页头操作区。
## 4. 验证
- [x] 4.1 运行 `openspec validate standardize-independent-page-right-actions --strict` 验证项目 change。
- [x] 4.2 运行相关页面测试,确认新布局测试通过且原有返回、保存、校验行为未回归。
- [x] 4.3 运行 `npm run typecheck`。
- [x] 4.4 运行 `npm run build`。
- [x] 4.5 启动本地页面并完成浏览器布局验证,确认桌面视口下页头右侧按钮可见、无重叠、sticky 有效。(用户已自行验证)
...@@ -97,17 +97,26 @@ TBD - created by archiving change add-admin-login-agent-list-mock. Update Purpos ...@@ -97,17 +97,26 @@ TBD - created by archiving change add-admin-login-agent-list-mock. Update Purpos
- **AND** 点击二级菜单面包屑项返回该二级菜单页面 - **AND** 点击二级菜单面包屑项返回该二级菜单页面
### Requirement: 独立页面页头操作区 ### Requirement: 独立页面页头操作区
岗位 Agent 管理后台 SHALL 为新增、编辑等独立页面提供一致且滚动可见的页头操作区。 岗位 Agent 管理后台 SHALL 为新增、编辑、配置等独立页面提供一致且滚动可见的页头操作区。页头左侧只展示页面标题、说明和状态摘要等页面识别信息;页头右侧 MUST 展示 `返回` 和其他页面级操作按钮。
#### Scenario: 独立页面不展示右侧取消按钮 #### Scenario: 独立页面右侧集中展示操作按钮
- **WHEN** 已登录用户打开新增或编辑等独立页面 - **WHEN** 已登录用户打开新增、编辑、配置等独立页面
- **THEN** 独立页面页头左侧展示 `返回` 入口 - **THEN** 独立页面页头左侧展示页面标题和必要说明
- **AND** 独立页面页头右侧展示 `保存` 主操作 - **AND** 独立页面页头左侧不展示 `返回` 入口或其他按钮
- **AND** 独立页面页头右侧展示 `返回` 入口
- **AND** 独立页面页头右侧展示 `保存` 等主操作
- **AND** 独立页面页头右侧不展示 `取消` 按钮 - **AND** 独立页面页头右侧不展示 `取消` 按钮
#### Scenario: 右侧操作区按钮排序
- **WHEN** 独立页面页头右侧同时存在 `返回`、主操作和其他页面级操作
- **THEN** `返回` 位于右侧操作区内靠左位置
- **AND** 主操作位于右侧操作区内靠右位置
- **AND** 其他次级页面级操作位于 `返回` 和主操作之间,或收敛到更多操作菜单
#### Scenario: 滚动时保持页头操作区可见 #### Scenario: 滚动时保持页头操作区可见
- **WHEN** 已登录用户在新增或编辑等独立页面向下滚动表单内容 - **WHEN** 已登录用户在新增、编辑、配置等独立页面向下滚动表单内容
- **THEN** 独立页面页头操作区保持在内容滚动容器顶部可见 - **THEN** 独立页面页头操作区保持在内容滚动容器顶部可见
- **AND** `返回` 和 `保存` 入口保持可点击 - **AND** `返回` 和 `保存` 等页面级操作入口保持可点击
- **AND** 滚动内容不得覆盖页头操作区 - **AND** 滚动内容不得覆盖页头操作区
- **AND** 页头右侧操作区不得被页面标题或说明挤压到不可见
...@@ -78,42 +78,35 @@ TBD - created by archiving change global-search-filter-component. Update Purpose ...@@ -78,42 +78,35 @@ TBD - created by archiving change global-search-filter-component. Update Purpose
- **WHEN** 组件渲染 `range: true` 的日期字段 - **WHEN** 组件渲染 `range: true` 的日期字段
- **THEN** 范围日期字段占据两个普通搜索项的横向空间 - **THEN** 范围日期字段占据两个普通搜索项的横向空间
### Requirement: 操作按钮固定在右下角
系统 SHALL 在搜索区域右下角固定展示搜索与重置按钮,并 SHALL 保证搜索与重置按钮不被折叠隐藏。
#### Scenario: 折叠状态展示操作按钮
- **WHEN** 搜索字段数量超过默认展示区域且组件处于折叠状态
- **THEN** 搜索与重置按钮仍展示在搜索区域右下角
#### Scenario: 展开状态展示操作按钮
- **WHEN** 用户展开搜索区域
- **THEN** 搜索与重置按钮仍展示在搜索区域右下角
#### Scenario: 触发搜索和重置回调
- **WHEN** 用户点击搜索或重置按钮
- **THEN** 组件分别调用传入的搜索或重置回调
### Requirement: 最多两行默认展示 ### Requirement: 最多两行默认展示
系统 SHALL 默认最多展示两行搜索区域内容,且 SHALL 将操作按钮所在区域计入两行展示高度。 系统 SHALL 默认最多展示两行搜索区域内容,且 SHALL 将操作按钮所在区域计入两行展示高度。
#### Scenario: 字段未超过两行 #### Scenario: 字段在一行内完整展示
- **WHEN** 字段数量在默认两行内可完整展示 - **WHEN** 搜索字段与操作按钮在一行内可完整展示
- **THEN** 组件不展示展开/收起按钮 - **THEN** 组件展示一行内容
- **AND** 组件不展示展开/收起按钮
#### Scenario: 字段在两行内完整展示
- **WHEN** 搜索字段与操作按钮在两行内可完整展示
- **THEN** 组件展示两行内容
- **AND** 组件不展示展开/收起按钮
#### Scenario: 字段超过两行 #### Scenario: 字段超过两行
- **WHEN** 字段数量超过默认两行可展示范围 - **WHEN** 搜索字段与操作按钮超过默认两行可展示范围
- **THEN** 组件折叠状态仅展示前两行范围内内容,并展示展开按钮 - **THEN** 组件折叠状态仅展示前两行范围内内容
- **AND** 组件展示展开按钮
### Requirement: 展开收起交互 ### Requirement: 展开收起交互
系统 SHALL 在字段超过默认展示区域时提供展开/收起文字按钮,按钮 SHALL 位于搜索与重置按钮左侧,并 SHALL 使用文字与箭头表达当前操作。 系统 SHALL 在搜索字段与操作按钮超过默认两行展示区域时提供展开/收起文字按钮,按钮 SHALL 位于查询与重置按钮之后,并 SHALL 使用文字与箭头表达当前操作。
#### Scenario: 折叠状态展示展开按钮 #### Scenario: 折叠状态展示展开按钮
- **WHEN** 组件处于折叠状态且存在溢出字段 - **WHEN** 组件处于折叠状态且存在第三行及后续被隐藏内容
- **THEN** 操作区在搜索与重置按钮左侧展示“展开”文字按钮和向下箭头 - **THEN** 操作按钮组在查询与重置按钮之后展示“展开”文字按钮和向下箭头
#### Scenario: 展开状态展示收起按钮 #### Scenario: 展开状态展示收起按钮
- **WHEN** 用户点击展开按钮后 - **WHEN** 用户点击展开按钮后
- **THEN** 组件展示全部搜索字段,并在搜索与重置按钮左侧展示“收起”文字按钮和向上箭头 - **THEN** 组件展示全部搜索字段
- **AND** 操作按钮组在查询与重置按钮之后展示“收起”文字按钮和向上箭头
#### Scenario: 展开收起具有动画 #### Scenario: 展开收起具有动画
- **WHEN** 用户切换展开或收起状态 - **WHEN** 用户切换展开或收起状态
...@@ -170,3 +163,49 @@ TBD - created by archiving change global-search-filter-component. Update Purpose ...@@ -170,3 +163,49 @@ TBD - created by archiving change global-search-filter-component. Update Purpose
- **WHEN** 用户在迁移后的任一列表页点击重置 - **WHEN** 用户在迁移后的任一列表页点击重置
- **THEN** 页面清空对应筛选条件并按原查询参数语义刷新列表 - **THEN** 页面清空对应筛选条件并按原查询参数语义刷新列表
### Requirement: 操作按钮跟随搜索条件
系统 SHALL 将 `SearchFilter` 的查询、重置和展开/收起按钮作为搜索条件布局的一部分展示,并 SHALL 让操作按钮跟随在当前可见查询条件之后。
#### Scenario: 默认态展示操作按钮
- **WHEN** 搜索字段内容超过默认两行展示区域且组件处于默认折叠状态
- **THEN** 组件在默认可见区域内展示查询、重置和展开按钮
- **AND** 查询按钮位于最后一个可见查询条件之后
#### Scenario: 展开态展示操作按钮
- **WHEN** 用户展开搜索区域
- **THEN** 组件展示全部搜索字段
- **AND** 查询、重置和收起按钮跟随在最后一个搜索条件之后
#### Scenario: 触发查询和重置回调
- **WHEN** 用户点击查询或重置按钮
- **THEN** 组件分别调用传入的搜索或重置回调
### Requirement: 操作按钮顺序
系统 SHALL 按“查询、重置、展开/收起”的顺序展示 `SearchFilter` 操作按钮。
#### Scenario: 展示查询和重置按钮
- **WHEN** 组件渲染搜索区域
- **THEN** 操作按钮组先展示“查询”按钮
- **AND** 随后展示“重置”按钮
#### Scenario: 展示展开按钮
- **WHEN** 组件处于默认折叠状态且存在第三行及后续被隐藏内容
- **THEN** “展开”按钮展示在“查询”和“重置”按钮之后
#### Scenario: 展示收起按钮
- **WHEN** 用户展开搜索区域
- **THEN** “收起”按钮展示在“查询”和“重置”按钮之后
### Requirement: 响应式自然换行
系统 SHALL 在 `SearchFilter` 容器宽度变化时重新布局搜索条件与操作按钮,并 MUST 通过自然换行适配窄容器,且 MUST NOT 出现横向滚动条。
#### Scenario: 容器变窄
- **WHEN** `SearchFilter` 容器宽度不足以在一行展示原有数量的搜索条件
- **THEN** 搜索条件和操作按钮按容器宽度自然换行
- **AND** 搜索区不出现横向滚动条
#### Scenario: 容器宽度变化后重新判断折叠
- **WHEN** `SearchFilter` 容器宽度变化导致内容行数变化
- **THEN** 组件重新判断是否存在第三行及后续内容
- **AND** 组件按新的布局结果展示或隐藏展开/收起按钮
## ADDED Requirements ## Purpose
定义官网方法论展示配置页的入口、表单字段、步骤配置、图片配置、页面状态、保存行为和最小前端 mock 契约。
## Requirements
### Requirement: 方法论展示配置页入口 ### Requirement: 方法论展示配置页入口
系统 SHALL 在管理后台提供官网配置下的方法论展示配置页入口。 系统 SHALL 在管理后台提供官网配置下的方法论展示配置页入口。
...@@ -36,12 +37,19 @@ ...@@ -36,12 +37,19 @@
- **AND** 系统 SHALL 在副标题字段附近展示校验错误 - **AND** 系统 SHALL 在副标题字段附近展示校验错误
### Requirement: 步骤配置 ### Requirement: 步骤配置
系统 SHALL 支持方法论步骤的添加、删除、排序和步骤字段校验。 系统 SHALL 支持方法论步骤的添加、删除、排序、倒序配置展示和步骤字段校验。
#### Scenario: 倒序展示步骤
- **WHEN** 后端返回步骤一、步骤二、步骤三的正序步骤数据
- **THEN** 方法论展示配置页 SHALL 按步骤三、步骤二、步骤一的倒序展示步骤卡片
- **AND** 系统 SHALL 保持内部保存数据仍为 `step_order` 正序
#### Scenario: 添加步骤 #### Scenario: 添加步骤
- **WHEN** 用户点击「添加步骤」 - **WHEN** 用户在方法论展示配置页点击「添加步骤」
- **THEN** 系统 SHALL 在步骤列表中新增一个可编辑步骤 - **THEN** 系统 SHALL 在正序数据末尾新增一个最大 `step_order` 的可编辑步骤
- **AND** 系统 SHALL 因倒序展示将新步骤显示在步骤列表最上方
- **AND** 新步骤 SHALL 可配置步骤图标、步骤名称和内容图 - **AND** 新步骤 SHALL 可配置步骤图标、步骤名称和内容图
- **AND** 系统 SHALL 保持保存 payload 的 `steps` 仍按 `step_order` 正序排列
#### Scenario: 删除步骤 #### Scenario: 删除步骤
- **WHEN** 用户删除一个步骤 - **WHEN** 用户删除一个步骤
...@@ -50,8 +58,10 @@ ...@@ -50,8 +58,10 @@
#### Scenario: 调整步骤排序 #### Scenario: 调整步骤排序
- **WHEN** 用户对步骤执行上移或下移 - **WHEN** 用户对步骤执行上移或下移
- **THEN** 系统 SHALL 调整步骤顺序 - **THEN** 系统 SHALL 按当前可见倒序列表的方向调整步骤位置
- **AND** 系统 SHALL 重新维护步骤排序序号 - **AND** 用户点击可见「上移」时对应步骤 SHALL 向页面上方移动
- **AND** 用户点击可见「下移」时对应步骤 SHALL 向页面下方移动
- **AND** 系统 SHALL 重新维护正序数据中的步骤排序序号
#### Scenario: 步骤名称校验 #### Scenario: 步骤名称校验
- **WHEN** 用户保存空步骤名称或超过 20 字的步骤名称 - **WHEN** 用户保存空步骤名称或超过 20 字的步骤名称
...@@ -152,3 +162,4 @@ ...@@ -152,3 +162,4 @@
#### Scenario: fixture 覆盖 #### Scenario: fixture 覆盖
- **WHEN** 测试读取方法论配置 mock fixture - **WHEN** 测试读取方法论配置 mock fixture
- **THEN** fixture SHALL 覆盖正常配置、关闭展示、步骤为空、图片上传失败、图片格式错误、图片过大、保存失败和加载失败 - **THEN** fixture SHALL 覆盖正常配置、关闭展示、步骤为空、图片上传失败、图片格式错误、图片过大、保存失败和加载失败
import { fireEvent, render, screen, waitFor } from '@testing-library/react'; import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
import { describe, expect, it, vi } from 'vitest'; import { afterEach, describe, expect, it, vi } from 'vitest';
import { MediaWall, SearchFilter, StatePlaceholder } from '@gl/business-components'; import { MediaWall, SearchFilter, StatePlaceholder } from '@gl/business-components';
const searchFields = [
{ key: 'keyword', label: '关键词', type: 'input' as const, defaultValue: '项目' },
{ key: 'count', label: '数量', type: 'numberInput' as const },
{ key: 'status', label: '状态', type: 'select' as const, options: [{ label: '启用', value: 'enabled' }] },
];
function mockSearchFilterLayout({ containerWidth, fieldWidth = 284, actionsWidth = 220 }: {
containerWidth: number;
fieldWidth?: number;
actionsWidth?: number;
}) {
const originalClientWidth = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'clientWidth');
const originalOffsetWidth = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'offsetWidth');
const originalScrollHeight = Object.getOwnPropertyDescriptor(HTMLElement.prototype, 'scrollHeight');
const originalGetComputedStyle = window.getComputedStyle;
Object.defineProperty(HTMLElement.prototype, 'clientWidth', {
configurable: true,
get() {
if ((this as HTMLElement).dataset.searchFilterFlow === 'true') return containerWidth;
return originalClientWidth?.get?.call(this) ?? 0;
},
});
Object.defineProperty(HTMLElement.prototype, 'offsetWidth', {
configurable: true,
get() {
const element = this as HTMLElement;
if (element.dataset.searchFilterActions === 'true') return actionsWidth;
if (element.dataset.fieldKey) return fieldWidth;
return originalOffsetWidth?.get?.call(this) ?? 0;
},
});
Object.defineProperty(HTMLElement.prototype, 'scrollHeight', {
configurable: true,
get() {
return 96;
},
});
window.getComputedStyle = ((element: Element) => {
const style = originalGetComputedStyle(element);
if ((element as HTMLElement).dataset.searchFilterFlow === 'true') {
return new Proxy(style, {
get(target, property, receiver) {
if (property === 'columnGap') return '16px';
if (property === 'rowGap') return '12px';
return Reflect.get(target, property, receiver);
},
});
}
return style;
}) as typeof window.getComputedStyle;
return () => {
if (originalClientWidth) Object.defineProperty(HTMLElement.prototype, 'clientWidth', originalClientWidth);
if (originalOffsetWidth) Object.defineProperty(HTMLElement.prototype, 'offsetWidth', originalOffsetWidth);
if (originalScrollHeight) Object.defineProperty(HTMLElement.prototype, 'scrollHeight', originalScrollHeight);
window.getComputedStyle = originalGetComputedStyle;
};
}
describe('global business components', () => { describe('global business components', () => {
afterEach(() => {
vi.restoreAllMocks();
});
it('keeps SearchFilter draft values until search and restores defaults on reset', () => { it('keeps SearchFilter draft values until search and restores defaults on reset', () => {
const onReset = vi.fn(); const onReset = vi.fn();
const onSearch = vi.fn(); const onSearch = vi.fn();
render( render(
<SearchFilter <SearchFilter
fields={[ fields={searchFields}
{ key: 'keyword', label: '关键词', type: 'input', defaultValue: '项目' },
{ key: 'count', label: '数量', type: 'numberInput' },
{ key: 'status', label: '状态', type: 'select', options: [{ label: '启用', value: 'enabled' }] },
]}
onReset={onReset} onReset={onReset}
onSearch={onSearch} onSearch={onSearch}
/>, />,
); );
fireEvent.change(screen.getByLabelText('数量'), { target: { value: '12a3' } }); fireEvent.change(screen.getByLabelText('数量'), { target: { value: '12a3' } });
fireEvent.click(screen.getByRole('button', { name: '搜索' })); fireEvent.click(screen.getByRole('button', { name: '查询' }));
expect(screen.getByLabelText('数量')).toHaveValue('123'); expect(screen.getByLabelText('数量')).toHaveValue('123');
expect(onSearch).toHaveBeenCalledWith({ keyword: '项目', count: '123', status: '' }); expect(onSearch).toHaveBeenCalledWith({ keyword: '项目', count: '123', status: '' });
...@@ -33,6 +96,67 @@ describe('global business components', () => { ...@@ -33,6 +96,67 @@ describe('global business components', () => {
expect(onReset).toHaveBeenCalledTimes(1); expect(onReset).toHaveBeenCalledTimes(1);
}); });
it('renders SearchFilter actions after fields in query, reset, expand order', async () => {
const restoreLayout = mockSearchFilterLayout({ containerWidth: 640, fieldWidth: 200, actionsWidth: 260 });
render(
<SearchFilter
fields={[
...searchFields,
{ key: 'owner', label: '负责人', type: 'input' },
{ key: 'department', label: '部门', type: 'input' },
]}
/>,
);
await waitFor(() => expect(screen.getByRole('button', { name: '展开' })).toBeInTheDocument());
const root = screen.getByLabelText('搜索过滤条件');
const controls = within(root).getAllByRole('button').map((button) => button.textContent?.trim());
expect(controls).toEqual(['查询', '重置', '展开']);
restoreLayout();
});
it('does not show expand or collapse when fields and actions fit in two rows', async () => {
const restoreLayout = mockSearchFilterLayout({ containerWidth: 920, fieldWidth: 200, actionsWidth: 220 });
render(
<SearchFilter
fields={[
...searchFields,
{ key: 'owner', label: '负责人', type: 'input' },
{ key: 'department', label: '部门', type: 'input' },
]}
/>,
);
await waitFor(() => expect(screen.queryByRole('button', { name: '展开' })).not.toBeInTheDocument());
expect(screen.queryByRole('button', { name: '收起' })).not.toBeInTheDocument();
restoreLayout();
});
it('only folds when the responsive layout needs more than two rows', async () => {
const restoreLayout = mockSearchFilterLayout({ containerWidth: 640, fieldWidth: 200, actionsWidth: 260 });
render(
<SearchFilter
fields={[
...searchFields,
{ key: 'owner', label: '负责人', type: 'input' },
{ key: 'department', label: '部门', type: 'input' },
]}
/>,
);
await waitFor(() => expect(screen.getByRole('button', { name: '展开' })).toBeInTheDocument());
fireEvent.click(screen.getByRole('button', { name: '展开' }));
expect(screen.getByRole('button', { name: '收起' })).toBeInTheDocument();
restoreLayout();
});
it('renders an empty range date field without TDesign value warnings', () => { it('renders an empty range date field without TDesign value warnings', () => {
const consoleError = vi.spyOn(console, 'error').mockImplementation(() => undefined); const consoleError = vi.spyOn(console, 'error').mockImplementation(() => undefined);
......
...@@ -163,17 +163,17 @@ export function AgentTagEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -163,17 +163,17 @@ export function AgentTagEditorPage({ mode }: { mode: 'create' | 'edit' }) {
return ( return (
<section className="grid gap-6"> <section className="grid gap-6">
<header className="sticky top-0 z-10 flex items-center justify-between gap-6 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-6"> <header className="sticky top-0 z-10 flex items-start justify-between gap-6 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-6">
<div className="flex items-center gap-4"> <div aria-label="页面标题" className="min-w-0 flex-1">
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">{mode === 'create' ? '新建岗位标签' : '编辑岗位标签'}</h2>
<p className="m-0 mt-1 text-sm text-[var(--gl-color-text-secondary)]">
{mode === 'create' ? '创建新的岗位标签' : '编辑已有岗位标签信息'}
</p>
</div>
<div aria-label="页面操作" className="flex shrink-0 items-center gap-2">
<Button variant="outline" onClick={goBackToList}>返回</Button> <Button variant="outline" onClick={goBackToList}>返回</Button>
<div> <Button theme="primary" loading={saving} onClick={handleSave}>保存</Button>
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">{mode === 'create' ? '新建岗位标签' : '编辑岗位标签'}</h2>
<p className="m-0 mt-1 text-sm text-[var(--gl-color-text-secondary)]">
{mode === 'create' ? '创建新的岗位标签' : '编辑已有岗位标签信息'}
</p>
</div>
</div> </div>
<Button theme="primary" loading={saving} onClick={handleSave}>保存</Button>
</header> </header>
{notice ? ( {notice ? (
......
...@@ -166,7 +166,7 @@ describe('Agent tag routes and list page', () => { ...@@ -166,7 +166,7 @@ describe('Agent tag routes and list page', () => {
expect(screen.getAllByText('标签名称').length).toBeGreaterThan(0); expect(screen.getAllByText('标签名称').length).toBeGreaterThan(0);
expect(screen.getByLabelText('标签名称')).toBeInTheDocument(); expect(screen.getByLabelText('标签名称')).toBeInTheDocument();
expect(screen.getByPlaceholderText('搜索标签名称')).toBeInTheDocument(); expect(screen.getByPlaceholderText('搜索标签名称')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '搜索' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '查询' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '重置' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '重置' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '新建岗位标签' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '新建岗位标签' })).toBeInTheDocument();
expect(screen.getAllByText('标签名称').length).toBeGreaterThan(0); expect(screen.getAllByText('标签名称').length).toBeGreaterThan(0);
...@@ -184,7 +184,7 @@ describe('Agent tag routes and list page', () => { ...@@ -184,7 +184,7 @@ describe('Agent tag routes and list page', () => {
await screen.findByText('店销顾问'); await screen.findByText('店销顾问');
fireEvent.change(screen.getByLabelText('标签名称'), { target: { value: '售后' } }); fireEvent.change(screen.getByLabelText('标签名称'), { target: { value: '售后' } });
fireEvent.click(screen.getByRole('button', { name: '搜索' })); fireEvent.click(screen.getByRole('button', { name: '查询' }));
await waitFor(() => { await waitFor(() => {
expect(getPositionTagList).toHaveBeenLastCalledWith(expect.objectContaining({ keyword: '售后' })); expect(getPositionTagList).toHaveBeenLastCalledWith(expect.objectContaining({ keyword: '售后' }));
...@@ -280,9 +280,11 @@ describe('Agent tag create and edit pages', () => { ...@@ -280,9 +280,11 @@ describe('Agent tag create and edit pages', () => {
await screen.findByRole('heading', { name: '新建岗位标签' }); await screen.findByRole('heading', { name: '新建岗位标签' });
const pageHeader = screen.getByRole('heading', { name: '新建岗位标签' }).closest('header') as HTMLElement; const pageHeader = screen.getByRole('heading', { name: '新建岗位标签' }).closest('header') as HTMLElement;
expect(pageHeader).toHaveClass('sticky', 'top-0', 'z-10'); expect(pageHeader).toHaveClass('sticky', 'top-0', 'z-10');
expect(within(pageHeader).getByRole('button', { name: '返回' })).toBeInTheDocument(); expect(within(screen.getByLabelText('页面标题')).queryByRole('button')).not.toBeInTheDocument();
const pageActions = screen.getByLabelText('页面操作');
expect(within(pageActions).getByRole('button', { name: '返回' })).toBeInTheDocument();
expect(within(pageActions).getByRole('button', { name: '保存' })).toBeInTheDocument();
expect(within(pageHeader).queryByRole('button', { name: '取消' })).not.toBeInTheDocument(); expect(within(pageHeader).queryByRole('button', { name: '取消' })).not.toBeInTheDocument();
expect(within(pageHeader).getByRole('button', { name: '保存' })).toBeInTheDocument();
// 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: '保存' }));
......
...@@ -178,11 +178,13 @@ describe('Agent editor routes and detail drawer', () => { ...@@ -178,11 +178,13 @@ describe('Agent editor routes and detail drawer', () => {
const pageHeader = screen.getByRole('heading', { name: '新建Agent' }).closest('header') as HTMLElement; const pageHeader = screen.getByRole('heading', { name: '新建Agent' }).closest('header') as HTMLElement;
expect(within(screen.getByLabelText('左侧导航')).getByText('Agent列表').closest('li')).toHaveClass('t-is-active'); expect(within(screen.getByLabelText('左侧导航')).getByText('Agent列表').closest('li')).toHaveClass('t-is-active');
expect(pageHeader).toHaveClass('sticky', 'top-0', 'z-10'); expect(pageHeader).toHaveClass('sticky', 'top-0', 'z-10');
expect(within(pageHeader).getByRole('button', { name: '返回' })).toBeInTheDocument(); expect(within(screen.getByLabelText('页面标题')).queryByRole('button')).not.toBeInTheDocument();
const pageActions = screen.getByLabelText('页面操作');
expect(within(pageActions).getByRole('button', { name: '返回' })).toBeInTheDocument();
expect(within(pageActions).getByRole('button', { name: '保存' })).toBeInTheDocument();
expect(within(pageHeader).queryByRole('button', { name: '取消' })).not.toBeInTheDocument(); expect(within(pageHeader).queryByRole('button', { name: '取消' })).not.toBeInTheDocument();
expect(within(pageHeader).getByRole('button', { name: '保存' })).toBeInTheDocument();
fireEvent.click(within(pageHeader).getByRole('button', { name: '返回' })); fireEvent.click(within(pageActions).getByRole('button', { name: '返回' }));
await waitFor(() => { await waitFor(() => {
expect(screen.getByRole('heading', { name: 'Agent管理' })).toBeInTheDocument(); expect(screen.getByRole('heading', { name: 'Agent管理' })).toBeInTheDocument();
......
...@@ -577,17 +577,17 @@ export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -577,17 +577,17 @@ export function AgentEditorPage({ mode }: { mode: 'create' | 'edit' }) {
return ( return (
<section className="grid gap-6"> <section className="grid gap-6">
<header className="sticky top-0 z-10 flex items-center justify-between gap-6 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-6"> <header className="sticky top-0 z-10 flex items-start justify-between gap-6 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-6">
<div className="flex items-center gap-4"> <div aria-label="页面标题" className="min-w-0 flex-1">
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">{title}</h2>
<p className="m-0 mt-1 text-sm text-[var(--gl-color-text-secondary)]">
{mode === 'create' ? '创建新的岗位 Agent 配置' : '编辑已存在的 Agent 配置'}
</p>
</div>
<div aria-label="页面操作" className="flex shrink-0 items-center gap-2">
<Button variant="outline" onClick={() => goBackToList(Boolean(routeState.detail && mode === 'edit'))}>返回</Button> <Button variant="outline" onClick={() => goBackToList(Boolean(routeState.detail && mode === 'edit'))}>返回</Button>
<div> <Button theme="primary" loading={saveLoading} onClick={handleSave}>保存</Button>
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">{title}</h2>
<p className="m-0 mt-1 text-sm text-[var(--gl-color-text-secondary)]">
{mode === 'create' ? '创建新的岗位 Agent 配置' : '编辑已存在的 Agent 配置'}
</p>
</div>
</div> </div>
<Button theme="primary" loading={saveLoading} onClick={handleSave}>保存</Button>
</header> </header>
{saveError ? ( {saveError ? (
......
...@@ -120,7 +120,7 @@ describe('AgentListPage', () => { ...@@ -120,7 +120,7 @@ describe('AgentListPage', () => {
expect(screen.getByPlaceholderText('搜索Agent名称')).toBeInTheDocument(); expect(screen.getByPlaceholderText('搜索Agent名称')).toBeInTheDocument();
expect(screen.getByLabelText('所属岗位')).toBeInTheDocument(); expect(screen.getByLabelText('所属岗位')).toBeInTheDocument();
expect(screen.getByLabelText('状态')).toBeInTheDocument(); expect(screen.getByLabelText('状态')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '搜索' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '查询' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '重置' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '重置' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '新建Agent' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '新建Agent' })).toBeInTheDocument();
...@@ -164,7 +164,7 @@ describe('AgentListPage', () => { ...@@ -164,7 +164,7 @@ describe('AgentListPage', () => {
expect(within(toolbar).getAllByText('Agent名称').length).toBeGreaterThan(0); expect(within(toolbar).getAllByText('Agent名称').length).toBeGreaterThan(0);
expect(within(toolbar).getAllByText('所属岗位').length).toBeGreaterThan(0); expect(within(toolbar).getAllByText('所属岗位').length).toBeGreaterThan(0);
expect(within(toolbar).getAllByText('状态').length).toBeGreaterThan(0); expect(within(toolbar).getAllByText('状态').length).toBeGreaterThan(0);
expect(within(toolbar).getByRole('button', { name: '搜索' })).toBeInTheDocument(); expect(within(toolbar).getByRole('button', { name: '查询' })).toBeInTheDocument();
expect(within(toolbar).getByRole('button', { name: '重置' })).toBeInTheDocument(); expect(within(toolbar).getByRole('button', { name: '重置' })).toBeInTheDocument();
}); });
...@@ -188,7 +188,7 @@ describe('AgentListPage', () => { ...@@ -188,7 +188,7 @@ describe('AgentListPage', () => {
expect(screen.getByText('复盘Agent')).toBeInTheDocument(); expect(screen.getByText('复盘Agent')).toBeInTheDocument();
}); });
fireEvent.click(screen.getByRole('button', { name: '搜索' })); fireEvent.click(screen.getByRole('button', { name: '查询' }));
// 搜索提交后,URL 参数更新,需要等待 API 返回新数据 // 搜索提交后,URL 参数更新,需要等待 API 返回新数据
await waitFor(() => { await waitFor(() => {
...@@ -225,7 +225,7 @@ describe('AgentListPage', () => { ...@@ -225,7 +225,7 @@ describe('AgentListPage', () => {
fireEvent.click(screen.getByLabelText('所属岗位')); fireEvent.click(screen.getByLabelText('所属岗位'));
expect(getSelectOption('全部')).toBeInTheDocument(); expect(getSelectOption('全部')).toBeInTheDocument();
fireEvent.click(getSelectOption('客服岗')); fireEvent.click(getSelectOption('客服岗'));
fireEvent.click(screen.getByRole('button', { name: '搜索' })); fireEvent.click(screen.getByRole('button', { name: '查询' }));
await waitFor(() => { await waitFor(() => {
expect(screen.queryByRole('button', { name: '清空所属岗位' })).not.toBeInTheDocument(); expect(screen.queryByRole('button', { name: '清空所属岗位' })).not.toBeInTheDocument();
...@@ -648,7 +648,7 @@ describe('AgentListPage', () => { ...@@ -648,7 +648,7 @@ describe('AgentListPage', () => {
fireEvent.change(screen.getByLabelText('Agent名称'), { target: { value: '复盘' } }); fireEvent.change(screen.getByLabelText('Agent名称'), { target: { value: '复盘' } });
vi.clearAllMocks(); vi.clearAllMocks();
fireEvent.click(screen.getByRole('button', { name: '搜索' })); fireEvent.click(screen.getByRole('button', { name: '查询' }));
await waitFor(() => { await waitFor(() => {
expect(reportAnalyticsEvents).toHaveBeenCalledWith([ expect(reportAnalyticsEvents).toHaveBeenCalledWith([
...@@ -668,7 +668,7 @@ describe('AgentListPage', () => { ...@@ -668,7 +668,7 @@ describe('AgentListPage', () => {
fireEvent.click(getSelectOption('客服岗')); fireEvent.click(getSelectOption('客服岗'));
vi.clearAllMocks(); vi.clearAllMocks();
fireEvent.click(screen.getByRole('button', { name: '搜索' })); fireEvent.click(screen.getByRole('button', { name: '查询' }));
await waitFor(() => { await waitFor(() => {
expect(reportAnalyticsEvents).toHaveBeenCalledWith([ expect(reportAnalyticsEvents).toHaveBeenCalledWith([
......
...@@ -225,9 +225,11 @@ describe('Channel code create page', () => { ...@@ -225,9 +225,11 @@ describe('Channel code create page', () => {
}); });
const pageHeader = screen.getByRole('heading', { name: '新增员工渠道活码' }).closest('header') as HTMLElement; const pageHeader = screen.getByRole('heading', { name: '新增员工渠道活码' }).closest('header') as HTMLElement;
expect(pageHeader).toHaveClass('sticky', 'top-0', 'z-10'); expect(pageHeader).toHaveClass('sticky', 'top-0', 'z-10');
expect(within(pageHeader).getByRole('button', { name: '返回' })).toBeInTheDocument(); expect(within(screen.getByLabelText('页面标题')).queryByRole('button')).not.toBeInTheDocument();
const pageActions = screen.getByLabelText('页面操作');
expect(within(pageActions).getByRole('button', { name: '返回' })).toBeInTheDocument();
expect(within(pageActions).getByRole('button', { name: '保存' })).toBeInTheDocument();
expect(within(pageHeader).queryByRole('button', { name: '取消' })).not.toBeInTheDocument(); expect(within(pageHeader).queryByRole('button', { name: '取消' })).not.toBeInTheDocument();
expect(within(pageHeader).getByRole('button', { name: '保存' })).toBeInTheDocument();
}); });
// Legacy test: status switch no longer rendered (updated to not check status) // Legacy test: status switch no longer rendered (updated to not check status)
......
...@@ -414,19 +414,19 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) { ...@@ -414,19 +414,19 @@ export function ChannelCodeEditorPage({ mode }: { mode: 'create' | 'edit' }) {
return ( return (
<section className="grid gap-6"> <section className="grid gap-6">
<header className="sticky top-0 z-10 flex items-center justify-between gap-6 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-6"> <header className="sticky top-0 z-10 flex items-start justify-between gap-6 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-6">
<div className="flex items-center gap-4"> <div aria-label="页面标题" className="min-w-0 flex-1">
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">
{mode === 'create' ? '新增员工渠道活码' : '编辑员工渠道活码'}
</h2>
<p className="m-0 mt-1 text-sm text-[var(--gl-color-text-secondary)]">
{mode === 'create' ? '创建新的员工渠道活码' : '编辑已有员工渠道活码信息'}
</p>
</div>
<div aria-label="页面操作" className="flex shrink-0 items-center gap-2">
<Button variant="outline" onClick={goBackToList}>返回</Button> <Button variant="outline" onClick={goBackToList}>返回</Button>
<div> <Button theme="primary" loading={saving} onClick={handleSave}>保存</Button>
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">
{mode === 'create' ? '新增员工渠道活码' : '编辑员工渠道活码'}
</h2>
<p className="m-0 mt-1 text-sm text-[var(--gl-color-text-secondary)]">
{mode === 'create' ? '创建新的员工渠道活码' : '编辑已有员工渠道活码信息'}
</p>
</div>
</div> </div>
<Button theme="primary" loading={saving} onClick={handleSave}>保存</Button>
</header> </header>
{notice ? ( {notice ? (
......
...@@ -132,7 +132,7 @@ describe('Channel code list page', () => { ...@@ -132,7 +132,7 @@ describe('Channel code list page', () => {
expect(screen.getByLabelText('活码名称')).toBeInTheDocument(); expect(screen.getByLabelText('活码名称')).toBeInTheDocument();
expect(screen.getAllByText('状态').length).toBeGreaterThan(0); expect(screen.getAllByText('状态').length).toBeGreaterThan(0);
expect(screen.getByLabelText('状态')).toBeInTheDocument(); expect(screen.getByLabelText('状态')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '搜索' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '查询' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '重置' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '重置' })).toBeInTheDocument();
expect(screen.getByPlaceholderText('搜索活码名称')).toBeInTheDocument(); expect(screen.getByPlaceholderText('搜索活码名称')).toBeInTheDocument();
}); });
...@@ -185,7 +185,7 @@ describe('Channel code list page', () => { ...@@ -185,7 +185,7 @@ describe('Channel code list page', () => {
page: 1, page: 1,
page_size: 10, page_size: 10,
}); });
fireEvent.click(screen.getByRole('button', { name: '搜索' })); fireEvent.click(screen.getByRole('button', { name: '查询' }));
await waitFor(() => { await waitFor(() => {
expect(screen.getByText('售后客服渠道活码')).toBeInTheDocument(); expect(screen.getByText('售后客服渠道活码')).toBeInTheDocument();
...@@ -227,7 +227,7 @@ describe('Channel code list page', () => { ...@@ -227,7 +227,7 @@ describe('Channel code list page', () => {
page: 1, page: 1,
page_size: 10, page_size: 10,
}); });
fireEvent.click(screen.getByRole('button', { name: '搜索' })); fireEvent.click(screen.getByRole('button', { name: '查询' }));
await waitFor(() => { await waitFor(() => {
expect(getChannelQRCodeList).toHaveBeenLastCalledWith(expect.objectContaining({ status: 'disable' })); expect(getChannelQRCodeList).toHaveBeenLastCalledWith(expect.objectContaining({ status: 'disable' }));
......
...@@ -53,7 +53,7 @@ describe('ComponentsDemoPage', () => { ...@@ -53,7 +53,7 @@ describe('ComponentsDemoPage', () => {
fireEvent.click(scoped.getByRole('button', { name: '展开' })); fireEvent.click(scoped.getByRole('button', { name: '展开' }));
expect(scoped.getByRole('button', { name: '收起' })).toBeInTheDocument(); expect(scoped.getByRole('button', { name: '收起' })).toBeInTheDocument();
fireEvent.click(scoped.getByRole('button', { name: '搜索' })); fireEvent.click(scoped.getByRole('button', { name: '查询' }));
expect(scoped.getByText(/"keyword": "智能审批"/)).toBeInTheDocument(); expect(scoped.getByText(/"keyword": "智能审批"/)).toBeInTheDocument();
fireEvent.click(scoped.getByRole('button', { name: '重置' })); fireEvent.click(scoped.getByRole('button', { name: '重置' }));
......
...@@ -73,12 +73,12 @@ export function OfficialSiteAgentDisplayConfigPage() { ...@@ -73,12 +73,12 @@ export function OfficialSiteAgentDisplayConfigPage() {
if (loading) { if (loading) {
return ( return (
<section className="grid gap-6"> <section className="grid gap-6">
<header className="flex items-center justify-between gap-6 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-6"> <header className="sticky top-0 z-10 flex items-start justify-between gap-6 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-6">
<div className="flex items-center gap-4"> <div aria-label="页面标题" className="min-w-0 flex-1">
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">Agent展示配置页</h2>
</div>
<div aria-label="页面操作" className="flex shrink-0 items-center gap-2">
<Button variant="outline" onClick={goBackToList}>返回</Button> <Button variant="outline" onClick={goBackToList}>返回</Button>
<div>
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">Agent展示配置页</h2>
</div>
</div> </div>
</header> </header>
<div className="grid gap-4 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] p-6"> <div className="grid gap-4 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] p-6">
...@@ -169,17 +169,17 @@ export function OfficialSiteAgentDisplayConfigPage() { ...@@ -169,17 +169,17 @@ export function OfficialSiteAgentDisplayConfigPage() {
return ( return (
<section className="grid gap-6"> <section className="grid gap-6">
<header className="flex items-center justify-between gap-6 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-6"> <header className="sticky top-0 z-10 flex items-start justify-between gap-6 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-6">
<div className="flex items-center gap-4"> <div aria-label="页面标题" className="min-w-0 flex-1">
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">
{tabDetail?.position_name ?? '-'} Agent展示配置页
</h2>
<p className="m-0 mt-1 text-sm text-[var(--gl-color-text-secondary)]">
配置该岗位下 Agent 在官网的展示素材和状态
</p>
</div>
<div aria-label="页面操作" className="flex shrink-0 items-center gap-2">
<Button variant="outline" onClick={goBackToList}>返回</Button> <Button variant="outline" onClick={goBackToList}>返回</Button>
<div>
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">
{tabDetail?.position_name ?? '-'} Agent展示配置页
</h2>
<p className="m-0 mt-1 text-sm text-[var(--gl-color-text-secondary)]">
配置该岗位下 Agent 在官网的展示素材和状态
</p>
</div>
</div> </div>
</header> </header>
......
...@@ -140,8 +140,13 @@ describe('official site agent display config routes and navigation', () => { ...@@ -140,8 +140,13 @@ describe('official site agent display config routes and navigation', () => {
it('shows return to list button', async () => { it('shows return to list button', async () => {
renderApp(); renderApp();
await waitFor(() => { await waitFor(() => {
expect(screen.getByRole('button', { name: '返回' })).toBeInTheDocument(); expect(screen.getByRole('heading', { name: '店销顾问 Agent展示配置页' })).toBeInTheDocument();
}); });
const pageHeader = screen.getByRole('heading', { name: '店销顾问 Agent展示配置页' }).closest('header') as HTMLElement;
expect(pageHeader).toHaveClass('sticky', 'top-0', 'z-10');
expect(within(screen.getByLabelText('页面标题')).queryByRole('button')).not.toBeInTheDocument();
const pageActions = screen.getByLabelText('页面操作');
expect(within(pageActions).getByRole('button', { name: '返回' })).toBeInTheDocument();
}); });
it('shows position name in page title', async () => { it('shows position name in page title', async () => {
...@@ -173,7 +178,7 @@ describe('official site agent display config routes and navigation', () => { ...@@ -173,7 +178,7 @@ describe('official site agent display config routes and navigation', () => {
await waitFor(() => { await waitFor(() => {
expect(screen.getByRole('heading', { name: '店销顾问 Agent展示配置页' })).toBeInTheDocument(); expect(screen.getByRole('heading', { name: '店销顾问 Agent展示配置页' })).toBeInTheDocument();
}); });
fireEvent.click(screen.getByRole('button', { name: '返回' })); fireEvent.click(within(screen.getByLabelText('页面操作')).getByRole('button', { name: '返回' }));
await waitFor(() => { await waitFor(() => {
expect(screen.getByRole('heading', { name: '岗位展示配置' })).toBeInTheDocument(); expect(screen.getByRole('heading', { name: '岗位展示配置' })).toBeInTheDocument();
}); });
......
...@@ -107,9 +107,11 @@ describe('OfficialSiteJobTabEditorPage', () => { ...@@ -107,9 +107,11 @@ describe('OfficialSiteJobTabEditorPage', () => {
expect(await screen.findByRole('heading', { name: '新建岗位展示' })).toBeInTheDocument(); expect(await screen.findByRole('heading', { name: '新建岗位展示' })).toBeInTheDocument();
const pageHeader = screen.getByRole('heading', { name: '新建岗位展示' }).closest('header') as HTMLElement; const pageHeader = screen.getByRole('heading', { name: '新建岗位展示' }).closest('header') as HTMLElement;
expect(pageHeader).toHaveClass('sticky', 'top-0', 'z-10'); expect(pageHeader).toHaveClass('sticky', 'top-0', 'z-10');
expect(within(pageHeader).getByRole('button', { name: '返回' })).toBeInTheDocument(); expect(within(screen.getByLabelText('页面标题')).queryByRole('button')).not.toBeInTheDocument();
const pageActions = screen.getByLabelText('页面操作');
expect(within(pageActions).getByRole('button', { name: '返回' })).toBeInTheDocument();
expect(within(pageActions).getByRole('button', { name: '保存' })).toBeInTheDocument();
expect(within(pageHeader).queryByRole('button', { name: '取消' })).not.toBeInTheDocument(); expect(within(pageHeader).queryByRole('button', { name: '取消' })).not.toBeInTheDocument();
expect(within(pageHeader).getByRole('button', { name: '保存' })).toBeInTheDocument();
}); });
it('renders required form fields', () => { it('renders required form fields', () => {
......
...@@ -380,19 +380,19 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit' ...@@ -380,19 +380,19 @@ export function OfficialSiteJobTabEditorPage({ mode }: { mode: 'create' | 'edit'
return ( return (
<section className="grid gap-6"> <section className="grid gap-6">
<header className="sticky top-0 z-10 flex items-center justify-between gap-6 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-6"> <header className="sticky top-0 z-10 flex items-start justify-between gap-6 rounded-[var(--gl-radius-md)] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-container)] px-8 py-6">
<div className="flex items-center gap-4"> <div aria-label="页面标题" className="min-w-0 flex-1">
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">
{mode === 'create' ? '新建岗位展示' : '编辑岗位展示'}
</h2>
<p className="m-0 mt-1 text-sm text-[var(--gl-color-text-secondary)]">
{mode === 'create' ? '创建新的官网岗位展示配置' : '编辑已有官网岗位展示配置'}
</p>
</div>
<div aria-label="页面操作" className="flex shrink-0 items-center gap-2">
<Button variant="outline" onClick={goBackToList}>返回</Button> <Button variant="outline" onClick={goBackToList}>返回</Button>
<div> <Button theme="primary" loading={saving} onClick={handleSave}>保存</Button>
<h2 className="m-0 text-2xl leading-[var(--gl-line-height-xl)]">
{mode === 'create' ? '新建岗位展示' : '编辑岗位展示'}
</h2>
<p className="m-0 mt-1 text-sm text-[var(--gl-color-text-secondary)]">
{mode === 'create' ? '创建新的官网岗位展示配置' : '编辑已有官网岗位展示配置'}
</p>
</div>
</div> </div>
<Button theme="primary" loading={saving} onClick={handleSave}>保存</Button>
</header> </header>
{notice ? ( {notice ? (
......
...@@ -197,7 +197,7 @@ describe('OfficialSiteJobTabListPage', () => { ...@@ -197,7 +197,7 @@ describe('OfficialSiteJobTabListPage', () => {
expect(screen.getByLabelText('关键词')).toBeInTheDocument(); expect(screen.getByLabelText('关键词')).toBeInTheDocument();
expect(screen.getByPlaceholderText('搜索岗位名称或渠道活码')).toBeInTheDocument(); expect(screen.getByPlaceholderText('搜索岗位名称或渠道活码')).toBeInTheDocument();
expect(screen.getByLabelText('展示状态')).toBeInTheDocument(); expect(screen.getByLabelText('展示状态')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '搜索' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '查询' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '重置' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '重置' })).toBeInTheDocument();
}); });
...@@ -246,7 +246,7 @@ describe('OfficialSiteJobTabListPage', () => { ...@@ -246,7 +246,7 @@ describe('OfficialSiteJobTabListPage', () => {
renderApp(); renderApp();
const keywordInput = screen.getByLabelText('关键词'); const keywordInput = screen.getByLabelText('关键词');
fireEvent.change(keywordInput, { target: { value: '不存在的关键词' } }); fireEvent.change(keywordInput, { target: { value: '不存在的关键词' } });
fireEvent.click(screen.getByRole('button', { name: '搜索' })); fireEvent.click(screen.getByRole('button', { name: '查询' }));
await waitFor(() => { await waitFor(() => {
expect(screen.getByText('未找到匹配结果')).toBeInTheDocument(); expect(screen.getByText('未找到匹配结果')).toBeInTheDocument();
expect(screen.queryByText('暂无数据')).not.toBeInTheDocument(); expect(screen.queryByText('暂无数据')).not.toBeInTheDocument();
...@@ -289,7 +289,7 @@ describe('OfficialSiteJobTabListPage', () => { ...@@ -289,7 +289,7 @@ describe('OfficialSiteJobTabListPage', () => {
page: 1, page: 1,
page_size: 10, page_size: 10,
}); });
fireEvent.click(screen.getByRole('button', { name: '搜索' })); fireEvent.click(screen.getByRole('button', { name: '查询' }));
await waitFor(() => { await waitFor(() => {
expect(screen.getByText('店销顾问')).toBeInTheDocument(); expect(screen.getByText('店销顾问')).toBeInTheDocument();
}); });
...@@ -320,7 +320,7 @@ describe('OfficialSiteJobTabListPage', () => { ...@@ -320,7 +320,7 @@ describe('OfficialSiteJobTabListPage', () => {
page_size: 10, page_size: 10,
}); });
await act(async () => { await act(async () => {
fireEvent.click(screen.getByRole('button', { name: '搜索' })); fireEvent.click(screen.getByRole('button', { name: '查询' }));
}); });
await waitFor(() => { await waitFor(() => {
expect(screen.getByText('私域增长')).toBeInTheDocument(); expect(screen.getByText('私域增长')).toBeInTheDocument();
...@@ -334,7 +334,7 @@ describe('OfficialSiteJobTabListPage', () => { ...@@ -334,7 +334,7 @@ describe('OfficialSiteJobTabListPage', () => {
}); });
const keywordInput = screen.getByLabelText('关键词'); const keywordInput = screen.getByLabelText('关键词');
fireEvent.change(keywordInput, { target: { value: '店销' } }); fireEvent.change(keywordInput, { target: { value: '店销' } });
fireEvent.click(screen.getByRole('button', { name: '搜索' })); fireEvent.click(screen.getByRole('button', { name: '查询' }));
fireEvent.click(screen.getByRole('button', { name: '重置' })); fireEvent.click(screen.getByRole('button', { name: '重置' }));
await waitFor(() => { await waitFor(() => {
expect(keywordInput).toHaveValue(''); expect(keywordInput).toHaveValue('');
......
...@@ -24,6 +24,7 @@ const mockMethodologyConfig = { ...@@ -24,6 +24,7 @@ const mockMethodologyConfig = {
steps: [ steps: [
{ step_id: 's1', step_icon: 'https://cdn.example.com/icon1.png', step_name: '需求澄清', step_order: 1, step_image: 'https://cdn.example.com/image1.png' }, { step_id: 's1', step_icon: 'https://cdn.example.com/icon1.png', step_name: '需求澄清', step_order: 1, step_image: 'https://cdn.example.com/image1.png' },
{ step_id: 's2', step_icon: 'https://cdn.example.com/icon2.png', step_name: '方案设计', step_order: 2, step_image: 'https://cdn.example.com/image2.png' }, { step_id: 's2', step_icon: 'https://cdn.example.com/icon2.png', step_name: '方案设计', step_order: 2, step_image: 'https://cdn.example.com/image2.png' },
{ step_id: 's3', step_icon: 'https://cdn.example.com/icon3.png', step_name: '上线复盘', step_order: 3, step_image: 'https://cdn.example.com/image3.png' },
], ],
updated_at: '2026-05-16T10:00:00Z', updated_at: '2026-05-16T10:00:00Z',
}; };
...@@ -59,9 +60,10 @@ describe('OfficialSiteMethodologyPage form and steps', () => { ...@@ -59,9 +60,10 @@ describe('OfficialSiteMethodologyPage form and steps', () => {
expect(screen.getByLabelText('副标题')).toHaveValue('从目标澄清到上线复盘,帮助团队沉淀一套稳定可复制的方法论。'); expect(screen.getByLabelText('副标题')).toHaveValue('从目标澄清到上线复盘,帮助团队沉淀一套稳定可复制的方法论。');
const cards = screen.getAllByTestId('methodology-step-card'); const cards = screen.getAllByTestId('methodology-step-card');
expect(cards).toHaveLength(2); expect(cards).toHaveLength(3);
expect(within(cards[0]).getByLabelText('步骤1名称')).toHaveValue('需求澄清'); expect(within(cards[0]).getByLabelText('步骤3名称')).toHaveValue('上线复盘');
expect(within(cards[1]).getByLabelText('步骤2名称')).toHaveValue('方案设计'); expect(within(cards[1]).getByLabelText('步骤2名称')).toHaveValue('方案设计');
expect(within(cards[2]).getByLabelText('步骤1名称')).toHaveValue('需求澄清');
}); });
it('supports disabled display status and empty-step fixtures', async () => { it('supports disabled display status and empty-step fixtures', async () => {
...@@ -101,6 +103,7 @@ describe('OfficialSiteMethodologyPage form and steps', () => { ...@@ -101,6 +103,7 @@ describe('OfficialSiteMethodologyPage form and steps', () => {
fireEvent.change(screen.getByLabelText('副标题'), { target: { value: '' } }); fireEvent.change(screen.getByLabelText('副标题'), { target: { value: '' } });
fireEvent.click(screen.getByRole('button', { name: '删除步骤 1' })); fireEvent.click(screen.getByRole('button', { name: '删除步骤 1' }));
fireEvent.click(screen.getByRole('button', { name: '删除步骤 1' })); fireEvent.click(screen.getByRole('button', { name: '删除步骤 1' }));
fireEvent.click(screen.getByRole('button', { name: '删除步骤 1' }));
fireEvent.click(screen.getByRole('button', { name: '保存配置' })); fireEvent.click(screen.getByRole('button', { name: '保存配置' }));
expect(screen.getByText('请输入主标题')).toBeInTheDocument(); expect(screen.getByText('请输入主标题')).toBeInTheDocument();
...@@ -112,27 +115,46 @@ describe('OfficialSiteMethodologyPage form and steps', () => { ...@@ -112,27 +115,46 @@ describe('OfficialSiteMethodologyPage form and steps', () => {
renderMethodology(); renderMethodology();
await waitFor(() => { await waitFor(() => {
expect(screen.getAllByTestId('methodology-step-card')).toHaveLength(2); expect(screen.getAllByTestId('methodology-step-card')).toHaveLength(3);
}); });
fireEvent.click(screen.getByRole('button', { name: '添加步骤' })); fireEvent.click(screen.getByRole('button', { name: '添加步骤' }));
let cards = screen.getAllByTestId('methodology-step-card'); let cards = screen.getAllByTestId('methodology-step-card');
expect(cards).toHaveLength(3); expect(cards).toHaveLength(4);
expect(within(cards[0]).getByLabelText('步骤4名称')).toHaveValue('');
expect(within(cards[1]).getByLabelText('步骤3名称')).toHaveValue('上线复盘');
fireEvent.click(within(cards[1]).getByRole('button', { name: '下移步骤 3' }));
cards = screen.getAllByTestId('methodology-step-card');
expect(within(cards[1]).getByLabelText('步骤3名称')).toHaveValue('方案设计');
expect(within(cards[2]).getByLabelText('步骤2名称')).toHaveValue('上线复盘');
fireEvent.change(within(cards[2]).getByLabelText('步骤3名称'), { target: { value: '上线复盘' } }); fireEvent.click(within(cards[2]).getByRole('button', { name: '上移步骤 2' }));
fireEvent.click(within(cards[2]).getByRole('button', { name: '上移步骤 3' }));
fireEvent.click(within(screen.getAllByTestId('methodology-step-card')[1]).getByRole('button', { name: '上移步骤 2' }));
cards = screen.getAllByTestId('methodology-step-card'); cards = screen.getAllByTestId('methodology-step-card');
expect(within(cards[0]).getByLabelText('步骤1名称')).toHaveValue('上线复盘'); expect(within(cards[1]).getByLabelText('步骤3名称')).toHaveValue('上线复盘');
expect(within(cards[1]).getByLabelText('步骤2名称')).toHaveValue('需求澄清'); expect(within(cards[2]).getByLabelText('步骤2名称')).toHaveValue('方案设计');
fireEvent.click(within(cards[1]).getByRole('button', { name: '删除步骤 2' })); fireEvent.click(within(cards[0]).getByRole('button', { name: '删除步骤 4' }));
cards = screen.getAllByTestId('methodology-step-card'); cards = screen.getAllByTestId('methodology-step-card');
expect(cards).toHaveLength(2); expect(cards).toHaveLength(3);
expect(within(cards[0]).getByLabelText('步骤3名称')).toHaveValue('上线复盘');
expect(within(cards[1]).getByLabelText('步骤2名称')).toHaveValue('方案设计'); expect(within(cards[1]).getByLabelText('步骤2名称')).toHaveValue('方案设计');
fireEvent.click(screen.getByRole('button', { name: '保存配置' }));
await waitFor(() => {
expect(saveMethodologyConfig).toHaveBeenCalled();
});
expect(vi.mocked(saveMethodologyConfig).mock.calls[0][0].steps.map((step) => step.step_name)).toEqual([
'需求澄清',
'方案设计',
'上线复盘',
]);
expect(vi.mocked(saveMethodologyConfig).mock.calls[0][0].steps.map((step) => step.step_order)).toEqual([1, 2, 3]);
}); });
describe('analytics tracking', () => { describe('analytics tracking', () => {
......
...@@ -296,6 +296,10 @@ export function OfficialSiteMethodologyPage() { ...@@ -296,6 +296,10 @@ export function OfficialSiteMethodologyPage() {
); );
} }
const visibleSteps = form.steps
.map((step, index) => ({ step, index }))
.reverse();
return ( return (
<> <>
{notice ? ( {notice ? (
...@@ -369,29 +373,29 @@ export function OfficialSiteMethodologyPage() { ...@@ -369,29 +373,29 @@ export function OfficialSiteMethodologyPage() {
</div> </div>
) : ( ) : (
<div className="mt-6 grid gap-4"> <div className="mt-6 grid gap-4">
{form.steps.map((step, index) => ( {visibleSteps.map(({ step, index }, visibleIndex) => (
<section <section
key={step.step_id} key={step.step_id}
aria-label={`方法论步骤 ${index + 1}`} aria-label={`方法论步骤 ${step.step_order}`}
className="grid gap-5 rounded-[8px] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-page)] p-5" className="grid gap-5 rounded-[8px] border border-[var(--gl-color-border-secondary)] bg-[var(--gl-color-bg-page)] p-5"
data-testid="methodology-step-card" data-testid="methodology-step-card"
> >
<div className="flex flex-wrap items-center justify-between gap-3"> <div className="flex flex-wrap items-center justify-between gap-3">
<div className="grid gap-1"> <div className="grid gap-1">
<strong>步骤 {index + 1}</strong> <strong>步骤 {step.step_order}</strong>
{/* <span className="text-sm text-[var(--gl-color-text-secondary)]">{`sort_order = ${step.step_order}`}</span> */} {/* <span className="text-sm text-[var(--gl-color-text-secondary)]">{`sort_order = ${step.step_order}`}</span> */}
</div> </div>
<div className="flex flex-wrap items-center gap-2"> <div className="flex flex-wrap items-center gap-2">
<Button <Button
size="small" size="small"
variant="outline" variant="outline"
disabled={index === 0} disabled={visibleIndex === 0}
aria-label={`上移步骤 ${index + 1}`} aria-label={`上移步骤 ${step.step_order}`}
onClick={() => { onClick={() => {
if (index === 0) return; if (visibleIndex === 0) return;
updateForm((current) => { updateForm((current) => {
const nextSteps = [...current.steps]; const nextSteps = [...current.steps];
[nextSteps[index - 1], nextSteps[index]] = [nextSteps[index], nextSteps[index - 1]]; [nextSteps[index], nextSteps[index + 1]] = [nextSteps[index + 1], nextSteps[index]];
return { ...current, steps: normalizeSteps(nextSteps) }; return { ...current, steps: normalizeSteps(nextSteps) };
}); });
}} }}
...@@ -401,13 +405,13 @@ export function OfficialSiteMethodologyPage() { ...@@ -401,13 +405,13 @@ export function OfficialSiteMethodologyPage() {
<Button <Button
size="small" size="small"
variant="outline" variant="outline"
disabled={index === form.steps.length - 1} disabled={visibleIndex === visibleSteps.length - 1}
aria-label={`下移步骤 ${index + 1}`} aria-label={`下移步骤 ${step.step_order}`}
onClick={() => { onClick={() => {
if (index === form.steps.length - 1) return; if (visibleIndex === visibleSteps.length - 1) return;
updateForm((current) => { updateForm((current) => {
const nextSteps = [...current.steps]; const nextSteps = [...current.steps];
[nextSteps[index], nextSteps[index + 1]] = [nextSteps[index + 1], nextSteps[index]]; [nextSteps[index - 1], nextSteps[index]] = [nextSteps[index], nextSteps[index - 1]];
return { ...current, steps: normalizeSteps(nextSteps) }; return { ...current, steps: normalizeSteps(nextSteps) };
}); });
}} }}
...@@ -417,7 +421,7 @@ export function OfficialSiteMethodologyPage() { ...@@ -417,7 +421,7 @@ export function OfficialSiteMethodologyPage() {
<Button <Button
size="small" size="small"
theme="danger" theme="danger"
aria-label={`删除步骤 ${index + 1}`} aria-label={`删除步骤 ${step.step_order}`}
onClick={() => { onClick={() => {
updateForm((current) => ({ updateForm((current) => ({
...current, ...current,
...@@ -496,7 +500,7 @@ export function OfficialSiteMethodologyPage() { ...@@ -496,7 +500,7 @@ export function OfficialSiteMethodologyPage() {
<Button <Button
size="small" size="small"
variant="outline" variant="outline"
aria-label={`使用默认图标 步骤 ${index + 1}`} aria-label={`使用默认图标 步骤 ${step.step_order}`}
disabled={defaultIconUploading.has(step.step_id)} disabled={defaultIconUploading.has(step.step_id)}
onClick={async () => { onClick={async () => {
const stepId = step.step_id; const stepId = step.step_id;
...@@ -567,7 +571,7 @@ export function OfficialSiteMethodologyPage() { ...@@ -567,7 +571,7 @@ export function OfficialSiteMethodologyPage() {
<FormItem label="步骤名称" requiredMark status={step.nameError ? 'error' : undefined} tips={step.nameError}> <FormItem label="步骤名称" requiredMark status={step.nameError ? 'error' : undefined} tips={step.nameError}>
<Input <Input
aria-label={`步骤${index + 1}名称`} aria-label={`步骤${step.step_order}名称`}
className="w-full max-w-[360px]" className="w-full max-w-[360px]"
maxlength={20} maxlength={20}
allowInputOverMax allowInputOverMax
......
...@@ -368,8 +368,8 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => { ...@@ -368,8 +368,8 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => {
await waitFor(() => { await waitFor(() => {
expect(saveMethodologyConfig).toHaveBeenCalled(); expect(saveMethodologyConfig).toHaveBeenCalled();
const savePayload = vi.mocked(saveMethodologyConfig).mock.calls[0][0]; const savePayload = vi.mocked(saveMethodologyConfig).mock.calls[0][0];
// 第一个步骤的 step_icon 应该是新的 file_url // 第一张可见卡是倒序展示的步骤 2,保存 payload 仍按正序提交
expect(savePayload.steps[0].step_icon).toBe('https://cdn.example.com/new-icon.png'); expect(savePayload.steps[1].step_icon).toBe('https://cdn.example.com/new-icon.png');
}); });
}); });
}); });
...@@ -427,8 +427,8 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => { ...@@ -427,8 +427,8 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => {
await waitFor(() => { await waitFor(() => {
expect(saveMethodologyConfig).toHaveBeenCalled(); expect(saveMethodologyConfig).toHaveBeenCalled();
const savePayload = vi.mocked(saveMethodologyConfig).mock.calls[0][0]; const savePayload = vi.mocked(saveMethodologyConfig).mock.calls[0][0];
// 第一个步骤的 step_image 应该是新的 file_url // 第一张可见卡是倒序展示的步骤 2,保存 payload 仍按正序提交
expect(savePayload.steps[0].step_image).toBe('https://cdn.example.com/new-content.png'); expect(savePayload.steps[1].step_image).toBe('https://cdn.example.com/new-content.png');
}); });
}); });
}); });
...@@ -457,7 +457,7 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => { ...@@ -457,7 +457,7 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => {
}); });
// 点击「使用默认图标」按钮 // 点击「使用默认图标」按钮
const defaultIconButton = within(firstCard).getByRole('button', { name: '使用默认图标 步骤 1' }); const defaultIconButton = within(firstCard).getByRole('button', { name: '使用默认图标 步骤 2' });
fireEvent.click(defaultIconButton); fireEvent.click(defaultIconButton);
await waitFor(() => { await waitFor(() => {
...@@ -483,9 +483,9 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => { ...@@ -483,9 +483,9 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => {
await waitFor(() => { await waitFor(() => {
expect(saveMethodologyConfig).toHaveBeenCalled(); expect(saveMethodologyConfig).toHaveBeenCalled();
const savePayload = vi.mocked(saveMethodologyConfig).mock.calls[0][0]; const savePayload = vi.mocked(saveMethodologyConfig).mock.calls[0][0];
expect(savePayload.steps[0].step_icon).toBe('https://cdn.example.com/default-icon-1.png'); expect(savePayload.steps[1].step_icon).toBe('https://cdn.example.com/default-icon-1.png');
// 不应为 data: URL // 不应为 data: URL
expect(savePayload.steps[0].step_icon).not.toMatch(/^data:/); expect(savePayload.steps[1].step_icon).not.toMatch(/^data:/);
}); });
}); });
...@@ -506,7 +506,7 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => { ...@@ -506,7 +506,7 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => {
clickDeleteIcon(uploadContainers[0] as HTMLElement); clickDeleteIcon(uploadContainers[0] as HTMLElement);
} }
const defaultIconButton = within(firstCard).getByRole('button', { name: '使用默认图标 步骤 1' }); const defaultIconButton = within(firstCard).getByRole('button', { name: '使用默认图标 步骤 2' });
fireEvent.click(defaultIconButton); fireEvent.click(defaultIconButton);
// 等待上传失败 // 等待上传失败
...@@ -543,7 +543,7 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => { ...@@ -543,7 +543,7 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => {
// 模拟上传失败 // 模拟上传失败
vi.mocked(uploadMethodologyAsset).mockRejectedValueOnce(new Error('Upload failed')); vi.mocked(uploadMethodologyAsset).mockRejectedValueOnce(new Error('Upload failed'));
const defaultIconButton = within(firstCard).getByRole('button', { name: '使用默认图标 步骤 1' }); const defaultIconButton = within(firstCard).getByRole('button', { name: '使用默认图标 步骤 2' });
fireEvent.click(defaultIconButton); fireEvent.click(defaultIconButton);
await waitFor(() => { await waitFor(() => {
...@@ -559,7 +559,7 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => { ...@@ -559,7 +559,7 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => {
}); });
// 再次点击「使用默认图标」重试 // 再次点击「使用默认图标」重试
fireEvent.click(within(firstCard).getByRole('button', { name: '使用默认图标 步骤 1' })); fireEvent.click(within(firstCard).getByRole('button', { name: '使用默认图标 步骤 2' }));
await waitFor(() => { await waitFor(() => {
const images = within(firstCard).getAllByRole('img'); const images = within(firstCard).getAllByRole('img');
...@@ -594,7 +594,7 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => { ...@@ -594,7 +594,7 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => {
file_size: 5000, file_size: 5000,
}), 1000))); }), 1000)));
const defaultIconButton = within(firstCard).getByRole('button', { name: '使用默认图标 步骤 1' }); const defaultIconButton = within(firstCard).getByRole('button', { name: '使用默认图标 步骤 2' });
fireEvent.click(defaultIconButton); fireEvent.click(defaultIconButton);
// 等待上传开始 // 等待上传开始
...@@ -603,7 +603,7 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => { ...@@ -603,7 +603,7 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => {
}); });
// 上传中按钮应禁用 // 上传中按钮应禁用
expect(within(getFirstCard()).getByLabelText('使用默认图标 步骤 1')).toHaveAttribute('disabled'); expect(within(getFirstCard()).getByLabelText('使用默认图标 步骤 2')).toHaveAttribute('disabled');
// 等待上传完成(需要额外 timeout 以覆盖 mock 延迟) // 等待上传完成(需要额外 timeout 以覆盖 mock 延迟)
await waitFor(() => { await waitFor(() => {
...@@ -613,7 +613,7 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => { ...@@ -613,7 +613,7 @@ describe('OfficialSiteMethodologyPage upload, save, and state handling', () => {
}, { timeout: 2000 }); }, { timeout: 2000 });
// 上传完成后按钮恢复可用 // 上传完成后按钮恢复可用
expect(within(getFirstCard()).getByRole('button', { name: '使用默认图标 步骤 1' })).not.toBeDisabled(); expect(within(getFirstCard()).getByRole('button', { name: '使用默认图标 步骤 2' })).not.toBeDisabled();
}); });
}); });
}); });
...@@ -76,7 +76,7 @@ describe('SkillListPage', () => { ...@@ -76,7 +76,7 @@ describe('SkillListPage', () => {
expect(screen.getAllByText('关键词').length).toBeGreaterThan(0); expect(screen.getAllByText('关键词').length).toBeGreaterThan(0);
expect(screen.getByLabelText('关键词')).toBeInTheDocument(); expect(screen.getByLabelText('关键词')).toBeInTheDocument();
expect(screen.getByPlaceholderText('搜索Skill名称或编码')).toBeInTheDocument(); expect(screen.getByPlaceholderText('搜索Skill名称或编码')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '搜索' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '查询' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '重置' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '重置' })).toBeInTheDocument();
expect(screen.getByRole('columnheader', { name: 'Skill编码' })).toBeInTheDocument(); expect(screen.getByRole('columnheader', { name: 'Skill编码' })).toBeInTheDocument();
expect(screen.getByRole('columnheader', { name: 'Skill名称' })).toBeInTheDocument(); expect(screen.getByRole('columnheader', { name: 'Skill名称' })).toBeInTheDocument();
...@@ -100,7 +100,7 @@ describe('SkillListPage', () => { ...@@ -100,7 +100,7 @@ describe('SkillListPage', () => {
expect(screen.getByLabelText('关键词')).toBeInTheDocument(); expect(screen.getByLabelText('关键词')).toBeInTheDocument();
}); });
expect(screen.getByPlaceholderText('搜索Skill名称或编码')).toBeInTheDocument(); expect(screen.getByPlaceholderText('搜索Skill名称或编码')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '搜索' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '查询' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '重置' })).toBeInTheDocument(); expect(screen.getByRole('button', { name: '重置' })).toBeInTheDocument();
}); });
...@@ -119,7 +119,7 @@ describe('SkillListPage', () => { ...@@ -119,7 +119,7 @@ describe('SkillListPage', () => {
vi.mocked(getSkillList).mockResolvedValueOnce({ vi.mocked(getSkillList).mockResolvedValueOnce({
list: [mockSkills[1]], list: [mockSkills[1]],
}); });
fireEvent.click(screen.getByRole('button', { name: '搜索' })); fireEvent.click(screen.getByRole('button', { name: '查询' }));
await waitFor(() => { await waitFor(() => {
expect(getSkillList).toHaveBeenLastCalledWith('markdown'); expect(getSkillList).toHaveBeenLastCalledWith('markdown');
...@@ -148,7 +148,7 @@ describe('SkillListPage', () => { ...@@ -148,7 +148,7 @@ describe('SkillListPage', () => {
vi.mocked(getSkillList).mockResolvedValueOnce({ vi.mocked(getSkillList).mockResolvedValueOnce({
list: [mockSkills[0]], list: [mockSkills[0]],
}); });
fireEvent.click(screen.getByRole('button', { name: '搜索' })); fireEvent.click(screen.getByRole('button', { name: '查询' }));
await waitFor(() => { await waitFor(() => {
expect(getSkillList).toHaveBeenLastCalledWith('browser'); expect(getSkillList).toHaveBeenLastCalledWith('browser');
}); });
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!