feat(login): 任务列表支持分页、跨页全选与一键清空
任务量早就过了单页能装下的规模(库里 1.4 万条,单批就 177 条),但接口
硬编码 limit(200)、前端 pagination={false},于是「全选」其实只能选到前
200 条,失败任务清不干净。
- 接口加 page/page_size/status:不传 page 时仍返回裸数组(Cookie 页等
老调用方依赖这个契约,不能改);传了才返回 {items,total},total 供跨页全选。
- 删除支持 all_matching:按当前筛选条件删全部,不必先翻完所有页去勾。
- 前端:分页控件(20/50/100/200/500,记住选择)、状态筛选、表头
「选择全部 N 条(含其他页)」、「清空失败」一键操作。
两条护栏:
- **pending/running 一律不删** —— 删掉会让批次线程找不到记录;要停批次
走 /stop/{batch_id}。
- 不给任何条件就拒绝删除,绝不默认全删。
顺带:带 join 的 query 不能 bulk delete(SQLAlchemy 会拒绝),改成先查
id 再按主键删。
This commit is contained in:
@@ -10,13 +10,28 @@ interface CreateBatchParams {
|
||||
mode?: 'login' | 'check';
|
||||
}
|
||||
|
||||
export interface TaskPage {
|
||||
items: LoginTaskItem[];
|
||||
total: number;
|
||||
page: number;
|
||||
page_size: number;
|
||||
}
|
||||
|
||||
export const loginApi = {
|
||||
createBatch: (params: CreateBatchParams) =>
|
||||
api.post<BatchLoginResult, BatchLoginResult>('/login/batch', params),
|
||||
// 不传 page 时后端返回裸数组(老调用方契约),传了才返回 {items,total}。
|
||||
listTasks: (batch_id?: string) =>
|
||||
api.get<LoginTaskItem[], LoginTaskItem[]>('/login/tasks', { params: batch_id ? { batch_id } : {} }),
|
||||
listTasksPaged: (params: { page: number; page_size: number; batch_id?: string; status?: string }) =>
|
||||
api.get<TaskPage, TaskPage>('/login/tasks', { params: { ...params, batch_id: params.batch_id ?? '' } }),
|
||||
tasksSummary: () => api.get<TaskSummary, TaskSummary>('/login/tasks/summary'),
|
||||
stop: (batch_id: string) => api.post<MessageResponse, MessageResponse>(`/login/stop/${batch_id}`),
|
||||
deleteTask: (id: number) => api.delete<MessageResponse, MessageResponse>(`/login/tasks/${id}`),
|
||||
deleteTasks: (ids: number[]) => api.delete<MessageDeletedResponse, MessageDeletedResponse>(`/login/tasks`, { params: { task_ids: ids.join(',') } }),
|
||||
// 跨页全选用:按当前筛选条件删除全部(后端会跳过在途任务)。
|
||||
deleteTasksMatching: (params: { batch_id?: string; status?: string }) =>
|
||||
api.delete<MessageDeletedResponse, MessageDeletedResponse>('/login/tasks', {
|
||||
params: { all_matching: true, batch_id: params.batch_id ?? '', status: params.status ?? '' },
|
||||
}),
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user