马一丁

Optimize Progress Bar Display Issues

@@ -1212,13 +1212,6 @@ @@ -1212,13 +1212,6 @@
1212 forum: 'stopped', // 前端启动后再标记为 running 1212 forum: 'stopped', // 前端启动后再标记为 running
1213 report: 'stopped' // Report Engine 1213 report: 'stopped' // Report Engine
1214 }; 1214 };
1215 - // 为每个Engine存储进度条状态  
1216 - let engineProgress = {  
1217 - insight: null,  
1218 - media: null,  
1219 - query: null,  
1220 - report: null  
1221 - };  
1222 let customTemplate = ''; // 存储用户上传的自定义模板内容 1215 let customTemplate = ''; // 存储用户上传的自定义模板内容
1223 let configValues = {}; 1216 let configValues = {};
1224 let configDirty = false; 1217 let configDirty = false;
@@ -1243,8 +1236,7 @@ @@ -1243,8 +1236,7 @@
1243 refreshConsole: null, 1236 refreshConsole: null,
1244 refreshForum: null, 1237 refreshForum: null,
1245 reportLockCheck: null, 1238 reportLockCheck: null,
1246 - connectionProbe: null,  
1247 - updateEngineProgress: null // 新增:更新所有Engine进度的定时器 1239 + connectionProbe: null
1248 }; 1240 };
1249 1241
1250 // 页面可见性变化处理 1242 // 页面可见性变化处理
@@ -1289,9 +1281,6 @@ @@ -1289,9 +1281,6 @@
1289 1281
1290 // 报告锁定检查定时器 - 从10秒增加到15秒 1282 // 报告锁定检查定时器 - 从10秒增加到15秒
1291 allTimers.reportLockCheck = setInterval(checkReportLockStatus, 15000); 1283 allTimers.reportLockCheck = setInterval(checkReportLockStatus, 15000);
1292 -  
1293 - // 更新所有Engine进度的定时器 - 每5秒更新一次  
1294 - allTimers.updateEngineProgress = setInterval(updateAllEngineProgress, 5000);  
1295 } 1284 }
1296 1285
1297 // 暂停所有定时器 1286 // 暂停所有定时器
@@ -1787,9 +1776,6 @@ @@ -1787,9 +1776,6 @@
1787 // 启动所有定时器 1776 // 启动所有定时器
1788 startAllTimers(); 1777 startAllTimers();
1789 1778
1790 - // 立即更新一次所有Engine的进度,恢复刷新前的状态  
1791 - updateAllEngineProgress();  
1792 -  
1793 // 监听页面可见性变化 1779 // 监听页面可见性变化
1794 document.addEventListener('visibilitychange', handleVisibilityChange); 1780 document.addEventListener('visibilitychange', handleVisibilityChange);
1795 1781
@@ -2428,7 +2414,7 @@ @@ -2428,7 +2414,7 @@
2428 if (appStatus[app] === 'running' && ports[app]) { 2414 if (appStatus[app] === 'running' && ports[app]) {
2429 totalRunning++; 2415 totalRunning++;
2430 2416
2431 - // 懒加载iframe(如果还没有加载) 2417 + // 懒加载iframe(如果还没有加载)
2432 let iframe = preloadedIframes[app]; 2418 let iframe = preloadedIframes[app];
2433 if (!iframe) { 2419 if (!iframe) {
2434 iframe = lazyLoadIframe(app); 2420 iframe = lazyLoadIframe(app);
@@ -2439,8 +2425,32 @@ @@ -2439,8 +2425,32 @@
2439 const searchUrl = `http://${window.location.hostname}:${ports[app]}?query=${encodeURIComponent(query)}&auto_search=true`; 2425 const searchUrl = `http://${window.location.hostname}:${ports[app]}?query=${encodeURIComponent(query)}&auto_search=true`;
2440 console.log(`向 ${app} 发送搜索请求: ${searchUrl}`); 2426 console.log(`向 ${app} 发送搜索请求: ${searchUrl}`);
2441 2427
2442 - // 直接更新iframe的src来传递搜索参数  
2443 - iframe.src = searchUrl; 2428 + // 检查iframe是否已经加载了相同的查询,避免不必要的重新加载
  2429 + const currentSrc = iframe.src || '';
  2430 +
  2431 + // 只在查询不同时才更新iframe
  2432 + // 提取当前URL的query参数
  2433 + let needsUpdate = true;
  2434 + try {
  2435 + const currentUrl = new URL(currentSrc);
  2436 + const newUrl = new URL(searchUrl);
  2437 + const currentQuery = currentUrl.searchParams.get('query');
  2438 + const newQuery = newUrl.searchParams.get('query');
  2439 +
  2440 + // 如果query参数相同,不需要重新加载
  2441 + if (currentQuery === newQuery) {
  2442 + needsUpdate = false;
  2443 + console.log(`${app} iframe已有相同查询,跳过重新加载`);
  2444 + }
  2445 + } catch (e) {
  2446 + // URL解析失败,执行更新
  2447 + needsUpdate = true;
  2448 + }
  2449 +
  2450 + if (needsUpdate) {
  2451 + // 直接更新iframe的src来传递搜索参数
  2452 + iframe.src = searchUrl;
  2453 + }
2444 } 2454 }
2445 } 2455 }
2446 }); 2456 });
@@ -2469,12 +2479,6 @@ @@ -2469,12 +2479,6 @@
2469 } 2479 }
2470 } 2480 }
2471 2481
2472 - // 隐藏当前Engine的进度条  
2473 - const engines = ['insight', 'media', 'query'];  
2474 - if (engines.includes(currentApp)) {  
2475 - hideEngineProgress(currentApp);  
2476 - }  
2477 -  
2478 // 更新按钮状态 2482 // 更新按钮状态
2479 document.querySelectorAll('.app-button').forEach(btn => { 2483 document.querySelectorAll('.app-button').forEach(btn => {
2480 btn.classList.remove('active'); 2484 btn.classList.remove('active');
@@ -2531,13 +2535,6 @@ @@ -2531,13 +2535,6 @@
2531 // 追加提示并加载新的控制台输出 2535 // 追加提示并加载新的控制台输出
2532 appendConsoleTextLine(app, '[系统] 切换到 ' + appNames[app]); 2536 appendConsoleTextLine(app, '[系统] 切换到 ' + appNames[app]);
2533 loadConsoleOutput(app); 2537 loadConsoleOutput(app);
2534 -  
2535 - // 显示该Engine的进度条(如果有)  
2536 - if (engines.includes(app)) {  
2537 - showEngineProgress(app);  
2538 - // 立即更新一次进度,确保显示最新状态  
2539 - updateEngineProgress(app);  
2540 - }  
2541 } 2538 }
2542 2539
2543 // 更新嵌入页面 2540 // 更新嵌入页面
@@ -2807,10 +2804,14 @@ @@ -2807,10 +2804,14 @@
2807 const apps = ['insight', 'media', 'query']; 2804 const apps = ['insight', 'media', 'query'];
2808 apps.forEach(app => { 2805 apps.forEach(app => {
2809 if (app !== currentApp && preloadedIframes[app]) { 2806 if (app !== currentApp && preloadedIframes[app]) {
2810 - // 延迟卸载给一些缓冲时间 2807 + // 延迟卸载,给一些缓冲时间
2811 setTimeout(() => { 2808 setTimeout(() => {
2812 - if (currentApp !== app) { // 再次确认没有切换回来 2809 + // 再次确认没有切换回来,并且该应用已经停止运行
  2810 + // 重要:不要卸载正在运行的iframe,否则会丢失进度
  2811 + if (currentApp !== app && appStatus[app] !== 'running' && appStatus[app] !== 'starting') {
2813 unloadIframe(app); 2812 unloadIframe(app);
  2813 + } else {
  2814 + console.log(`保留 ${app} iframe - 应用正在运行或已切换回来`);
2814 } 2815 }
2815 }, 30000); // 30秒后卸载不活跃的iframe 2816 }, 30000); // 30秒后卸载不活跃的iframe
2816 } 2817 }
@@ -3105,163 +3106,6 @@ @@ -3105,163 +3106,6 @@
3105 // Forum Engine 相关函数 3106 // Forum Engine 相关函数
3106 let forumLogLineCount = 0; 3107 let forumLogLineCount = 0;
3107 3108
3108 - // 更新所有Engine的进度条  
3109 - function updateAllEngineProgress() {  
3110 - // 通过现有的status API获取所有Engine的状态  
3111 - fetch('/api/status')  
3112 - .then(response => response.json())  
3113 - .then(data => {  
3114 - // 为每个需要进度显示的Engine更新状态  
3115 - const engines = ['insight', 'media', 'query'];  
3116 -  
3117 - engines.forEach(engine => {  
3118 - if (data[engine]) {  
3119 - const info = data[engine];  
3120 - const status = info.status === 'running' ? 'running' : 'stopped';  
3121 -  
3122 - // 如果Engine正在运行,显示进度条  
3123 - if (status === 'running') {  
3124 - // 尝试从API获取详细进度,如果失败则显示基本运行状态  
3125 - updateEngineProgress(engine);  
3126 - } else {  
3127 - // Engine未运行,清除进度信息  
3128 - engineProgress[engine] = null;  
3129 - const progressContainer = document.getElementById(`progress-${engine}`);  
3130 - if (progressContainer && progressContainer.parentNode) {  
3131 - progressContainer.parentNode.removeChild(progressContainer);  
3132 - }  
3133 - }  
3134 - }  
3135 - });  
3136 - })  
3137 - .catch(error => {  
3138 - console.log('获取Engine状态失败:', error);  
3139 - });  
3140 - }  
3141 -  
3142 - // 更新单个Engine的进度  
3143 - function updateEngineProgress(engine) {  
3144 - // 先尝试从专用进度API获取  
3145 - fetch(`/api/${engine}/progress`)  
3146 - .then(response => {  
3147 - if (!response.ok) {  
3148 - throw new Error('Progress API not available');  
3149 - }  
3150 - return response.json();  
3151 - })  
3152 - .then(data => {  
3153 - if (data.success && data.progress) {  
3154 - // 存储进度信息  
3155 - engineProgress[engine] = {  
3156 - status: data.progress.status || 'running',  
3157 - progress: data.progress.progress || 0,  
3158 - message: data.progress.message || '正在处理...',  
3159 - updated_at: new Date().toISOString()  
3160 - };  
3161 -  
3162 - // 如果当前正在查看该Engine,更新显示  
3163 - if (currentApp === engine) {  
3164 - displayEngineProgress(engine);  
3165 - }  
3166 - }  
3167 - })  
3168 - .catch(error => {  
3169 - // 如果专用API不可用,使用基本的运行状态  
3170 - if (appStatus[engine] === 'running') {  
3171 - // 使用基本的进度信息  
3172 - if (!engineProgress[engine]) {  
3173 - engineProgress[engine] = {  
3174 - status: 'running',  
3175 - progress: 50, // 默认显示50%表示运行中  
3176 - message: '正在分析中...',  
3177 - updated_at: new Date().toISOString()  
3178 - };  
3179 - }  
3180 -  
3181 - // 如果当前正在查看该Engine,更新显示  
3182 - if (currentApp === engine) {  
3183 - displayEngineProgress(engine);  
3184 - }  
3185 - }  
3186 - });  
3187 - }  
3188 -  
3189 - // 在嵌入页面区域显示Engine进度  
3190 - function displayEngineProgress(engine) {  
3191 - const progress = engineProgress[engine];  
3192 - if (!progress) return;  
3193 -  
3194 - // 查找或创建进度显示容器  
3195 - let progressContainer = document.getElementById(`progress-${engine}`);  
3196 - if (!progressContainer) {  
3197 - // 在嵌入内容区域的顶部创建进度条容器  
3198 - const embeddedContent = document.getElementById('embeddedContent');  
3199 - if (!embeddedContent) return;  
3200 -  
3201 - progressContainer = document.createElement('div');  
3202 - progressContainer.id = `progress-${engine}`;  
3203 - progressContainer.className = 'task-progress-container';  
3204 - progressContainer.style.position = 'absolute';  
3205 - progressContainer.style.top = '10px';  
3206 - progressContainer.style.left = '10px';  
3207 - progressContainer.style.right = '10px';  
3208 - progressContainer.style.zIndex = '100';  
3209 - progressContainer.style.backgroundColor = '#f5f5f0';  
3210 - embeddedContent.insertBefore(progressContainer, embeddedContent.firstChild);  
3211 - }  
3212 -  
3213 - // 更新进度条内容  
3214 - const loadingIndicator = progress.status !== 'completed' && progress.status !== 'error'  
3215 - ? '<span class="report-loading-spinner"></span>'  
3216 - : '';  
3217 -  
3218 - progressContainer.innerHTML = `  
3219 - <div class="task-progress-header">  
3220 - <div class="task-progress-title">  
3221 - ${loadingIndicator}${appNames[engine] || engine} - ${progress.message}  
3222 - </div>  
3223 - <div class="task-progress-bar">  
3224 - <div class="task-progress-fill" style="width: ${Math.min(Math.max(progress.progress || 0, 0), 100)}%"></div>  
3225 - <div class="task-progress-text">${progress.progress || 0}%</div>  
3226 - </div>  
3227 - </div>  
3228 - `;  
3229 -  
3230 - // 如果任务已完成,5秒后淡出进度条  
3231 - if (progress.status === 'completed') {  
3232 - setTimeout(() => {  
3233 - if (progressContainer && progressContainer.parentNode) {  
3234 - progressContainer.style.transition = 'opacity 1s';  
3235 - progressContainer.style.opacity = '0';  
3236 - setTimeout(() => {  
3237 - if (progressContainer && progressContainer.parentNode) {  
3238 - progressContainer.parentNode.removeChild(progressContainer);  
3239 - }  
3240 - }, 1000);  
3241 - }  
3242 - }, 5000);  
3243 - }  
3244 - }  
3245 -  
3246 - // 隐藏指定Engine的进度条(切换时使用)  
3247 - function hideEngineProgress(engine) {  
3248 - const progressContainer = document.getElementById(`progress-${engine}`);  
3249 - if (progressContainer) {  
3250 - progressContainer.style.display = 'none';  
3251 - }  
3252 - }  
3253 -  
3254 - // 显示指定Engine的进度条(切换时使用)  
3255 - function showEngineProgress(engine) {  
3256 - const progressContainer = document.getElementById(`progress-${engine}`);  
3257 - if (progressContainer) {  
3258 - progressContainer.style.display = 'block';  
3259 - } else if (engineProgress[engine]) {  
3260 - // 如果有缓存的进度信息但容器不存在,重新创建  
3261 - displayEngineProgress(engine);  
3262 - }  
3263 - }  
3264 -  
3265 // Report Engine 相关函数 3109 // Report Engine 相关函数
3266 let reportLogLineCount = 0; 3110 let reportLogLineCount = 0;
3267 let reportLockCheckInterval = null; 3111 let reportLockCheckInterval = null;