refactor: 消除前端52处any类型+删除冗余requirements.txt+调试print改日志
- 删除 requirements.txt,pyproject.toml 为唯一依赖源(含 requests[socks] extra) - core/geetest 下 5 处 print() 替换为 loguru logger.debug() - api/modules.ts 新增 13 个响应接口,消除所有 api.xxx<any, any> - 新建 utils/error.ts 提供 getErrorMessage(e: unknown) 安全取消息 - 11 个页面组件 catch (e: any) 改为 catch (e: unknown) - useState<any[]>、columns: any[]、render 参数全部类型化 - TypeScript 类型检查零错误通过
This commit is contained in:
@@ -3,9 +3,10 @@ import {
|
||||
Table, Button, Select, message, Tag, Space, Spin, InputNumber, Tooltip, Popconfirm, theme,
|
||||
} from 'antd';
|
||||
import { PlayCircleOutlined, StopOutlined, FilterOutlined, ThunderboltOutlined, ReloadOutlined, DownOutlined, UpOutlined, DeleteOutlined, SwapOutlined } from '@ant-design/icons';
|
||||
import { accountApi, loginApi } from '../api/modules';
|
||||
import { accountApi, loginApi, type AccountItem, type LoginTaskItem } from '../api/modules';
|
||||
import { getUser, hasPerm } from '../store/auth';
|
||||
import { formatTime } from '../utils/time';
|
||||
import { getErrorMessage } from '../utils/error';
|
||||
|
||||
const STATUS_COLORS: Record<string, string> = {
|
||||
pending: 'default',
|
||||
@@ -23,10 +24,15 @@ const STATUS_LABELS: Record<string, string> = {
|
||||
error: '异常',
|
||||
};
|
||||
|
||||
interface SelectGroupOption {
|
||||
label: string;
|
||||
options: { value: number; label: string }[];
|
||||
}
|
||||
|
||||
export default function LoginTasksPage() {
|
||||
const [accounts, setAccounts] = useState<any[]>([]);
|
||||
const [accounts, setAccounts] = useState<AccountItem[]>([]);
|
||||
const [selectedIds, setSelectedIds] = useState<number[]>([]);
|
||||
const [tasks, setTasks] = useState<any[]>([]);
|
||||
const [tasks, setTasks] = useState<LoginTaskItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [batchId, setBatchId] = useState<string | null>(null);
|
||||
const [logs, setLogs] = useState<{ level: string; message: string }[]>([]);
|
||||
@@ -67,8 +73,8 @@ export default function LoginTasksPage() {
|
||||
try {
|
||||
const data = await accountApi.list();
|
||||
setAccounts(data);
|
||||
} catch (e: any) {
|
||||
message.error(e.message);
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -158,8 +164,8 @@ export default function LoginTasksPage() {
|
||||
ws.onerror = () => {
|
||||
setWsConnected(false);
|
||||
};
|
||||
} catch (e: any) {
|
||||
message.error(e.message);
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -191,8 +197,8 @@ export default function LoginTasksPage() {
|
||||
try {
|
||||
await loginApi.stop(batchId);
|
||||
message.success('已发送停止信号');
|
||||
} catch (e: any) {
|
||||
message.error(e.message);
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -203,8 +209,8 @@ export default function LoginTasksPage() {
|
||||
message.success('已删除');
|
||||
loadTasks();
|
||||
setSelectedRowKeys((prev) => prev.filter((k) => k !== taskId));
|
||||
} catch (e: any) {
|
||||
message.error(e.message);
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -218,8 +224,8 @@ export default function LoginTasksPage() {
|
||||
message.success(`已删除 ${selectedRowKeys.length} 个任务`);
|
||||
setSelectedRowKeys([]);
|
||||
loadTasks();
|
||||
} catch (e: any) {
|
||||
message.error(e.message);
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -239,7 +245,7 @@ export default function LoginTasksPage() {
|
||||
{
|
||||
title: '操作',
|
||||
width: 120,
|
||||
render: (_: any, record: any) => (
|
||||
render: (_: unknown, record: LoginTaskItem) => (
|
||||
<Space size={4}>
|
||||
{['failed', 'error'].includes(record.status) && !wsConnected && (
|
||||
<Button
|
||||
@@ -298,7 +304,7 @@ export default function LoginTasksPage() {
|
||||
noTag.push({ value: a.id, label: a.username });
|
||||
}
|
||||
});
|
||||
const result: any[] = [];
|
||||
const result: SelectGroupOption[] = [];
|
||||
Object.keys(grouped).sort().forEach((tag) => {
|
||||
result.push({ label: tag, options: grouped[tag] });
|
||||
});
|
||||
@@ -312,7 +318,7 @@ export default function LoginTasksPage() {
|
||||
size="small"
|
||||
filterOption={(input, option) => {
|
||||
if (!option) return false;
|
||||
const label = (option as any).label as string || '';
|
||||
const label = (option as { label?: string }).label || '';
|
||||
return label.toLowerCase().includes(input.toLowerCase());
|
||||
}}
|
||||
dropdownRender={(menu) => (
|
||||
|
||||
Reference in New Issue
Block a user