feat: 优化支付码队列与支付超时
This commit is contained in:
@@ -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>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user