为 Worklist 和 History 等页面的表格添加列显示控制功能,支持通过配置信息控制显示哪些列。配置信息可来自本地硬编码或远程 API。
采用端口适配器模式,支持两种配置源:
配置源 (本地/远程)
↓
ColumnConfigService (领域服务)
↓
父组件 (worklist.tsx / HistoryList.tsx)
↓ (通过 props)
WorklistTable (表格组件)
↓
渲染过滤后的列
文件路径: cypress/e2e/patient/worklist/column-config.cy.ts
测试目标: 验证在无网络配置时,表格使用本地硬编码配置
验证点:
预期列数: 9 个(示例)
前置条件:
测试目标: 验证从 API 获取配置并正确应用
验证点:
Mock 配置示例:
{
"tableName": "worklist",
"columns": [
{ "key": "PatientID", "visible": true, "order": 1, "width": 120 },
{ "key": "PatientName", "visible": true, "order": 2, "width": 150 },
{ "key": "Modality", "visible": true, "order": 3, "width": 100 },
{ "key": "StudyStatus", "visible": true, "order": 4, "width": 100 }
]
}
测试目标: 验证配置提供者的容错机制
验证点:
测试目标: 验证列配置的可见性控制
验证点:
测试目标: 验证列按配置顺序排列
验证点:
特殊配置示例:
{
"columns": [
{ "key": "StudyStatus", "visible": true, "order": 1 },
{ "key": "PatientID", "visible": true, "order": 2 },
{ "key": "Modality", "visible": true, "order": 3 },
{ "key": "PatientName", "visible": true, "order": 4 }
]
}
测试目标: 验证列宽度应用
验证点:
测试目标: 验证默认行为(向后兼容)
验证点:
文件路径: cypress/e2e/patient/history/column-config.cy.ts
测试目标: 验证 history 使用与 worklist 不同的配置
验证点:
示例配置:
{
"tableName": "history",
"columns": [
{ "key": "StudyID", "visible": true, "order": 1 },
{ "key": "IsExported", "visible": true, "order": 2 },
{ "key": "StudyDescription", "visible": true, "order": 3 }
]
}
测试目标: 验证 history 特有列的配置
验证点:
测试目标: 验证不同表格配置互不影响
验证点:
文件路径: cypress/e2e/patient/column-config-adapters.cy.ts
测试目标: 验证本地适配器总是可用
验证点:
测试目标: 验证远程适配器的可用性检测
验证点:
测试目标: 验证运行时切换配置源
验证点:
const worklistDefaultColumns = [
{ key: 'PatientID', visible: true, order: 1, width: 120 },
{ key: 'PatientName', visible: true, order: 2, width: 150 },
{ key: 'StudyID', visible: true, order: 3, width: 120 },
{ key: 'AccessionNumber', visible: true, order: 4, width: 150 },
{ key: 'StudyStatus', visible: true, order: 5, width: 100 },
{ key: 'Modality', visible: true, order: 6, width: 100 },
{ key: 'StudyStartDatetime', visible: true, order: 7, width: 180 },
{ key: 'PatientAge', visible: true, order: 8, width: 80 },
{ key: 'PatientSex', visible: true, order: 9, width: 80 },
// 其他列 visible: false
];
{
"success": true,
"data": [
{
"tableName": "worklist",
"columns": [...],
"version": "1.0.0",
"updatedAt": "2025-10-07T10:00:00Z"
},
{
"tableName": "history",
"columns": [...],
"version": "1.0.0",
"updatedAt": "2025-10-07T10:00:00Z"
}
]
}
class WorklistPage {
// 现有方法
getTable() { ... }
// 新增:获取表头
getTableHeaders() {
return cy.get('table thead th').not(':first'); // 排除选择框列
}
// 新增:获取特定列
getColumn(columnName: string) {
return cy.get('table thead th').contains(columnName);
}
// 新增:验证列是否存在
columnExists(columnName: string) {
return this.getTableHeaders().contains(columnName).should('exist');
}
// 新增:验证列不存在
columnNotExists(columnName: string) {
return this.getTableHeaders().contains(columnName).should('not.exist');
}
// 新增:获取列宽
getColumnWidth(columnName: string) {
return cy.get('table thead th')
.contains(columnName)
.invoke('width');
}
}
cypress/support/mock/handlers/columnConfig.ts
export const mockColumnConfigSuccess = () => {
cy.intercept('GET', '/api/config/table-columns', {
statusCode: 200,
body: {
success: true,
data: [
{
tableName: 'worklist',
columns: [
{ key: 'PatientID', visible: true, order: 1, width: 120 },
{ key: 'PatientName', visible: true, order: 2, width: 150 },
{ key: 'StudyID', visible: true, order: 3, width: 120 },
{ key: 'AccessionNumber', visible: true, order: 4, width: 150 },
{ key: 'StudyStatus', visible: true, order: 5, width: 100 },
{ key: 'Modality', visible: true, order: 6, width: 100 },
{ key: 'StudyStartDatetime', visible: true, order: 7, width: 180 },
{ key: 'PatientAge', visible: true, order: 8, width: 80 },
{ key: 'PatientSex', visible: true, order: 9, width: 80 },
],
version: '1.0.0',
},
],
},
}).as('columnConfig');
};
export const mockColumnConfigFail = () => {
cy.intercept('GET', '/api/config/table-columns', {
statusCode: 500,
}).as('columnConfigFail');
};