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) {