/* * MC Report System * Copyright (C) 2026 Sea Network Technology Studio * Author: CangLan * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published * by the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ const LogsPage = { tab: 'system', async render() { return '
'; }, async mount() { document.getElementById('page-title').textContent = '系统日志'; document.getElementById('page-actions').innerHTML = ``; const ct = document.getElementById('page-content'); ct.innerHTML = `
`; document.querySelectorAll('#logs-tabs button').forEach(b => { b.onclick = () => { document.querySelectorAll('#logs-tabs button').forEach(x => x.classList.remove('active')); b.classList.add('active'); this.tab = b.dataset.tab; this.load(); }; }); await this.load(); }, refresh() { this.load(); }, async applyFilter() { this.load(); }, async load() { const list = document.getElementById('logs-list'); U.loading(list); const level = document.getElementById('lg-level')?.value || ''; const src = document.getElementById('lg-source')?.value.trim() || ''; const isEmail = this.tab === 'email'; try { const params = new URLSearchParams(); if (level) params.set('level', level); if (src) params.set(isEmail ? 'email' : 'source', src); const qs = params.toString(); const rows = await API.get('/logs/' + (isEmail ? 'emails' : 'system') + (qs ? '?' + qs : '')); this.renderList(list, rows, isEmail); } catch (e) { list.innerHTML = `
${e.message}
`; } }, renderList(ct, rows, isEmail) { if (isEmail) { ct.innerHTML = rows.length === 0 ? '

暂无邮件日志

' : `
${rows.map(r => ` `).join('')}
#收件人模板主题状态错误时间
${r.id} ${U.esc(r.to_email)} ${U.esc(r.template_code||'-')} ${U.esc(r.subject||'')} ${r.status==='sent'?'成功':'失败'} ${U.esc(r.error||'-')} ${U.date(r.created_at)}
`; } else { const lv = { info:'信息', warn:'警告', error:'错误' }; ct.innerHTML = rows.length === 0 ? '

暂无系统日志

' : `
${rows.map(r => ` `).join('')}
#级别来源消息详情时间
${r.id} ${lv[r.level]||r.level} ${U.esc(r.source)} ${U.esc(r.message)} ${U.esc(r.details||'-')} ${U.date(r.created_at)}
`; } } };