diff --git a/web/mysql_app.py b/web/mysql_app.py index 5484d65..25c863d 100644 --- a/web/mysql_app.py +++ b/web/mysql_app.py @@ -254,7 +254,14 @@ def api_run_analysis(): logger.error(f"后台市场分析异常: {e}") finally: # 重置分析状态 - analysis_status['is_running'] = False + analysis_status.update({ + 'is_running': False, + 'progress': 0, + 'current_stock': '', + 'start_time': None, + 'stock_count': 0, + 'estimated_completion': None + }) # 启动后台线程执行分析 analysis_thread = threading.Thread(target=run_analysis_background) diff --git a/web/templates/signals.html b/web/templates/signals.html index 5ec84d3..16d2231 100644 --- a/web/templates/signals.html +++ b/web/templates/signals.html @@ -352,6 +352,9 @@ }); } + // 用于防止重复刷新的标志 + let hasRefreshedAfterCompletion = false; + // 更新分析状态UI function updateAnalysisStatusUI(status) { const $statusDiv = $('#analysisStatus'); @@ -370,14 +373,19 @@ // 更新信息文本 const runningTime = Math.floor(status.running_time / 60); const remainingTime = Math.max(0, Math.ceil((status.stock_count / 200 * 5) - (status.running_time / 60))); - $info.text(`进度: ${status.progress}% | 已运行: ${runningTime}分钟 | 预计剩余: ${remainingTime}分钟`); + + if (status.progress >= 95) { + $info.text(`分析即将完成... ${status.progress}%`); + } else { + $info.text(`进度: ${status.progress}% | 已运行: ${runningTime}分钟 | 预计剩余: ${remainingTime}分钟`); + } // 开始轮询(如果还没开始) if (!analysisStatusInterval) { analysisStatusInterval = setInterval(checkAnalysisStatus, 3000); // 每3秒检查一次 } } else { - // 隐藏分析状态 + // 分析已完成,隐藏分析状态 $statusDiv.hide(); $runBtn.prop('disabled', false).html('立即分析'); @@ -387,11 +395,22 @@ analysisStatusInterval = null; } - // 如果刚完成分析,刷新页面 - if (status.progress === 100) { + // 如果是刚完成分析且还没刷新过,则刷新页面 + if (status.progress >= 95 && !hasRefreshedAfterCompletion) { + hasRefreshedAfterCompletion = true; + + // 显示完成提示 + $statusDiv.show(); + $statusDiv.html(` +