blob: a7985bec92fd290ac6a9653d423213bcb4e2d407 [file] [log] [blame]
ym9232a70a622025-06-09 20:12:13 +08001import React, { useEffect, useState } from 'react';
2import {
3 Table,
4 Button,
5 Modal,
6 message,
7 Tag,
8 Space,
9 Tooltip,
10} from 'antd';
11import { ExclamationCircleOutlined } from '@ant-design/icons';
12import {
13 getAllComplains,
14 deleteComplain,
15 // 预留:你后续可以新增处理投诉的API
16} from '../api/complain';
17import { useNavigate } from 'react-router-dom';
18
19const { confirm } = Modal;
20
21const ComplainAdminPanel = () => {
22 const [complains, setComplains] = useState([]);
23 const [loading, setLoading] = useState(false);
24 const navigate = useNavigate();
25
26 const fetchComplains = async () => {
27 setLoading(true);
28 try {
29 const data = await getAllComplains();
30 setComplains(data);
31 } catch (error) {
32 message.error('获取投诉记录失败');
33 } finally {
34 setLoading(false);
35 }
36 };
37
38 useEffect(() => {
39 fetchComplains();
40 }, []);
41
42 const showDeleteConfirm = (complainid) => {
43 confirm({
44 title: '确认删除该投诉记录吗?',
45 icon: <ExclamationCircleOutlined />,
46 okText: '删除',
47 okType: 'danger',
48 cancelText: '取消',
49 onOk() {
50 handleDelete(complainid);
51 },
52 });
53 };
54
55 const handleDelete = async (complainid) => {
56 try {
57 const success = await deleteComplain(complainid);
58 if (success) {
59 message.success('删除成功');
60 fetchComplains();
61 } else {
62 message.error('删除失败');
63 }
64 } catch {
65 message.error('删除请求失败');
66 }
67 };
68
69 const handleProcess = (complain) => {
70 const { complainid, duser, torrentid } = complain;
71 navigate(`/complain-process/${complainid}`, {
72 state: { complainid, duser, torrentid },
73 });
74 };
75
76 const columns = [
77 {
78 title: '投诉ID',
79 dataIndex: 'complainid',
80 key: 'complainid',
81 width: 80,
82 fixed: 'left',
83 },
84 {
85 title: '投诉人ID',
86 dataIndex: 'puse',
87 key: 'puse',
88 width: 120,
89 },
90 {
91 title: '被投诉人ID',
92 dataIndex: 'duser',
93 key: 'duser',
94 width: 120,
95 },
96 {
97 title: '投诉内容',
98 dataIndex: 'content',
99 key: 'content',
100 ellipsis: { showTitle: false },
101 render: (text) => (
102 <Tooltip placement="topLeft" title={text}>
103 {text}
104 </Tooltip>
105 ),
106 },
107 {
108 title: '相关种子ID',
109 dataIndex: 'torrentid',
110 key: 'torrentid',
111 width: 120,
112 render: (val) => val ?? <Tag color="default">无</Tag>,
113 },
114 {
115 title: '操作',
116 key: 'action',
117 fixed: 'right',
118 width: 150,
119 render: (_, record) => (
120 <Space size="middle">
121 <Button type="primary" onClick={() => handleProcess(record)}>
122 处理
123 </Button>
124 <Button danger onClick={() => showDeleteConfirm(record.complainid)}>
125 删除
126 </Button>
127 </Space>
128 ),
129 },
130 ];
131
132 return (
133 <div style={{ padding: 20 }}>
134 <h2 style={{ marginBottom: 20 }}>投诉管理面板</h2>
135 <Table
136 rowKey="complainid"
137 columns={columns}
138 dataSource={complains}
139 loading={loading}
140 scroll={{ x: 1000 }}
141 pagination={{ pageSize: 10 }}
142 bordered
143 size="middle"
144 />
145 </div>
146 );
147};
148
149export default ComplainAdminPanel;