'use client'; // 管理后台 - 举报处理 import { useEffect, useState } from 'react'; import { API } from '@/lib/api'; import { Icon } from '../Icons'; const STATUS = { pending: '⏳ 待处理', approved: '✅ 已删除', rejected: '❌ 已驳回' }; export default function AdminReports() { const [reports, setReports] = useState(null); const [error, setError] = useState(null); const load = () => { API.getReports() .then((data) => { setReports(data || []); setError(null); }) .catch((e) => { setError(e.message); setReports([]); }); }; useEffect(load, []); const handleAction = async (r, action) => { const status = action === 'approve' ? 'approved' : 'rejected'; const note = action === 'approve' ? '已删除违规帖子' : '举报不成立'; if (action === 'approve' && !confirm('确定要删除该帖子并标记举报为已处理吗?')) return; try { await API.updateReport(r.id, status, note); if (action === 'approve' && r.post_id) { API.deletePost(r.post_id).catch(() => {}); } load(); } catch (err) { alert('操作失败:' + err.message); } }; if (error) return
加载失败:{error}
; if (!reports) return
加载中...
; if (reports.length === 0) return
✅ 暂无举报
; return reports.map((r) => (
{r.reporter_name || '匿名'} 举报了帖子
原因:{r.reason}
帖子:{r.post_title || '无标题'} — {(r.post_content || '').substring(0, 30)} {(r.post_content || '').length > 30 ? '...' : ''}
状态:{STATUS[r.status] || r.status}
{r.handler_name && (
处理人:{r.handler_name}{r.handler_note ? ' (' + r.handler_note + ')' : ''}
)} {r.status === 'pending' && (
)}
)); }