/** * SearchPanelPage - 搜索面板的 Page Object Model * 用于 Worklist 和 History 页面的搜索功能 */ class SearchPanelPage { /** * 获取患者名称输入框 */ getPatientNameInput() { return cy.get('input[placeholder*="患者姓名"], input[placeholder*="Patient Name"]'); } /** * 获取患者ID输入框 */ getPatientIdInput() { return cy.get('input[placeholder*="患者ID"], input[placeholder*="Patient ID"]'); } /** * 获取登记号输入框 */ getAccessionNumberInput() { return cy.get('input[placeholder*="登记号"], input[placeholder*="Registration"], input[placeholder*="Accession"]'); } /** * 输入患者名称 * @param name 患者名称 */ typePatientName(name: string) { this.getPatientNameInput().clear().type(name); } /** * 输入患者ID * @param id 患者ID */ typePatientId(id: string) { this.getPatientIdInput().clear().type(id); } /** * 输入登记号 * @param accNo 登记号 */ typeAccessionNumber(accNo: string) { this.getAccessionNumberInput().clear().type(accNo); } /** * 清空患者名称 */ clearPatientName() { this.getPatientNameInput().clear(); } /** * 清空患者ID */ clearPatientId() { this.getPatientIdInput().clear(); } /** * 清空登记号 */ clearAccessionNumber() { this.getAccessionNumberInput().clear(); } // ============ 时间范围选择器操作 ============ /** * 选择"今天"时间范围 */ selectTimeRangeToday() { cy.contains('label', '今天').click(); } /** * 选择"7天"时间范围 */ selectTimeRange7Days() { cy.contains('label', '7天').click(); } /** * 选择"所有"时间范围 */ selectTimeRangeAll() { cy.contains('label', '所有').click(); } /** * 验证时间范围选中状态 * @param type 时间范围类型 */ verifyTimeRangeSelected(type: 'today' | '7days' | 'all') { const labelText = { today: '今天', '7days': '7天', all: '所有', }; cy.contains('label', labelText[type]) .find('input[type="radio"]') .should('be.checked'); } /** * 获取时间范围选择器组 */ getTimeRangeSelector() { return cy.get('.ant-radio-group'); } // ============ 自定义日期范围操作 ============ /** * 选择自定义日期范围 * @param startDate 开始日期,格式:YYYY-MM-DD * @param endDate 结束日期,格式:YYYY-MM-DD */ selectCustomDateRange(startDate: string, endDate: string) { // 点击日期范围选择器 cy.get('.ant-picker-range').click(); // 选择开始日期 this.selectDateInPicker(startDate, 'start'); // 选择结束日期 this.selectDateInPicker(endDate, 'end'); } /** * 在日期选择器中选择日期 * @param date 日期字符串,格式:YYYY-MM-DD * @param type 'start' 或 'end' */ private selectDateInPicker(date: string, type: 'start' | 'end') { const [year, month, day] = date.split('-').map(Number); // 等待日期选择器面板显示 cy.get('.ant-picker-dropdown').should('be.visible'); // 选择年份 if (type === 'start') { cy.get('.ant-picker-dropdown') .first() .find('.ant-picker-header-year-btn') .click(); cy.get('.ant-picker-year-panel').contains('.ant-picker-cell', year.toString()).click(); } // 选择月份 if (type === 'start') { cy.get('.ant-picker-dropdown') .first() .find('.ant-picker-header-month-btn') .click(); cy.get('.ant-picker-month-panel') .contains('.ant-picker-cell', new RegExp(`^${month}月?$`)) .click(); } // 选择日期 cy.get('.ant-picker-dropdown') .find('.ant-picker-cell') .not('.ant-picker-cell-disabled') .contains(new RegExp(`^${day}$`)) .click(); } /** * 清空自定义日期范围 */ clearCustomDateRange() { cy.get('.ant-picker-range').within(() => { cy.get('.ant-picker-clear').click({ force: true }); }); } /** * 获取日期范围选择器 */ getDateRangePicker() { return cy.get('.ant-picker-range'); } /** * 验证日期范围选择器中的值 * @param startDate 开始日期,格式:YYYY-MM-DD * @param endDate 结束日期,格式:YYYY-MM-DD */ verifyDateRangeValue(startDate: string, endDate: string) { cy.get('.ant-picker-range input').first().should('have.value', startDate); cy.get('.ant-picker-range input').last().should('have.value', endDate); } /** * 验证日期范围选择器为空 */ verifyDateRangeEmpty() { cy.get('.ant-picker-range input').first().should('have.value', ''); cy.get('.ant-picker-range input').last().should('have.value', ''); } // ============ 搜索按钮 ============ /** * 点击搜索按钮 */ clickSearchButton() { cy.contains('button', '搜索').click(); } /** * 获取搜索按钮 */ getSearchButton() { return cy.contains('button', '搜索'); } /** * 验证搜索按钮可点击 */ verifySearchButtonEnabled() { this.getSearchButton().should('not.be.disabled'); } /** * 验证搜索按钮禁用 */ verifySearchButtonDisabled() { this.getSearchButton().should('be.disabled'); } // ============ 整体验证 ============ /** * 验证搜索面板可见 */ verifySearchPanelVisible() { this.getPatientNameInput().should('be.visible'); this.getPatientIdInput().should('be.visible'); this.getAccessionNumberInput().should('be.visible'); this.getTimeRangeSelector().should('be.visible'); this.getDateRangePicker().should('be.visible'); this.getSearchButton().should('be.visible'); } /** * 清空所有搜索条件 */ clearAllFilters() { this.clearPatientName(); this.clearPatientId(); this.clearAccessionNumber(); this.selectTimeRangeAll(); } /** * 填写完整的搜索条件并搜索 * @param options 搜索选项 */ searchWithFilters(options: { patientName?: string; patientId?: string; accessionNumber?: string; timeRange?: 'today' | '7days' | 'all'; customDateRange?: { start: string; end: string }; }) { // 清空现有条件 this.clearAllFilters(); // 填写患者名称 if (options.patientName) { this.typePatientName(options.patientName); } // 填写患者ID if (options.patientId) { this.typePatientId(options.patientId); } // 填写登记号 if (options.accessionNumber) { this.typeAccessionNumber(options.accessionNumber); } // 选择预设时间范围 if (options.timeRange) { switch (options.timeRange) { case 'today': this.selectTimeRangeToday(); break; case '7days': this.selectTimeRange7Days(); break; case 'all': this.selectTimeRangeAll(); break; } } // 选择自定义日期范围 if (options.customDateRange) { this.selectCustomDateRange( options.customDateRange.start, options.customDateRange.end ); } // 点击搜索 this.clickSearchButton(); } } export default SearchPanelPage;