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
+167 -26
View File
@@ -1,5 +1,22 @@
import api from './index';
// ==================== 通用响应类型 ====================
interface MessageResponse {
message: string;
success: boolean;
}
interface MessageCountResponse extends MessageResponse {
count: number;
}
interface MessageDeletedResponse extends MessageResponse {
deleted: number;
}
// ==================== Auth ====================
export interface LoginResult {
access_token: string;
token_type: string;
@@ -8,6 +25,16 @@ export interface LoginResult {
permissions: string[];
}
export interface CurrentUser {
id: number;
username: string;
role: string;
role_label: string;
is_active: boolean;
remark: string | null;
permissions: string[];
}
export interface UserInfo {
id: number;
username: string;
@@ -18,13 +45,127 @@ export interface UserInfo {
custom_permissions?: string[] | null;
}
// ==================== Account ====================
export interface AccountItem {
id: number;
username: string;
password?: string | null;
email?: string | null;
email_password?: string | null;
tag: string;
assigned_to: number | null;
assigned_username: string | null;
remark: string;
created_at: string | null;
}
export interface AssignmentsSummary {
support_users: SupportUserItem[];
unassigned_count: number;
}
export interface SupportUserItem {
id: number;
username: string;
assigned_count: number;
}
// ==================== Login Task ====================
export interface LoginTaskItem {
id: number;
batch_id: string;
account_id: number;
account_username: string;
status: string;
cookie: string;
message: string;
created_by: number;
created_at: string | null;
finished_at: string | null;
}
export interface BatchLoginResult {
batch_id: string;
count: number;
success: boolean;
}
// ==================== Cookie ====================
export interface CookieItem {
id: number;
batch_id: string;
account_id: number;
account_username: string;
assigned_to: number | null;
assigned_username: string | null;
created_at: string | null;
cookie: string;
cookie_preview: string;
}
// ==================== Proxy ====================
export interface ProxyConfig {
enabled: boolean;
api_url: string;
http: string;
https: string;
whitelist_enabled: boolean;
whitelist_uid: string;
whitelist_ukey: string;
}
export interface ProxyTestResult {
test_id: string;
success: boolean;
}
// ==================== Log ====================
export interface HttpLogEntry {
timestamp: string;
ts: number;
category: string;
tag: string;
method: string;
url: string;
proxy: string | null;
request: { headers: Record<string, string>; body: string };
response: { status_code: number | null; headers: Record<string, string>; body: string };
duration_ms: number | null;
error: string | null;
level: string;
}
export interface HttpLogListResult {
items: HttpLogEntry[];
total: number;
}
export interface HttpLogClearResult {
success: boolean;
cleared: number;
}
// ==================== Permissions ====================
export interface PermissionsListResult {
permissions: Record<string, string>;
role_permissions: Record<string, string[]>;
}
// ==================== API 定义 ====================
export const authApi = {
login: (username: string, password: string) =>
api.post<any, LoginResult>('/auth/login', { username, password }),
me: () => api.get<any, any>('/auth/me'),
me: () => api.get<any, CurrentUser>('/auth/me'),
logout: () => api.post<any, any>('/auth/logout'),
logout: () => api.post<any, MessageResponse>('/auth/logout'),
};
export const userApi = {
@@ -33,55 +174,55 @@ export const userApi = {
api.post<any, UserInfo>('/users', data),
update: (id: number, data: { password?: string; role?: string; is_active?: boolean; remark?: string; custom_permissions?: string[] | null }) =>
api.put<any, UserInfo>(`/users/${id}`, data),
delete: (id: number) => api.delete<any, any>(`/users/${id}`),
listPermissions: () => api.get<any, any>('/users/permissions/list'),
delete: (id: number) => api.delete<any, MessageResponse>(`/users/${id}`),
listPermissions: () => api.get<any, PermissionsListResult>('/users/permissions/list'),
};
export const accountApi = {
list: (params?: { assigned_only?: boolean; tag?: string; has_cookie?: boolean }) =>
api.get<any, any[]>('/accounts', { params }),
import: (text: string) => api.post<any, any>('/accounts/import', { text }),
api.get<any, AccountItem[]>('/accounts', { params }),
import: (text: string) => api.post<any, MessageCountResponse>('/accounts/import', { text }),
assign: (id: number, assigned_to: number | null) =>
api.put<any, any>(`/accounts/${id}/assign`, { assigned_to }),
api.put<any, MessageResponse>(`/accounts/${id}/assign`, { assigned_to }),
batchAssign: (account_ids: number[], assigned_to: number | null) =>
api.post<any, any>('/accounts/batch-assign', { account_ids, assigned_to }),
api.post<any, MessageCountResponse>('/accounts/batch-assign', { account_ids, assigned_to }),
assignmentsSummary: () =>
api.get<any, any>('/accounts/assignments/summary'),
api.get<any, AssignmentsSummary>('/accounts/assignments/summary'),
setTag: (id: number, tag: string) =>
api.put<any, any>(`/accounts/${id}/tag`, { tag }),
api.put<any, MessageResponse>(`/accounts/${id}/tag`, { tag }),
batchTag: (account_ids: number[], tag: string) =>
api.put<any, any>('/accounts/batch-tag', { account_ids, tag }),
api.put<any, MessageCountResponse>('/accounts/batch-tag', { account_ids, tag }),
listTags: () => api.get<any, string[]>('/accounts/tags/list'),
delete: (id: number) => api.delete<any, any>(`/accounts/${id}`),
delete: (id: number) => api.delete<any, MessageResponse>(`/accounts/${id}`),
batchDelete: (account_ids: number[]) =>
api.delete<any, any>('/accounts/batch/delete', { params: { account_ids: account_ids.join(',') } }),
api.delete<any, MessageDeletedResponse>('/accounts/batch/delete', { params: { account_ids: account_ids.join(',') } }),
};
export const loginApi = {
createBatch: (account_ids: number[], max_geetest_retries?: number, concurrency?: number, max_proxy_retries?: number) =>
api.post<any, any>('/login/batch', { account_ids, max_geetest_retries, concurrency, max_proxy_retries }),
api.post<any, BatchLoginResult>('/login/batch', { account_ids, max_geetest_retries, concurrency, max_proxy_retries }),
listTasks: (batch_id?: string) =>
api.get<any, any[]>('/login/tasks', { params: batch_id ? { batch_id } : {} }),
stop: (batch_id: string) => api.post<any, any>(`/login/stop/${batch_id}`),
deleteTask: (id: number) => api.delete<any, any>(`/login/tasks/${id}`),
deleteTasks: (ids: number[]) => api.delete<any, any>(`/login/tasks`, { params: { task_ids: ids.join(',') } }),
api.get<any, LoginTaskItem[]>('/login/tasks', { params: batch_id ? { batch_id } : {} }),
stop: (batch_id: string) => api.post<any, MessageResponse>(`/login/stop/${batch_id}`),
deleteTask: (id: number) => api.delete<any, MessageResponse>(`/login/tasks/${id}`),
deleteTasks: (ids: number[]) => api.delete<any, MessageDeletedResponse>(`/login/tasks`, { params: { task_ids: ids.join(',') } }),
};
export const cookieApi = {
list: () => api.get<any, any[]>('/cookies'),
list: () => api.get<any, CookieItem[]>('/cookies'),
exportCsv: (format?: string) => api.get('/cookies/export', { responseType: 'blob', params: format ? { format } : {} }),
delete: (id: number) => api.delete<any, any>(`/cookies/${id}`),
delete: (id: number) => api.delete<any, MessageResponse>(`/cookies/${id}`),
};
export const proxyApi = {
get: () => api.get<any, any>('/proxy'),
update: (data: any) => api.put<any, any>('/proxy', data),
test: () => api.post<any, any>('/proxy/test'),
testWhitelist: () => api.post<any, any>('/proxy/whitelist/test'),
get: () => api.get<any, ProxyConfig>('/proxy'),
update: (data: ProxyConfig) => api.put<any, ProxyConfig>('/proxy', data),
test: () => api.post<any, ProxyTestResult>('/proxy/test'),
testWhitelist: () => api.post<any, ProxyTestResult>('/proxy/whitelist/test'),
};
export const logApi = {
listHttp: (params?: { limit?: number; offset?: number; category?: string; level?: string; keyword?: string }) =>
api.get<any, { items: any[]; total: number }>('/logs/http', { params }),
clearHttp: () => api.delete<any, { success: boolean; cleared: number }>('/logs/http'),
api.get<any, HttpLogListResult>('/logs/http', { params }),
clearHttp: () => api.delete<any, HttpLogClearResult>('/logs/http'),
};