fix bug
This commit is contained in:
parent
6ea3aa0b8a
commit
95a44deb23
@ -254,7 +254,14 @@ def api_run_analysis():
|
|||||||
logger.error(f"后台市场分析异常: {e}")
|
logger.error(f"后台市场分析异常: {e}")
|
||||||
finally:
|
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)
|
analysis_thread = threading.Thread(target=run_analysis_background)
|
||||||
|
|||||||
@ -352,6 +352,9 @@
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 用于防止重复刷新的标志
|
||||||
|
let hasRefreshedAfterCompletion = false;
|
||||||
|
|
||||||
// 更新分析状态UI
|
// 更新分析状态UI
|
||||||
function updateAnalysisStatusUI(status) {
|
function updateAnalysisStatusUI(status) {
|
||||||
const $statusDiv = $('#analysisStatus');
|
const $statusDiv = $('#analysisStatus');
|
||||||
@ -370,14 +373,19 @@
|
|||||||
// 更新信息文本
|
// 更新信息文本
|
||||||
const runningTime = Math.floor(status.running_time / 60);
|
const runningTime = Math.floor(status.running_time / 60);
|
||||||
const remainingTime = Math.max(0, Math.ceil((status.stock_count / 200 * 5) - (status.running_time / 60)));
|
const remainingTime = Math.max(0, Math.ceil((status.stock_count / 200 * 5) - (status.running_time / 60)));
|
||||||
|
|
||||||
|
if (status.progress >= 95) {
|
||||||
|
$info.text(`分析即将完成... ${status.progress}%`);
|
||||||
|
} else {
|
||||||
$info.text(`进度: ${status.progress}% | 已运行: ${runningTime}分钟 | 预计剩余: ${remainingTime}分钟`);
|
$info.text(`进度: ${status.progress}% | 已运行: ${runningTime}分钟 | 预计剩余: ${remainingTime}分钟`);
|
||||||
|
}
|
||||||
|
|
||||||
// 开始轮询(如果还没开始)
|
// 开始轮询(如果还没开始)
|
||||||
if (!analysisStatusInterval) {
|
if (!analysisStatusInterval) {
|
||||||
analysisStatusInterval = setInterval(checkAnalysisStatus, 3000); // 每3秒检查一次
|
analysisStatusInterval = setInterval(checkAnalysisStatus, 3000); // 每3秒检查一次
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// 隐藏分析状态
|
// 分析已完成,隐藏分析状态
|
||||||
$statusDiv.hide();
|
$statusDiv.hide();
|
||||||
$runBtn.prop('disabled', false).html('<i class="fas fa-play me-1"></i>立即分析');
|
$runBtn.prop('disabled', false).html('<i class="fas fa-play me-1"></i>立即分析');
|
||||||
|
|
||||||
@ -387,11 +395,22 @@
|
|||||||
analysisStatusInterval = null;
|
analysisStatusInterval = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 如果刚完成分析,刷新页面
|
// 如果是刚完成分析且还没刷新过,则刷新页面
|
||||||
if (status.progress === 100) {
|
if (status.progress >= 95 && !hasRefreshedAfterCompletion) {
|
||||||
|
hasRefreshedAfterCompletion = true;
|
||||||
|
|
||||||
|
// 显示完成提示
|
||||||
|
$statusDiv.show();
|
||||||
|
$statusDiv.html(`
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<i class="fas fa-check-circle text-success me-2"></i>
|
||||||
|
<small class="text-success fw-bold">分析完成!正在加载新结果...</small>
|
||||||
|
</div>
|
||||||
|
`);
|
||||||
|
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
location.reload();
|
location.reload();
|
||||||
}, 2000);
|
}, 1500);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -419,6 +438,9 @@
|
|||||||
}),
|
}),
|
||||||
success: function(response) {
|
success: function(response) {
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
|
// 重置刷新标志
|
||||||
|
hasRefreshedAfterCompletion = false;
|
||||||
|
|
||||||
// 立即开始状态轮询
|
// 立即开始状态轮询
|
||||||
checkAnalysisStatus();
|
checkAnalysisStatus();
|
||||||
alert(`分析任务已启动!正在后台扫描 ${response.stock_count} 只股票\n\n启动时间: ${response.start_time}\n\n页面将自动显示分析进度`);
|
alert(`分析任务已启动!正在后台扫描 ${response.stock_count} 只股票\n\n启动时间: ${response.start_time}\n\n页面将自动显示分析进度`);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user