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:
@@ -1,15 +1,16 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Table, Button, Card, Row, Col, Statistic, message, Tag, Popconfirm, Space, Typography, Input, theme, Dropdown } from 'antd';
|
||||
import { DownloadOutlined, DeleteOutlined, CopyOutlined, SearchOutlined } from '@ant-design/icons';
|
||||
import { cookieApi } from '../api/modules';
|
||||
import { cookieApi, type CookieItem } from '../api/modules';
|
||||
import { getUser, hasPerm } from '../store/auth';
|
||||
import { formatTime } from '../utils/time';
|
||||
import { getErrorMessage } from '../utils/error';
|
||||
|
||||
const { Text } = Typography;
|
||||
|
||||
export default function CookiePage() {
|
||||
const { token } = theme.useToken();
|
||||
const [cookies, setCookies] = useState<any[]>([]);
|
||||
const [cookies, setCookies] = useState<CookieItem[]>([]);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [selectedRowKeys, setSelectedRowKeys] = useState<React.Key[]>([]);
|
||||
const [searchText, setSearchText] = useState('');
|
||||
@@ -23,8 +24,8 @@ export default function CookiePage() {
|
||||
try {
|
||||
const data = await cookieApi.list();
|
||||
setCookies(data);
|
||||
} catch (e: any) {
|
||||
message.error(e.message);
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
@@ -37,15 +38,15 @@ export default function CookiePage() {
|
||||
const handleExport = async (format: string = 'csv') => {
|
||||
try {
|
||||
const blob = await cookieApi.exportCsv(format);
|
||||
const url = URL.createObjectURL(blob instanceof Blob ? blob : new Blob([blob as any]));
|
||||
const url = URL.createObjectURL(blob instanceof Blob ? blob : new Blob([blob]));
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = format === 'custom' ? 'cookies_custom.txt' : 'cookies.csv';
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
message.success('已导出');
|
||||
} catch (e: any) {
|
||||
message.error(e.message);
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -83,8 +84,8 @@ export default function CookiePage() {
|
||||
message.success('已删除');
|
||||
setSelectedRowKeys((prev) => prev.filter((k) => k !== id));
|
||||
loadCookies();
|
||||
} catch (e: any) {
|
||||
message.error(e.message);
|
||||
} catch (e: unknown) {
|
||||
message.error(getErrorMessage(e));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -98,8 +99,8 @@ export default function CookiePage() {
|
||||
);
|
||||
});
|
||||
|
||||
const columns: any[] = [
|
||||
{ title: 'ID', dataIndex: 'id', width: 60, align: 'center' },
|
||||
const columns = [
|
||||
{ title: 'ID', dataIndex: 'id', width: 60, align: 'center' as const },
|
||||
{
|
||||
title: '账号',
|
||||
dataIndex: 'account_username',
|
||||
@@ -110,7 +111,7 @@ export default function CookiePage() {
|
||||
title: '分配',
|
||||
dataIndex: 'assigned_username',
|
||||
width: 100,
|
||||
align: 'center',
|
||||
align: 'center' as const,
|
||||
render: (name: string | null) =>
|
||||
name ? <Tag color="green">{name}</Tag> : <Text type="secondary" style={{ fontSize: 12 }}>未分配</Text>,
|
||||
},
|
||||
@@ -127,15 +128,15 @@ export default function CookiePage() {
|
||||
title: '时间',
|
||||
dataIndex: 'created_at',
|
||||
width: 180,
|
||||
align: 'center',
|
||||
align: 'center' as const,
|
||||
render: (val: string) => formatTime(val),
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: 130,
|
||||
align: 'center',
|
||||
fixed: 'right',
|
||||
render: (_: any, record: any) => (
|
||||
align: 'center' as const,
|
||||
fixed: 'right' as const,
|
||||
render: (_: unknown, record: CookieItem) => (
|
||||
<Space size={4}>
|
||||
<Button
|
||||
size="small"
|
||||
@@ -234,4 +235,4 @@ export default function CookiePage() {
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user