点击"生成最终报告"开始生成综合分析报告
@@ -1556,29 +1702,80 @@
`;
reportContent.innerHTML = interfaceHTML;
+
+ // 立即更新状态信息
+ updateEngineStatusDisplay(statusData);
+
+ // 如果有当前任务,显示任务状态
+ if (statusData.current_task) {
+ const taskArea = document.getElementById('taskProgressArea');
+ if (taskArea) {
+ taskArea.innerHTML = renderTaskStatus(statusData.current_task);
+ }
+ }
}
- // 渲染任务状态
+ // 渲染任务状态(使用新的进度条样式)
function renderTaskStatus(task) {
- const statusClass = task.status === 'completed' ? 'success' :
- task.status === 'error' ? 'error' : 'loading';
+ // 状态文本的中文映射
+ const statusText = {
+ 'running': '正在生成',
+ 'completed': '已完成',
+ 'error': '生成失败',
+ 'pending': '等待中'
+ };
+
+ // 状态徽章样式
+ const statusBadgeClass = {
+ 'running': 'task-status-running',
+ 'completed': 'task-status-completed',
+ 'error': 'task-status-error',
+ 'pending': 'task-status-running'
+ };
+
+ // 为运行状态添加加载指示器
+ const loadingIndicator = task.status !== 'completed' && task.status !== 'error'
+ ? '
'
+ : '';
let statusHTML = `
-
-
任务ID: ${task.task_id}
-
查询: ${task.query}
-
状态: ${task.status}
-
进度: ${task.progress}%
-
创建时间: ${new Date(task.created_at).toLocaleString()}
-
更新时间: ${new Date(task.updated_at).toLocaleString()}
+
+
+
+
+
+ 任务ID:
+ ${task.task_id}
+
+
+ 查询内容:
+ ${task.query}
+
+
+ 开始时间:
+ ${new Date(task.created_at).toLocaleString()}
+
+
+ 更新时间:
+ ${new Date(task.updated_at).toLocaleString()}
+
+
`;
if (task.error_message) {
- statusHTML += `
错误信息: ${task.error_message}`;
- }
-
- if (task.has_result) {
- statusHTML += `
`;
+ statusHTML += `
+
+ 错误信息: ${task.error_message}
+
+ `;
}
statusHTML += '
';
@@ -1596,9 +1793,10 @@
const consoleOutput = document.getElementById('consoleOutput');
consoleOutput.innerHTML = '
[系统] 开始生成报告,日志已重置
';
- const generateBtn = document.getElementById('generateBtn');
- generateBtn.disabled = true;
- generateBtn.textContent = '生成中...';
+ // 按钮已移除,无需操作按钮状态
+
+ // 在现有状态信息后添加任务进度状态,而不是替换
+ addTaskProgressStatus('正在启动报告生成任务...', 'loading');
fetch('/api/report/generate', {
method: 'POST',
@@ -1613,6 +1811,16 @@
reportTaskId = data.task_id;
showMessage('报告生成已启动', 'success');
+ // 更新任务状态显示
+ updateTaskProgressStatus({
+ task_id: data.task_id,
+ query: query,
+ status: 'running',
+ progress: 5, // 初始进度设为5%,确保进度条可见
+ created_at: new Date().toISOString(),
+ updated_at: new Date().toISOString()
+ });
+
// 立即刷新一次日志以确保同步
setTimeout(() => {
refreshReportLog();
@@ -1621,16 +1829,18 @@
// 开始轮询任务状态
startProgressPolling(data.task_id);
} else {
- showMessage('启动失败: ' + data.error, 'error');
- generateBtn.disabled = false;
- generateBtn.textContent = '生成最终报告';
+ updateTaskProgressStatus(null, 'error', '启动失败: ' + data.error);
+ // 重置标志允许重新尝试
+ autoGenerateTriggered = false;
+ reportTaskId = null;
}
})
.catch(error => {
console.error('生成报告失败:', error);
- showMessage('生成报告失败: ' + error.message, 'error');
- generateBtn.disabled = false;
- generateBtn.textContent = '生成最终报告';
+ updateTaskProgressStatus(null, 'error', '生成报告失败: ' + error.message);
+ // 重置标志允许重新尝试
+ autoGenerateTriggered = false;
+ reportTaskId = null;
});
}
@@ -1663,18 +1873,16 @@
// 自动显示报告
viewReport(taskId);
- // 重新启用生成按钮
- const generateBtn = document.getElementById('generateBtn');
- generateBtn.disabled = false;
- generateBtn.textContent = '生成最终报告';
+ // 重置自动生成标志,允许下次自动生成
+ autoGenerateTriggered = false;
+ reportTaskId = null;
} else if (data.task.status === 'error') {
clearInterval(reportPollingInterval);
showMessage('报告生成失败: ' + data.task.error_message, 'error');
- // 重新启用生成按钮
- const generateBtn = document.getElementById('generateBtn');
- generateBtn.disabled = false;
- generateBtn.textContent = '生成最终报告';
+ // 重置自动生成标志,允许重新尝试
+ autoGenerateTriggered = false;
+ reportTaskId = null;
}
}
})
@@ -1683,20 +1891,61 @@
});
}
- // 更新进度显示
- function updateProgressDisplay(task) {
- const reportContent = document.getElementById('reportContent');
- const existingStatus = reportContent.querySelector('.report-status');
+ // 添加任务进度状态(使用固定区域)
+ function addTaskProgressStatus(message, status) {
+ const taskArea = document.getElementById('taskProgressArea');
- if (existingStatus) {
- existingStatus.outerHTML = renderTaskStatus(task);
+ if (taskArea) {
+ const loadingIndicator = status === 'loading' ? '
' : '';
+
+ taskArea.innerHTML = `
+
+
+
+ `;
}
}
+
+ // 更新任务进度状态(使用固定区域)
+ function updateTaskProgressStatus(task, status = null, errorMessage = null) {
+ const taskArea = document.getElementById('taskProgressArea');
+
+ if (!taskArea) {
+ console.error('taskProgressArea not found');
+ return;
+ }
+
+ if (task) {
+ taskArea.innerHTML = renderTaskStatus(task);
+ } else if (status && errorMessage) {
+ const loadingIndicator = status === 'loading' ? '
' : '';
+ const statusBadgeClass = status === 'error' ? 'task-status-error' : 'task-status-running';
+ const statusText = status === 'error' ? '错误' : '处理中';
+
+ taskArea.innerHTML = `
+
+
+
+ ${errorMessage}
+
+
+ `;
+ }
+ }
+
+ // 更新进度显示(保持向后兼容)
+ function updateProgressDisplay(task) {
+ updateTaskProgressStatus(task);
+ }
// 查看报告
function viewReport(taskId) {
const reportPreview = document.getElementById('reportPreview');
- reportPreview.innerHTML = '
加载报告中...
';
+ reportPreview.innerHTML = '
加载报告中...
';
fetch(`/api/report/result/${taskId}`)
.then(response => {
@@ -1706,12 +1955,33 @@
throw new Error('报告加载失败');
}
})
- .then(htmlContent => {
+ .then(rawContent => {
+ let htmlContent = rawContent;
+
+ // 检查是否是JSON格式的响应(包含html_content字段)
+ try {
+ if (rawContent.includes('"html_content":')) {
+ // 提取JSON中的html_content
+ const jsonMatch = rawContent.match(/\{[\s\S]*\}/);
+ if (jsonMatch) {
+ const jsonData = JSON.parse(jsonMatch[0]);
+ if (jsonData.html_content) {
+ htmlContent = jsonData.html_content;
+ // 处理转义字符
+ htmlContent = htmlContent.replace(/\\"/g, '"').replace(/\\n/g, '\n');
+ }
+ }
+ }
+ } catch (e) {
+ console.warn('解析JSON格式报告失败,使用原始内容:', e);
+ }
+
// 创建iframe来显示HTML内容
const iframe = document.createElement('iframe');
iframe.style.width = '100%';
- iframe.style.height = '600px';
iframe.style.border = 'none';
+ iframe.style.minHeight = '800px'; // 增加最小高度
+ iframe.id = 'report-iframe';
reportPreview.innerHTML = '';
reportPreview.appendChild(iframe);
@@ -1720,6 +1990,61 @@
iframe.contentDocument.open();
iframe.contentDocument.write(htmlContent);
iframe.contentDocument.close();
+
+ // 等待内容加载完成后调整iframe高度
+ iframe.onload = function() {
+ setTimeout(() => {
+ try {
+ // 获取iframe内容的实际高度
+ const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
+
+ // 等待所有资源加载完成
+ let contentHeight = 0;
+
+ // 尝试多种方式获取内容高度
+ if (iframeDoc.body) {
+ contentHeight = Math.max(
+ iframeDoc.body.scrollHeight || 0,
+ iframeDoc.body.offsetHeight || 0,
+ iframeDoc.body.clientHeight || 0
+ );
+ }
+
+ if (iframeDoc.documentElement) {
+ contentHeight = Math.max(
+ contentHeight,
+ iframeDoc.documentElement.scrollHeight || 0,
+ iframeDoc.documentElement.offsetHeight || 0,
+ iframeDoc.documentElement.clientHeight || 0
+ );
+ }
+
+ // 设置iframe高度为内容高度,最小800px
+ const finalHeight = Math.max(contentHeight + 100, 800); // 添加100px的缓冲
+ iframe.style.height = finalHeight + 'px';
+
+ console.log(`报告iframe高度已调整为: ${finalHeight}px (内容高度: ${contentHeight}px)`);
+
+ // 确保父容器也能正确显示
+ reportPreview.style.minHeight = finalHeight + 'px';
+
+ } catch (error) {
+ console.error('调整iframe高度失败:', error);
+ // 如果调整失败,使用更大的默认高度
+ iframe.style.height = '1200px';
+ reportPreview.style.minHeight = '1200px';
+ }
+ }, 1000); // 延迟1秒等待内容完全渲染
+ };
+
+ // 备用方案:如果onload没有触发,延迟调整高度
+ setTimeout(() => {
+ if (iframe.style.height === 'auto' || iframe.style.height === '') {
+ iframe.style.height = '1200px';
+ reportPreview.style.minHeight = '1200px';
+ console.log('使用备用高度设置: 1200px');
+ }
+ }, 3000);
})
.catch(error => {
console.error('查看报告失败:', error);
@@ -1731,9 +2056,65 @@
});
}
- // 检查报告状态
+ // 检查报告状态(不重新加载整个界面)
function checkReportStatus() {
- loadReportInterface();
+ // 只更新状态信息,不重新渲染整个界面
+ fetch('/api/report/status')
+ .then(response => response.json())
+ .then(data => {
+ if (data.success) {
+ // 更新ReportEngine状态指示器
+ const indicator = document.getElementById('status-report');
+ if (indicator) {
+ if (data.initialized) {
+ indicator.className = 'status-indicator running';
+ appStatus.report = 'running';
+ } else {
+ indicator.className = 'status-indicator';
+ appStatus.report = 'stopped';
+ }
+ }
+
+ // 更新状态信息(如果存在)
+ updateEngineStatusDisplay(data);
+
+ showMessage('状态检查完成', 'success');
+ } else {
+ showMessage('状态检查失败: ' + data.error, 'error');
+ }
+ })
+ .catch(error => {
+ console.error('检查报告状态失败:', error);
+ showMessage('状态检查失败: ' + error.message, 'error');
+ });
+ }
+
+ // 更新引擎状态显示(只更新文本内容)
+ function updateEngineStatusDisplay(statusData) {
+ const statusContent = document.getElementById('engineStatusContent');
+
+ if (statusContent) {
+ // 确定状态样式
+ const statusClass = statusData.initialized ? 'success' : 'error';
+
+ // 更新状态信息内容
+ let statusHTML = '';
+ if (statusData.initialized) {
+ statusHTML = `
+
ReportEngine状态: 已初始化
+
文件检查: ${statusData.engines_ready ? '准备就绪' : '文件未就绪'}
+
找到文件: ${statusData.files_found ? statusData.files_found.join(', ') : '无'}
+ ${statusData.missing_files && statusData.missing_files.length > 0 ?
+ `
缺失文件: ${statusData.missing_files.join(', ')}` : ''}
+ `;
+ } else {
+ statusHTML = `
ReportEngine状态: 未初始化`;
+ }
+
+ // 更新内容和样式
+ statusContent.innerHTML = statusHTML;
+ statusContent.className = `report-status ${statusClass}`;
+ }
}