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:
yml2213
2026-06-23 07:14:08 +08:00
parent 453a637480
commit 12c31c2e09
16 changed files with 305 additions and 189 deletions
+25 -24
View File
@@ -4,8 +4,9 @@ import {
Row, Col, Card, Statistic,
} from 'antd';
import { ImportOutlined, DeleteOutlined, TagOutlined, FilterOutlined } from '@ant-design/icons';
import { accountApi, userApi } from '../api/modules';
import { accountApi, userApi, type AccountItem, type UserInfo } from '../api/modules';
import { getUser, hasPerm } from '../store/auth';
import { getErrorMessage } from '../utils/error';
const { TextArea } = Input;
const { Text } = Typography;
@@ -15,8 +16,8 @@ const TAG_COLORS = [
];
export default function AccountsPage() {
const [accounts, setAccounts] = useState<any[]>([]);
const [users, setUsers] = useState<any[]>([]);
const [accounts, setAccounts] = useState<AccountItem[]>([]);
const [users, setUsers] = useState<UserInfo[]>([]);
const [tags, setTags] = useState<string[]>([]);
const [loading, setLoading] = useState(false);
const [importOpen, setImportOpen] = useState(false);
@@ -36,12 +37,12 @@ export default function AccountsPage() {
const loadAccounts = async () => {
setLoading(true);
try {
const params: any = {};
const params: { tag?: string } = {};
if (tagFilter) params.tag = tagFilter;
const data = await accountApi.list(params);
setAccounts(data);
} catch (e: any) {
message.error(e.message);
} catch (e: unknown) {
message.error(getErrorMessage(e));
} finally {
setLoading(false);
}
@@ -50,7 +51,7 @@ export default function AccountsPage() {
const loadUsers = async () => {
try {
const data = await userApi.list();
setUsers(data.filter((u: any) => u.role === 'support'));
setUsers(data.filter((u) => u.role === 'support'));
} catch {}
};
@@ -92,8 +93,8 @@ export default function AccountsPage() {
setImportText('');
loadAccounts();
loadTags();
} catch (e: any) {
message.error(e.message);
} catch (e: unknown) {
message.error(getErrorMessage(e));
} finally {
setImporting(false);
}
@@ -104,8 +105,8 @@ export default function AccountsPage() {
await accountApi.assign(accountId, assignedTo);
message.success('已分配');
loadAccounts();
} catch (e: any) {
message.error(e.message);
} catch (e: unknown) {
message.error(getErrorMessage(e));
}
};
@@ -115,8 +116,8 @@ export default function AccountsPage() {
message.success('标签已更新');
loadAccounts();
loadTags();
} catch (e: any) {
message.error(e.message);
} catch (e: unknown) {
message.error(getErrorMessage(e));
}
};
@@ -133,8 +134,8 @@ export default function AccountsPage() {
setSelectedRowKeys([]);
loadAccounts();
loadTags();
} catch (e: any) {
message.error(e.message);
} catch (e: unknown) {
message.error(getErrorMessage(e));
}
};
@@ -145,8 +146,8 @@ export default function AccountsPage() {
setSelectedRowKeys((prev) => prev.filter((k) => k !== id));
loadAccounts();
loadTags();
} catch (e: any) {
message.error(e.message);
} catch (e: unknown) {
message.error(getErrorMessage(e));
}
};
@@ -161,19 +162,19 @@ export default function AccountsPage() {
setSelectedRowKeys([]);
loadAccounts();
loadTags();
} catch (e: any) {
message.error(e.message);
} catch (e: unknown) {
message.error(getErrorMessage(e));
}
};
const columns: any[] = [
const columns = [
{ title: 'ID', dataIndex: 'id', width: 60 },
{ title: '用户名', dataIndex: 'username' },
{
title: '标签',
dataIndex: 'tag',
width: 120,
render: (tag: string, record: any) => {
render: (tag: string, record: AccountItem) => {
if (!tag) {
if (canImport) {
return (
@@ -224,7 +225,7 @@ export default function AccountsPage() {
columns.push({
title: '分配给',
dataIndex: 'assigned_username',
render: (_: any, record: any) => {
render: (_: unknown, record: AccountItem) => {
if (canAssign) {
return (
<Select
@@ -233,7 +234,7 @@ export default function AccountsPage() {
placeholder="未分配"
value={record.assigned_to}
onChange={(val) => handleAssign(record.id, val ?? null)}
options={users.map((u: any) => ({ value: u.id, label: u.username }))}
options={users.map((u) => ({ value: u.id, label: u.username }))}
/>
);
}
@@ -245,7 +246,7 @@ export default function AccountsPage() {
columns.push({
title: '操作',
width: 80,
render: (_: any, record: any) => (
render: (_: unknown, record: AccountItem) => (
<Popconfirm title="确认删除?" onConfirm={() => handleDelete(record.id)}>
<Button danger size="small" icon={<DeleteOutlined />}></Button>
</Popconfirm>