优化电竞手册换绑时间展示
This commit is contained in:
@@ -181,6 +181,21 @@ function formatWaitSeconds(seconds: number | null | undefined): string {
|
||||
return `${minutes}分${secs}秒`;
|
||||
}
|
||||
|
||||
function esportsRebindStatus(canChangeTime: number | null | undefined): {
|
||||
available: boolean;
|
||||
text: string;
|
||||
} | null {
|
||||
if (canChangeTime == null || Number.isNaN(Number(canChangeTime))) return null;
|
||||
const timestamp = Math.floor(Number(canChangeTime));
|
||||
if (timestamp <= 0 || timestamp <= Math.floor(Date.now() / 1000)) {
|
||||
return { available: true, text: '可换绑' };
|
||||
}
|
||||
return {
|
||||
available: false,
|
||||
text: new Date(timestamp * 1000).toLocaleString('zh-CN', { hour12: false }),
|
||||
};
|
||||
}
|
||||
|
||||
function resultNumber(result: Record<string, unknown> | null | undefined, key: string): number | null {
|
||||
const value = result?.[key];
|
||||
if (typeof value === 'number' && Number.isFinite(value)) return value;
|
||||
@@ -267,7 +282,9 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
|
||||
|
||||
// 换绑时间:优先最近一次查询/拦截任务结果,回退账号落库字段
|
||||
const latestChangeWaitByAccount = useMemo(() => {
|
||||
const map = new Map<number, { wait: number | null; text: string; taskId: number }>();
|
||||
const map = new Map<number, {
|
||||
wait: number | null; canChangeTime: number | null; text: string; taskId: number;
|
||||
}>();
|
||||
for (const task of tasks) {
|
||||
const taskTypes = isEsportsHandbook
|
||||
? ['prepare_esports_bind', 'get_esports_bind_qr', 'query_esports_game_name', 'confirm_esports_bind']
|
||||
@@ -275,12 +292,14 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
|
||||
if (!taskTypes.includes(task.task_type)) continue;
|
||||
if (!['success', 'failed'].includes(task.status)) continue;
|
||||
const wait = resultNumber(task.result, 'change_role_wait_time');
|
||||
const canChangeTime = resultNumber(task.result, 'can_change_time');
|
||||
// get_bind_qr 只有冷却拦截时才有 wait;无 wait 时跳过,避免覆盖
|
||||
if (!isEsportsHandbook && task.task_type === 'get_bind_qr' && wait == null) continue;
|
||||
const existing = map.get(task.account_id);
|
||||
if (existing && existing.taskId > task.id) continue;
|
||||
const text = resultText(task.result, 'change_role_wait_text') || formatWaitSeconds(wait);
|
||||
map.set(task.account_id, { wait, text, taskId: task.id });
|
||||
const esportsStatus = isEsportsHandbook ? esportsRebindStatus(canChangeTime) : null;
|
||||
const text = esportsStatus?.text || resultText(task.result, 'change_role_wait_text') || formatWaitSeconds(wait);
|
||||
map.set(task.account_id, { wait, canChangeTime, text, taskId: task.id });
|
||||
}
|
||||
return map;
|
||||
}, [isEsportsHandbook, tasks]);
|
||||
@@ -610,7 +629,8 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
|
||||
const esportsPlatName = resultText(esportsResult, 'plat_name');
|
||||
const esportsRoleLine = [esportsPlatName, esportsAreaName].filter(Boolean).join(' / ');
|
||||
const esportsCanChangeRole = Boolean(esportsBindTask && !esportsConfirmRunning);
|
||||
const esportsChangeWait = resultNumber(esportsResult, 'change_role_wait_time');
|
||||
const esportsCanChangeTime = resultNumber(esportsResult, 'can_change_time');
|
||||
const esportsRebind = esportsRebindStatus(esportsCanChangeTime);
|
||||
const esportsQrUrl = resultText(esportsLatestQrTask?.result, 'url');
|
||||
const esportsAccountName = esportsBindTask
|
||||
? (
|
||||
@@ -786,6 +806,20 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
|
||||
title: '换绑时间', dataIndex: 'change_role_wait_time', width: 130,
|
||||
render: (_, record) => {
|
||||
const fromTask = latestChangeWaitByAccount.get(record.id);
|
||||
const canChangeTime = fromTask?.canChangeTime ?? (
|
||||
isEsportsHandbook ? record.esports_can_change_time : null
|
||||
);
|
||||
const esportsStatus = isEsportsHandbook ? esportsRebindStatus(canChangeTime) : null;
|
||||
if (esportsStatus) {
|
||||
return esportsStatus.available
|
||||
? <Tag color="success">可换绑</Tag>
|
||||
: (
|
||||
<Space direction="vertical" size={0}>
|
||||
<Tag color="orange">暂不可换绑</Tag>
|
||||
<Text type="secondary" style={{ fontSize: 12 }}>{esportsStatus.text}</Text>
|
||||
</Space>
|
||||
);
|
||||
}
|
||||
const wait = fromTask?.wait ?? (
|
||||
isEsportsHandbook ? record.esports_change_role_wait_time : record.change_role_wait_time
|
||||
);
|
||||
@@ -809,9 +843,13 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
|
||||
return <Text type="secondary">{text || '-'}</Text>;
|
||||
},
|
||||
sorter: (a, b) => {
|
||||
const aw = latestChangeWaitByAccount.get(a.id)?.wait
|
||||
const aw = isEsportsHandbook
|
||||
? latestChangeWaitByAccount.get(a.id)?.canChangeTime ?? a.esports_can_change_time ?? -1
|
||||
: latestChangeWaitByAccount.get(a.id)?.wait
|
||||
?? (isEsportsHandbook ? a.esports_change_role_wait_time : a.change_role_wait_time) ?? -1;
|
||||
const bw = latestChangeWaitByAccount.get(b.id)?.wait
|
||||
const bw = isEsportsHandbook
|
||||
? latestChangeWaitByAccount.get(b.id)?.canChangeTime ?? b.esports_can_change_time ?? -1
|
||||
: latestChangeWaitByAccount.get(b.id)?.wait
|
||||
?? (isEsportsHandbook ? b.esports_change_role_wait_time : b.change_role_wait_time) ?? -1;
|
||||
return aw - bw;
|
||||
},
|
||||
@@ -1391,8 +1429,10 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
|
||||
<Text type="secondary">当前未检测到游戏角色,请先切换角色。</Text>
|
||||
)}
|
||||
|
||||
{esportsChangeWait != null && esportsChangeWait > 0 && esportsRoleName ? (
|
||||
<Text type="secondary">换绑冷却剩余:{formatWaitSeconds(esportsChangeWait)}</Text>
|
||||
{esportsRebind && esportsRoleName ? (
|
||||
<Text type="secondary">
|
||||
{esportsRebind.available ? '当前可换绑' : `可换绑时间:${esportsRebind.text}`}
|
||||
</Text>
|
||||
) : null}
|
||||
|
||||
{esportsQrUrl ? (
|
||||
|
||||
Reference in New Issue
Block a user