优化(登录任务): 日志实时写库并支持弹窗自动刷新

- 进行中任务的日志每 3 秒增量写库,不再等结束才有内容
- 弹窗打开期间每 3 秒自动刷新,显示任务进行中提示
- 缺少邮箱/邮箱密码时直接失败,不再白等两轮验证码
- 邮箱验证码等待时长支持 DOUYU_EMAIL_CODE_WAIT_SECONDS 配置
- 补充对应测试
This commit is contained in:
yml
2026-11-25 18:27:56 +08:00
parent dcd11cb8b1
commit 5efe6b6949
5 changed files with 181 additions and 50 deletions
+37 -14
View File
@@ -580,20 +580,36 @@ export default function LoginTasksPage() {
[tagAccountIds],
);
const openTaskLogs = async (task: LoginTaskItem) => {
const openTaskLogs = (task: LoginTaskItem) => {
setLogTask(task);
setLogItems([]);
setLogsLoading(true);
try {
const data = await loginApi.taskLogs(task.id);
setLogItems(data.items || []);
} catch (error) {
message.error(getErrorMessage(error));
} finally {
setLogsLoading(false);
}
};
// 弹窗打开期间拉日志;任务还在跑就每 3 秒刷新,能看到实时进度。
useEffect(() => {
if (!logTask) return;
let alive = true;
const taskId = logTask.id;
const running = ['pending', 'running'].includes(logTask.status);
const load = async (silent: boolean) => {
if (!silent) setLogsLoading(true);
try {
const data = await loginApi.taskLogs(taskId);
if (alive) setLogItems(data.items || []);
} catch (error) {
if (alive && !silent) message.error(getErrorMessage(error));
} finally {
if (alive && !silent) setLogsLoading(false);
}
};
void load(false);
const timer = running ? window.setInterval(() => void load(true), 3000) : undefined;
return () => {
alive = false;
if (timer) window.clearInterval(timer);
};
}, [logTask]);
const columns = [
{ title: 'ID', dataIndex: 'id', width: 78 },
{
@@ -1193,13 +1209,20 @@ export default function LoginTasksPage() {
</div>
) : logItems.length === 0 ? (
<Text type="secondary">
暂无日志。逐账号日志在本次登录尝试结束后写入;旧的登录任务不会再补。
{logTask && ['pending', 'running'].includes(logTask.status)
? '该账号还没产生日志(可能仍在排队或刚开始),页面会每 3 秒自动刷新。'
: '暂无日志。逐账号日志在登录过程中实时写入;部署前的旧任务不会补。'}
</Text>
) : (
<>
<Text type="secondary" style={{ fontSize: 12 }}>
共 {logItems.length} 条,包含代理预检、极验、登录步骤和邮箱取码等完整过程。
</Text>
<Space size={8} wrap>
<Text type="secondary" style={{ fontSize: 12 }}>
共 {logItems.length} 条,包含代理预检、极验、登录步骤和邮箱取码等完整过程。
</Text>
{logTask && ['pending', 'running'].includes(logTask.status) ? (
<Tag color="processing">任务进行中,每 3 秒自动刷新</Tag>
) : null}
</Space>
<div style={{ maxHeight: '58vh', overflow: 'auto', display: 'grid', gap: 6, marginTop: 8 }}>
{logItems.map((item, index) => (
<div