| 177 | } |
| 178 | |
| 179 | async function cleanupLogs() { |
| 180 | const retentionDays = Number(el.cleanupRetentionDays.value || 14); |
| 181 | const maxRows = Number(el.cleanupMaxRows.value || 50000); |
| 182 | const ok = await confirm( |
| 183 | `确认清理日志吗?\n保留天数=${retentionDays},最大条数=${maxRows}`, |
| 184 | "清理后台日志" |
| 185 | ); |
| 186 | if (!ok) return; |
| 187 | |
| 188 | try { |
| 189 | loading.show(el.cleanupBtn, "清理中..."); |
| 190 | const data = await api.post("/logs/cleanup", { |
| 191 | retention_days: retentionDays, |
| 192 | max_rows: maxRows, |
| 193 | }); |
| 194 | toast.success(`清理完成:删除 ${data.deleted_total || 0} 条,剩余 ${data.remaining || 0} 条`); |
| 195 | logsState.page = 1; |
| 196 | await Promise.all([loadLogs(true), loadStats(true)]); |
| 197 | setLogsSummary(); |
| 198 | } catch (error) { |
| 199 | toast.error(`清理失败: ${error?.message || error}`); |
| 200 | } finally { |
| 201 | loading.hide(el.cleanupBtn); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | async function clearAllLogs() { |
| 206 | const ok = await confirm("确认清空全部后台日志吗?该操作不可恢复。", "清空后台日志"); |