disability-person.page.ts 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  1. import { Page, Locator } from '@playwright/test';
  2. import { selectRadixOption, selectProvinceCity } from '@d8d/e2e-test-utils';
  3. // 注意:@d8d/e2e-test-utils 包已安装,将在后续 story (2.2, 2.3) 中实际使用
  4. export class DisabilityPersonManagementPage {
  5. readonly page: Page;
  6. readonly pageTitle: Locator;
  7. readonly addPersonButton: Locator;
  8. readonly keywordSearchInput: Locator;
  9. readonly searchButton: Locator;
  10. readonly personTable: Locator;
  11. constructor(page: Page) {
  12. this.page = page;
  13. this.pageTitle = page.getByText('残疾人个人管理');
  14. this.addPersonButton = page.getByRole('button', { name: '新增残疾人' });
  15. this.keywordSearchInput = page.getByPlaceholder('搜索姓名或身份证号');
  16. this.searchButton = page.getByRole('button', { name: '搜索' });
  17. this.personTable = page.locator('table');
  18. }
  19. async goto() {
  20. await this.page.goto('/admin/disabilities');
  21. await this.page.waitForLoadState('domcontentloaded');
  22. // 等待页面标题出现
  23. await this.pageTitle.waitFor({ state: 'visible', timeout: 15000 });
  24. // 等待表格数据加载
  25. await this.page.waitForSelector('table tbody tr', { state: 'visible', timeout: 20000 });
  26. await this.expectToBeVisible();
  27. }
  28. async expectToBeVisible() {
  29. await this.pageTitle.waitFor({ state: 'visible', timeout: 15000 });
  30. await this.addPersonButton.waitFor({ state: 'visible', timeout: 10000 });
  31. }
  32. async openCreateDialog() {
  33. // 监听网络请求
  34. const responses: any[] = [];
  35. this.page.on('response', async (response) => {
  36. if (response.url().includes('disabled-person') || response.url().includes('aggregated')) {
  37. try {
  38. const responseData = await response.json().catch(() => ({ status: response.status() }));
  39. responses.push({
  40. url: response.url(),
  41. status: response.status(),
  42. data: responseData
  43. });
  44. } catch (e) {
  45. responses.push({
  46. url: response.url(),
  47. status: response.status(),
  48. error: e
  49. });
  50. }
  51. }
  52. });
  53. await this.addPersonButton.click();
  54. await this.page.waitForSelector('[data-testid="create-disabled-person-dialog-title"]', { state: 'visible', timeout: 5000 });
  55. return responses;
  56. }
  57. async fillBasicForm(data: {
  58. name: string;
  59. gender: string;
  60. idCard: string;
  61. disabilityId: string;
  62. disabilityType: string;
  63. disabilityLevel: string;
  64. phone: string;
  65. idAddress: string;
  66. province: string;
  67. city: string;
  68. }) {
  69. // 等待表单出现
  70. const form = this.page.locator('form#create-form');
  71. await form.waitFor({ state: 'visible', timeout: 5000 });
  72. console.debug('开始填写表单...');
  73. // 填写基本信息 - 使用 form locator 确保只在对话框内查找
  74. await form.getByLabel('姓名 *').fill(data.name);
  75. console.debug('✓ 姓名已填写:', data.name);
  76. // 性别 - 使用 data-testid
  77. const genderTrigger = this.page.locator('[data-testid="gender-select"]');
  78. await genderTrigger.click();
  79. await this.page.getByRole('option', { name: data.gender }).click();
  80. console.debug('✓ 性别已选择:', data.gender);
  81. await form.getByLabel('身份证号 *').fill(data.idCard);
  82. console.debug('✓ 身份证号已填写');
  83. await form.getByLabel('残疾证号 *').fill(data.disabilityId);
  84. console.debug('✓ 残疾证号已填写');
  85. // 残疾类型 - 使用 data-testid
  86. const disabilityTypeTrigger = this.page.locator('[data-testid="disability-type-select"]');
  87. await disabilityTypeTrigger.scrollIntoViewIfNeeded();
  88. await this.page.waitForTimeout(200);
  89. await disabilityTypeTrigger.click();
  90. await this.page.getByRole('option', { name: data.disabilityType }).click();
  91. console.debug('✓ 残疾类型已选择:', data.disabilityType);
  92. // 残疾等级 - 使用 data-testid
  93. const disabilityLevelTrigger = this.page.locator('[data-testid="disability-level-select"]');
  94. await disabilityLevelTrigger.scrollIntoViewIfNeeded();
  95. await this.page.waitForTimeout(200);
  96. await disabilityLevelTrigger.click();
  97. await this.page.getByRole('option', { name: data.disabilityLevel }).click();
  98. console.debug('✓ 残疾等级已选择:', data.disabilityLevel);
  99. await form.getByLabel('联系电话 *').fill(data.phone);
  100. console.debug('✓ 联系电话已填写');
  101. await form.getByLabel('身份证地址 *').fill(data.idAddress);
  102. console.debug('✓ 身份证地址已填写');
  103. // 居住地址 - 省市区级联选择
  104. // AreaSelectForm 使用 data-testid="area-select-province" 等属性
  105. const provinceTrigger = this.page.locator('[data-testid="area-select-province"]');
  106. await provinceTrigger.scrollIntoViewIfNeeded();
  107. await provinceTrigger.click();
  108. await this.page.getByRole('option', { name: data.province }).click();
  109. console.debug('✓ 省份已选择:', data.province);
  110. const cityTrigger = this.page.locator('[data-testid="area-select-city"]');
  111. await cityTrigger.click();
  112. await this.page.getByRole('option', { name: data.city }).click();
  113. console.debug('✓ 城市已选择:', data.city);
  114. console.debug('表单填写完成');
  115. }
  116. async submitForm() {
  117. // 收集网络响应
  118. const responses: any[] = [];
  119. // 监听所有网络请求
  120. this.page.on('response', async (response) => {
  121. const url = response.url();
  122. if (url.includes('disabled-person') || url.includes('aggregated')) {
  123. const requestBody = response.request()?.postData();
  124. const responseBody = await response.text().catch(() => '');
  125. let jsonBody = null;
  126. try {
  127. jsonBody = JSON.parse(responseBody);
  128. } catch (e) {
  129. // 不是 JSON
  130. }
  131. responses.push({
  132. url,
  133. method: response.request()?.method(),
  134. status: response.status(),
  135. ok: response.ok(),
  136. requestHeaders: await response.allHeaders().catch(() => ({})),
  137. responseHeaders: await response.allHeaders().catch(() => ({})),
  138. requestBody: requestBody ? JSON.parse(requestBody) : null,
  139. responseBody: jsonBody || responseBody,
  140. statusText: response.statusText()
  141. });
  142. }
  143. });
  144. // 点击创建按钮
  145. const submitButton = this.page.getByRole('button', { name: '创建' });
  146. await submitButton.click();
  147. // 等待网络请求完成
  148. await this.page.waitForLoadState('networkidle', { timeout: 10000 });
  149. // 等待一段时间让 Toast 消息显示
  150. await this.page.waitForTimeout(2000);
  151. // 检查是否有错误提示
  152. const errorToast = this.page.locator('[data-sonner-toast][data-type="error"]');
  153. const successToast = this.page.locator('[data-sonner-toast][data-type="success"]');
  154. const hasError = await errorToast.count() > 0;
  155. const hasSuccess = await successToast.count() > 0;
  156. let errorMessage = null;
  157. let successMessage = null;
  158. if (hasError) {
  159. errorMessage = await errorToast.first().textContent();
  160. }
  161. if (hasSuccess) {
  162. successMessage = await successToast.first().textContent();
  163. }
  164. return {
  165. responses,
  166. hasError,
  167. hasSuccess,
  168. errorMessage,
  169. successMessage
  170. };
  171. }
  172. async searchByName(name: string) {
  173. await this.keywordSearchInput.fill(name);
  174. await this.searchButton.click();
  175. await this.page.waitForLoadState('networkidle');
  176. await this.page.waitForTimeout(1000);
  177. }
  178. async personExists(name: string): Promise<boolean> {
  179. const personRow = this.personTable.locator('tbody tr').filter({ hasText: name }).first();
  180. return (await personRow.count()) > 0;
  181. }
  182. /**
  183. * 上传照片
  184. * @param photoType 照片类型(身份证照片、残疾证照片、个人照片、其他照片)
  185. * @param fileName 文件名
  186. */
  187. async uploadPhoto(photoType: string, fileName: string) {
  188. // 找到对应照片类型的上传按钮区域
  189. const photoSection = this.page.locator('text=' + photoType).first();
  190. await photoSection.scrollIntoViewIfNeeded();
  191. // 查找该类型照片区域的"上传"按钮
  192. const uploadButton = photoSection.locator('xpath=ancestor::div[contains(@class, "space-y-")]').first()
  193. .getByRole('button', { name: /上传/ }).first();
  194. // 创建测试文件
  195. const fileInput = await uploadButton.evaluateHandle((el: any) => {
  196. const input = el.querySelector('input[type="file"]');
  197. return input;
  198. });
  199. // 使用临时文件上传
  200. const file = {
  201. name: fileName,
  202. mimeType: 'image/jpeg',
  203. buffer: Buffer.from('fake image content')
  204. };
  205. await fileInput.uploadFile(file as any);
  206. await this.page.waitForTimeout(500); // 等待上传处理
  207. console.log(` ✓ 上传照片: ${photoType} - ${fileName}`);
  208. }
  209. /**
  210. * 添加银行卡(内联表单模式)
  211. * @param bankCard 银行卡信息
  212. */
  213. async addBankCard(bankCard: {
  214. bankName: string;
  215. subBankName: string;
  216. cardNumber: string;
  217. cardholderName: string;
  218. cardType?: string;
  219. isDefault?: boolean;
  220. }) {
  221. // 滚动到银行卡管理区域
  222. const bankCardLabel = this.page.getByText('银行卡管理');
  223. await bankCardLabel.scrollIntoViewIfNeeded();
  224. await this.page.waitForTimeout(300);
  225. // 获取当前银行卡数量
  226. const currentCardCount = await this.page.locator('[data-testid^="remove-bank-card-"]').count();
  227. // 点击"添加银行卡"按钮
  228. const addButton = this.page.locator('[data-testid="add-bank-card-button"]');
  229. await addButton.click();
  230. await this.page.waitForTimeout(500);
  231. // 等待新的银行卡卡片出现
  232. const newCardCount = await this.page.locator('[data-testid^="remove-bank-card-"]').count();
  233. if (newCardCount !== currentCardCount + 1) {
  234. throw new Error(`添加银行卡失败:预期 ${currentCardCount + 1} 张,实际 ${newCardCount} 张`);
  235. }
  236. // 新添加的银行卡索引
  237. const cardIndex = currentCardCount;
  238. // 1. 选择银行名称
  239. const bankSelectTrigger = this.page.locator(`[data-testid="bank-select-${cardIndex}"]`);
  240. await bankSelectTrigger.click();
  241. await this.page.waitForTimeout(300);
  242. await this.page.getByRole('option', { name: bankCard.bankName }).click();
  243. // 2. 填写发卡支行
  244. const subBankInput = this.page.locator(`[data-testid="sub-bank-name-input-${cardIndex}"]`);
  245. await subBankInput.fill(bankCard.subBankName);
  246. // 3. 填写银行卡号
  247. const cardNumberInput = this.page.locator(`[data-testid="card-number-input-${cardIndex}"]`);
  248. await cardNumberInput.fill(bankCard.cardNumber);
  249. // 4. 填写持卡人姓名
  250. const cardholderInput = this.page.locator(`[data-testid="cardholder-name-input-${cardIndex}"]`);
  251. await cardholderInput.fill(bankCard.cardholderName);
  252. // 5. 选择银行卡类型(可选)
  253. if (bankCard.cardType) {
  254. const cardTypeTrigger = this.page.locator(`[data-testid="card-type-select-${cardIndex}"]`);
  255. await cardTypeTrigger.click();
  256. await this.page.waitForTimeout(300);
  257. await this.page.getByRole('option', { name: bankCard.cardType }).click();
  258. }
  259. // 6. 设置默认银行卡(可选)
  260. if (bankCard.isDefault) {
  261. const defaultSwitch = this.page.locator(`[data-testid="default-card-switch-${cardIndex}"]`);
  262. const isChecked = await defaultSwitch.isChecked();
  263. if (!isChecked) {
  264. await defaultSwitch.click();
  265. }
  266. }
  267. console.log(` ✓ 添加银行卡: ${bankCard.bankName} - ${bankCard.cardNumber}`);
  268. return cardIndex;
  269. }
  270. /**
  271. * 编辑指定索引的银行卡
  272. * @param cardIndex 银行卡索引(从0开始)
  273. * @param updatedData 更新的银行卡数据
  274. */
  275. async editBankCard(cardIndex: number, updatedData: {
  276. bankName?: string;
  277. subBankName?: string;
  278. cardNumber?: string;
  279. cardholderName?: string;
  280. cardType?: string;
  281. isDefault?: boolean;
  282. }) {
  283. console.debug(` 编辑银行卡 ${cardIndex}`);
  284. // 编辑银行名称
  285. if (updatedData.bankName !== undefined) {
  286. const bankSelectTrigger = this.page.locator(`[data-testid="bank-select-${cardIndex}"]`);
  287. await bankSelectTrigger.click();
  288. await this.page.waitForTimeout(300);
  289. await this.page.getByRole('option', { name: updatedData.bankName }).click();
  290. console.debug(` ✓ 更新银行名称: ${updatedData.bankName}`);
  291. }
  292. // 编辑发卡支行
  293. if (updatedData.subBankName !== undefined) {
  294. const subBankInput = this.page.locator(`[data-testid="sub-bank-name-input-${cardIndex}"]`);
  295. await subBankInput.clear();
  296. await subBankInput.fill(updatedData.subBankName);
  297. console.debug(` ✓ 更新发卡支行: ${updatedData.subBankName}`);
  298. }
  299. // 编辑银行卡号
  300. if (updatedData.cardNumber !== undefined) {
  301. const cardNumberInput = this.page.locator(`[data-testid="card-number-input-${cardIndex}"]`);
  302. await cardNumberInput.clear();
  303. await cardNumberInput.fill(updatedData.cardNumber);
  304. console.debug(` ✓ 更新银行卡号: ${updatedData.cardNumber}`);
  305. }
  306. // 编辑持卡人姓名
  307. if (updatedData.cardholderName !== undefined) {
  308. const cardholderInput = this.page.locator(`[data-testid="cardholder-name-input-${cardIndex}"]`);
  309. await cardholderInput.clear();
  310. await cardholderInput.fill(updatedData.cardholderName);
  311. console.debug(` ✓ 更新持卡人姓名: ${updatedData.cardholderName}`);
  312. }
  313. // 编辑银行卡类型
  314. if (updatedData.cardType !== undefined) {
  315. const cardTypeTrigger = this.page.locator(`[data-testid="card-type-select-${cardIndex}"]`);
  316. await cardTypeTrigger.click();
  317. await this.page.waitForTimeout(300);
  318. await this.page.getByRole('option', { name: updatedData.cardType }).click();
  319. console.debug(` ✓ 更新银行卡类型: ${updatedData.cardType}`);
  320. }
  321. // 设置默认银行卡
  322. if (updatedData.isDefault !== undefined) {
  323. const defaultSwitch = this.page.locator(`[data-testid="default-card-switch-${cardIndex}"]`);
  324. const isChecked = await defaultSwitch.isChecked();
  325. if (isChecked !== updatedData.isDefault) {
  326. await defaultSwitch.click();
  327. console.debug(` ✓ 设置默认银行卡: ${updatedData.isDefault}`);
  328. }
  329. }
  330. console.debug(` ✓ 银行卡 ${cardIndex} 编辑完成`);
  331. }
  332. /**
  333. * 删除指定索引的银行卡
  334. * @param cardIndex 银行卡索引(从0开始)
  335. */
  336. async deleteBankCard(cardIndex: number) {
  337. console.debug(` 删除银行卡 ${cardIndex}`);
  338. const removeButton = this.page.locator(`[data-testid="remove-bank-card-${cardIndex}"]`);
  339. await removeButton.click();
  340. await this.page.waitForTimeout(500);
  341. console.debug(` ✓ 银行卡 ${cardIndex} 已删除`);
  342. }
  343. /**
  344. * 获取银行卡列表
  345. * @returns 银行卡号数组
  346. */
  347. async getBankCardList(): Promise<string[]> {
  348. const cards: string[] = [];
  349. const cardCount = await this.page.locator('[data-testid^="remove-bank-card-"]').count();
  350. for (let i = 0; i < cardCount; i++) {
  351. const cardNumberInput = this.page.locator(`[data-testid="card-number-input-${i}"]`);
  352. const cardNumber = await cardNumberInput.inputValue();
  353. cards.push(cardNumber);
  354. }
  355. return cards;
  356. }
  357. /**
  358. * 获取默认银行卡的索引
  359. * @returns 默认银行卡的索引,如果没有则返回 null
  360. */
  361. async getDefaultBankCardIndex(): Promise<number | null> {
  362. const cardCount = await this.page.locator('[data-testid^="remove-bank-card-"]').count();
  363. for (let i = 0; i < cardCount; i++) {
  364. const defaultSwitch = this.page.locator(`[data-testid="default-card-switch-${i}"]`);
  365. const isChecked = await defaultSwitch.isChecked();
  366. if (isChecked) {
  367. return i;
  368. }
  369. }
  370. return null;
  371. }
  372. /**
  373. * 获取当前银行卡数量
  374. * @returns 银行卡数量
  375. */
  376. async getBankCardCount(): Promise<number> {
  377. return await this.page.locator('[data-testid^="remove-bank-card-"]').count();
  378. }
  379. /**
  380. * 检查添加银行卡按钮是否被禁用
  381. * @returns 是否禁用
  382. */
  383. async isAddBankCardButtonDisabled(): Promise<boolean> {
  384. const addButton = this.page.locator('[data-testid="add-bank-card-button"]');
  385. return await addButton.isDisabled();
  386. }
  387. /**
  388. * 添加备注
  389. * @param remark 备注信息
  390. */
  391. async addRemark(remark: {
  392. content: string;
  393. isSpecialNeeds?: boolean;
  394. }) {
  395. // 点击"添加备注"按钮
  396. const addRemarkButton = this.page.getByRole('button', { name: /添加备注/ });
  397. await addRemarkButton.click();
  398. await this.page.waitForTimeout(300);
  399. // 填写备注内容
  400. const remarkTextarea = this.page.getByPlaceholder(/请输入备注内容/).last();
  401. await remarkTextarea.fill(remark.content);
  402. // 标记特殊需求(如果需要)
  403. if (remark.isSpecialNeeds) {
  404. const specialNeedsCheckbox = this.page.getByRole('checkbox', { name: /特殊需求/ });
  405. const isChecked = await specialNeedsCheckbox.isChecked();
  406. if (!isChecked) {
  407. await specialNeedsCheckbox.click();
  408. }
  409. }
  410. console.log(` ✓ 添加备注: ${remark.content.substring(0, 20)}...`);
  411. }
  412. /**
  413. * 添加回访记录
  414. * @param visit 回访信息
  415. */
  416. async addVisit(visit: {
  417. visitDate: string;
  418. visitType: string;
  419. visitContent: string;
  420. visitResult?: string;
  421. nextVisitDate?: string;
  422. }) {
  423. // 点击"添加回访"按钮
  424. const addVisitButton = this.page.getByRole('button', { name: /添加回访/ });
  425. await addVisitButton.click();
  426. await this.page.waitForTimeout(300);
  427. // 填写回访信息
  428. await this.page.getByLabel(/回访日期/).fill(visit.visitDate);
  429. await selectRadixOption(this.page, '回访类型', visit.visitType);
  430. // 查找回访内容输入框(可能有多个,使用最后一个)
  431. const visitContentTextarea = this.page.locator('textarea').filter({ hasText: '' }).last();
  432. await visitContentTextarea.fill(visit.visitContent);
  433. // 填写回访结果(可选)
  434. if (visit.visitResult) {
  435. const resultTextareas = this.page.locator('textarea');
  436. const count = await resultTextareas.count();
  437. if (count > 0) {
  438. await resultTextareas.nth(count - 1).fill(visit.visitResult);
  439. }
  440. }
  441. // 填写下一次回访日期(可选)
  442. if (visit.nextVisitDate) {
  443. const nextDateInput = this.page.getByLabel(/下次回访日期/);
  444. await nextDateInput.fill(visit.nextVisitDate);
  445. }
  446. console.log(` ✓ 添加回访: ${visit.visitType} - ${visit.visitDate}`);
  447. }
  448. /**
  449. * 滚动表单到指定区域
  450. * @param sectionName 区域名称
  451. */
  452. async scrollToSection(sectionName: string) {
  453. const section = this.page.locator(`text=${sectionName}`).first();
  454. await section.scrollIntoViewIfNeeded();
  455. await this.page.waitForTimeout(300);
  456. }
  457. /**
  458. * 等待对话框关闭
  459. */
  460. async waitForDialogClosed() {
  461. const dialog = this.page.locator('[role="dialog"]');
  462. await dialog.waitFor({ state: 'hidden', timeout: 5000 }).catch(() => {});
  463. await this.page.waitForTimeout(500);
  464. }
  465. /**
  466. * 取消对话框
  467. */
  468. async cancelDialog() {
  469. const cancelButton = this.page.getByRole('button', { name: '取消' });
  470. await cancelButton.click();
  471. await this.waitForDialogClosed();
  472. }
  473. /**
  474. * 添加备注(内联表单模式)
  475. * @param content 备注内容
  476. * @param options 选项
  477. */
  478. async addNote(content: string, options?: { isSpecialNeeds?: boolean }): Promise<number> {
  479. // 点击"添加备注"按钮
  480. const addButton = this.page.locator('[data-testid="add-remark-button"]');
  481. await addButton.click();
  482. await this.page.waitForTimeout(300);
  483. // 获取当前备注数量
  484. const noteCount = await this.getNoteCount();
  485. const noteIndex = noteCount > 0 ? noteCount - 1 : 0;
  486. // 填写备注内容
  487. const textarea = this.page.locator(`[data-testid="remark-content-textarea-${noteIndex}"]`);
  488. await textarea.fill(content);
  489. // 标记特殊需求(如果需要)
  490. if (options?.isSpecialNeeds) {
  491. const switchControl = this.page.locator(`[data-testid="special-needs-switch-${noteIndex}"]`);
  492. const isChecked = await switchControl.isChecked();
  493. if (!isChecked) {
  494. await switchControl.click();
  495. }
  496. }
  497. console.debug(` ✓ 添加备注: ${content.substring(0, 30)}...`);
  498. return noteIndex;
  499. }
  500. /**
  501. * 编辑指定索引的备注
  502. * @param index 备注索引(从0开始)
  503. * @param content 更新的备注内容
  504. */
  505. async editNote(index: number, content: string): Promise<void> {
  506. console.debug(` 编辑备注 ${index}`);
  507. const textarea = this.page.locator(`[data-testid="remark-content-textarea-${index}"]`);
  508. await textarea.clear();
  509. await textarea.fill(content);
  510. console.debug(` ✓ 备注 ${index} 编辑完成`);
  511. }
  512. /**
  513. * 删除指定索引的备注
  514. * @param index 备注索引(从0开始)
  515. */
  516. async deleteNote(index: number): Promise<void> {
  517. console.debug(` 删除备注 ${index}`);
  518. const removeButton = this.page.locator(`[data-testid="remove-remark-${index}"]`);
  519. await removeButton.click();
  520. await this.page.waitForTimeout(300);
  521. console.debug(` ✓ 备注 ${index} 已删除`);
  522. }
  523. /**
  524. * 获取备注列表
  525. * @returns 备注内容数组
  526. */
  527. async getNoteList(): Promise<string[]> {
  528. const notes: string[] = [];
  529. const noteCount = await this.page.locator('[data-testid^="remark-content-textarea-"]').count();
  530. for (let i = 0; i < noteCount; i++) {
  531. const textarea = this.page.locator(`[data-testid="remark-content-textarea-${i}"]`);
  532. const content = await textarea.inputValue();
  533. notes.push(content);
  534. }
  535. return notes;
  536. }
  537. /**
  538. * 获取备注数量
  539. * @returns 备注数量
  540. */
  541. async getNoteCount(): Promise<number> {
  542. return await this.page.locator('[data-testid^="remark-content-textarea-"]').count();
  543. }
  544. /**
  545. * 获取指定备注的特殊需求状态
  546. * @param index 备注索引(从0开始)
  547. * @returns 是否标记为特殊需求
  548. */
  549. async getNoteSpecialNeedsStatus(index: number): Promise<boolean> {
  550. const switchControl = this.page.locator(`[data-testid="special-needs-switch-${index}"]`);
  551. return await switchControl.isChecked();
  552. }
  553. /**
  554. * 检查添加备注按钮是否被禁用
  555. * @returns 是否禁用
  556. */
  557. async isAddNoteButtonDisabled(): Promise<boolean> {
  558. const addButton = this.page.locator('[data-testid="add-remark-button"]');
  559. return await addButton.isDisabled();
  560. }
  561. }