feat: 实现受控真实下单安全边界 (#99)
This commit is contained in:
@@ -212,6 +212,7 @@ class SettingsPage(QWidget):
|
||||
android_device_service=None,
|
||||
update_service=None,
|
||||
update_credential_store=None,
|
||||
live_purchase_adapter_ready: bool = False,
|
||||
):
|
||||
super().__init__(parent)
|
||||
self.setObjectName("settingsPage")
|
||||
@@ -227,6 +228,7 @@ class SettingsPage(QWidget):
|
||||
android_device_service=android_device_service,
|
||||
update_service=update_service,
|
||||
update_credential_store=update_credential_store,
|
||||
live_purchase_adapter_ready=live_purchase_adapter_ready,
|
||||
)
|
||||
|
||||
def _build_ui(self) -> None:
|
||||
@@ -296,6 +298,34 @@ class SettingsPage(QWidget):
|
||||
self.pddAppStatusLabel.setWordWrap(True)
|
||||
self.androidDeviceCard = self._build_android_device_card()
|
||||
|
||||
self.livePurchaseStatusLabel = CaptionLabel(
|
||||
"真实下单默认关闭,仅允许创建未付款订单", self
|
||||
)
|
||||
self.livePurchaseStatusLabel.setAccessibleName("真实下单授权状态")
|
||||
self.livePurchaseStatusLabel.setWordWrap(True)
|
||||
self.livePurchaseClientLabel = CaptionLabel("—", self)
|
||||
self.livePurchaseDeviceLabel = CaptionLabel("—", self)
|
||||
self.livePurchaseConfirmedAtLabel = CaptionLabel("—", self)
|
||||
self.livePurchaseConfirmationInput = LineEdit(self)
|
||||
self.livePurchaseConfirmationInput.setPlaceholderText(
|
||||
"请输入“创建未付款订单”"
|
||||
)
|
||||
self.livePurchaseConfirmationInput.setClearButtonEnabled(True)
|
||||
self.livePurchaseConfirmationInput.setAccessibleName(
|
||||
"真实下单确认文字"
|
||||
)
|
||||
self.livePurchaseEnableButton = PushButton(
|
||||
FIF.ACCEPT, "启用真实下单", self
|
||||
)
|
||||
self.livePurchaseEnableButton.setAccessibleName(
|
||||
"为当前 Client 和 Android 设备启用真实下单"
|
||||
)
|
||||
self.livePurchaseDisableButton = PushButton(
|
||||
FIF.CANCEL, "关闭真实下单", self
|
||||
)
|
||||
self.livePurchaseDisableButton.setAccessibleName("关闭真实下单")
|
||||
self.livePurchaseCard = self._build_live_purchase_card()
|
||||
|
||||
self.currentVersionLabel = CaptionLabel(__version__, self)
|
||||
self.currentVersionLabel.setAccessibleName("当前软件版本")
|
||||
self.updateManifestUrlInput = LineEdit(self)
|
||||
@@ -331,6 +361,7 @@ class SettingsPage(QWidget):
|
||||
contentLayout.addWidget(TitleLabel("设置", content))
|
||||
contentLayout.addWidget(self.currentDeviceCard)
|
||||
contentLayout.addWidget(self.androidDeviceCard)
|
||||
contentLayout.addWidget(self.livePurchaseCard)
|
||||
contentLayout.addWidget(self.softwareUpdateCard)
|
||||
contentLayout.addStretch(1)
|
||||
|
||||
@@ -455,6 +486,52 @@ class SettingsPage(QWidget):
|
||||
layout.addLayout(commandLayout)
|
||||
return card
|
||||
|
||||
def _build_live_purchase_card(self) -> CardWidget:
|
||||
card = CardWidget(self)
|
||||
card.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
|
||||
layout = QVBoxLayout(card)
|
||||
layout.setContentsMargins(24, 20, 24, 22)
|
||||
layout.setSpacing(12)
|
||||
|
||||
titleLayout = QHBoxLayout()
|
||||
titleLayout.setSpacing(12)
|
||||
titleLayout.addWidget(SubtitleLabel("真实下单(不支付)", card))
|
||||
titleLayout.addStretch(1)
|
||||
titleLayout.addWidget(self.livePurchaseStatusLabel, 1)
|
||||
layout.addLayout(titleLayout)
|
||||
|
||||
form = QFormLayout()
|
||||
form.setHorizontalSpacing(16)
|
||||
form.setVerticalSpacing(12)
|
||||
form.addRow(
|
||||
CaptionLabel("绑定 Client", card), self.livePurchaseClientLabel
|
||||
)
|
||||
form.addRow(
|
||||
CaptionLabel("绑定设备", card), self.livePurchaseDeviceLabel
|
||||
)
|
||||
form.addRow(
|
||||
CaptionLabel("确认时间", card), self.livePurchaseConfirmedAtLabel
|
||||
)
|
||||
confirmationLabel = CaptionLabel("确认文字", card)
|
||||
confirmationLabel.setBuddy(self.livePurchaseConfirmationInput)
|
||||
form.addRow(confirmationLabel, self.livePurchaseConfirmationInput)
|
||||
layout.addLayout(form)
|
||||
|
||||
warning = CaptionLabel(
|
||||
"启用后只允许提交一次订单并停在支付前;验证码、风控、登录失效、"
|
||||
"规格或价格不一致时立即停止。",
|
||||
card,
|
||||
)
|
||||
warning.setWordWrap(True)
|
||||
layout.addWidget(warning)
|
||||
|
||||
commandLayout = QHBoxLayout()
|
||||
commandLayout.addStretch(1)
|
||||
commandLayout.addWidget(self.livePurchaseDisableButton)
|
||||
commandLayout.addWidget(self.livePurchaseEnableButton)
|
||||
layout.addLayout(commandLayout)
|
||||
return card
|
||||
|
||||
def set_client_info(self, device_id: str, device_name: str) -> None:
|
||||
"""显示后续设备身份服务提供的当前客户端信息。"""
|
||||
|
||||
@@ -482,6 +559,28 @@ class SettingsPage(QWidget):
|
||||
|
||||
self.updateStatusLabel.setText(message)
|
||||
|
||||
def set_live_purchase_authorization(
|
||||
self,
|
||||
*,
|
||||
enabled: bool,
|
||||
client_id: str = "",
|
||||
device_serial: str = "",
|
||||
confirmed_at: str = "",
|
||||
message: str = "",
|
||||
) -> None:
|
||||
"""显示真实下单授权,不通过颜色单独表达状态。"""
|
||||
|
||||
self.livePurchaseClientLabel.setText(client_id or "—")
|
||||
self.livePurchaseDeviceLabel.setText(device_serial or "—")
|
||||
self.livePurchaseConfirmedAtLabel.setText(confirmed_at or "—")
|
||||
if message:
|
||||
status = message
|
||||
elif enabled:
|
||||
status = "已启用:仅限绑定 Client 和设备,且不会自动支付"
|
||||
else:
|
||||
status = "已关闭:所有采购任务只允许演练"
|
||||
self.livePurchaseStatusLabel.setText(status)
|
||||
|
||||
def set_saved_android_device(self, serial: str) -> None:
|
||||
"""显示已经保存并实际用于自动化的 Android 设备。"""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user