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>
);
}