From dc5f9e939bd71a24d278c48a1b58e74ca4f52f9d Mon Sep 17 00:00:00 2001 From: root Date: Wed, 10 Dec 2025 17:14:08 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AE=9A=E6=97=B6=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=97=A5=E5=BF=97=E5=BC=B9=E7=AA=97=E6=98=BE=E7=A4=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 问题:点击日志按钮无反应 修复: 1. 重新格式化viewScheduleLogs函数(原本全部压缩成一行) 2. 添加详细的console.log调试日志 3. 每个步骤都有日志输出,便于调试 调试日志包括: - 开始查看日志 - 找到任务 - API响应状态 - 收到的数据 - 打开弹窗 现在可以通过浏览器控制台查看完整的执行流程。 位置: templates/index.html viewScheduleLogs函数 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- templates/index.html | 64 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/templates/index.html b/templates/index.html index 4b71c57..99f98eb 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1304,7 +1304,69 @@ if (schedule) openScheduleModal(schedule); } - function viewScheduleLogs(scheduleId) { const schedule = schedules.find(s => s.id === scheduleId); if (!schedule) return; document.getElementById("scheduleLogsTitle").textContent = "【" + (schedule.name || "未命名任务") + "】 执行日志"; fetch("/api/schedules/" + scheduleId + "/logs?limit=20") .then(r => r.json()) .then(logs => { const container = document.getElementById("scheduleLogsList"); if (!logs || logs.length === 0) { container.innerHTML = "

暂无执行日志

"; } else { let html = "
"; logs.forEach(log => { const statusClass = log.status === "success" ? "status-completed" : (log.status === "failed" ? "status-error" : "status-running"); const statusText = log.status === "success" ? "成功" : (log.status === "failed" ? "失败" : "进行中"); html += "
" + "
" + "" + (log.created_at || "") + "" + "" + statusText + "" + "
" + "
" + "
账号数: " + (log.total_accounts || 0) + " 个
" + "
成功: " + (log.success_count || 0) + " 个 | 失败: " + (log.failed_count || 0) + " 个
" + "
耗时: " + formatDuration(log.duration || 0) + "
" + (log.error_message ? "
错误: " + escapeHtml(log.error_message) + "
" : "") + "
"; }); html += "
"; container.innerHTML = html; } openModal("scheduleLogsModal"); }) .catch(err => { showToast("加载日志失败", "error"); }); } function formatDuration(seconds) { if (seconds < 60) return seconds + "秒"; const minutes = Math.floor(seconds / 60); const secs = seconds % 60; return minutes + "分" + secs + "秒"; } + function viewScheduleLogs(scheduleId) { + console.log('[日志弹窗] 开始查看日志, scheduleId=', scheduleId); + + const schedule = schedules.find(s => s.id === scheduleId); + if (!schedule) { + console.log('[日志弹窗] 未找到任务'); + return; + } + + console.log('[日志弹窗] 找到任务:', schedule); + document.getElementById("scheduleLogsTitle").textContent = "【" + (schedule.name || "未命名任务") + "】 执行日志"; + + console.log('[日志弹窗] 开始请求API'); + fetch("/api/schedules/" + scheduleId + "/logs?limit=20") + .then(r => { + console.log('[日志弹窗] API响应状态:', r.status); + return r.json(); + }) + .then(logs => { + console.log('[日志弹窗] 收到日志数据:', logs); + + const container = document.getElementById("scheduleLogsList"); + if (!logs || logs.length === 0) { + console.log('[日志弹窗] 无日志,显示空状态'); + container.innerHTML = "

暂无执行日志

"; + } else { + console.log('[日志弹窗] 渲染', logs.length, '条日志'); + let html = "
"; + logs.forEach(log => { + const statusClass = log.status === "success" ? "status-completed" : (log.status === "failed" ? "status-error" : "status-running"); + const statusText = log.status === "success" ? "成功" : (log.status === "failed" ? "失败" : "进行中"); + html += "
" + + "
" + + "" + (log.created_at || "") + "" + + "" + statusText + "" + + "
" + + "
" + + "
账号数: " + (log.total_accounts || 0) + " 个
" + + "
成功: " + (log.success_count || 0) + " 个 | 失败: " + (log.failed_count || 0) + " 个
" + + "
耗时: " + formatDuration(log.duration || 0) + "
" + + (log.error_message ? "
错误: " + escapeHtml(log.error_message) + "
" : "") + + "
"; + }); + html += "
"; + container.innerHTML = html; + } + + console.log('[日志弹窗] 准备打开弹窗'); + openModal("scheduleLogsModal"); + console.log('[日志弹窗] 弹窗已打开'); + }) + .catch(err => { + console.error('[日志弹窗] 请求失败:', err); + showToast("加载日志失败", "error"); + }); + } + + function formatDuration(seconds) { + if (seconds < 60) return seconds + "秒"; + const minutes = Math.floor(seconds / 60); + const secs = seconds % 60; + return minutes + "分" + secs + "秒"; + } function deleteSchedule(id) { if (!confirm('确定要删除此定时任务吗?')) return; fetch('/api/schedules/' + id, {method: 'DELETE'}).then(r => r.json()).then(function(data) {