diff --git a/services/process_monitor.py b/services/process_monitor.py index be14e1f..f05d141 100644 --- a/services/process_monitor.py +++ b/services/process_monitor.py @@ -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 diff --git a/static/css/process.css b/static/css/process.css index 98e8ce3..908fae2 100644 --- a/static/css/process.css +++ b/static/css/process.css @@ -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); } } /* 操作按钮 */ diff --git a/static/js/process.js b/static/js/process.js index e3e3d1d..e224823 100644 --- a/static/js/process.js +++ b/static/js/process.js @@ -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 = '
'; 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) {
${i}
${stepNames[i-1]}
+ ${stepValue ? `
${stepValue}
` : ''}
`; } html += '
'; - // 添加简要数值显示 - html += '
'; - - // 步骤1:内容库搜索结果数 - if (stepDataMap[1]) { - const count = stepDataMap[1].count || 0; - const status = stepStatuses[1]; - html += `
- 内容库: - ${count} 篇 -
`; - } - - // 步骤2:互联网搜索结果数 - if (stepDataMap[2]) { - const count = stepDataMap[2].count || 0; - const status = stepStatuses[2]; - html += `
- 互联网: - ${count} 条 -
`; - } - - // 步骤3:抓取成功数 - if (stepDataMap[3]) { - const count = stepDataMap[3].count || 0; - const status = stepStatuses[3]; - html += `
- 抓取成功: - ${count} 个 -
`; - } - - // 步骤4:提取状态 - if (stepDataMap[4]) { - const hasData = stepDataMap[4].has_data || stepDataMap[4].extracted; - const status = stepStatuses[4]; - html += `
- 数据提取: - ${hasData ? '成功' : '无数据'} -
`; - } - - // 步骤5:填充状态 - if (stepDataMap[5]) { - const filled = stepDataMap[5].filled; - const status = stepStatuses[5]; - html += `
- 字段填充: - ${filled ? '完成' : '失败'} -
`; - } - - // 步骤6:审核ID - if (stepDataMap[6]) { - const reviewId = stepDataMap[6].review_id; - const status = stepStatuses[6]; - html += `
- 审核ID: - ${reviewId || '-'} -
`; - } - - html += '
'; - return html; } diff --git a/static/js/search.js b/static/js/search.js index 1cc039d..3b51e01 100644 --- a/static/js/search.js +++ b/static/js/search.js @@ -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 `