fix(fg_trace): handle date column index out of range error

Improve robustness by checking if the requested dateIndex is within the available day columns before attempting to locate the element. This prevents a silent failure and provides a clear error message.
This commit is contained in:
duanshuwen committed 2026-04-06 20:17:06 +08:00
1 parent f8ddecc6dd
commit 2b250a58ea
2 files changed
+11 -7

No files matched your search

+1 -1
View File
@@ -1,3 +1,3 @@
```html
<div class="tableContainer___xK0Sl" id="price-reserve-table-container" style="width: 1734px;"><div class="headerRow___i4Ntk"><div class="headerOpt___d3aVu"><div class="roomVsManage-tour-step5" elementtiming="rp-home-tableHeader" data-node-type="main-content">房型排序<span role="img" aria-label="unordered-list" class="anticon anticon-unordered-list" style="margin-left: 6px;"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="unordered-list" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M912 192H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zm0 284H328c-4.4 0-8 3.6-8 8v56c0 4.4 3.6 8 8 8h584c4.4 0 8-3.6 8-8v-56c0-4.4-3.6-8-8-8zM104 228a56 56 0 10112 0 56 56 0 10-112 0zm0 284a56 56 0 10112 0 56 56 0 10-112 0zm0 284a56 56 0 10112 0 56 56 0 10-112 0z"></path></svg></span></div><div>全部展开 &nbsp;<span role="img" aria-label="down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></span></div></div><div class="headerContent___JNzby"><div class="day___QuKiX" style="font-size: 14px;">周三(今天)</div><div class="fontConfig___lUoMm" style="font-size: 14px;">03-11</div></div><div class="headerContent___JNzby"><div class="day___QuKiX" style="font-size: 14px;">周四</div><div class="fontConfig___lUoMm" style="font-size: 14px;">03-12</div></div><div class="headerContent___JNzby"><div class="day___QuKiX" style="font-size: 14px;">周五</div><div class="fontConfig___lUoMm" style="font-size: 14px;">03-13</div></div><div class="headerContent___JNzby dayOff___LszDG"><div class="day___QuKiX" style="font-size: 14px;">周六</div><div class="fontConfig___lUoMm" style="font-size: 14px;">03-14</div></div><div class="headerContent___JNzby"><div class="day___QuKiX" style="font-size: 14px;">周日</div><div class="fontConfig___lUoMm" style="font-size: 14px;">03-15</div></div><div class="headerContent___JNzby"><div class="day___QuKiX" style="font-size: 14px;">周一</div><div class="fontConfig___lUoMm" style="font-size: 14px;">03-16</div></div><div class="headerContent___JNzby"><div class="day___QuKiX" style="font-size: 14px;">周二</div><div class="fontConfig___lUoMm" style="font-size: 14px;">03-17</div></div><div class="headerContent___JNzby"><div class="day___QuKiX" style="font-size: 14px;">周三</div><div class="fontConfig___lUoMm" style="font-size: 14px;">03-18</div></div><div class="headerContent___JNzby"><div class="day___QuKiX" style="font-size: 14px;">周四</div><div class="fontConfig___lUoMm" style="font-size: 14px;">03-19</div></div><div class="headerContent___JNzby"><div class="day___QuKiX" style="font-size: 14px;">周五</div><div class="fontConfig___lUoMm" style="font-size: 14px;">03-20</div></div><div class="headerContent___JNzby dayOff___LszDG"><div class="day___QuKiX" style="font-size: 14px;">周六</div><div class="fontConfig___lUoMm" style="font-size: 14px;">03-21</div></div><div class="headerContent___JNzby"><div class="day___QuKiX" style="font-size: 14px;">周日</div><div class="fontConfig___lUoMm" style="font-size: 14px;">03-22</div></div><div class="headerContent___JNzby"><div class="day___QuKiX" style="font-size: 14px;">周一</div><div class="fontConfig___lUoMm" style="font-size: 14px;">03-23</div></div><div class="headerContent___JNzby"><div class="day___QuKiX" style="font-size: 14px;">周二</div><div class="fontConfig___lUoMm" style="font-size: 14px;">03-24</div></div></div><div><div class="boardRow___p2ZiO roomTypeRow-0"><div class="rpNameCell___S4Cbf" style="width: 226px; padding-right: 24px;"><div class="nameWrapper___vR2_P"><div class="topContent___dNQJv"><div class="flexMain___f0uUn"><span class="isRoomType___lsn8D roomName___zF3pX roomVsManage-tour-step6" style="flex: 1 1 0%;">雅致大床房</span><div class="tagContent___VpAzH"><div class="tagPos___migUC"></div></div></div></div></div><div class="roomTypeOptBtn___X5vJA" style=""><span role="img" aria-label="down" class="anticon anticon-down" style="margin-top: 4px; color: rgb(153, 153, 153);"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></span></div></div><div style="display: flex; margin-left: -8px;"><div class="flex justify-center items-center flex-col" style="width: 106px; display: flex; align-items: center; justify-content: center;"><div class="ant-spinLine truncated
<div class="ant-pro-grid-content"><div class="ant-pro-grid-content-children"><div class="ant-pro-page-container-children-content"><div class="columnWrapper___c2wUd"><div class="ant-spin-nested-loading"><div class="ant-spin-container"><div class="ant-pro-card optionArea___oJUtg"><div class="ant-pro-card-body" style="padding: 10px 12px;"><div class="flex justify-between w-full items-start" data-spm-anchor-id="0.0.0.i3.43d517aetjaKiq"><div class="flex items-center"><div class="ant-space ant-space-horizontal ant-space-align-center roomVsManage-tour-step2" style="gap: 8px;"><div class="ant-space-item" style=""><button type="button" class="ant-btn ant-btn-primary"><span>快速筛选</span></button></div><div class="ant-space-item" style=""><button type="button" class="ant-btn ant-btn-primary ant-btn-background-ghost"><span>批量改房量</span></button></div><div class="ant-space-item"><button type="button" class="ant-btn ant-btn-primary ant-btn-background-ghost"><span>批量改房价</span></button></div><div class="ant-space-item"><button type="button" class="ant-btn ant-btn-primary ant-btn-background-ghost"><div class="flex items-center gap-1">到手价查询<span class="newIcon">new</span></div></button></div></div><button type="button" class="ant-btn ant-dropdown-trigger roomVsManage-tour-step3"><span>更多</span><span role="img" aria-label="down" class="anticon anticon-down"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="down" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 39 17.6 51.7 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z"></path></svg></span></button></div><div class="flex items-center flex-wrap justify-end gap-1" style="gap: 4px;"><div class="ant-checkbox-group checkboxGroup___BEi5L roomVsManage-tour-step4"><span style="color: rgb(92, 95, 102); margin-right: 8px;">显示</span><label class="ant-checkbox-wrapper ant-checkbox-wrapper-checked"><span class="ant-checkbox ant-checkbox-checked"><input type="checkbox" class="ant-checkbox-input" value="2" checked=""><span class="ant-checkbox-inner"></span></span><span>房价</span></label><label class="ant-checkbox-wrapper ant-checkbox-wrapper-checked"><span class="ant-checkbox ant-checkbox-checked"><input type="checkbox" class="ant-checkbox-input" value="1" checked=""><span class="ant-checkbox-inner"></span></span><span>房态</span></label><label class="ant-checkbox-wrapper ant-checkbox-wrapper-checked"><span class="ant-checkbox ant-checkbox-checked"><input type="checkbox" class="ant-checkbox-input" value="4" checked=""><span class="ant-checkbox-inner"></span></span><span>直连产品</span></label></div><div><span class="ant-tooltip-disabled-compatible-wrapper" style="display: inline-block; cursor: not-allowed;"><button disabled="" type="button" class="ant-btn" style="box-shadow: none; border-right: none; pointer-events: none;"><span role="img" aria-label="left" class="anticon anticon-left"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="left" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M724 218.3V141c0-6.7-7.7-10.4-12.9-6.3L260.3 486.8a31.86 31.86 0 000 50.3l450.8 352.1c5.3 4.1 12.9.4 12.9-6.3v-77.3c0-4.9-2.3-9.6-6.1-12.6l-360-281 360-281.1c3.8-3 6.1-7.7 6.1-12.6z"></path></svg></span></button></span><div class="ant-picker" style="box-shadow: none;"><div class="ant-picker-input"><input readonly="" placeholder="请选择日期" title="2026-04-06" size="12" autocomplete="off" value="2026-04-06"><span class="ant-picker-suffix"><span role="img" aria-label="calendar" class="anticon anticon-calendar"><svg viewBox="64 64 896 896" focusable="false" data-icon="calendar" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M880 184H712v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H384v-64c0-4.4-3.6-8-8-8h-56c-4.4 0-8 3.6-8 8v64H144c-17.7 0-32 14.3-32 32v664c0 17.7 14.3 32 32 32h736c17.7 0 32-14.3 32-32V216c0-17.7-14.3-32-32-32zm-40 656H184V460h656v380zM184 392V256h128v48c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-48h256v48c0 4.4 3.6 8 8 8h56c4.4 0 8-3.6 8-8v-48h128v136H184z"></path></svg></span></span></div></div><button type="button" class="ant-btn" style="box-shadow: none; border-left: none;"><span role="img" aria-label="right" class="anticon anticon-right"><svg viewBox="64 64 896 896" focusable="false" class="" data-icon="right" width="1em" height="1em" fill="currentColor" aria-hidden="true"><path d="M765.7 486.8L314.9 134.7A7.97 7.97 0 00302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 000-50.4z"></path></svg></span></button></div></div></div></div></div></div></div><div class="tableContainer___aFTMt"><div class="hidePromotion___yFb6w dateTableWrp___kFEWe"><div class="ant-spin-nested-loading"><div class="ant-spin-container"><div style="min-heiLine truncated
```
+10 -6
View File
@@ -104,13 +104,17 @@ const toggleRoomByDateIndex = async (container, { roomType, dateIndex, operation
}
await roomAnchor.scrollIntoViewIfNeeded();
const row = roomAnchor.locator(
"xpath=ancestor::*[.//div[contains(@class,'boardRow')]][1]",
const boardRow = roomAnchor.locator("xpath=ancestor::div[contains(@class,'boardRow')][1]");
const dayColumns = boardRow.locator(
"xpath=.//div[contains(@class,'switchbar')]/ancestor::div[contains(@class,'flex-col')][1]",
);
const boardRow = row.locator("xpath=.//div[contains(@class,'boardRow')]").first();
const boardColPosition = dateIndex + 2;
const dayColumn = boardRow.locator(`xpath=./div[${boardColPosition}]`);
const dayColumnCount = await dayColumns.count();
if (dateIndex >= dayColumnCount) {
throw new Error(
`Date column out of range for room ${roomType}: index=${dateIndex}, available=${dayColumnCount}`,
);
}
const dayColumn = dayColumns.nth(dateIndex);
const targetStateClass = operation === 'open' ? 'error' : 'success';
const expectedCurrentLabel = operation === 'open' ? '满' : '有';