feat(douyu): 整合自动化中心并修复重登队列

This commit is contained in:
yml
2026-11-22 21:17:37 +08:00
parent af05c54c3f
commit 94de1d167b
18 changed files with 854 additions and 1029 deletions
+1 -1
View File
@@ -78,7 +78,7 @@ export default function MainLayout({ onLogout }: { onLogout?: () => void }) {
douyuItems.push({ key: '/cookie-operations', label: 'CK 检测与重登', icon: <SafetyCertificateOutlined /> });
}
if (can('automation:view')) {
douyuItems.push({ key: '/automation', label: '自动巡检', icon: <RobotOutlined /> });
douyuItems.push({ key: '/automation', label: '斗鱼自动化', icon: <RobotOutlined /> });
}
if (can('douyu:task')) {
douyuItems.push({ key: '/douyu/elite', label: '精英宝典', icon: <BookOutlined /> });
@@ -9,7 +9,6 @@ import { DownloadOutlined, PlayCircleOutlined, ReloadOutlined, StopOutlined } fr
import { accountApi, accountCheckApi, type AccountCheckBatch, type AccountCheckItem } from '../api/modules';
import { formatTime } from '../utils/time';
import { getErrorMessage } from '../utils/error';
import AccountPlatformStatusPanel from './douyu-tasks/AccountPlatformStatusPanel';
const { TextArea } = Input;
const { Text, Title } = Typography;
@@ -341,8 +340,6 @@ export default function AccountCheckPage() {
<Space orientation="vertical" size={16} style={{ width: '100%' }}>
<Title level={3} style={{ margin: 0 }}>账号检测</Title>
<AccountPlatformStatusPanel />
<Card title="选择账号来源">
<Space orientation="vertical" size={12} style={{ width: '100%' }}>
{/* 两种来源并存:手动粘贴是旧逻辑,一条没动;
File diff suppressed because it is too large Load Diff
@@ -4,6 +4,7 @@ import {
Button,
Card,
Col,
Collapse,
Empty,
Form,
Input,
@@ -80,6 +81,76 @@ interface TrendRow {
reloginOk: number;
}
function MiniTrend({
title,
values,
dates,
color,
suffix = '',
}: {
title: string;
values: number[];
dates: string[];
color: string;
suffix?: string;
}) {
const width = 260;
const height = 64;
const padding = 5;
const max = Math.max(...values, 1);
const step = values.length > 1 ? (width - padding * 2) / (values.length - 1) : 0;
const points = values.map((value, index) => {
const x = padding + step * index;
const y = height - padding - (Math.max(0, value) / max) * (height - padding * 2);
return `${x},${y}`;
}).join(' ');
const latest = values.at(-1) || 0;
return (
<div style={{ minWidth: 0 }}>
<Space size={8} align="baseline">
<Text strong>{title}</Text>
<Text type="secondary" style={{ fontSize: 12 }}>
最近 {latest}{suffix}
</Text>
</Space>
<svg
viewBox={`0 0 ${width} ${height}`}
width="100%"
height={74}
role="img"
aria-label={`${title}趋势`}
preserveAspectRatio="none"
style={{ display: 'block', marginTop: 6 }}
>
<line
x1={padding}
y1={height - padding}
x2={width - padding}
y2={height - padding}
stroke="currentColor"
opacity={0.12}
/>
{points ? (
<polyline
points={points}
fill="none"
stroke={color}
strokeWidth={2.5}
strokeLinecap="round"
strokeLinejoin="round"
vectorEffect="non-scaling-stroke"
/>
) : null}
</svg>
<div style={{ display: 'flex', justifyContent: 'space-between' }}>
<Text type="secondary" style={{ fontSize: 11 }}>{dates[0]?.slice(5) || '-'}</Text>
<Text type="secondary" style={{ fontSize: 11 }}>{dates.at(-1)?.slice(5) || '-'}</Text>
</div>
</div>
);
}
export default function AccountPlatformStatusPanel() {
const { can } = usePermissions();
const canManage = can('douyu:config');
@@ -606,16 +677,66 @@ export default function AccountPlatformStatusPanel() {
}}
/>
<Space orientation="vertical" size={8} style={{ width: '100%', marginTop: 20 }}>
<Text strong>{`近 ${trends?.days || 7} 天趋势`}</Text>
<Table
rowKey="date"
size="small"
columns={trendColumns}
dataSource={trendRows}
loading={trendsLoading}
pagination={false}
scroll={{ x: 750 }}
<Space orientation="vertical" size={12} style={{ width: '100%', marginTop: 20 }}>
<div>
<Text strong>{`近 ${trends?.days || 7} 天运行趋势`}</Text>
<Text type="secondary" style={{ marginLeft: 8 }}>
查询、登录、CK 失效和重登结果
</Text>
</div>
<Row gutter={[24, 16]}>
<Col xs={24} md={12} xl={6}>
<MiniTrend
title="查询量"
values={trendRows.map((row) => row.queryTotal)}
dates={trendRows.map((row) => row.date)}
color="#1677ff"
/>
</Col>
<Col xs={24} md={12} xl={6}>
<MiniTrend
title="登录量"
values={trendRows.map((row) => row.loginTotal)}
dates={trendRows.map((row) => row.date)}
color="#13c2c2"
/>
</Col>
<Col xs={24} md={12} xl={6}>
<MiniTrend
title="CK 失效"
values={trendRows.map((row) => row.ckInvalid)}
dates={trendRows.map((row) => row.date)}
color="#ff4d4f"
/>
</Col>
<Col xs={24} md={12} xl={6}>
<MiniTrend
title="重登成功"
values={trendRows.map((row) => row.reloginOk)}
dates={trendRows.map((row) => row.date)}
color="#52c41a"
/>
</Col>
</Row>
<Collapse
ghost
items={[
{
key: 'trend-detail',
label: '查看每日趋势明细',
children: (
<Table
rowKey="date"
size="small"
columns={trendColumns}
dataSource={trendRows}
loading={trendsLoading}
pagination={false}
scroll={{ x: 750 }}
/>
),
},
]}
/>
</Space>
</Card>
@@ -171,6 +171,21 @@ function isLoopbackPaymentUrl(value: string): boolean {
return /^https?:\/\/(localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\])(:|\/|$)/i.test(value);
}
async function waitForBatchCompletion(
handbook: HandbookKind,
batchId: string,
expectedCount: number,
): Promise<DouyuTaskItem[]> {
const deadline = Date.now() + 180_000;
while (true) {
const batchTasks = await douyuApi.listTasks(handbook, batchId);
const allFinished = batchTasks.length >= expectedCount
&& batchTasks.every((task) => !['planned', 'pending', 'running'].includes(task.status));
if (allFinished || Date.now() >= deadline) return batchTasks;
await new Promise((resolve) => window.setTimeout(resolve, 800));
}
}
/** 绑定状态小标签:取值 unknown / unbound / pending / bound。 */
function BindStatusTag({ status, label }: { status?: string; label?: string }) {
if (!status) return null;
@@ -1100,15 +1115,11 @@ export default function DouyuTasksPage({ handbook }: { handbook: HandbookKind })
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 batchTasks = await waitForBatchCompletion(
handbook,
created.batch_id,
created.count,
);
const unopenedIds = new Set(
batchTasks