diff --git a/web/frontend/src/pages/douyu-tasks/DouyuTasksPage.tsx b/web/frontend/src/pages/douyu-tasks/DouyuTasksPage.tsx index 2e1ea36..da8e390 100644 --- a/web/frontend/src/pages/douyu-tasks/DouyuTasksPage.tsx +++ b/web/frontend/src/pages/douyu-tasks/DouyuTasksPage.tsx @@ -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([]); const [workbenchReady, setWorkbenchReady] = useState(false); const [selectedIds, setSelectedIds] = useState([]); + const [eliteSelectLoading, setEliteSelectLoading] = useState(false); const [goods, setGoods] = useState([]); const [tasks, setTasks] = useState([]); const [taskTypes, setTaskTypes] = useState>({}); @@ -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 = { ...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['columns'] = [ { - title: '#', width: 45, + title: '#', width: 50, render: (_, __, index) => {index + 1}, }, { - title: '账号', dataIndex: 'username', width: 150, + title: '账号', dataIndex: 'username', width: 180, render: (_, record) => ( {record.nickname || record.username} @@ -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 }>检测中; @@ -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 ?? -, }, // 精英宝典开通状态:积分区分不了「开通后积分花完」和「从未开通」,单独展示 ...(isEliteHandbook ? [{ - title: '宝典状态', dataIndex: 'elite_opened', width: 150, + title: '宝典状态', dataIndex: 'elite_opened', width: 160, render: (_: unknown, record: DouyuTaskAccountItem) => { const text = eliteStatusText(record); if (!text) return 未查; @@ -1689,11 +1768,11 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind }) }] as NonNullable['columns']> : [ { - title: '鱼翅', dataIndex: 'gold_balance', width: 70, + title: '鱼翅', dataIndex: 'gold_balance', width: 80, render: (v: number | null) => v ?? -, }, { - 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['columns']>), { - title: '最近操作', width: 220, + title: '最近操作', width: 260, render: (_, record) => { const latest = latestTaskByAccount.get(record.id); if (!latest) return 暂无操作; @@ -1772,7 +1851,7 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind }) {TASK_STATUS_LABELS[latest.status] || latest.status} - + {taskTypes[latest.task_type] || latest.task_type} @@ -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 -; @@ -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 -; @@ -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 }) } + placeholder="搜索账号/昵称/游戏名" prefix={} value={accountSearch} onChange={(e) => { setAccountSearch(e.target.value); setAccountPage(1); }} - style={{ width: 200 }} allowClear + style={{ width: 240 }} allowClear /> + + {isEliteHandbook && ( + + + + )} - + {isAdmin && ( )} {selectedIds.length > 0 && ( - + )}
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 }) } open={payOpen} - onCancel={() => setPayOpen(false)} - footer={( - - - {activePaySessionView && activePaySessionOwned && ( - void stopActivePaySession()} - > - - - )} - - - - )} + + + + ) + : null + } centered width={920} > @@ -3138,6 +3241,25 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind }) setActivePayBatchId(batchId); void loadPaySessionTasks([batchId]); }} + tabBarExtraContent={historicalPaySessionIds.length > 0 ? ( + +