fix(platform): 持久化并完善斗鱼兑换结果图片
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import dayjs from 'dayjs';
|
||||
import type { Dayjs } from 'dayjs';
|
||||
import { Alert, Button, Card, DatePicker, Descriptions, Drawer, Empty, Input, InputNumber, Modal, QRCode, Segmented, Select, Space, Switch, Table, Tabs, Tag, Timeline, Typography } from 'antd';
|
||||
import { CheckCircleOutlined, CopyOutlined, CreditCardOutlined, GiftOutlined, LinkOutlined, QrcodeOutlined, ReloadOutlined, SettingOutlined, ShoppingOutlined, SyncOutlined, UndoOutlined, UserSwitchOutlined } from '@ant-design/icons';
|
||||
import { CheckCircleOutlined, CopyOutlined, CreditCardOutlined, DownloadOutlined, GiftOutlined, LinkOutlined, QrcodeOutlined, ReloadOutlined, SettingOutlined, ShoppingOutlined, SyncOutlined, UndoOutlined, UserSwitchOutlined } from '@ant-design/icons';
|
||||
import type { ColumnsType } from 'antd/es/table';
|
||||
import { douyuApi, platformFulfillmentApi } from '../api/modules';
|
||||
import type { DouyuGoodsItem, DouyuTaskItem, PlatformFulfillmentDetail, PlatformFulfillmentMapping, PlatformFulfillmentSettings, PlatformFulfillmentTask } from '../api/modules';
|
||||
import ExchangeResultImage from '../components/ExchangeResultImage';
|
||||
import { copyImageToClipboard, fetchExchangeImageBlob, getExchangeImage, isExchangeTask } from '../utils/exchangeImage';
|
||||
import { TASK_STATUS_COLORS, TASK_STATUS_LABELS, taskQrUrl } from './douyu-tasks/config';
|
||||
import { getErrorMessage } from '../utils/error';
|
||||
import { message } from '../utils/antdMessage';
|
||||
@@ -342,6 +343,11 @@ export default function PlatformFulfillmentPage() {
|
||||
const [douyuActionType, setDouyuActionType] = useState('');
|
||||
const [douyuActionBatchId, setDouyuActionBatchId] = useState('');
|
||||
const [douyuActionTask, setDouyuActionTask] = useState<DouyuTaskItem | null>(null);
|
||||
const [exchangeImageViewer, setExchangeImageViewer] = useState<{
|
||||
url: string;
|
||||
title: string;
|
||||
} | null>(null);
|
||||
const exchangeImageSaveAttempts = useRef(new Set<number>());
|
||||
const [goldAmount, setGoldAmount] = useState(30);
|
||||
const [giftCount, setGiftCount] = useState(1);
|
||||
|
||||
@@ -427,6 +433,8 @@ export default function PlatformFulfillmentPage() {
|
||||
}, [douyuActionBatchId]);
|
||||
|
||||
const selected = detail?.task || null;
|
||||
const selectedExchangeTaskId = selected?.exchangeTaskId ?? null;
|
||||
const selectedExchangeImageKey = selected?.exchangeResultImage?.objectKey || '';
|
||||
const qrValue = selected?.bindTask?.qrUrl || '';
|
||||
const douyuActionQrValue = douyuActionTask ? taskQrUrl(douyuActionTask) : '';
|
||||
|
||||
@@ -434,6 +442,31 @@ export default function PlatformFulfillmentPage() {
|
||||
if (qrValue) setQrOpen(true);
|
||||
}, [qrValue]);
|
||||
|
||||
useEffect(() => {
|
||||
if (
|
||||
!selectedId
|
||||
|| !selectedExchangeTaskId
|
||||
|| selectedExchangeImageKey
|
||||
|| exchangeImageSaveAttempts.current.has(selectedExchangeTaskId)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
exchangeImageSaveAttempts.current.add(selectedExchangeTaskId);
|
||||
void douyuApi.getTask(selectedExchangeTaskId)
|
||||
.then(async (task) => {
|
||||
if (task.status !== 'success' || !isExchangeTask(task)) return false;
|
||||
await getExchangeImage(task);
|
||||
return true;
|
||||
})
|
||||
.then((saved) => {
|
||||
if (saved) void loadDetail(selectedId, true);
|
||||
})
|
||||
.catch(() => {
|
||||
// 图片补存失败不影响履约详情;下次重新打开详情时会再次尝试。
|
||||
exchangeImageSaveAttempts.current.delete(selectedExchangeTaskId);
|
||||
});
|
||||
}, [selectedId, selectedExchangeTaskId, selectedExchangeImageKey, loadDetail]);
|
||||
|
||||
const sync = async () => {
|
||||
setSyncing(true);
|
||||
try {
|
||||
@@ -652,6 +685,28 @@ export default function PlatformFulfillmentPage() {
|
||||
void loadTasks();
|
||||
};
|
||||
|
||||
const copyExchangeImageViewer = async (url = exchangeImageViewer?.url) => {
|
||||
if (!url) return;
|
||||
try {
|
||||
const blob = await fetchExchangeImageBlob(url);
|
||||
await copyImageToClipboard(blob);
|
||||
message.success('兑换结果图片已复制');
|
||||
} catch (error) {
|
||||
message.error(`复制兑换结果图片失败:${getErrorMessage(error)}`);
|
||||
}
|
||||
};
|
||||
|
||||
const downloadExchangeImageViewer = (
|
||||
url = exchangeImageViewer?.url,
|
||||
title = exchangeImageViewer?.title,
|
||||
) => {
|
||||
if (!url) return;
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = `${title || '斗鱼兑换结果'}.png`;
|
||||
link.click();
|
||||
};
|
||||
|
||||
const openMapping = async (task?: PlatformFulfillmentTask) => {
|
||||
setMappingSku(task?.internalSkuKey || '');
|
||||
setMappingGoodsId(task?.commodityId || '');
|
||||
@@ -1147,6 +1202,55 @@ export default function PlatformFulfillmentPage() {
|
||||
/>
|
||||
) : null}
|
||||
|
||||
{selected.exchangeResultImage ? (
|
||||
<Card
|
||||
size="small"
|
||||
title="兑换结果凭证"
|
||||
extra={(
|
||||
<Space>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<CopyOutlined />}
|
||||
onClick={() => void copyExchangeImageViewer(selected.exchangeResultImage!.url)}
|
||||
>
|
||||
复制图片
|
||||
</Button>
|
||||
<Button
|
||||
size="small"
|
||||
icon={<DownloadOutlined />}
|
||||
onClick={() => downloadExchangeImageViewer(
|
||||
selected.exchangeResultImage!.url,
|
||||
`斗鱼兑换结果-${selected.skuName || selected.platformOrderId}`,
|
||||
)}
|
||||
>
|
||||
下载图片
|
||||
</Button>
|
||||
</Space>
|
||||
)}
|
||||
>
|
||||
<div
|
||||
onClick={() => setExchangeImageViewer({
|
||||
url: selected.exchangeResultImage!.url,
|
||||
title: `斗鱼兑换结果-${selected.skuName || selected.platformOrderId}`,
|
||||
})}
|
||||
style={{ cursor: 'zoom-in', textAlign: 'center' }}
|
||||
title="点击查看大图"
|
||||
>
|
||||
<img
|
||||
src={selected.exchangeResultImage.url}
|
||||
alt="兑换结果凭证"
|
||||
style={{
|
||||
width: '100%',
|
||||
maxWidth: 480,
|
||||
height: 'auto',
|
||||
borderRadius: 8,
|
||||
border: '1px solid #f0f0f0',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</Card>
|
||||
) : null}
|
||||
|
||||
<div
|
||||
style={{
|
||||
display: 'grid',
|
||||
@@ -1348,7 +1452,14 @@ export default function PlatformFulfillmentPage() {
|
||||
<QRCode value={douyuActionQrValue} size={260} />
|
||||
) : null}
|
||||
{douyuActionType === 'exchange_goods' && douyuActionTask.status === 'success' ? (
|
||||
<ExchangeResultImage task={douyuActionTask} variant="detail" />
|
||||
<ExchangeResultImage
|
||||
task={douyuActionTask}
|
||||
variant="detail"
|
||||
onClick={(_task, url) => setExchangeImageViewer({
|
||||
url,
|
||||
title: `斗鱼兑换结果-${selected?.skuName || selected?.platformOrderId || douyuActionTask.id}`,
|
||||
})}
|
||||
/>
|
||||
) : null}
|
||||
</>
|
||||
) : (
|
||||
@@ -1357,6 +1468,33 @@ export default function PlatformFulfillmentPage() {
|
||||
</Space>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
open={Boolean(exchangeImageViewer)}
|
||||
title="兑换结果图片"
|
||||
width={620}
|
||||
centered
|
||||
footer={(
|
||||
<Space>
|
||||
<Button onClick={() => setExchangeImageViewer(null)}>关闭</Button>
|
||||
<Button icon={<CopyOutlined />} onClick={() => void copyExchangeImageViewer()}>
|
||||
复制图片
|
||||
</Button>
|
||||
<Button icon={<DownloadOutlined />} onClick={() => downloadExchangeImageViewer()}>
|
||||
下载图片
|
||||
</Button>
|
||||
</Space>
|
||||
)}
|
||||
onCancel={() => setExchangeImageViewer(null)}
|
||||
>
|
||||
{exchangeImageViewer ? (
|
||||
<img
|
||||
src={exchangeImageViewer.url}
|
||||
alt="兑换结果"
|
||||
style={{ width: '100%', maxHeight: '72vh', objectFit: 'contain', display: 'block' }}
|
||||
/>
|
||||
) : null}
|
||||
</Modal>
|
||||
|
||||
<Modal open={qrOpen && Boolean(qrValue)} title="客户扫码绑定游戏角色" footer={null} onCancel={() => setQrOpen(false)}>
|
||||
<Space direction="vertical" align="center" style={{ width: '100%' }}>
|
||||
{qrValue ? <QRCode value={qrValue} size={260} /> : null}
|
||||
|
||||
Reference in New Issue
Block a user