feat(douyu): 优化精英宝典批量选择与工作台交互

This commit is contained in:
yml
2026-11-21 16:50:10 +08:00
parent 6eaeaa1578
commit f74573a9c0
@@ -1,13 +1,13 @@
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
import {
Alert, Button, Card, Input, InputNumber, Modal, Popconfirm, QRCode, Select,
Alert, Button, Card, Dropdown, Input, InputNumber, Modal, Popconfirm, QRCode, Select,
Space, Table, Tabs, Tag, Tooltip, Typography, theme,
} from 'antd';
import type { TableProps } from 'antd';
import {
CheckCircleOutlined, ColumnWidthOutlined, CopyOutlined, CreditCardOutlined, ExclamationCircleOutlined, FieldTimeOutlined, FilterOutlined, GiftOutlined,
ImportOutlined, LoadingOutlined, QrcodeOutlined, ReloadOutlined,
SearchOutlined, SettingOutlined, ShoppingOutlined, StopOutlined,
ImportOutlined, LoadingOutlined, MoreOutlined, QrcodeOutlined, ReloadOutlined,
SearchOutlined, SettingOutlined, ShoppingOutlined, StopOutlined, SwapOutlined,
} from '@ant-design/icons';
import {
accountApi,
@@ -194,6 +194,7 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
const [workbenchIds, setWorkbenchIds] = useState<number[]>([]);
const [workbenchReady, setWorkbenchReady] = useState(false);
const [selectedIds, setSelectedIds] = useState<number[]>([]);
const [eliteSelectLoading, setEliteSelectLoading] = useState(false);
const [goods, setGoods] = useState<DouyuGoodsItem[]>([]);
const [tasks, setTasks] = useState<DouyuTaskItem[]>([]);
const [taskTypes, setTaskTypes] = useState<Record<string, string>>({});
@@ -963,21 +964,21 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
const ids = accountIds || selectedIds;
if (ids.length === 0) {
message.warning('请先选择账号');
return;
return null;
}
// 多批次并发:不再拦截,允许在已有批次运行时继续创建新批次
if (['lock_goods', 'exchange_goods', 'exchange_esports_goods', 'exchange_xpd_goods'].includes(taskType) && !selectedGoodsId) {
message.warning('请先选择兑换商品');
return;
return null;
}
if (taskType === 'exchange_xpd_goods') {
if (selectedXpdGoodsSoldOut) {
message.warning('该商品库存不足,请刷新商品列表后重试');
return;
return null;
}
if (!xpdPaymentOptions.some((option) => option.value === xpdPayType)) {
message.warning('该商品不支持当前兑换方式');
return;
return null;
}
}
const payload: Record<string, unknown> = { ...extraPayload };
@@ -1067,8 +1068,86 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
});
message.success(`已创建 ${result.count} 个任务`);
setTimeout(() => { void loadTasks(); }, 400);
return result;
} catch (error) {
message.error(getErrorMessage(error));
return null;
}
};
const invertCurrentPageSelection = () => {
const currentPageIds = new Set(accounts.map((account) => account.id));
setSelectedIds((current) => {
const next = new Set(current);
for (const accountId of currentPageIds) {
if (next.has(accountId)) next.delete(accountId);
else next.add(accountId);
}
return Array.from(next);
});
};
const queryAndSelectUnopenedElite = async () => {
if (!isEliteHandbook) return;
const targetIds = accounts.map((account) => account.id);
if (targetIds.length === 0) {
message.warning('当前页没有可查询的账号');
return;
}
setEliteSelectLoading(true);
try {
const created = await startTask('query_elite_status', targetIds);
if (!created) return;
const deadline = Date.now() + 180_000;
let batchTasks: DouyuTaskItem[] = [];
while (true) {
batchTasks = await douyuApi.listTasks(handbook, created.batch_id);
const allFinished = batchTasks.length >= created.count
&& batchTasks.every((task) => !['planned', 'pending', 'running'].includes(task.status));
if (allFinished || Date.now() >= deadline) break;
await new Promise((resolve) => window.setTimeout(resolve, 800));
}
const unopenedIds = new Set(
batchTasks
.filter((task) => task.status === 'success' && task.result?.elite_opened === false)
.map((task) => task.account_id),
);
let refreshedAccounts = accounts;
if (workbenchIds.length > 0) {
const refreshed = await douyuApi.listAccountsPaged({
ids: workbenchIds.join(','),
search: accountSearch.trim() || undefined,
page: accountPage,
page_size: accountPageSize,
});
refreshedAccounts = refreshed.items;
setAccounts(refreshed.items);
setAccountTotal(refreshed.total);
}
const selected = refreshedAccounts
.filter((account) => unopenedIds.has(account.id))
.map((account) => account.id);
setSelectedIds(selected);
const unfinished = batchTasks.filter(
(task) => ['planned', 'pending', 'running'].includes(task.status),
).length;
if (unfinished > 0) {
message.warning(`查询超时,已按完成的 ${batchTasks.length - unfinished} 个任务选中 ${selected.length} 个未开通账号`);
} else if (selected.length > 0) {
message.success(`查询完成,已选中 ${selected.length} 个未开通精英宝典的账号`);
} else {
message.info('查询完成,当前页没有未开通精英宝典的账号');
}
} catch (error) {
message.error(`查询未开通账号失败: ${getErrorMessage(error)}`);
} finally {
setEliteSelectLoading(false);
}
};
@@ -1548,11 +1627,11 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
// Account table
const accountColumns: TableProps<DouyuTaskAccountItem>['columns'] = [
{
title: '#', width: 45,
title: '#', width: 50,
render: (_, __, index) => <Text type="secondary">{index + 1}</Text>,
},
{
title: '账号', dataIndex: 'username', width: 150,
title: '账号', dataIndex: 'username', width: 180,
render: (_, record) => (
<Space direction="vertical" size={0}>
<Text strong>{record.nickname || record.username}</Text>
@@ -1561,7 +1640,7 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
),
},
{
title: 'CK状态', width: 100, align: 'center',
title: 'CK状态', width: 110, align: 'center',
render: (_, record) => {
if (ckCheckingIds.has(record.id)) {
return <Tag color="processing" icon={<LoadingOutlined />}>检测中</Tag>;
@@ -1584,7 +1663,7 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
},
},
{
title: '游戏名', dataIndex: 'game_name', width: 170,
title: '游戏名', dataIndex: 'game_name', width: 220,
render: (_, record) => {
if (isPeaceHandbook) {
// 和平小店:角色名与绑定状态都读**账号字段**(不再从任务日志反推)。
@@ -1665,13 +1744,13 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
{
title: isPeaceHandbook ? '点券' : (isEsportsHandbook ? '电竞积分' : '积分'),
dataIndex: isPeaceHandbook ? 'xpd_balance' : (isEsportsHandbook ? 'esports_points' : 'points'),
width: 80,
width: 88,
render: (v) => v ?? <Text type="secondary">-</Text>,
},
// 精英宝典开通状态:积分区分不了「开通后积分花完」和「从未开通」,单独展示
...(isEliteHandbook
? [{
title: '宝典状态', dataIndex: 'elite_opened', width: 150,
title: '宝典状态', dataIndex: 'elite_opened', width: 160,
render: (_: unknown, record: DouyuTaskAccountItem) => {
const text = eliteStatusText(record);
if (!text) return <Text type="secondary">未查</Text>;
@@ -1689,11 +1768,11 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
}] as NonNullable<TableProps<DouyuTaskAccountItem>['columns']>
: [
{
title: '鱼翅', dataIndex: 'gold_balance', width: 70,
title: '鱼翅', dataIndex: 'gold_balance', width: 80,
render: (v: number | null) => v ?? <Text type="secondary">-</Text>,
},
{
title: '限制兑换', dataIndex: 'exchange_balance', width: 150, ellipsis: true,
title: '限制兑换', dataIndex: 'exchange_balance', width: 160, ellipsis: true,
render: (_, record) => {
const latestLimitedTask = latestLimitedGoodsTaskByAccount.get(record.id);
const text = limitedGoodsTaskText(latestLimitedTask);
@@ -1709,7 +1788,7 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
},
},
{
title: '换绑时间', dataIndex: 'change_role_wait_time', width: 130,
title: '换绑时间', dataIndex: 'change_role_wait_time', width: 150,
render: (_, record) => {
const fromTask = latestChangeWaitByAccount.get(record.id);
const canChangeTime = fromTask?.canChangeTime ?? (
@@ -1762,7 +1841,7 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
},
] as NonNullable<TableProps<DouyuTaskAccountItem>['columns']>),
{
title: '最近操作', width: 220,
title: '最近操作', width: 260,
render: (_, record) => {
const latest = latestTaskByAccount.get(record.id);
if (!latest) return <Text type="secondary">暂无操作</Text>;
@@ -1772,7 +1851,7 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
<Tag color={TASK_STATUS_COLORS[latest.status] || 'default'}>
{TASK_STATUS_LABELS[latest.status] || latest.status}
</Tag>
<Text strong ellipsis style={{ maxWidth: 130 }}>
<Text strong ellipsis style={{ maxWidth: 170 }}>
{taskTypes[latest.task_type] || latest.task_type}
</Text>
</Space>
@@ -1789,7 +1868,7 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
},
},
{
title: '二维码', width: 76, align: 'center',
title: '二维码', width: 92, align: 'center',
render: (_, record) => {
const task = latestTaskByAccount.get(record.id);
// 只要结果里还有二维码地址就一直展示:绑定类任务等不到扫码时也会以
@@ -1819,7 +1898,7 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
},
},
{
title: '兑换图片', width: 80, align: 'center',
title: '兑换图片', width: 100, align: 'center',
render: (_, record) => {
const task = latestExchangeTaskByAccount.get(record.id);
if (!task) return <Text type="secondary">-</Text>;
@@ -1852,7 +1931,7 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
},
}] : []),
...(!isPeaceHandbook && !isEsportsHandbook ? [{
title: '锁单', width: 150, align: 'center' as const,
title: '锁单', width: 170, align: 'center' as const,
render: (_: unknown, record: DouyuTaskAccountItem) => {
const task = latestLockedTaskByAccount.get(record.id);
if (!task) return <Text type="secondary">-</Text>;
@@ -2110,6 +2189,19 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
const activePaySessionView = visiblePaySessionViews.find(
(view) => view.session.batchId === activePayBatchId,
) || visiblePaySessionViews[0];
const requestClosePayModal = () => {
if (activePaySessionView?.active) {
Modal.confirm({
title: '关闭当前支付任务?',
content: '关闭只会移除当前支付码会话,后台任务仍会继续运行;如需停止任务,请使用“停止当前批次”。',
okText: '关闭会话',
cancelText: '取消',
onOk: closeActivePaySession,
});
return;
}
closeActivePaySession();
};
const payReadyCount = activePaySessionView?.readyCount || 0;
const payQueuedCount = activePaySessionView?.queuedCount || 0;
const payDoneCount = activePaySessionView?.doneCount || 0;
@@ -2442,19 +2534,37 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
<Space style={{ marginBottom: 8, width: '100%', justifyContent: 'space-between', flexShrink: 0 }} wrap>
<Space>
<Input
size="small" placeholder="搜索账号/昵称/游戏名" prefix={<SearchOutlined />}
placeholder="搜索账号/昵称/游戏名" prefix={<SearchOutlined />}
value={accountSearch}
onChange={(e) => {
setAccountSearch(e.target.value);
setAccountPage(1);
}}
style={{ width: 200 }} allowClear
style={{ width: 240 }} allowClear
/>
<Button
icon={<SwapOutlined />}
disabled={accounts.length === 0}
onClick={invertCurrentPageSelection}
>
反选本页
</Button>
{isEliteHandbook && (
<Tooltip title="查询当前页账号并选中未开通精英宝典的账号">
<Button
icon={<FilterOutlined />}
loading={eliteSelectLoading}
disabled={accounts.length === 0}
onClick={() => void queryAndSelectUnopenedElite()}
>
查询并选未开通
</Button>
</Tooltip>
)}
</Space>
<Space>
<Button size="small" icon={<ImportOutlined />} onClick={() => setImportOpen(true)}>导入账号</Button>
<Button icon={<ImportOutlined />} onClick={() => setImportOpen(true)}>导入账号</Button>
<Button
size="small"
icon={<CheckCircleOutlined />}
disabled={selectedIds.length === 0 || ckCheckingIds.size > 0}
onClick={() => void checkWorkbenchCk(selectedIds)}
@@ -2463,7 +2573,6 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
</Button>
{isAdmin && (
<Button
size="small"
danger
icon={<ReloadOutlined />}
disabled={selectedIds.length === 0}
@@ -2473,20 +2582,20 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
</Button>
)}
{selectedIds.length > 0 && (
<Button size="small" danger onClick={removeSelected}>移出选中</Button>
<Button danger onClick={removeSelected}>移出选中</Button>
)}
</Space>
</Space>
<div ref={accountTableAreaRef} style={{ flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }}>
<Table
rowKey="id"
size="small"
className="douyu-task-record-table"
loading={loading || !workbenchReady}
locale={{ emptyText: '工作台暂无账号,点击右上角「导入账号」添加' }}
rowSelection={{
selectedRowKeys: selectedIds,
onChange: (keys) => setSelectedIds(keys.map(Number)),
preserveSelectedRowKeys: true,
}}
columns={accountColumns}
dataSource={accounts}
@@ -2496,7 +2605,6 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
total: accountTotal,
showSizeChanger: true,
pageSizeOptions: [10, 20, 50, 100],
size: 'small',
showLessItems: true,
showTotal: (total) => `共 ${total} 条`,
onChange: (page, size) => {
@@ -2508,7 +2616,7 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
},
}}
tableLayout="fixed"
scroll={{ x: 1380, y: Math.max(120, accountTableAreaHeight - 80) }}
scroll={{ x: 1880, y: Math.max(120, accountTableAreaHeight - 80) }}
onRow={(record) => ({
onContextMenu: (e) => handleRowContextMenu(record, e),
style: { cursor: 'context-menu' },
@@ -2536,7 +2644,7 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
.douyu-task-record-table .ant-table {
flex: 1;
min-height: 0;
font-size: 12px;
font-size: 13px;
display: flex;
flex-direction: column;
}
@@ -2556,22 +2664,26 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
}
.douyu-task-record-table .ant-table-thead > tr > th,
.douyu-task-record-table .ant-table-tbody > tr > td {
padding: 4px 8px;
line-height: 20px;
padding: 7px 10px;
line-height: 21px;
}
.douyu-task-record-table .ant-table-thead > tr > th {
font-size: 13px;
font-weight: 600;
}
.douyu-task-record-table .ant-typography {
font-size: 12px;
font-size: 13px;
}
.douyu-task-record-table .ant-tag {
font-size: 11px;
line-height: 18px;
font-size: 12px;
line-height: 20px;
margin-inline-end: 0;
padding-inline: 5px;
padding-inline: 7px;
}
.douyu-task-record-table .ant-pagination {
flex-shrink: 0;
margin: 0;
padding: 6px 4px 2px;
padding: 8px 4px 2px;
border-top: 1px solid ${token.colorBorderSecondary};
}
`;
@@ -3095,39 +3207,30 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
</Space>
}
open={payOpen}
onCancel={() => setPayOpen(false)}
footer={(
<Space wrap>
<Button onClick={() => setPayOpen(false)}>关闭</Button>
{activePaySessionView && activePaySessionOwned && (
<Popconfirm
title="停止当前充值批次?"
description="只停止当前 Tab 的批次,不会影响其他批次。"
okText="停止"
cancelText="取消"
onConfirm={() => void stopActivePaySession()}
>
<Button
danger
icon={<StopOutlined />}
loading={stoppingPayBatchId === activePaySessionView.session.batchId}
disabled={!activePaySessionView.active}
onCancel={requestClosePayModal}
footer={
activePaySessionView && activePaySessionOwned && activePaySessionView.active
? (
<Space wrap>
<Popconfirm
title="停止当前充值批次?"
description="只停止当前 Tab 的批次,不会影响其他批次。"
okText="停止"
cancelText="取消"
onConfirm={() => void stopActivePaySession()}
>
停止当前批次
</Button>
</Popconfirm>
)}
<Button
onClick={clearHistoricalPaySessions}
disabled={historicalPaySessionIds.length === 0}
>
清理历史会话
</Button>
<Button onClick={closeActivePaySession} disabled={!activePaySessionView}>
关闭当前会话
</Button>
</Space>
)}
<Button
danger
icon={<StopOutlined />}
loading={stoppingPayBatchId === activePaySessionView.session.batchId}
>
停止当前批次
</Button>
</Popconfirm>
</Space>
)
: null
}
centered
width={920}
>
@@ -3138,6 +3241,25 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
setActivePayBatchId(batchId);
void loadPaySessionTasks([batchId]);
}}
tabBarExtraContent={historicalPaySessionIds.length > 0 ? (
<Dropdown
trigger={['click']}
menu={{
items: [{
key: 'clear-history',
label: `清理历史会话(${historicalPaySessionIds.length})`,
onClick: clearHistoricalPaySessions,
}],
}}
>
<Button
type="text"
icon={<MoreOutlined />}
aria-label="更多会话操作"
title="更多会话操作"
/>
</Dropdown>
) : null}
items={visiblePaySessionViews.map((view) => ({
key: view.session.batchId,
label: (