修复定时任务日志弹窗显示问题
问题:点击日志按钮无反应 修复: 1. 重新格式化viewScheduleLogs函数(原本全部压缩成一行) 2. 添加详细的console.log调试日志 3. 每个步骤都有日志输出,便于调试 调试日志包括: - 开始查看日志 - 找到任务 - API响应状态 - 收到的数据 - 打开弹窗 现在可以通过浏览器控制台查看完整的执行流程。 位置: templates/index.html viewScheduleLogs函数 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1304,7 +1304,69 @@
|
|||||||
if (schedule) openScheduleModal(schedule);
|
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 = "<div class=\"empty-state\"><p>暂无执行日志</p></div>"; } else { let html = "<div style=\"display: flex; flex-direction: column; gap: 12px;\">"; 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 += "<div style=\"border: 1px solid var(--md-divider); border-radius: 8px; padding: 12px; background: var(--md-surface);\">" + "<div style=\"display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;\">" + "<span style=\"font-size: 14px; color: var(--md-on-surface-medium);\">" + (log.created_at || "") + "</span>" + "<span class=\"status-chip " + statusClass + "\">" + statusText + "</span>" + "</div>" + "<div style=\"font-size: 13px; line-height: 1.6;\">" + "<div><strong>账号数:</strong> " + (log.total_accounts || 0) + " 个</div>" + "<div><strong>成功:</strong> " + (log.success_count || 0) + " 个 | <strong>失败:</strong> " + (log.failed_count || 0) + " 个</div>" + "<div><strong>耗时:</strong> " + formatDuration(log.duration || 0) + "</div>" + (log.error_message ? "<div style=\"color: var(--md-error); margin-top: 4px;\"><strong>错误:</strong> " + escapeHtml(log.error_message) + "</div>" : "") + "</div></div>"; }); html += "</div>"; 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 = "<div class=\"empty-state\"><p>暂无执行日志</p></div>";
|
||||||
|
} else {
|
||||||
|
console.log('[日志弹窗] 渲染', logs.length, '条日志');
|
||||||
|
let html = "<div style=\"display: flex; flex-direction: column; gap: 12px;\">";
|
||||||
|
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 += "<div style=\"border: 1px solid var(--md-divider); border-radius: 8px; padding: 12px; background: var(--md-surface);\">" +
|
||||||
|
"<div style=\"display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px;\">" +
|
||||||
|
"<span style=\"font-size: 14px; color: var(--md-on-surface-medium);\"">" + (log.created_at || "") + "</span>" +
|
||||||
|
"<span class=\"status-chip " + statusClass + "\">" + statusText + "</span>" +
|
||||||
|
"</div>" +
|
||||||
|
"<div style=\"font-size: 13px; line-height: 1.6;\">" +
|
||||||
|
"<div><strong>账号数:</strong> " + (log.total_accounts || 0) + " 个</div>" +
|
||||||
|
"<div><strong>成功:</strong> " + (log.success_count || 0) + " 个 | <strong>失败:</strong> " + (log.failed_count || 0) + " 个</div>" +
|
||||||
|
"<div><strong>耗时:</strong> " + formatDuration(log.duration || 0) + "</div>" +
|
||||||
|
(log.error_message ? "<div style=\"color: var(--md-error); margin-top: 4px;\"><strong>错误:</strong> " + escapeHtml(log.error_message) + "</div>" : "") +
|
||||||
|
"</div></div>";
|
||||||
|
});
|
||||||
|
html += "</div>";
|
||||||
|
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) {
|
function deleteSchedule(id) {
|
||||||
if (!confirm('确定要删除此定时任务吗?')) return;
|
if (!confirm('确定要删除此定时任务吗?')) return;
|
||||||
fetch('/api/schedules/' + id, {method: 'DELETE'}).then(r => r.json()).then(function(data) {
|
fetch('/api/schedules/' + id, {method: 'DELETE'}).then(r => r.json()).then(function(data) {
|
||||||
|
|||||||
Reference in New Issue
Block a user