统一控制延时
This commit is contained in:
+27
-26
@@ -14,7 +14,8 @@
|
||||
*/
|
||||
|
||||
import type { MatchedFormField } from "./types"
|
||||
import { delay, forceSetValue, closePopup } from "./autofill"
|
||||
import { forceSetValue, closePopup } from "./autofill"
|
||||
import { delay } from "~utils/delay"
|
||||
|
||||
// ============ 常量 ============
|
||||
|
||||
@@ -560,7 +561,7 @@ async function detectNavButtons(panel: CalendarPanelInfo): Promise<NavButtons> {
|
||||
|
||||
// 点击按钮
|
||||
btn.click()
|
||||
await delay(150)
|
||||
await delay("mid")
|
||||
|
||||
const afterYear = readCurrentYear(panel)
|
||||
const afterMonth = readCurrentMonth(panel)
|
||||
@@ -626,21 +627,21 @@ async function detectNavButtons(panel: CalendarPanelInfo): Promise<NavButtons> {
|
||||
|
||||
if (restoreBtn) {
|
||||
restoreBtn.click()
|
||||
await delay(150)
|
||||
await delay("mid")
|
||||
} else {
|
||||
// 没有已知反向按钮,尝试用位置对称的按钮恢复
|
||||
// 如果当前按钮在前半部分,对称按钮在后半部分
|
||||
const symmetricIdx = buttons.length - 1 - i
|
||||
if (symmetricIdx !== i && symmetricIdx >= 0 && symmetricIdx < buttons.length) {
|
||||
buttons[symmetricIdx].click()
|
||||
await delay(150)
|
||||
await delay("mid")
|
||||
// 验证是否恢复
|
||||
const checkYear = readCurrentYear(panel)
|
||||
const checkMonth = readCurrentMonth(panel)
|
||||
if (checkYear !== beforeYear || checkMonth !== beforeMonth) {
|
||||
// 没恢复成功,再点一次原按钮的对称位置
|
||||
buttons[symmetricIdx].click()
|
||||
await delay(150)
|
||||
await delay("mid")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -684,7 +685,7 @@ async function restoreToDate(
|
||||
if (yearBtn) {
|
||||
for (let i = 0; i < Math.abs(yearDiff) && i < 50; i++) {
|
||||
yearBtn.click()
|
||||
await delay(80)
|
||||
await delay("low")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -700,7 +701,7 @@ async function restoreToDate(
|
||||
if (monthBtn) {
|
||||
for (let i = 0; i < Math.abs(monthDiff) && i < 24; i++) {
|
||||
monthBtn.click()
|
||||
await delay(80)
|
||||
await delay("low")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -731,7 +732,7 @@ async function navigateToYearMonth(
|
||||
console.log(`OfferPie: [datePicker] 年份需要${yearDiff > 0 ? "增加" : "减少"} ${steps} 年`)
|
||||
for (let i = 0; i < steps && i < 100; i++) {
|
||||
yearBtn.click()
|
||||
await delay(100)
|
||||
await delay("mid")
|
||||
// 验证年份确实变了
|
||||
const newYear = readCurrentYear(panel)
|
||||
if (newYear === targetYear) break
|
||||
@@ -744,7 +745,7 @@ async function navigateToYearMonth(
|
||||
console.log(`OfferPie: [datePicker] 无年份按钮,用月份按钮跨 ${Math.abs(totalMonthDiff)} 个月`)
|
||||
for (let i = 0; i < Math.abs(totalMonthDiff) && i < 200; i++) {
|
||||
monthBtn.click()
|
||||
await delay(60)
|
||||
await delay("low")
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -770,7 +771,7 @@ async function navigateToYearMonth(
|
||||
console.log(`OfferPie: [datePicker] 月份需要${monthDiff > 0 ? "增加" : "减少"} ${steps} 月`)
|
||||
for (let i = 0; i < steps && i < 24; i++) {
|
||||
btn.click()
|
||||
await delay(100)
|
||||
await delay("mid")
|
||||
const newMonth = readCurrentMonth(panel)
|
||||
if (newMonth === targetMonth) break
|
||||
}
|
||||
@@ -887,7 +888,7 @@ async function tryFillMonthPanel(
|
||||
console.log(`OfferPie: [datePicker] 月份面板年份导航: ${yearDiff > 0 ? "+" : ""}${yearDiff}年`)
|
||||
for (let i = 0; i < steps && i < 50; i++) {
|
||||
yearBtn.click()
|
||||
await delay(150)
|
||||
await delay("mid")
|
||||
const newYear = readCurrentYear(tempPanel)
|
||||
if (newYear === targetYear) break
|
||||
}
|
||||
@@ -901,7 +902,7 @@ async function tryFillMonthPanel(
|
||||
const steps = Math.abs(yearDiff)
|
||||
for (let i = 0; i < steps && i < 50; i++) {
|
||||
btn.click()
|
||||
await delay(150)
|
||||
await delay("mid")
|
||||
const newYear = readCurrentYear(tempPanel)
|
||||
if (newYear === targetYear) break
|
||||
}
|
||||
@@ -926,9 +927,9 @@ async function tryFillMonthPanel(
|
||||
if (inner && isVisible(inner)) deepest = inner as HTMLElement
|
||||
|
||||
deepest.click()
|
||||
await delay(100)
|
||||
await delay("mid")
|
||||
if (deepest !== cell) cell.click()
|
||||
await delay(300)
|
||||
await delay("mid")
|
||||
await closePopup(inputElement)
|
||||
console.log(`OfferPie: ✅ [月份选择器] 已选择 "${labelText}" = "${fillValue}" (${targetYear}年${targetMonth}月)`)
|
||||
return true
|
||||
@@ -1059,12 +1060,12 @@ async function clickDayCell(
|
||||
|
||||
// 三层点击:叶子 → 父级 → 原始元素
|
||||
deepest.click()
|
||||
await delay(50)
|
||||
await delay("low")
|
||||
if (deepest.parentElement) deepest.parentElement.click()
|
||||
await delay(50)
|
||||
await delay("low")
|
||||
if (cell !== deepest && cell !== deepest.parentElement) (cell as HTMLElement).click()
|
||||
|
||||
await delay(300)
|
||||
await delay("mid")
|
||||
await closePopup(inputElement)
|
||||
console.log(`OfferPie: ✅ [日期] 已选择 "${labelText}" = "${fillValue}" (日期 ${targetDay})`)
|
||||
return true
|
||||
@@ -1158,9 +1159,9 @@ export async function fillDatePicker(field: MatchedFormField): Promise<boolean>
|
||||
console.warn(`OfferPie: [datePicker] 无法解析日期值: "${fillValue}"`)
|
||||
// 兜底:直接写入值 + Enter
|
||||
forceSetValue(inputElement, fillValue)
|
||||
await delay(300)
|
||||
await delay("mid")
|
||||
inputElement.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", code: "Enter", keyCode: 13, bubbles: true }))
|
||||
await delay(300)
|
||||
await delay("mid")
|
||||
await closePopup(inputElement as HTMLElement)
|
||||
return true
|
||||
}
|
||||
@@ -1170,7 +1171,7 @@ export async function fillDatePicker(field: MatchedFormField): Promise<boolean>
|
||||
|
||||
// ---- 步骤2:写入日期字符串(触发面板联动) ----
|
||||
forceSetValue(inputElement, fillValue)
|
||||
await delay(500)
|
||||
await delay("high")
|
||||
|
||||
// ---- 步骤2.5:如果只有年月(day=0),检测是否为月份面板 ----
|
||||
if (targetDay === 0) {
|
||||
@@ -1208,13 +1209,13 @@ export async function fillDatePicker(field: MatchedFormField): Promise<boolean>
|
||||
if (targetDay === 0) {
|
||||
// 只需要年月,不需要点日期格子。尝试点击月份面板中的月份
|
||||
// 如果导航成功了,可能面板已经关闭(某些组件选完月份自动关闭)
|
||||
await delay(200)
|
||||
await delay("mid")
|
||||
await closePopup(inputElement as HTMLElement)
|
||||
console.log(`OfferPie: ✅ [日期] 已导航到 "${labelText}" = "${fillValue}" (${targetYear}年${targetMonth}月)`)
|
||||
return true
|
||||
}
|
||||
|
||||
await delay(200)
|
||||
await delay("mid")
|
||||
const clicked = await clickDayCell(panel, targetDay, labelText, fillValue, inputElement as HTMLElement)
|
||||
if (clicked) return true
|
||||
|
||||
@@ -1250,10 +1251,10 @@ async function fallbackClickDay(
|
||||
break
|
||||
}
|
||||
}
|
||||
deepest.click(); await delay(50)
|
||||
if (deepest.parentElement) deepest.parentElement.click(); await delay(50)
|
||||
deepest.click(); await delay("low")
|
||||
if (deepest.parentElement) deepest.parentElement.click(); await delay("low")
|
||||
if (cell !== deepest && cell !== deepest.parentElement) (cell as HTMLElement).click()
|
||||
await delay(300)
|
||||
await delay("mid")
|
||||
await closePopup(inputElement)
|
||||
console.log(`OfferPie: ✅ [日期-兜底] 已选择 "${labelText}" = "${fillValue}" (日期 ${targetDay})`)
|
||||
return true
|
||||
@@ -1263,7 +1264,7 @@ async function fallbackClickDay(
|
||||
// 最终兜底:Enter 确认
|
||||
console.warn(`OfferPie: ⚠ [日期] "${labelText}" 未找到日历格子,Enter 确认`)
|
||||
inputElement.dispatchEvent(new KeyboardEvent("keydown", { key: "Enter", code: "Enter", keyCode: 13, bubbles: true }))
|
||||
await delay(300)
|
||||
await delay("mid")
|
||||
await closePopup(inputElement)
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user