feat(apply): open product page on left double click
This commit is contained in:
+85
-2
@@ -2,10 +2,16 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from PySide6.QtCore import QModelIndex, Signal
|
||||
|
||||
from ... import product_status
|
||||
from ..models import ApplyTaskTableModel
|
||||
from ..widgets import *
|
||||
from ..workers import ApplyWorker as _RealApplyWorker, WriteBackWorker as _RealWriteBackWorker
|
||||
from ..workers import (
|
||||
ApplyWorker as _RealApplyWorker,
|
||||
ProductTabOpenWorker as _RealProductTabOpenWorker,
|
||||
WriteBackWorker as _RealWriteBackWorker,
|
||||
)
|
||||
|
||||
|
||||
def ApplyWorker(*args, **kwargs):
|
||||
@@ -15,6 +21,27 @@ def ApplyWorker(*args, **kwargs):
|
||||
def WriteBackWorker(*args, **kwargs):
|
||||
return _call_package_attr("WriteBackWorker", _RealWriteBackWorker, *args, **kwargs)
|
||||
|
||||
|
||||
def ProductTabOpenWorker(*args, **kwargs):
|
||||
return _call_package_attr(
|
||||
"ProductTabOpenWorker", _RealProductTabOpenWorker, *args, **kwargs
|
||||
)
|
||||
|
||||
|
||||
class _ApplyTaskTableView(QTableView):
|
||||
"""任务表仅向外发出左键双击事件,供人工查看商品页。"""
|
||||
|
||||
leftDoubleClicked = Signal(QModelIndex)
|
||||
|
||||
def mouseDoubleClickEvent(self, event):
|
||||
super().mouseDoubleClickEvent(event)
|
||||
if event.button() != Qt.LeftButton:
|
||||
return
|
||||
index = self.indexAt(event.position().toPoint())
|
||||
if index.isValid():
|
||||
self.leftDoubleClicked.emit(index)
|
||||
|
||||
|
||||
class ApplyTab(QWidget):
|
||||
"""Tab 3: list generated tasks and confirm the update scope."""
|
||||
|
||||
@@ -53,6 +80,8 @@ class ApplyTab(QWidget):
|
||||
self.apply_thread = None
|
||||
self.result_write_back_worker = None
|
||||
self.result_write_back_thread = None
|
||||
self.product_tab_open_worker = None
|
||||
self.product_tab_open_thread = None
|
||||
self.last_apply_summary = None
|
||||
|
||||
self.batch_filter = QComboBox()
|
||||
@@ -95,7 +124,7 @@ class ApplyTab(QWidget):
|
||||
) = _build_empty_state_card("applyEmptyStateCard")
|
||||
if self.open_accounts_callback is not None:
|
||||
self.empty_state_button.clicked.connect(self.open_accounts_callback)
|
||||
self.task_table = QTableView()
|
||||
self.task_table = _ApplyTaskTableView()
|
||||
self.model = ApplyTaskTableModel(self.task_table)
|
||||
self.task_table.setModel(self.model)
|
||||
self.task_table.setSelectionBehavior(QAbstractItemView.SelectRows)
|
||||
@@ -168,6 +197,7 @@ class ApplyTab(QWidget):
|
||||
self.update_mode_combo.currentIndexChanged.connect(self._on_update_mode_changed)
|
||||
self.stop_update_button.clicked.connect(self.stop_update)
|
||||
self.reset_update_button.clicked.connect(self.reset_apply_status)
|
||||
self.task_table.leftDoubleClicked.connect(self.open_or_focus_selected_product)
|
||||
self.task_table.customContextMenuRequested.connect(self.show_task_context_menu)
|
||||
self.write_back_button.clicked.connect(self.write_back_results)
|
||||
|
||||
@@ -444,6 +474,59 @@ class ApplyTab(QWidget):
|
||||
self._set_status(message, level="success")
|
||||
QMessageBox.information(self, "删除本条记录", message)
|
||||
|
||||
def open_or_focus_selected_product(self, index):
|
||||
if self.apply_thread is not None or self.result_write_back_thread is not None:
|
||||
self._set_status("更新或回写正在进行,暂不能打开商品详情页", level="warning")
|
||||
return
|
||||
if self.product_tab_open_thread is not None:
|
||||
self._set_status("正在打开商品详情页,请稍候", level="info")
|
||||
return
|
||||
if not index.isValid():
|
||||
self._set_status("请选择要查看的商品记录", level="warning")
|
||||
return
|
||||
self.task_table.selectRow(index.row())
|
||||
self.task_table.setCurrentIndex(index)
|
||||
task = self.model.task_at(index.row())
|
||||
if task is None:
|
||||
self._set_status("未找到要查看的商品记录", level="warning")
|
||||
return
|
||||
worker = ProductTabOpenWorker(
|
||||
task.alias,
|
||||
task.item_id,
|
||||
db_path=self.db_path,
|
||||
config=self.config,
|
||||
)
|
||||
worker.finished.connect(self._on_product_tab_open_finished)
|
||||
worker.failed.connect(self._on_product_tab_open_failed)
|
||||
thread = run_worker(worker, thread_name="ProductTabOpenWorker", start=False)
|
||||
thread.finished.connect(lambda: self._forget_product_tab_open_thread(thread))
|
||||
self.product_tab_open_worker = worker
|
||||
self.product_tab_open_thread = thread
|
||||
self._set_status(f"正在打开商品 {task.item_id} 的详情页...", level="info")
|
||||
thread.start()
|
||||
|
||||
def _on_product_tab_open_finished(self, payload):
|
||||
if not payload.get("ok"):
|
||||
self._set_status(
|
||||
payload.get("message") or "打开商品详情页失败,请检查账号登录状态。",
|
||||
level="warning",
|
||||
)
|
||||
return
|
||||
action = "已打开新页面" if payload.get("created") else "已聚焦现有页面"
|
||||
account_name = payload.get("account_name") or payload.get("alias") or "账号"
|
||||
self._set_status(
|
||||
f"商品 {payload.get('item_id')}:{account_name}{action}",
|
||||
level="success",
|
||||
)
|
||||
|
||||
def _on_product_tab_open_failed(self, task_id, error):
|
||||
self._set_status("打开商品详情页失败,请检查账号 Chrome 和登录状态。", level="danger")
|
||||
|
||||
def _forget_product_tab_open_thread(self, thread):
|
||||
if self.product_tab_open_thread is thread:
|
||||
self.product_tab_open_thread = None
|
||||
self.product_tab_open_worker = None
|
||||
|
||||
def reset_apply_status(self, checked=False):
|
||||
if self.apply_thread is not None or self.result_write_back_thread is not None:
|
||||
self._set_status("更新或回写正在进行,不能重置")
|
||||
|
||||
Reference in New Issue
Block a user