From efcbd9a6912800e975f670e21fc5783f0736b3db Mon Sep 17 00:00:00 2001 From: yml Date: Sun, 29 Nov 2026 14:28:23 +0800 Subject: [PATCH] =?UTF-8?q?feat(frontend):=20=E4=BC=98=E5=8C=96=E6=96=97?= =?UTF-8?q?=E9=B1=BC=E6=89=B9=E9=87=8F=E6=94=AF=E4=BB=98=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E5=8F=8C=E7=A0=81=E5=A4=A7=E9=97=B4=E8=B7=9D=E6=89=AB=E7=A0=81?= =?UTF-8?q?=E6=A0=B7=E5=BC=8F=E4=B8=8E=E8=A1=A5=E4=BD=8D=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- pyproject.toml | 2 +- uv.lock | 2 +- .../src/components/PaymentQrQueue.tsx | 203 +++++++++++++++--- .../src/pages/douyu-tasks/DouyuTasksPage.tsx | 29 ++- 5 files changed, 208 insertions(+), 30 deletions(-) diff --git a/README.md b/README.md index c2e2821..bf7253f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # 直播账号运营后台 -斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.23)。 +斗鱼 / 虎牙账号运营 Web 平台:批量登录拿 Cookie、按工作台跑活动任务、应用宝点券充值。版本见 `pyproject.toml`(当前 0.4.24)。 ## 能做什么 diff --git a/pyproject.toml b/pyproject.toml index e78b8ed..8d56210 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "live-hub-py" -version = "0.4.23" +version = "0.4.24" description = "直播账号运营 Web 后台" readme = "README.md" requires-python = ">=3.12,<3.13" diff --git a/uv.lock b/uv.lock index 5705a2c..97cc1ed 100644 --- a/uv.lock +++ b/uv.lock @@ -381,7 +381,7 @@ wheels = [ [[package]] name = "live-hub-py" -version = "0.4.23" +version = "0.4.24" source = { editable = "." } dependencies = [ { name = "alembic" }, diff --git a/web/frontend/src/components/PaymentQrQueue.tsx b/web/frontend/src/components/PaymentQrQueue.tsx index 2969c3c..840c192 100644 --- a/web/frontend/src/components/PaymentQrQueue.tsx +++ b/web/frontend/src/components/PaymentQrQueue.tsx @@ -1,13 +1,17 @@ +import { useEffect, useState } from 'react'; import { Alert, Button, QRCode, + Segmented, Space, Spin, Tag, Typography, } from 'antd'; import { + AppstoreOutlined, + ColumnWidthOutlined, CopyOutlined, ReloadOutlined, ZoomInOutlined, @@ -16,6 +20,7 @@ import { const { Text } = Typography; export type PaymentQrQueuePhase = 'queued' | 'generating' | 'ready' | 'error'; +export type PaymentQrLayoutMode = 'all' | 'pair'; export interface PaymentQrQueueItem { key: string | number; @@ -37,19 +42,65 @@ interface PaymentQrQueueProps { items: PaymentQrQueueItem[]; emptyText: string; queuedText?: string; + defaultLayoutMode?: PaymentQrLayoutMode; + layoutMode?: PaymentQrLayoutMode; + layoutStorageKey?: string; + onLayoutModeChange?: (mode: PaymentQrLayoutMode) => void; onZoom?: (item: PaymentQrQueueItem) => void; onCopy?: (item: PaymentQrQueueItem) => void; onRefresh?: (item: PaymentQrQueueItem) => void; } +const DEFAULT_LAYOUT_STORAGE_KEY = 'payment_qr_queue_layout_mode'; + +function readStoredLayoutMode( + storageKey: string, + fallback: PaymentQrLayoutMode, +): PaymentQrLayoutMode { + try { + const raw = window.localStorage.getItem(storageKey); + if (raw === 'all' || raw === 'pair') return raw; + } catch { + // 隐私模式或禁用存储时静默回退默认值 + } + return fallback; +} + export default function PaymentQrQueue({ items, emptyText, queuedText = '正在排队生成支付码', + defaultLayoutMode = 'all', + layoutMode, + layoutStorageKey = DEFAULT_LAYOUT_STORAGE_KEY, + onLayoutModeChange, onZoom, onCopy, onRefresh, }: PaymentQrQueueProps) { + const [innerMode, setInnerMode] = useState(() => + readStoredLayoutMode(layoutStorageKey, defaultLayoutMode), + ); + const effectiveMode = layoutMode ?? innerMode; + + useEffect(() => { + if (layoutMode === undefined) return; + setInnerMode(layoutMode); + }, [layoutMode]); + + const handleModeChange = (value: string | number) => { + const next: PaymentQrLayoutMode = value === 'pair' ? 'pair' : 'all'; + if (layoutMode === undefined) { + setInnerMode(next); + } + try { + window.localStorage.setItem(layoutStorageKey, next); + } catch { + // ignore storage errors + } + onLayoutModeChange?.(next); + }; + if (items.length === 0) { return (
@@ -61,24 +112,106 @@ export default function PaymentQrQueue({ const queuedCount = items.filter( (item) => item.phase === 'queued' || item.phase === 'generating', ).length; + + const readyItems = items.filter((item) => item.phase === 'ready'); + const pendingItems = items.filter( + (item) => item.phase === 'queued' || item.phase === 'generating', + ); + const errorItems = items.filter((item) => item.phase === 'error'); + const activePairPool = [...readyItems, ...pendingItems]; + + const isPairMode = effectiveMode === 'pair'; + const displayItems = isPairMode + ? (activePairPool.length > 0 ? activePairPool.slice(0, 2) : errorItems) + : items; + const waitingItems = isPairMode && activePairPool.length > 2 + ? activePairPool.slice(2) + : []; + const qrSize = isPairMode ? 220 : 160; + + const waitingPreview = waitingItems + .slice(0, 4) + .map((item) => item.title) + .join('、'); + return ( - - {queuedCount > 0 && ( - - {queuedText}({queuedCount} 个) - - )} +
- {items.map((item) => { +
+ {isPairMode ? ( + + {activePairPool.length > 0 ? ( + <> + 当前展示前 {displayItems.length} 个(共 {activePairPool.length} 个待完成 + {waitingItems.length > 0 ? ` · 后续 ${waitingItems.length} 个自动补位` : ''} + )· 支付成功后自动移除 + + ) : ( + <>共 {errorItems.length} 个失败项 + )} + + ) : ( + queuedCount > 0 && ( + + {queuedText}({queuedCount} 个) + + ) + )} +
+ , + }, + { + label: '双码大间距', + value: 'pair', + icon: , + }, + ]} + /> +
+ +
+ {displayItems.map((item) => { const hasQr = Boolean(item.qrValue || item.qrImage); const copyValue = item.copyValue || item.qrValue || ''; return ( @@ -86,13 +219,13 @@ export default function PaymentQrQueue({ key={item.key} style={{ border: '1px solid rgba(128, 128, 128, .24)', - borderRadius: 8, - padding: 12, + borderRadius: isPairMode ? 12 : 8, + padding: isPairMode ? '20px 18px' : 12, textAlign: 'center', background: 'rgba(255, 255, 255, .015)', }} > - + {item.title} {item.subtitle && ( @@ -103,7 +236,7 @@ export default function PaymentQrQueue({
)} {item.phase === 'queued' && ( -
+
排队中 @@ -111,7 +244,7 @@ export default function PaymentQrQueue({
)} {item.phase === 'generating' && ( -
+
正在创建订单并解析二维码 @@ -130,17 +263,17 @@ export default function PaymentQrQueue({ {item.phase === 'ready' && ( {hasQr ? (
{item.qrImage ? ( @@ -148,15 +281,15 @@ export default function PaymentQrQueue({ src={item.qrImage} alt="支付二维码" style={{ - width: 160, - height: 160, + width: qrSize, + height: qrSize, objectFit: 'contain', }} /> ) : ( + + {isPairMode && waitingItems.length > 0 && ( +
+ + 待补位队列({waitingItems.length}):{waitingPreview} + {waitingItems.length > 4 ? ` 等 ${waitingItems.length} 个账号` : ''} + +
+ )} + + {isPairMode && activePairPool.length > 0 && errorItems.length > 0 && ( + `${item.title}:${item.error || '支付码生成失败'}`) + .join(';')} + /> + )} ); } diff --git a/web/frontend/src/pages/douyu-tasks/DouyuTasksPage.tsx b/web/frontend/src/pages/douyu-tasks/DouyuTasksPage.tsx index 93e2b89..0797f05 100644 --- a/web/frontend/src/pages/douyu-tasks/DouyuTasksPage.tsx +++ b/web/frontend/src/pages/douyu-tasks/DouyuTasksPage.tsx @@ -18,7 +18,10 @@ import { type DouyuTaskItem, } from '../../api/modules'; import ExchangeResultImage from '../../components/ExchangeResultImage'; -import PaymentQrQueue, { type PaymentQrQueueItem } from '../../components/PaymentQrQueue'; +import PaymentQrQueue, { + type PaymentQrLayoutMode, + type PaymentQrQueueItem, +} from '../../components/PaymentQrQueue'; import QrActions from '../../components/QrActions'; import { usePermissions } from '../../hooks/usePermissions'; import { useWebSocketLogs } from '../../hooks/useWebSocketLogs'; @@ -271,6 +274,13 @@ export default function DouyuTasksPage({ const [paySessionTasks, setPaySessionTasks] = useState>({}); const [stoppingPayBatchId, setStoppingPayBatchId] = useState(null); const [payOpen, setPayOpen] = useState(false); + const [payQrLayoutMode, setPayQrLayoutMode] = useState(() => { + try { + return localStorage.getItem('douyu_pay_qr_layout_mode') === 'pair' ? 'pair' : 'all'; + } catch { + return 'all'; + } + }); const [zoomPayTask, setZoomPayTask] = useState(null); const qrCanvasWrapRef = useRef(null); const esportsQrCanvasWrapRef = useRef(null); @@ -2447,6 +2457,17 @@ export default function DouyuTasksPage({ const activePaySessionView = visiblePaySessionViews.find( (view) => view.session.batchId === activePayBatchId, ) || visiblePaySessionViews[0]; + useEffect(() => { + if (!payOpen || !activePaySessionView?.active) return undefined; + const batchId = activePaySessionView.session.batchId; + const pollActivePaySession = () => { + if (document.visibilityState === 'visible') { + void loadPaySessionTasks([batchId]); + } + }; + const timer = window.setInterval(pollActivePaySession, 2500); + return () => window.clearInterval(timer); + }, [activePaySessionView?.active, activePaySessionView?.session.batchId, loadPaySessionTasks, payOpen]); const requestClosePayModal = () => { if (activePaySessionView?.active) { Modal.confirm({ @@ -3571,7 +3592,8 @@ export default function DouyuTasksPage({ : null } centered - width={920} + width={payQrLayoutMode === 'pair' ? 1000 : 920} + style={{ maxWidth: 'calc(100vw - 32px)' }} > {visiblePaySessionViews.length > 0 ? ( 0 ? '当前批次已到账,支付完成的账号已原位移除' : '当前批次没有待扫码支付码'}