// ============================================================
// 🛡️ 管理后台
// ============================================================
function renderAdminReports() {
const container = document.getElementById('adminContent');
container.innerHTML = '
加载中...
';
API.getReports().then(reports => {
if (!reports || reports.length === 0) {
container.innerHTML = '
${r.reporter_name || '匿名'} 举报了帖子
原因:${r.reason}
帖子:${postTitle} — ${(r.post_content || '').substring(0, 30)}${(r.post_content || '').length > 30 ? '...' : ''}
状态:${statusMap[r.status] || r.status}
${r.handler_name ? `
处理人:${r.handler_name}${r.handler_note ? ' (' + r.handler_note + ')' : ''}
` : ''}
${r.status === 'pending' ? `
` : ''}
`;
});
container.innerHTML = html;
container.querySelectorAll('[data-action]').forEach(btn => {
btn.addEventListener('click', function() {
const id = this.dataset.reportid;
const action = this.dataset.action;
const status = action === 'approve' ? 'approved' : 'rejected';
const note = action === 'approve' ? '已删除违规帖子' : '举报不成立';
if (action === 'approve' && !confirm('确定要删除该帖子并标记举报为已处理吗?')) return;
API.updateReport(id, status, note).then(() => {
if (action === 'approve') {
const report = reports.find(r => r.id === id);
if (report && report.post_id) {
API.deletePost(report.post_id).catch(() => {});
}
}
renderAdminReports();
}).catch(err => alert('操作失败:' + err.message));
});
});
}).catch(() => {
container.innerHTML = '加载中...
';
API.getUsers().then(users => {
let html = `
加载中...
';
API.getEventLogs().then(logs => {
if (!logs || logs.length === 0) {
container.innerHTML = '