feat: 增强任务监控功能,添加任务结果、错误信息和完成时间的显示,优化前端样式和数据格式化
This commit is contained in:
parent
2556191eee
commit
9ad4d09f2a
|
|
@ -92,6 +92,9 @@ async def get_runs(
|
|||
"created_at": run.get("created_at"),
|
||||
"updated_at": run.get("updated_at"),
|
||||
"api_spec": run.get("api_spec"),
|
||||
"result": run.get("result"), # 添加任务结果
|
||||
"error_message": run.get("error_message"), # 添加错误信息
|
||||
"completed_at": run.get("completed_at"), # 添加完成时间
|
||||
}
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -282,6 +282,31 @@ body {
|
|||
.task-meta {
|
||||
color: #7f8c8d;
|
||||
font-size: 0.85em;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.task-meta > div {
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.task-result {
|
||||
color: #27ae60;
|
||||
font-size: 0.85em;
|
||||
margin-top: 8px;
|
||||
padding: 8px;
|
||||
background: #f0fff4;
|
||||
border-radius: 6px;
|
||||
border-left: 3px solid #27ae60;
|
||||
}
|
||||
|
||||
.task-error {
|
||||
color: #e74c3c;
|
||||
font-size: 0.85em;
|
||||
margin-top: 8px;
|
||||
padding: 8px;
|
||||
background: #fff5f5;
|
||||
border-radius: 6px;
|
||||
border-left: 3px solid #e74c3c;
|
||||
}
|
||||
|
||||
.error-message {
|
||||
|
|
|
|||
|
|
@ -112,6 +112,37 @@ function updateRecentTasks(tasks) {
|
|||
'failed': '失败'
|
||||
}[task.status] || task.status;
|
||||
|
||||
// 格式化时间
|
||||
const formatTime = (timeStr) => {
|
||||
if (!timeStr) return 'N/A';
|
||||
try {
|
||||
return new Date(timeStr).toLocaleString();
|
||||
} catch {
|
||||
return timeStr;
|
||||
}
|
||||
};
|
||||
|
||||
// 格式化结果数据
|
||||
const formatResult = (result) => {
|
||||
if (!result) return '暂无结果';
|
||||
try {
|
||||
const parsed = JSON.parse(result);
|
||||
if (typeof parsed === 'object') {
|
||||
// 如果是对象,尝试提取关键信息
|
||||
if (parsed.images && Array.isArray(parsed.images)) {
|
||||
return `生成图片: ${parsed.images.length} 张`;
|
||||
}
|
||||
if (parsed.output && typeof parsed.output === 'object') {
|
||||
return `输出数据: ${Object.keys(parsed.output).length} 项`;
|
||||
}
|
||||
return `结果数据: ${JSON.stringify(parsed).substring(0, 100)}...`;
|
||||
}
|
||||
return `结果: ${String(result).substring(0, 100)}...`;
|
||||
} catch {
|
||||
return `结果: ${String(result).substring(0, 100)}...`;
|
||||
}
|
||||
};
|
||||
|
||||
container.innerHTML += `
|
||||
<div class="task-item">
|
||||
<div class="task-header">
|
||||
|
|
@ -120,8 +151,11 @@ function updateRecentTasks(tasks) {
|
|||
</div>
|
||||
<div class="task-meta">
|
||||
<div>ID: ${task.id}</div>
|
||||
<div>创建时间: ${new Date(task.created_at).toLocaleString()}</div>
|
||||
<div>创建时间: ${formatTime(task.created_at)}</div>
|
||||
${task.completed_at ? `<div>完成时间: ${formatTime(task.completed_at)}</div>` : ''}
|
||||
</div>
|
||||
${task.error_message ? `<div class="task-error">❌ 错误: ${task.error_message}</div>` : ''}
|
||||
${task.result ? `<div class="task-result">📊 ${formatResult(task.result)}</div>` : ''}
|
||||
</div>
|
||||
`;
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue