debug: 添加详细调试日志,诊断下载按钮不显示的问题

问题:日报生成成功后,历史记录中没有下载按钮。

改进内容:

1. lib/report_generator.py:
   - 在生成Excel文件后添加日志:显示文件路径
   - 在保存历史记录前添加日志:显示file_path值
   - 在save_report_history函数中添加详细日志:
     * 显示准备保存的信息
     * 显示file_path和status的值
     * 显示SQL执行结果

2. app.py:
   - 在历史记录API中添加调试日志
   - 显示每条记录的status和file_path
   - 确保file_path不为None(转换为空字符串)
   - 添加错误堆栈输出

3. templates/index.html:
   - 在渲染历史记录时添加console.log调试
   - 显示每条记录的详细信息
   - 显示status和file_path的类型
   - 改进下载按钮判断逻辑
   - 添加title提示显示文件路径

4. 新增文档:
   - 查看调试日志.md:详细的调试步骤和问题诊断方法

现在用户可以通过日志准确定位问题:
- 服务器控制台:查看后端日志
- 浏览器控制台:查看前端日志
- curl测试:直接查看API返回数据

Coze-Commit-Type: user
Coze-User-ID: 3722323274763196
Coze-Conversation-ID: 9894087
This commit is contained in:
user9994793890
2026-07-09 12:59:40 +08:00
parent 9fa2745daa
commit 2ad6e27131
6 changed files with 239 additions and 7 deletions

View File

@@ -950,7 +950,16 @@
return;
}
tbody.innerHTML = history.map(item => `
tbody.innerHTML = history.map(item => {
// 调试信息
console.log('历史记录项:', item);
console.log(' status:', item.status, '类型:', typeof item.status);
console.log(' file_path:', item.file_path, '类型:', typeof item.file_path);
console.log(' 是否有文件:', !!(item.status === 1 && item.file_path));
const hasFile = item.status === 1 && item.file_path && item.file_path.trim() !== '';
return `
<tr>
<td>${item.report_date}</td>
<td style="font-size: 12px;">${item.start_time || '-'}<br>至<br>${item.end_time || '-'}</td>
@@ -964,12 +973,12 @@
</span>
</td>
<td>
${item.status === 1 && item.file_path ?
`<a href="/api/download?path=${item.file_path}" target="_blank" class="btn btn-sm btn-success">📥 下载</a>` :
'<span style="color: #999;">-</span>'}
${hasFile ?
`<a href="/api/download?path=${encodeURIComponent(item.file_path)}" target="_blank" class="btn btn-sm btn-success">📥 下载</a>` :
`<span style="color: #999;" title="文件路径: ${item.file_path || '无'}">-</span>`}
</td>
</tr>
`).join('');
`}).join('');
}
// 渲染分页