feat(apply): open product page on left double click

This commit is contained in:
chengma
2026-07-20 11:22:26 +08:00
parent 9f43e5547a
commit 7dbfcb5a24
11 changed files with 445 additions and 5 deletions
+77
View File
@@ -15,7 +15,9 @@ except ModuleNotFoundError: # pragma: no cover - GUI import guard
from .. import (
ai,
appconfig,
chrome,
cmhub_models,
editor,
image_studio,
image_studio_export,
image_studio_generation,
@@ -1237,6 +1239,81 @@ class GenerateWorker(BaseWorker):
except Exception:
return
class ProductTabOpenWorker(BaseWorker):
"""后台打开单个商品详情页供人工查看,不修改本地任务数据。"""
def __init__(self, alias, item_id, db_path=None, config=None):
super().__init__()
self.alias = str(alias or "").strip()
self.item_id = str(item_id or "").strip()
self.db_path = db_path
self.config = config
def execute(self):
if not self.alias:
return self._blocked("ACCOUNT_NOT_FOUND", "任务未关联账号,请先检查导入数据。")
if not self.item_id:
return self._blocked("ITEM_ID_EMPTY", "任务缺少商品ID,无法打开商品详情页。")
try:
account = db.get_account_by_alias(self.alias, path=self.db_path)
except Exception:
return self._blocked(
"ACCOUNT_LOOKUP_FAILED",
"账号信息读取失败,请先到④账号管理检查账号配置。",
)
if account is None:
return self._blocked(
"ACCOUNT_NOT_FOUND",
f"未找到账号「{self.alias}」,请先到④账号管理配置并登录。",
)
if not chrome.is_running(account.debug_port):
return self._blocked(
"CHROME_NOT_RUNNING",
f"账号「{account.account_name}」的 Chrome 未启动,请先到④账号管理启动并人工登录蝦皮。",
account=account,
)
try:
result = editor.open_or_focus_product_tab(account, self.item_id)
except editor.EditorError as exc:
return self._blocked(
"OPEN_PRODUCT_FAILED",
self._editor_error_message(exc, account),
account=account,
)
except Exception:
return self._blocked(
"CDP_UNAVAILABLE",
f"无法连接账号「{account.account_name}」的 Chrome,请先到④账号管理确认已启动并登录。",
account=account,
)
return {
"ok": True,
"alias": account.alias,
"account_name": account.account_name,
"item_id": self.item_id,
"created": bool(result.get("created")),
"target_id": result.get("target_id"),
}
def _blocked(self, reason, message, account=None):
return {
"ok": False,
"reason": reason,
"message": message,
"alias": getattr(account, "alias", self.alias),
"account_name": getattr(account, "account_name", ""),
"item_id": self.item_id,
}
def _editor_error_message(self, exc, account):
detail = diagnostics.redact_log_text(str(exc) or "")
if "商品失效" in detail:
return detail
if "登录" in detail:
return f"账号「{account.account_name}」未登录,请先到④账号管理人工登录蝦皮。"
return "打开商品详情页失败,请先到④账号管理确认 Chrome 已启动、已人工登录,并检查商品状态。"
class ApplyWorker(BaseWorker):
"""Apply generated title/cover changes, optionally previewing or grouping by account."""