feat: 优化支付码队列与支付超时

This commit is contained in:
yml
2026-11-13 21:21:19 +08:00
parent 76b344eb83
commit 8ba947e60f
11 changed files with 592 additions and 413 deletions
@@ -0,0 +1,229 @@
import {
Alert,
Button,
QRCode,
Space,
Spin,
Tag,
Typography,
} from 'antd';
import {
CopyOutlined,
ReloadOutlined,
ZoomInOutlined,
} from '@ant-design/icons';
const { Text } = Typography;
export type PaymentQrQueuePhase = 'queued' | 'generating' | 'ready' | 'error';
export interface PaymentQrQueueItem {
key: string | number;
title: string;
subtitle?: string;
description?: string;
phase: PaymentQrQueuePhase;
qrValue?: string;
qrImage?: string;
copyValue?: string;
statusLabel?: string;
statusColor?: string;
warning?: string;
error?: string;
refreshing?: boolean;
}
interface PaymentQrQueueProps {
items: PaymentQrQueueItem[];
emptyText: string;
queuedText?: string;
onZoom?: (item: PaymentQrQueueItem) => void;
onCopy?: (item: PaymentQrQueueItem) => void;
onRefresh?: (item: PaymentQrQueueItem) => void;
}
export default function PaymentQrQueue({
items,
emptyText,
queuedText = '正在排队生成支付码',
onZoom,
onCopy,
onRefresh,
}: PaymentQrQueueProps) {
if (items.length === 0) {
return (
<div style={{ padding: 28, textAlign: 'center' }}>
<Text type="secondary">{emptyText}</Text>
</div>
);
}
const queuedCount = items.filter(
(item) => item.phase === 'queued' || item.phase === 'generating',
).length;
return (
<Space orientation="vertical" size={10} style={{ width: '100%' }}>
{queuedCount > 0 && (
<Text type="secondary" style={{ fontSize: 12 }}>
{queuedText}({queuedCount} 个)
</Text>
)}
<div
style={{
display: 'grid',
gridTemplateColumns: 'repeat(auto-fill, minmax(230px, 1fr))',
gap: 12,
maxHeight: '64vh',
overflowY: 'auto',
paddingRight: 4,
}}
>
{items.map((item) => {
const hasQr = Boolean(item.qrValue || item.qrImage);
const copyValue = item.copyValue || item.qrValue || '';
return (
<div
key={item.key}
style={{
border: '1px solid rgba(128, 128, 128, .24)',
borderRadius: 8,
padding: 12,
textAlign: 'center',
background: 'rgba(255, 255, 255, .015)',
}}
>
<Text strong ellipsis title={item.title}>
{item.title}
</Text>
{item.subtitle && (
<div>
<Text type="secondary" style={{ fontSize: 12 }}>
{item.subtitle}
</Text>
</div>
)}
{item.phase === 'queued' && (
<div style={{ padding: '42px 0' }}>
<Spin size="small" />
<div>
<Text type="secondary">排队中</Text>
</div>
</div>
)}
{item.phase === 'generating' && (
<div style={{ padding: '42px 0' }}>
<Spin />
<div style={{ marginTop: 8 }}>
<Text type="secondary">正在创建订单并解析二维码</Text>
</div>
</div>
)}
{item.phase === 'error' && (
<Alert
type="error"
showIcon
style={{ marginTop: 10, textAlign: 'left' }}
title="支付码不可用"
description={item.error || '未知原因'}
/>
)}
{item.phase === 'ready' && (
<Space
orientation="vertical"
size={7}
style={{ width: '100%', marginTop: 8 }}
>
{hasQr ? (
<div
style={{
display: 'inline-block',
background: '#fff',
padding: 6,
lineHeight: 0,
borderRadius: 6,
}}
>
{item.qrImage ? (
<img
src={item.qrImage}
alt="支付二维码"
style={{
width: 160,
height: 160,
objectFit: 'contain',
}}
/>
) : (
<QRCode
value={item.qrValue || ''}
size={160}
bordered={false}
color="#000"
bgColor="#fff"
/>
)}
</div>
) : (
<Alert
type="warning"
showIcon
title="订单已创建但未解析到二维码"
description="可复制支付链接后手动打开"
/>
)}
{item.description && (
<Text type="secondary" style={{ fontSize: 12 }}>
{item.description}
</Text>
)}
{item.statusLabel && (
<Tag color={item.statusColor || 'processing'}>
{item.statusLabel}
</Tag>
)}
{item.warning && (
<Text type="warning" style={{ fontSize: 12 }}>
{item.warning}
</Text>
)}
{(onZoom || onCopy || onRefresh) && (
<Space wrap style={{ justifyContent: 'center' }}>
{onZoom && hasQr && (
<Button
size="small"
icon={<ZoomInOutlined />}
onClick={() => onZoom(item)}
>
放大扫码
</Button>
)}
{onCopy && copyValue && (
<Button
size="small"
icon={<CopyOutlined />}
onClick={() => onCopy(item)}
>
复制链接
</Button>
)}
{onRefresh && (
<Button
size="small"
icon={<ReloadOutlined />}
loading={item.refreshing}
onClick={() => onRefresh(item)}
>
刷新状态
</Button>
)}
</Space>
)}
</Space>
)}
</div>
);
})}
</div>
</Space>
);
}
@@ -0,0 +1,155 @@
import {
Alert,
Button,
InputNumber,
QRCode,
Space,
Tag,
Typography,
} from 'antd';
import { ReloadOutlined } from '@ant-design/icons';
import type {
WeiboPaymentStatusResult,
WeiboRechargeOrderResult,
} from '../api/modules';
import { WEIBO_PAYMENT_STATUS_LABELS } from '../utils/weiboPayment';
const { Text } = Typography;
interface WeiboRechargePanelProps {
enabled: boolean;
amount: number;
onAmountChange: (value: number) => void;
creating: boolean;
onCreate: () => void;
order: WeiboRechargeOrderResult | null;
paymentStatus: WeiboPaymentStatusResult | null;
statusLoading: boolean;
onRefreshStatus: () => void;
onRefreshBalance?: () => void;
}
export default function WeiboRechargePanel({
enabled,
amount,
onAmountChange,
creating,
onCreate,
order,
paymentStatus,
statusLoading,
onRefreshStatus,
onRefreshBalance,
}: WeiboRechargePanelProps) {
const paid = paymentStatus?.status === 'PAY_STATUS_SUCCESS';
const failed = paymentStatus?.status === 'PAY_STATUS_FAILED'
|| paymentStatus?.status === 'PAY_STATUS_CLOSED';
return (
<>
<Text strong>助威充值</Text>
<Space wrap style={{ marginTop: 8 }}>
<Space.Compact>
<InputNumber
min={1}
max={1000}
precision={0}
value={amount}
onChange={(value) => onAmountChange(Number(value) || 1)}
style={{ width: 110 }}
/>
<Button disabled>元</Button>
</Space.Compact>
<Button
type="primary"
loading={creating}
disabled={!enabled}
onClick={onCreate}
>
创建订单
</Button>
</Space>
{order && (
<Space
orientation="vertical"
size={8}
style={{ width: '100%', marginTop: 10 }}
>
{paid ? (
<Alert
type="success"
showIcon
title="支付成功,二维码已自动收起"
description="可继续刷新账号资料核对微豆到账。"
/>
) : failed ? (
<Alert
type="error"
showIcon
title={WEIBO_PAYMENT_STATUS_LABELS[paymentStatus?.status || ''] || '支付失败'}
description="该二维码已不可继续使用。"
/>
) : (
<div style={{ textAlign: 'center' }}>
<QRCode
value={order.alipay_qr_code}
size={180}
bordered={false}
color="#000"
bgColor="#fff"
/>
</div>
)}
<Text type="secondary" style={{ fontSize: 12 }}>
{order.amount_yuan} 元 · 预计{' '}
{order.single_reward.toLocaleString()} 微豆
</Text>
<Text type="secondary" style={{ fontSize: 12 }}>
订单号{' '}
<Text copyable style={{ fontSize: 12 }}>
{order.order_id}
</Text>
</Text>
<Space wrap>
<Button
size="small"
icon={<ReloadOutlined />}
loading={statusLoading}
onClick={onRefreshStatus}
>
刷新支付状态
</Button>
{order.desktop_pay_url && !paid && !failed && (
<Button
size="small"
href={order.desktop_pay_url}
target="_blank"
rel="noreferrer"
>
电脑端支付
</Button>
)}
{onRefreshBalance && (
<Button size="small" onClick={onRefreshBalance}>
刷新到账
</Button>
)}
</Space>
{paymentStatus && (
<Tag
color={
paid
? 'success'
: failed
? 'error'
: 'processing'
}
>
{WEIBO_PAYMENT_STATUS_LABELS[paymentStatus.status]
|| paymentStatus.status}
</Tag>
)}
</Space>
)}
</>
);
}