fix: 修正规格返回后的繁简体复核 (#260)
This commit is contained in:
@@ -597,9 +597,11 @@ def _page_kind(root: ET.Element, current_package: str) -> str:
|
||||
|
||||
|
||||
def _selected(root: ET.Element, target: str) -> bool:
|
||||
"""从最新控件树确认一个规格已选中。"""
|
||||
"""按采购规格的繁简归一化语义确认目标仍明确处于选中状态。"""
|
||||
|
||||
checked_target = target.strip().casefold()
|
||||
checked_target = normalize_spec_text(target)
|
||||
if not checked_target:
|
||||
return False
|
||||
parents = {
|
||||
child: parent
|
||||
for parent in root.iter()
|
||||
@@ -608,8 +610,8 @@ def _selected(root: ET.Element, target: str) -> bool:
|
||||
}
|
||||
for node in root.iter("node"):
|
||||
labels = {
|
||||
node.get("text", "").strip().casefold(),
|
||||
node.get("content-desc", "").strip().casefold(),
|
||||
normalize_spec_text(node.get("text", "")),
|
||||
normalize_spec_text(node.get("content-desc", "")),
|
||||
}
|
||||
if checked_target not in labels:
|
||||
continue
|
||||
@@ -624,7 +626,8 @@ def _selected(root: ET.Element, target: str) -> bool:
|
||||
|
||||
# 选中节点滑出屏幕后,PDD 仍会在顶部“已选”摘要中保留完整文字。
|
||||
return any(
|
||||
label.startswith("已选") and target.strip() in label
|
||||
label.startswith(("已选", "已選", "已选择", "已選擇"))
|
||||
and checked_target in normalize_spec_text(label)
|
||||
for label in _labels(root)
|
||||
)
|
||||
|
||||
@@ -1285,13 +1288,24 @@ class U2PddPurchaseAdapter(PddPurchaseAdapter):
|
||||
|
||||
current_xml = self._dump_hierarchy()
|
||||
root = _parse_xml(current_xml)
|
||||
if _page_kind(root, "") != "order_confirmation" or not _selected(
|
||||
root, expected_snapshot.selected_color
|
||||
):
|
||||
current_page_kind = _page_kind(root, "")
|
||||
if current_page_kind != "order_confirmation":
|
||||
raise PddPurchaseError(
|
||||
"PURCHASE_SPEC_CONTEXT_CHANGED",
|
||||
"等待规格解析期间页面或已选颜色发生变化",
|
||||
"等待规格解析期间页面已离开规格确认页",
|
||||
step="purchase_resolve_options",
|
||||
diagnostics={
|
||||
"context_check": "page_kind",
|
||||
"expected_page_kind": "order_confirmation",
|
||||
"observed_page_kind": current_page_kind,
|
||||
},
|
||||
)
|
||||
if not _selected(root, expected_snapshot.selected_color):
|
||||
raise PddPurchaseError(
|
||||
"PURCHASE_SPEC_CONTEXT_CHANGED",
|
||||
"等待规格解析期间已选颜色发生变化",
|
||||
step="purchase_resolve_options",
|
||||
diagnostics={"context_check": "selected_color"},
|
||||
)
|
||||
|
||||
current_xml = self._restore_purchase_panel_color_region(current_xml)
|
||||
|
||||
Reference in New Issue
Block a user