增加重试

This commit is contained in:
yml2213
2026-06-22 15:45:48 +08:00
parent 2443d23316
commit 9fba12aad0
8 changed files with 199 additions and 60 deletions
+71 -5
View File
@@ -1,8 +1,8 @@
import { useEffect, useState, useRef, useMemo, useCallback } from 'react';
import {
Table, Button, Select, message, Tag, Space, Card, Row, Col, Statistic, Spin,
Table, Button, Select, message, Tag, Space, Card, Row, Col, Statistic, Spin, InputNumber, Tooltip,
} from 'antd';
import { PlayCircleOutlined, StopOutlined, FilterOutlined } from '@ant-design/icons';
import { PlayCircleOutlined, StopOutlined, FilterOutlined, ThunderboltOutlined, ReloadOutlined } from '@ant-design/icons';
import { accountApi, loginApi } from '../api/modules';
import { getUser, hasPerm } from '../store/auth';
@@ -31,6 +31,7 @@ export default function LoginTasksPage() {
const [logs, setLogs] = useState<{ level: string; message: string }[]>([]);
const [wsConnected, setWsConnected] = useState(false);
const [selectedTags, setSelectedTags] = useState<string[]>([]);
const [concurrency, setConcurrency] = useState(3);
const wsRef = useRef<WebSocket | null>(null);
const user = getUser();
@@ -111,15 +112,16 @@ export default function LoginTasksPage() {
return () => clearInterval(timer);
}, [batchId]);
const handleBatchLogin = async () => {
if (selectedIds.length === 0) {
// 共享的批量登录启动逻辑
const startBatch = async (accountIds: number[]) => {
if (accountIds.length === 0) {
message.warning('请选择账号');
return;
}
setLoading(true);
setLogs([]);
try {
const result = await loginApi.createBatch(selectedIds);
const result = await loginApi.createBatch(accountIds, 5, concurrency);
setBatchId(result.batch_id);
message.success(`已创建登录任务,共 ${result.count} 个账号`);
@@ -148,6 +150,27 @@ export default function LoginTasksPage() {
}
};
const handleBatchLogin = () => startBatch(selectedIds);
// 重试当前批次所有失败的任务
const handleRetryFailed = () => {
const failedIds = tasks
.filter((t) => ['failed', 'error'].includes(t.status))
.map((t) => t.account_id);
if (failedIds.length === 0) {
message.info('没有失败的任务');
return;
}
startBatch(failedIds);
};
// 重试单个失败任务
const handleRetryOne = (taskId: number) => {
const task = tasks.find((t) => t.id === taskId);
if (!task) return;
startBatch([task.account_id]);
};
const handleStop = async () => {
if (batchId) {
try {
@@ -172,6 +195,25 @@ export default function LoginTasksPage() {
},
{ title: '消息', dataIndex: 'message', ellipsis: true },
{ title: '时间', dataIndex: 'created_at', width: 180 },
{
title: '操作',
width: 80,
render: (_: any, record: any) => {
if (['failed', 'error'].includes(record.status) && !wsConnected) {
return (
<Button
type="link"
size="small"
icon={<ReloadOutlined />}
onClick={() => handleRetryOne(record.id)}
>
</Button>
);
}
return null;
},
},
];
return (
@@ -252,6 +294,17 @@ export default function LoginTasksPage() {
</>
)}
/>
<Tooltip title="同时登录的账号数,1为顺序执行">
<ThunderboltOutlined style={{ color: '#888' }} />
</Tooltip>
<InputNumber
min={1}
max={10}
value={concurrency}
onChange={(v) => setConcurrency(v || 1)}
style={{ width: 60 }}
size="small"
/>
<Button
type="primary"
icon={<PlayCircleOutlined />}
@@ -291,6 +344,19 @@ export default function LoginTasksPage() {
<Card
title="任务列表"
size="small"
extra={
!wsConnected && failedCount > 0 && (
<Button
type="primary"
size="small"
icon={<ReloadOutlined />}
onClick={handleRetryFailed}
loading={loading}
>
({failedCount})
</Button>
)
}
style={{ flex: 1, display: 'flex', flexDirection: 'column', minHeight: 0 }}
bodyStyle={{ flex: 1, overflow: 'auto', padding: 0 }}
>