SearchPanelPage.ts 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. /**
  2. * SearchPanelPage - 搜索面板的 Page Object Model
  3. * 用于 Worklist 和 History 页面的搜索功能
  4. */
  5. class SearchPanelPage {
  6. /**
  7. * 获取患者名称输入框
  8. */
  9. getPatientNameInput() {
  10. return cy.get('input[placeholder*="患者姓名"], input[placeholder*="Patient Name"]');
  11. }
  12. /**
  13. * 获取患者ID输入框
  14. */
  15. getPatientIdInput() {
  16. return cy.get('input[placeholder*="患者ID"], input[placeholder*="Patient ID"]');
  17. }
  18. /**
  19. * 获取登记号输入框
  20. */
  21. getAccessionNumberInput() {
  22. return cy.get('input[placeholder*="登记号"], input[placeholder*="Registration"], input[placeholder*="Accession"]');
  23. }
  24. /**
  25. * 输入患者名称
  26. * @param name 患者名称
  27. */
  28. typePatientName(name: string) {
  29. this.getPatientNameInput().clear().type(name);
  30. }
  31. /**
  32. * 输入患者ID
  33. * @param id 患者ID
  34. */
  35. typePatientId(id: string) {
  36. this.getPatientIdInput().clear().type(id);
  37. }
  38. /**
  39. * 输入登记号
  40. * @param accNo 登记号
  41. */
  42. typeAccessionNumber(accNo: string) {
  43. this.getAccessionNumberInput().clear().type(accNo);
  44. }
  45. /**
  46. * 清空患者名称
  47. */
  48. clearPatientName() {
  49. this.getPatientNameInput().clear();
  50. }
  51. /**
  52. * 清空患者ID
  53. */
  54. clearPatientId() {
  55. this.getPatientIdInput().clear();
  56. }
  57. /**
  58. * 清空登记号
  59. */
  60. clearAccessionNumber() {
  61. this.getAccessionNumberInput().clear();
  62. }
  63. // ============ 时间范围选择器操作 ============
  64. /**
  65. * 选择"今天"时间范围
  66. */
  67. selectTimeRangeToday() {
  68. cy.contains('label', '今天').click();
  69. }
  70. /**
  71. * 选择"7天"时间范围
  72. */
  73. selectTimeRange7Days() {
  74. cy.contains('label', '7天').click();
  75. }
  76. /**
  77. * 选择"所有"时间范围
  78. */
  79. selectTimeRangeAll() {
  80. cy.contains('label', '所有').click();
  81. }
  82. /**
  83. * 验证时间范围选中状态
  84. * @param type 时间范围类型
  85. */
  86. verifyTimeRangeSelected(type: 'today' | '7days' | 'all') {
  87. const labelText = {
  88. today: '今天',
  89. '7days': '7天',
  90. all: '所有',
  91. };
  92. cy.contains('label', labelText[type])
  93. .find('input[type="radio"]')
  94. .should('be.checked');
  95. }
  96. /**
  97. * 获取时间范围选择器组
  98. */
  99. getTimeRangeSelector() {
  100. return cy.get('.ant-radio-group');
  101. }
  102. // ============ 自定义日期范围操作 ============
  103. /**
  104. * 选择自定义日期范围
  105. * @param startDate 开始日期,格式:YYYY-MM-DD
  106. * @param endDate 结束日期,格式:YYYY-MM-DD
  107. */
  108. selectCustomDateRange(startDate: string, endDate: string) {
  109. // 点击日期范围选择器
  110. cy.get('.ant-picker-range').click();
  111. // 选择开始日期
  112. this.selectDateInPicker(startDate, 'start');
  113. // 选择结束日期
  114. this.selectDateInPicker(endDate, 'end');
  115. }
  116. /**
  117. * 在日期选择器中选择日期
  118. * @param date 日期字符串,格式:YYYY-MM-DD
  119. * @param type 'start' 或 'end'
  120. */
  121. private selectDateInPicker(date: string, type: 'start' | 'end') {
  122. const [year, month, day] = date.split('-').map(Number);
  123. // 等待日期选择器面板显示
  124. cy.get('.ant-picker-dropdown').should('be.visible');
  125. // 选择年份
  126. if (type === 'start') {
  127. cy.get('.ant-picker-dropdown')
  128. .first()
  129. .find('.ant-picker-header-year-btn')
  130. .click();
  131. cy.get('.ant-picker-year-panel').contains('.ant-picker-cell', year.toString()).click();
  132. }
  133. // 选择月份
  134. if (type === 'start') {
  135. cy.get('.ant-picker-dropdown')
  136. .first()
  137. .find('.ant-picker-header-month-btn')
  138. .click();
  139. cy.get('.ant-picker-month-panel')
  140. .contains('.ant-picker-cell', new RegExp(`^${month}月?$`))
  141. .click();
  142. }
  143. // 选择日期
  144. cy.get('.ant-picker-dropdown')
  145. .find('.ant-picker-cell')
  146. .not('.ant-picker-cell-disabled')
  147. .contains(new RegExp(`^${day}$`))
  148. .click();
  149. }
  150. /**
  151. * 清空自定义日期范围
  152. */
  153. clearCustomDateRange() {
  154. cy.get('.ant-picker-range').within(() => {
  155. cy.get('.ant-picker-clear').click({ force: true });
  156. });
  157. }
  158. /**
  159. * 获取日期范围选择器
  160. */
  161. getDateRangePicker() {
  162. return cy.get('.ant-picker-range');
  163. }
  164. /**
  165. * 验证日期范围选择器中的值
  166. * @param startDate 开始日期,格式:YYYY-MM-DD
  167. * @param endDate 结束日期,格式:YYYY-MM-DD
  168. */
  169. verifyDateRangeValue(startDate: string, endDate: string) {
  170. cy.get('.ant-picker-range input').first().should('have.value', startDate);
  171. cy.get('.ant-picker-range input').last().should('have.value', endDate);
  172. }
  173. /**
  174. * 验证日期范围选择器为空
  175. */
  176. verifyDateRangeEmpty() {
  177. cy.get('.ant-picker-range input').first().should('have.value', '');
  178. cy.get('.ant-picker-range input').last().should('have.value', '');
  179. }
  180. // ============ 搜索按钮 ============
  181. /**
  182. * 点击搜索按钮
  183. */
  184. clickSearchButton() {
  185. cy.contains('button', '搜索').click();
  186. }
  187. /**
  188. * 获取搜索按钮
  189. */
  190. getSearchButton() {
  191. return cy.contains('button', '搜索');
  192. }
  193. /**
  194. * 验证搜索按钮可点击
  195. */
  196. verifySearchButtonEnabled() {
  197. this.getSearchButton().should('not.be.disabled');
  198. }
  199. /**
  200. * 验证搜索按钮禁用
  201. */
  202. verifySearchButtonDisabled() {
  203. this.getSearchButton().should('be.disabled');
  204. }
  205. // ============ 整体验证 ============
  206. /**
  207. * 验证搜索面板可见
  208. */
  209. verifySearchPanelVisible() {
  210. this.getPatientNameInput().should('be.visible');
  211. this.getPatientIdInput().should('be.visible');
  212. this.getAccessionNumberInput().should('be.visible');
  213. this.getTimeRangeSelector().should('be.visible');
  214. this.getDateRangePicker().should('be.visible');
  215. this.getSearchButton().should('be.visible');
  216. }
  217. /**
  218. * 清空所有搜索条件
  219. */
  220. clearAllFilters() {
  221. this.clearPatientName();
  222. this.clearPatientId();
  223. this.clearAccessionNumber();
  224. this.selectTimeRangeAll();
  225. }
  226. /**
  227. * 填写完整的搜索条件并搜索
  228. * @param options 搜索选项
  229. */
  230. searchWithFilters(options: {
  231. patientName?: string;
  232. patientId?: string;
  233. accessionNumber?: string;
  234. timeRange?: 'today' | '7days' | 'all';
  235. customDateRange?: { start: string; end: string };
  236. }) {
  237. // 清空现有条件
  238. this.clearAllFilters();
  239. // 填写患者名称
  240. if (options.patientName) {
  241. this.typePatientName(options.patientName);
  242. }
  243. // 填写患者ID
  244. if (options.patientId) {
  245. this.typePatientId(options.patientId);
  246. }
  247. // 填写登记号
  248. if (options.accessionNumber) {
  249. this.typeAccessionNumber(options.accessionNumber);
  250. }
  251. // 选择预设时间范围
  252. if (options.timeRange) {
  253. switch (options.timeRange) {
  254. case 'today':
  255. this.selectTimeRangeToday();
  256. break;
  257. case '7days':
  258. this.selectTimeRange7Days();
  259. break;
  260. case 'all':
  261. this.selectTimeRangeAll();
  262. break;
  263. }
  264. }
  265. // 选择自定义日期范围
  266. if (options.customDateRange) {
  267. this.selectCustomDateRange(
  268. options.customDateRange.start,
  269. options.customDateRange.end
  270. );
  271. }
  272. // 点击搜索
  273. this.clickSearchButton();
  274. }
  275. }
  276. export default SearchPanelPage;