chore(shipping-notice): 统一货代发货生命周期阶段命名并优化全链路业务逻辑

This commit is contained in:
hugo committed 2026-08-17 19:56:51 +08:00
1 parent 5ef8329bd8
commit 4ec4e57005
183 files changed
+14653 -3936

No files matched your search

+90 -2
View File
@@ -197,7 +197,53 @@ def _dsv_dropdown_text_visible(page: Any, text: str, *, timeout_ms: int = 1_000)
return False
def _click_dsv_menu_item(page: Any, text: str, *, next_text: str = "") -> None:
def _try_dsv_menu_item_fast_path(page: Any, text: str, *, next_text: str = "") -> bool:
"""
尝试一次 DSV 菜单标准点击,并确认预期下级已展开。
核心逻辑:真实页面已验证的菜单通常可由精确文本一次 hover/click 打开;
仅在明确看到 next_text 后才返回成功,避免把点击事件已发送误当作层级已切换。
Args:
page: Playwright Page 对象。
text: 当前菜单文本。
next_text: 点击后应出现的下级文本;为空时只确认点击本身完成。
Returns:
bool: 下一级已确认出现或无需确认时为 True;其余情况为 False。
"""
for container in ("#report-mega-legacy", ".mega-dropdown-menu", ".dropdown-menu"):
try:
locator = page.locator(container).get_by_text(text, exact=True).first
locator.wait_for(state="visible", timeout=1_500)
locator.hover(timeout=1_000)
locator.click(timeout=1_500)
if not next_text or _dsv_dropdown_text_visible(page, next_text, timeout_ms=1_500):
return True
except Exception:
continue
return False
def _try_dsv_report_group_fast_path(page: Any, text: str, *, next_text: str = "") -> bool:
"""
尝试一次 Report Group 标准点击,并确认目标报表已展开。
核心逻辑:Report Group 使用精确文本,避免旧逻辑对多个宽泛 selector
分别等待十秒;失败时由兼容路径继续处理 hover 丢失等旧页面结构。
Args:
page: Playwright Page 对象。
text: Report Group 文本。
next_text: 点击后应出现的报表名称。
Returns:
bool: 报表文本确认出现时为 True,否则为 False。
"""
return _try_dsv_menu_item_fast_path(page, text, next_text=next_text)
def _click_dsv_menu_item_compat(page: Any, text: str, *, next_text: str = "") -> None:
"""
点击 DSV 级联菜单项,并在需要时确认下一级目标已经出现。
@@ -320,7 +366,7 @@ def _click_dsv_menu_item(page: Any, text: str, *, next_text: str = "") -> None:
raise RuntimeError(f"DSV menu item was not found: {text}")
def _click_dsv_report_group(page: Any, text: str, *, next_text: str = "") -> None:
def _click_dsv_report_group_compat(page: Any, text: str, *, next_text: str = "") -> None:
"""
点击 DSV Report Group,并在需要时确认目标报表已经出现在菜单中。
@@ -418,6 +464,48 @@ def _click_dsv_report_group(page: Any, text: str, *, next_text: str = "") -> Non
raise RuntimeError(f"DSV report group was not found: {text}")
def _click_dsv_menu_item(page: Any, text: str, *, next_text: str = "") -> None:
"""
点击 DSV 级联菜单,并在标准路径失败后回退全部兼容动作。
核心逻辑:先走一次精确文本 hover/click 快速路径;只有下一级没有被确认时,
才调用原有多 selector、多输入方式的兼容逻辑,兼顾性能和历史页面兼容性。
Args:
page: Playwright Page 对象。
text: 当前菜单文案。
next_text: 预期出现的下一级菜单文案。
"""
text = str(text or "").strip()
if not text:
raise RuntimeError("DSV menu item text is empty")
if _try_dsv_menu_item_fast_path(page, text, next_text=next_text):
print(f"[dsv-navigation] fast-path menu item selected target={text!r}")
return
_click_dsv_menu_item_compat(page, text, next_text=next_text)
def _click_dsv_report_group(page: Any, text: str, *, next_text: str = "") -> None:
"""
点击 DSV Report Group,并在标准路径失败后回退完整兼容链。
核心逻辑:快速路径确认报表名称已出现才结束;否则保留历史多动作策略,
防止旧页面的 hover 状态不稳定时降低导出成功率。
Args:
page: Playwright Page 对象。
text: Report Group 文案。
next_text: 预期出现的报表名称。
"""
text = str(text or "").strip()
if not text:
raise RuntimeError("DSV report group text is empty")
if _try_dsv_report_group_fast_path(page, text, next_text=next_text):
print(f"[dsv-navigation] fast-path report group selected target={text!r}")
return
_click_dsv_report_group_compat(page, text, next_text=next_text)
def _click_dsv_view_report(page: Any) -> None:
"""
点击 SSRS 参数页 View Report。