From 95a44deb234318bebc70583d76276c6f9d313a36 Mon Sep 17 00:00:00 2001 From: aaron <> Date: Wed, 1 Oct 2025 11:07:25 +0800 Subject: [PATCH] fix bug --- web/mysql_app.py | 9 ++++++++- web/templates/signals.html | 32 +++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) 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(` +
+ + 分析完成!正在加载新结果... +
+ `); + setTimeout(() => { location.reload(); - }, 2000); + }, 1500); } } } @@ -419,6 +438,9 @@ }), success: function(response) { if (response.success) { + // 重置刷新标志 + hasRefreshedAfterCompletion = false; + // 立即开始状态轮询 checkAnalysisStatus(); alert(`分析任务已启动!正在后台扫描 ${response.stock_count} 只股票\n\n启动时间: ${response.start_time}\n\n页面将自动显示分析进度`);