fix: 修复处理流程和后台任务问题

- 步骤简要数值显示在每个步骤圆圈下方
- 处理流程抓取网页后保存到内容库
- 修复后台任务结果解析错误
This commit is contained in:
2026-07-14 15:13:31 +08:00
parent 1712fb0756
commit 5e3e9e7335
4 changed files with 63 additions and 105 deletions
+23 -2
View File
@@ -110,11 +110,32 @@ class ProcessMonitor:
fetch_result = search_service.fetch_url_content(url)
if fetch_result.get('success'):
title = fetch_result.get('title', '')
content = fetch_result.get('content', '')
fetched.append({
'url': url,
'title': fetch_result.get('title', ''),
'content': fetch_result.get('content', '')[:500]
'title': title,
'content': content[:500]
})
# 保存到内容库
try:
existing = db.search_articles(url)
if not any(a.get('url') == url for a in existing):
db.add_article(
product_names=[],
category=category or '',
keywords=[],
summary=content[:200] if content else '',
content=content,
source=url,
url=url,
search_title=title
)
logger.info(f"[{session_id}] 已保存到内容库: {title[:30]}")
except Exception as save_error:
logger.warning(f"[{session_id}] 保存内容库失败: {save_error}")
time.sleep(0.3)
all_data['fetched_contents'] = fetched
+16 -37
View File
@@ -175,55 +175,34 @@
max-width: 80px;
}
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.1); }
}
/* 步骤简要数值 */
.steps-summary {
display: flex;
flex-wrap: wrap;
gap: 10px;
padding: 12px 15px;
background: #f8f9fa;
border-radius: 8px;
margin-top: 10px;
}
.step-summary-item {
display: flex;
align-items: center;
gap: 5px;
padding: 4px 10px;
background: white;
border-radius: 4px;
font-size: 13px;
}
.step-summary-item.completed {
.step-value {
font-size: 12px;
font-weight: 600;
color: #10b981;
margin-top: 3px;
padding: 2px 6px;
background: #d1fae5;
border-radius: 3px;
}
.step-summary-item.running {
.step-node.running .step-value {
color: #667eea;
background: #e0e7ff;
}
.step-summary-item.failed {
.step-node.failed .step-value {
color: #ef4444;
background: #fee2e2;
}
.step-summary-item.skipped {
.step-node.skipped .step-value {
color: #6b7280;
background: #f3f4f6;
}
.step-summary-label {
color: #666;
}
.step-summary-value {
font-weight: 600;
color: #333;
@keyframes pulse {
0%, 100% { transform: scale(1); }
50% { transform: scale(1.1); }
}
/* 操作按钮 */
+18 -65
View File
@@ -149,9 +149,26 @@ function renderStepsProgress(steps, currentStep) {
const stepNames = ['搜索内容库', '搜索互联网', '抓取网页', '提取数据', '填充字段', '提交审核'];
// 获取每个步骤的简要数值
function getStepValue(stepNum) {
const data = stepDataMap[stepNum];
if (!data) return '';
switch (stepNum) {
case 1: return data.count !== undefined ? `${data.count}` : '';
case 2: return data.count !== undefined ? `${data.count}` : '';
case 3: return data.count !== undefined ? `${data.count}` : '';
case 4: return data.has_data !== undefined ? (data.has_data ? '✓' : '✗') : (data.extracted ? '✓' : '');
case 5: return data.filled !== undefined ? (data.filled ? '✓' : '✗') : '';
case 6: return data.review_id ? '✓' : '';
default: return '';
}
}
let html = '<div class="steps-progress">';
for (let i = 1; i <= totalSteps; i++) {
const status = stepStatuses[i] || (i > currentStep ? 'pending' : '');
const stepValue = getStepValue(i);
let className = '';
if (status === 'completed') className = 'completed';
@@ -163,76 +180,12 @@ function renderStepsProgress(steps, currentStep) {
<div class="step-node ${className}">
<div class="step-circle">${i}</div>
<div class="step-label">${stepNames[i-1]}</div>
${stepValue ? `<div class="step-value">${stepValue}</div>` : ''}
</div>
`;
}
html += '</div>';
// 添加简要数值显示
html += '<div class="steps-summary">';
// 步骤1:内容库搜索结果数
if (stepDataMap[1]) {
const count = stepDataMap[1].count || 0;
const status = stepStatuses[1];
html += `<div class="step-summary-item ${status || ''}">
<span class="step-summary-label">内容库:</span>
<span class="step-summary-value">${count} 篇</span>
</div>`;
}
// 步骤2:互联网搜索结果数
if (stepDataMap[2]) {
const count = stepDataMap[2].count || 0;
const status = stepStatuses[2];
html += `<div class="step-summary-item ${status || ''}">
<span class="step-summary-label">互联网:</span>
<span class="step-summary-value">${count} 条</span>
</div>`;
}
// 步骤3:抓取成功数
if (stepDataMap[3]) {
const count = stepDataMap[3].count || 0;
const status = stepStatuses[3];
html += `<div class="step-summary-item ${status || ''}">
<span class="step-summary-label">抓取成功:</span>
<span class="step-summary-value">${count} 个</span>
</div>`;
}
// 步骤4:提取状态
if (stepDataMap[4]) {
const hasData = stepDataMap[4].has_data || stepDataMap[4].extracted;
const status = stepStatuses[4];
html += `<div class="step-summary-item ${status || ''}">
<span class="step-summary-label">数据提取:</span>
<span class="step-summary-value">${hasData ? '成功' : '无数据'}</span>
</div>`;
}
// 步骤5:填充状态
if (stepDataMap[5]) {
const filled = stepDataMap[5].filled;
const status = stepStatuses[5];
html += `<div class="step-summary-item ${status || ''}">
<span class="step-summary-label">字段填充:</span>
<span class="step-summary-value">${filled ? '完成' : '失败'}</span>
</div>`;
}
// 步骤6:审核ID
if (stepDataMap[6]) {
const reviewId = stepDataMap[6].review_id;
const status = stepStatuses[6];
html += `<div class="step-summary-item ${status || ''}">
<span class="step-summary-label">审核ID:</span>
<span class="step-summary-value">${reviewId || '-'}</span>
</div>`;
}
html += '</div>';
return html;
}
+6 -1
View File
@@ -773,7 +773,12 @@ async function loadBackgroundTasks() {
const progressPercent = task.total > 0 ?
Math.round((task.progress / task.total) * 100) : 0;
const result = task.result ? JSON.parse(task.result) : {};
let result = {};
try {
result = task.result ? JSON.parse(task.result) : {};
} catch (e) {
result = {};
}
return `
<div class="background-task-item ${statusClass}">