feat: 优化支付码队列与支付超时
This commit is contained in:
@@ -7,11 +7,12 @@ import {
|
||||
import type { TableProps } from 'antd';
|
||||
import {
|
||||
CheckCircleOutlined, ColumnWidthOutlined, CopyOutlined, GiftOutlined, ImportOutlined, QrcodeOutlined,
|
||||
ReloadOutlined, SearchOutlined, SettingOutlined, ShoppingOutlined, StopOutlined, SwapOutlined, ZoomInOutlined,
|
||||
ReloadOutlined, SearchOutlined, SettingOutlined, ShoppingOutlined, StopOutlined, SwapOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { huyaApi, type HuyaAccountItem, type HuyaConfig, type HuyaGoodsItem, type HuyaRechargeGoodsItem, type HuyaTaskItem } from '../api/modules';
|
||||
import HuyaConfigFields from '../components/HuyaConfigFields';
|
||||
import HuyaExternalCkImportModal from '../components/HuyaExternalCkImportModal';
|
||||
import PaymentQrQueue, { type PaymentQrQueueItem } from '../components/PaymentQrQueue';
|
||||
import RealtimeLogPanel from '../components/RealtimeLogPanel';
|
||||
import { usePermissions } from '../hooks/usePermissions';
|
||||
import { useWebSocketLogs } from '../hooks/useWebSocketLogs';
|
||||
@@ -189,6 +190,10 @@ function taskQrUrl(task: HuyaTaskItem | undefined): string {
|
||||
return resultText(task, 'bind_redirect_url') || resultText(task, 'url');
|
||||
}
|
||||
|
||||
function payTaskLabel(task: HuyaTaskItem): string {
|
||||
return task.account_nickname || task.account_uid || `#${task.account_id}`;
|
||||
}
|
||||
|
||||
export default function HuyaElitePage() {
|
||||
const navigate = useNavigate();
|
||||
const { can } = usePermissions();
|
||||
@@ -569,30 +574,65 @@ export default function HuyaElitePage() {
|
||||
}
|
||||
}, [rechargeGoods, selectedRechargeSpu]);
|
||||
const exchangeCount = tasks.filter((task) => task.task_type === 'exchange_goods').length;
|
||||
// 开通支付码:同一批次里每个账号一个码,未支付的排前面;已支付/已开通的只留一行状态
|
||||
const payTasks = useMemo(() => {
|
||||
const list = tasks.filter((task) => ['create_recharge_order', 'exchange_goods'].includes(task.task_type)
|
||||
&& payBatchIds.includes(task.batch_id)
|
||||
&& Boolean(resultText(task, 'pay_url') || resultText(task, 'mini_qrcode_image')));
|
||||
return [...list].sort((a, b) => Number(needsScanPay(b)) - Number(needsScanPay(a)) || a.id - b.id);
|
||||
}, [tasks, payBatchIds]);
|
||||
const payPendingTasks = payTasks.filter(needsScanPay);
|
||||
const payDoneTasks = payTasks.filter((task) => !needsScanPay(task));
|
||||
// 支付完成后立即从待扫码队列移除,只保留仍需处理的账号。
|
||||
const payAllTasks = useMemo(() => tasks.filter((task) => ['create_recharge_order', 'exchange_goods'].includes(task.task_type)
|
||||
&& payBatchIds.includes(task.batch_id)
|
||||
&& Boolean(resultText(task, 'pay_url') || resultText(task, 'mini_qrcode_image'))), [tasks, payBatchIds]);
|
||||
const payTasks = useMemo(() => payAllTasks.filter(needsScanPay), [payAllTasks]);
|
||||
const payDoneCount = payAllTasks.length - payTasks.length;
|
||||
const payQrTaskIds = useMemo(() => new Set(payAllTasks.map((task) => task.id)), [payAllTasks]);
|
||||
// 多选账号时一次生成多个码:个别账号失败(限购、CK 失效…)要单独点名,否则少一个码看不出原因
|
||||
const payFailedTasks = useMemo(() => tasks.filter((task) => ['create_recharge_order', 'exchange_goods'].includes(task.task_type)
|
||||
&& payBatchIds.includes(task.batch_id)
|
||||
&& ['failed', 'error', 'stopped'].includes(task.status)), [tasks, payBatchIds]);
|
||||
&& !payQrTaskIds.has(task.id)
|
||||
&& ['failed', 'error', 'stopped'].includes(task.status)), [payBatchIds, payQrTaskIds, tasks]);
|
||||
// 还在排队/生成中的码(并发不够时,后面的码要等前面的码付完或超时才轮到)
|
||||
const payQueuedCount = useMemo(() => tasks.filter((task) => ['create_recharge_order', 'exchange_goods'].includes(task.task_type)
|
||||
&& payBatchIds.includes(task.batch_id)
|
||||
&& ['planned', 'pending', 'running'].includes(task.status)
|
||||
&& !resultText(task, 'pay_url')).length, [tasks, payBatchIds]);
|
||||
const payTaskById = useMemo(() => new Map(payAllTasks.map((task) => [task.id, task])), [payAllTasks]);
|
||||
const payQueueItems = useMemo<PaymentQrQueueItem[]>(() => {
|
||||
const pending = payTasks
|
||||
.map((task) => ({
|
||||
key: task.id,
|
||||
title: payTaskLabel(task),
|
||||
subtitle: `UID ${task.account_uid || '-'}`,
|
||||
description: [resultText(task, 'product_name') || '精英宝典', Number(resultText(task, 'count')) > 1 ? `×${resultText(task, 'count')}` : '', resultText(task, 'amount_text')].filter(Boolean).join(' '),
|
||||
phase: 'ready' as const,
|
||||
qrValue: payQrValue(task),
|
||||
qrImage: resultText(task, 'mini_qrcode_image') ? miniQrcodeSrc(resultText(task, 'mini_qrcode_image')) : '',
|
||||
copyValue: payQrValue(task),
|
||||
statusLabel: resultText(task, 'payment_status_label') || TASK_STATUS_LABELS[task.status] || task.status,
|
||||
statusColor: TASK_COLORS[task.status] || 'default',
|
||||
warning: isLoopbackUrl(payQrValue(task)) ? '二维码是本机地址(localhost),手机无法扫码' : '',
|
||||
}))
|
||||
.sort((a, b) => Number(a.key) - Number(b.key));
|
||||
const queued = tasks
|
||||
.filter((task) => ['create_recharge_order', 'exchange_goods'].includes(task.task_type)
|
||||
&& payBatchIds.includes(task.batch_id)
|
||||
&& ['planned', 'pending', 'running'].includes(task.status)
|
||||
&& !resultText(task, 'pay_url'))
|
||||
.map((task) => ({
|
||||
key: `queued-${task.id}`,
|
||||
title: payTaskLabel(task),
|
||||
subtitle: `UID ${task.account_uid || '-'}`,
|
||||
phase: task.status === 'running' ? 'generating' as const : 'queued' as const,
|
||||
}));
|
||||
const failed = payFailedTasks.map((task) => ({
|
||||
key: `failed-${task.id}`,
|
||||
title: payTaskLabel(task),
|
||||
subtitle: `UID ${task.account_uid || '-'}`,
|
||||
phase: 'error' as const,
|
||||
error: task.message || '支付码生成失败',
|
||||
}));
|
||||
return [...pending, ...queued, ...failed];
|
||||
}, [payBatchIds, payFailedTasks, payTasks, tasks]);
|
||||
|
||||
const openPayTasks = (batchId?: string) => {
|
||||
if (batchId) setPayBatchIds((prev) => (prev.includes(batchId) ? prev : [...prev, batchId]));
|
||||
setPayOpen(true);
|
||||
};
|
||||
const payTaskLabel = (task: HuyaTaskItem) => task.account_nickname || task.account_uid || `#${task.account_id}`;
|
||||
const copyPayLink = async (text: string, label: string) => {
|
||||
if (!text) { message.warning('没有可复制的链接'); return; }
|
||||
try { await navigator.clipboard.writeText(text); message.success(`${label}已复制`); }
|
||||
@@ -717,46 +757,22 @@ export default function HuyaElitePage() {
|
||||
</Modal>
|
||||
<Modal
|
||||
open={payOpen}
|
||||
title={payTasks.length ? `支付码(${payPendingTasks.length} 个待扫码 · 已完成 ${payDoneTasks.length}/${payTasks.length})` : '支付码'}
|
||||
title={`支付码${payQueueItems.length ? `(${payTasks.length} 个待扫码${payQueuedCount ? ` · ${payQueuedCount} 个排队中` : ''}${payDoneCount ? ` · ${payDoneCount} 个已支付` : ''})` : ''}`}
|
||||
width={920}
|
||||
centered
|
||||
onCancel={() => setPayOpen(false)}
|
||||
footer={<Space><Text type="secondary">多选账号会同时生成多个码并排展示,各自独立等待支付;支付后自动确认开通状态</Text><Button onClick={() => setPayOpen(false)}>关闭</Button><Button onClick={() => { setPayBatchIds([]); setPayOpen(false); }}>清空列表</Button></Space>}
|
||||
>
|
||||
{payTasks.length === 0 ? <div style={{ padding: 24, textAlign: 'center' }}><Text type="secondary">正在为选中的账号生成支付码…</Text></div> : <div style={{ maxHeight: '62vh', overflowY: 'auto' }}>
|
||||
{payQueuedCount > 0 && <div style={{ marginBottom: 10, textAlign: 'left' }}><Text type="secondary" style={{ fontSize: 12 }}>还有 {payQueuedCount} 个账号在排队生成支付码(并发不够时会等已出的码付完/超时,可调大右侧「并发」)</Text></div>}
|
||||
{payPendingTasks.length > 0 && <div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fill, minmax(230px, 1fr))', gap: 12 }}>
|
||||
{payPendingTasks.map((task) => {
|
||||
const qrValue = payQrValue(task);
|
||||
return (
|
||||
<div key={task.id} style={{ border: '1px solid rgba(128,128,128,.22)', borderRadius: 6, padding: 10, textAlign: 'center' }}>
|
||||
<div style={{ background: '#fff', padding: 6, borderRadius: 6, lineHeight: 0, display: 'inline-block' }}>{resultText(task, 'mini_qrcode_image') ? <img src={miniQrcodeSrc(resultText(task, 'mini_qrcode_image'))} alt="支付码" style={{ width: 150, height: 150, objectFit: 'contain' }} /> : <QRCode value={qrValue} size={150} type="svg" errorLevel="L" bordered={false} color="#000" bgColor="#fff" />}</div>
|
||||
<div><Text strong ellipsis>{payTaskLabel(task)}</Text></div>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>UID {task.account_uid || '-'}</Text>
|
||||
<div><Text type="secondary" style={{ fontSize: 12 }}>{[resultText(task, 'product_name') || '精英宝典', Number(resultText(task, 'count')) > 1 ? `×${resultText(task, 'count')}` : '', resultText(task, 'amount_text')].filter(Boolean).join(' ')}</Text></div>
|
||||
<div style={{ marginTop: 4 }}><Tag color={TASK_COLORS[task.status] || 'default'}>{resultText(task, 'payment_status_label') || TASK_STATUS_LABELS[task.status] || task.status}</Tag></div>
|
||||
<Text type="secondary" style={{ fontSize: 12 }} ellipsis title={task.message}>{task.message || '-'}</Text>
|
||||
{isLoopbackUrl(qrValue) && <div><Text type="warning" style={{ fontSize: 12 }}>二维码是本机地址(localhost),手机扫不开</Text></div>}
|
||||
<div style={{ marginTop: 6 }}><Space size={6}><Button size="small" icon={<ZoomInOutlined />} onClick={() => setZoomPayTask(task)}>放大扫码</Button><Button size="small" icon={<CopyOutlined />} onClick={() => void copyPayLink(qrValue, '支付链接')}>复制链接</Button></Space></div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>}
|
||||
{payFailedTasks.length > 0 && <div style={{ marginTop: payPendingTasks.length ? 12 : 0, textAlign: 'left' }}>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>生成失败(没有二维码)</Text>
|
||||
<div style={{ marginTop: 6, display: 'flex', flexWrap: 'wrap', gap: 6 }}>
|
||||
{payFailedTasks.map((task) => <Tag key={task.id} color="error" title={task.message}>{payTaskLabel(task)} · {task.message || '生成失败'}</Tag>)}
|
||||
</div>
|
||||
</div>}
|
||||
{payDoneTasks.length > 0 && <div style={{ marginTop: payPendingTasks.length ? 12 : 0, textAlign: 'left' }}>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>已完成(二维码已收起)</Text>
|
||||
<div style={{ marginTop: 6, display: 'flex', flexWrap: 'wrap', gap: 6 }}>
|
||||
{payDoneTasks.map((task) => (
|
||||
<Tag key={task.id} color={task.result?.elite_opened === true ? 'success' : task.result?.elite_opening === true ? 'processing' : 'blue'}>{payTaskLabel(task)} · {task.result?.elite_opened === true ? '已开通' : task.result?.elite_opening === true ? '开通中' : resultText(task, 'payment_status_label') || '已支付'}</Tag>
|
||||
))}
|
||||
</div>
|
||||
</div>}
|
||||
</div>}
|
||||
<PaymentQrQueue
|
||||
items={payQueueItems}
|
||||
emptyText={payDoneCount > 0 ? '待扫码队列已清空,支付完成的账号已自动移除' : '当前没有待扫码支付码'}
|
||||
queuedText="还有账号在排队生成支付码"
|
||||
onZoom={(item) => {
|
||||
const task = payTaskById.get(Number(item.key));
|
||||
if (task) setZoomPayTask(task);
|
||||
}}
|
||||
onCopy={(item) => void copyPayLink(item.copyValue || item.qrValue || '', '支付链接')}
|
||||
/>
|
||||
</Modal>
|
||||
<Modal open={zoomPayTask !== null} title={`扫码支付 · ${zoomPayTask ? payTaskLabel(zoomPayTask) : ''}`} footer={null} onCancel={() => setZoomPayTask(null)} width={680} centered>
|
||||
{zoomPayTask && <div style={{ textAlign: 'center' }}>
|
||||
|
||||
Reference in New Issue
Block a user