添加定时任务日志管理功能

- 添加用户清空日志按钮
- 添加30天自动清理定时任务执行日志
- 简化日志API代码,移除调试日志

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2025-12-10 20:20:44 +08:00
parent 9df2122fb5
commit 7954aeaf59
3 changed files with 71 additions and 43 deletions

View File

@@ -493,6 +493,7 @@
<div id="scheduleLogsList" style="max-height: 400px; overflow-y: auto;"></div>
</div>
<div class="modal-footer">
<button class="btn btn-text" style="color: var(--md-error);" onclick="clearScheduleLogs()">清空日志</button>
<button class="btn btn-primary" onclick="closeModal('scheduleLogsModal')">关闭</button>
</div>
</div>
@@ -1312,6 +1313,8 @@
if (schedule) openScheduleModal(schedule);
}
let currentLogsScheduleId = null;
function viewScheduleLogs(scheduleId) {
const numericId = parseInt(scheduleId, 10);
const schedule = schedules.find(s => s.id == numericId);
@@ -1320,6 +1323,7 @@
return;
}
currentLogsScheduleId = numericId;
document.getElementById("scheduleLogsTitle").textContent = "【" + (schedule.name || "未命名任务") + "】 执行日志";
fetch("/api/schedules/" + numericId + "/logs?limit=20")
@@ -1362,6 +1366,23 @@
});
}
function clearScheduleLogs() {
if (!currentLogsScheduleId) return;
if (!confirm('确定要清空该任务的所有执行日志吗?')) return;
fetch("/api/schedules/" + currentLogsScheduleId + "/logs", { method: 'DELETE' })
.then(r => r.json())
.then(data => {
if (data.success) {
showToast('已清空 ' + data.deleted + ' 条日志', 'success');
document.getElementById("scheduleLogsList").innerHTML = "<div class=\"empty-state\"><p>暂无执行日志</p></div>";
} else {
showToast(data.error || '清空失败', 'error');
}
})
.catch(err => showToast('清空失败', 'error'));
}
function formatDuration(seconds) {
if (seconds < 60) return seconds + "秒";
const minutes = Math.floor(seconds / 60);