import { useState } from 'react' import { useQuery, useQueryClient } from '@tanstack/react-query' import { Table, Button, Typography, App, Modal, Input, Select, Tag, Space, Tabs } from 'antd' import { ReloadOutlined, PlusOutlined, DeleteOutlined, SafetyOutlined } from '@ant-design/icons' import { contentSafetyAPI } from '@/api' import dayjs from 'dayjs' const { Title, Text } = Typography function CSPage() { const { modal, message } = App.useApp() const qc = useQueryClient() const [addOpen, setAddOpen] = useState(false) const [newWord, setNewWord] = useState('') const [category, setCategory] = useState('general') const [risk, setRisk] = useState('medium') const { data: words } = useQuery({ queryKey: ['safety', 'words'], queryFn: () => contentSafetyAPI.words() }) const { data: checks } = useQuery({ queryKey: ['safety', 'checks'], queryFn: () => contentSafetyAPI.checks() }) const { data: reports } = useQuery({ queryKey: ['safety', 'reports'], queryFn: () => contentSafetyAPI.reports() }) const { data: violations } = useQuery({ queryKey: ['safety', 'violations'], queryFn: () => contentSafetyAPI.violations() }) const addWord = async () => { await contentSafetyAPI.addWord({ word: newWord, category, riskLevel: risk }) message.success('已添加'); setAddOpen(false); setNewWord('') qc.invalidateQueries({ queryKey: ['safety'] }) } const removeWord = (id: string) => modal.confirm({ title: '删除敏感词', okType: 'danger', onOk: async () => { await contentSafetyAPI.deleteWord(id); qc.invalidateQueries({ queryKey: ['safety'] }) }, }) const handleReport = (id: string, action: string) => modal.confirm({ title: action === 'confirmed' ? '确认违规' : '驳回举报', content: action === 'confirmed' ? '确认后将创建违规记录' : '驳回后将关闭此举报', onOk: async () => { await contentSafetyAPI.handleReport(id, { action, note: `Admin ${action}` }) message.success('已处理'); qc.invalidateQueries({ queryKey: ['safety'] }) }, }) const applyPenalty = (id: string, penalty: string) => modal.confirm({ title: '应用处罚', content: `确认对违规记录应用「${penalty}」处罚?`, onOk: async () => { await contentSafetyAPI.penaltyViolation(id, { penalty }) message.success('处罚已应用'); qc.invalidateQueries({ queryKey: ['safety'] }) }, }) const wordCols = [ { title: '词汇', dataIndex: 'word', width: 150 }, { title: '分类', dataIndex: 'category', width: 100 }, { title: '等级', dataIndex: 'riskLevel', width: 80, render: (v: string) => {v} }, { title: '状态', dataIndex: 'enabled', width: 70, render: (v: boolean) => v ? 启用 : 禁用 }, { title: '添加时间', dataIndex: 'createdAt', width: 140, render: (d: string) => dayjs(d).format('MM-DD HH:mm') }, { title: '操作', width: 80, render: (_: any, r: any) => ) : - }, ] const violationCols = [ { title: '时间', dataIndex: 'createdAt', width: 130, render: (d: string) => dayjs(d).format('MM-DD HH:mm') }, { title: '用户', dataIndex: 'userId', width: 140, ellipsis: true , render: (_: any, r: any) => r.userName || r.userId }, { title: '类型', dataIndex: 'contentType', width: 100 }, { title: '内容', dataIndex: 'content', ellipsis: true, render: (v: string) => {v?.slice(0, 60)} }, { title: '风险', dataIndex: 'riskLevel', width: 70, render: (v: string) => {v} }, { title: '处罚', dataIndex: 'penalty', width: 80, render: (v: string) => v === 'none' ? : {v} }, { title: '操作', width: 120, render: (_: any, r: any) => r.penalty === 'none' ? ( ) : {r.penalty} }, ] return (
<SafetyOutlined /> 内容安全
}, { key: 'checks', label: '审核记录', children: }, { key: 'reports', label: '举报管理', children:
}, { key: 'violations', label: '违规记录', children:
}, ]} /> setAddOpen(false)} okText="添加"> setNewWord(e.target.value)} style={{ marginBottom: 12 }} /> ) } export default CSPage