update: 重构后台任务展示,采用悬浮窗样式

This commit is contained in:
xiamuceer-j
2026-04-29 17:31:06 +08:00
parent 9a9ae0608e
commit 5f5fd99005
10 changed files with 613 additions and 610 deletions
@@ -31,6 +31,22 @@ export interface TaskListResponse {
items: TaskStatus[];
}
/**
* 批量生成任务状态
*/
export interface BatchTaskStatus {
id: string;
project_id: string;
status: 'pending' | 'running' | 'completed' | 'failed' | 'cancelled';
total_chapters: number;
completed_chapters: number;
current_chapter_number: number | null;
error_message: string | null;
created_at: string | null;
started_at: string | null;
completed_at: string | null;
}
/**
* 查询任务状态
*/
@@ -59,6 +75,29 @@ export async function getProjectTasks(
return response.json();
}
/**
* 获取项目活跃的批量生成任务
*/
export async function getActiveBatchTasks(projectId: string): Promise<BatchTaskStatus[]> {
const response = await fetch(`/api/chapters/project/${projectId}/batch-generate/active`);
if (!response.ok) {
throw new Error(`获取批量生成任务失败: ${response.statusText}`);
}
const data = await response.json();
// API 返回单个任务或空,统一转为数组
return data ? [data] : [];
}
/**
* 取消批量生成任务
*/
export async function cancelBatchTask(batchId: string): Promise<void> {
const response = await fetch(`/api/chapters/batch-generate/${batchId}/cancel`, { method: 'POST' });
if (!response.ok) {
throw new Error(`取消批量生成任务失败: ${response.statusText}`);
}
}
/**
* 取消任务
*/
@@ -69,6 +108,17 @@ export async function cancelTask(taskId: string): Promise<void> {
}
}
/**
* 清理项目已结束的任务记录
*/
export async function clearProjectTasks(projectId: string): Promise<{ deleted_count: number }> {
const response = await fetch(`${API_BASE}/project/${projectId}/clear`, { method: 'DELETE' });
if (!response.ok) {
throw new Error(`清理任务记录失败: ${response.statusText}`);
}
return response.json();
}
/**
* 删除任务记录
*/