blob: 1b3e2af7d6b4374a0eea0a39f94ad02a4379c4b9 [file] [log] [blame]
whtdc90a032025-06-08 03:03:52 +08001import React, { useState } from "react";
2import { useParams } from "react-router-dom";
3
4// 求种任务示例数据
5const begSeedList = [
6 {
7 beg_id: "beg001",
8 info: "求《三体》高清资源",
9 beg_count: 5,
10 reward_magic: 100,
11 deadline: "2025-06-10T23:59:59",
12 has_match: 0,
13 },
14 {
15 beg_id: "beg002",
16 info: "求《灌篮高手》国语配音版",
17 beg_count: 3,
18 reward_magic: 50,
19 deadline: "2024-05-01T23:59:59",
20 has_match: 1,
21 },
22 {
23 beg_id: "beg003",
24 info: "求《黑暗之魂3》PC版种子",
25 beg_count: 2,
26 reward_magic: 80,
27 deadline: "2024-04-01T23:59:59",
28 has_match: 0,
29 },
30];
31
32// SubmitSeed表示例数据
33const submitSeedList = [
34 { beg_id: "beg001", seed_id: "seed001", votes: 3 },
35 { beg_id: "beg001", seed_id: "seed002", votes: 1 },
36 { beg_id: "beg002", seed_id: "seed003", votes: 2 },
37];
38
39// 种子信息映射
40const seedInfoMap = {
41 seed001: { title: "三体 1080P 蓝光", subtitle: "高码率无水印" },
42 seed002: { title: "三体 720P", subtitle: "清晰版" },
43 seed003: { title: "灌篮高手 国语配音", subtitle: "全剧集" },
44};
45
46export default function BegInfo() {
47 const { begid } = useParams();
48 const beg = begSeedList.find((b) => b.beg_id === begid);
49 const [seeds, setSeeds] = useState(
50 submitSeedList.filter((s) => s.beg_id === begid)
51 );
52 const [showForm, setShowForm] = useState(false);
53 const [formData, setFormData] = useState({
54 title: "",
55 subtitle: "",
56 torrentFile: null,
57 });
58
59 if (!beg) return <div style={{ padding: 40 }}>未找到该求种信息</div>;
60
61 const isExpired = new Date(beg.deadline) < new Date();
62 const isFinished = beg.has_match === 1;
63 const isActive = !isExpired && !isFinished;
64
65 // 投票功能(前端+1)
66 const handleVote = (seed_id) => {
67 setSeeds((prev) =>
68 prev.map((s) =>
69 s.seed_id === seed_id ? { ...s, votes: s.votes + 1 } : s
70 )
71 );
72 };
73
74 // 上传表单处理
75 const handleFormChange = (e) => {
76 const { name, value, files } = e.target;
77 if (name === "torrentFile") {
78 setFormData((f) => ({ ...f, torrentFile: files[0] }));
79 } else {
80 setFormData((f) => ({ ...f, [name]: value }));
81 }
82 };
83
84 const handleSubmitSeed = (e) => {
85 e.preventDefault();
86 // 这里只做前端演示,实际应上传到后端
87 const newSeedId = "seed" + Math.floor(Math.random() * 10000);
88 setSeeds((prev) => [
89 ...prev,
90 {
91 beg_id: begid,
92 seed_id: newSeedId,
93 votes: 0,
94 },
95 ]);
96 seedInfoMap[newSeedId] = {
97 title: formData.title,
98 subtitle: formData.subtitle,
99 };
100 setShowForm(false);
101 setFormData({ title: "", subtitle: "", torrentFile: null });
102 alert("提交成功(前端演示)");
103 };
104
105 return (
106 <div className="container">
107 <h1 style={{ margin: "24px 0 32px 0", color: "#1976d2" }}>
108 求种详情
109 </h1>
110 <div
111 style={{
112 background: "#e3f7e7",
113 border: "1.5px solid #b2d8ea",
114 borderRadius: 12,
115 padding: 24,
116 maxWidth: 600,
117 margin: "0 auto 32px auto",
118 boxShadow: "0 2px 8px #e0e7ff",
119 }}
120 >
121 <div style={{ fontWeight: 600, fontSize: 20, marginBottom: 12 }}>
122 {beg.info}
123 </div>
124 <div>求种人数:{beg.beg_count}</div>
125 <div>悬赏魔力值:{beg.reward_magic}</div>
126 <div>截止时间:{new Date(beg.deadline).toLocaleString()}</div>
127 <div>
128 状态:
129 {isFinished
130 ? "已完成"
131 : isExpired
132 ? "已过期"
133 : "进行中"}
134 </div>
135 </div>
136
137 <h2 style={{ margin: "24px 0 12px 0" }}>已提交种子</h2>
138 <table className="movie-table" style={{ maxWidth: 700, margin: "0 auto" }}>
139 <thead>
140 <tr>
141 <th>标题</th>
142 <th>简介</th>
143 <th>投票数</th>
144 <th>操作</th>
145 </tr>
146 </thead>
147 <tbody>
148 {seeds.length === 0 ? (
149 <tr>
150 <td colSpan={4} style={{ textAlign: "center" }}>暂无提交的种子</td>
151 </tr>
152 ) : (
153 seeds.map((s) => (
154 <tr key={s.seed_id}>
155 <td>{seedInfoMap[s.seed_id]?.title || "未知标题"}</td>
156 <td>{seedInfoMap[s.seed_id]?.subtitle || "无简介"}</td>
157 <td>{s.votes}</td>
158 <td>
159 {isActive ? (
160 <button
161 onClick={() => handleVote(s.seed_id)}
162 style={{
163 background: "#1976d2",
164 color: "#fff",
165 border: "none",
166 borderRadius: 6,
167 padding: "6px 18px",
168 fontWeight: 500,
169 cursor: "pointer",
170 transition: "background 0.2s",
171 }}
172 >
173 投票
174 </button>
175 ) : (
176 <span style={{ color: "#b0b0b0" }}>不可投票</span>
177 )}
178 </td>
179 </tr>
180 ))
181 )}
182 </tbody>
183 </table>
184
185 {isActive && (
186 <div style={{ margin: "32px 0", textAlign: "center" }}>
187 <button
188 onClick={() => setShowForm(true)}
189 style={{
190 fontSize: 18,
191 padding: "12px 36px",
192 background: "linear-gradient(90deg, #42a5f5 0%, #1976d2 100%)",
193 color: "#fff",
194 border: "none",
195 borderRadius: 8,
196 fontWeight: 600,
197 boxShadow: "0 2px 8px #b2d8ea",
198 cursor: "pointer",
199 transition: "background 0.2s",
200 }}
201 >
202 提交悬赏种子
203 </button>
204 </div>
205 )}
206
207 {showForm && isActive && (
208 <div
209 style={{
210 background: "#fff",
211 border: "1.5px solid #b2d8ea",
212 borderRadius: 12,
213 padding: 24,
214 maxWidth: 480,
215 margin: "0 auto",
216 boxShadow: "0 2px 8px #e0e7ff",
217 }}
218 >
219 <h3 style={{ color: "#1976d2", marginBottom: 18 }}>上传种子</h3>
220 <form onSubmit={handleSubmitSeed}>
221 <div style={{ marginBottom: 16 }}>
222 <label style={{ display: "inline-block", width: 60 }}>标题:</label>
223 <input
224 type="text"
225 name="title"
226 value={formData.title}
227 onChange={handleFormChange}
228 required
229 style={{
230 padding: "6px 12px",
231 borderRadius: 6,
232 border: "1px solid #b2d8ea",
233 width: 280,
234 }}
235 />
236 </div>
237 <div style={{ marginBottom: 16 }}>
238 <label style={{ display: "inline-block", width: 60 }}>简介:</label>
239 <input
240 type="text"
241 name="subtitle"
242 value={formData.subtitle}
243 onChange={handleFormChange}
244 style={{
245 padding: "6px 12px",
246 borderRadius: 6,
247 border: "1px solid #b2d8ea",
248 width: 280,
249 }}
250 />
251 </div>
252 <div style={{ marginBottom: 16 }}>
253 <label style={{ display: "inline-block", width: 60 }}>种子文件:</label>
254 <input
255 type="file"
256 name="torrentFile"
257 accept=".torrent"
258 onChange={handleFormChange}
259 required
260 style={{
261 padding: "6px 0",
262 borderRadius: 6,
263 border: "1px solid #b2d8ea",
264 width: 280,
265 }}
266 />
267 </div>
268 <div style={{ marginTop: 18 }}>
269 <button
270 type="submit"
271 style={{
272 background: "#1976d2",
273 color: "#fff",
274 border: "none",
275 borderRadius: 6,
276 padding: "8px 28px",
277 fontWeight: 500,
278 fontSize: 16,
279 marginRight: 18,
280 cursor: "pointer",
281 }}
282 >
283 提交
284 </button>
285 <button
286 type="button"
287 onClick={() => setShowForm(false)}
288 style={{
289 background: "#b0b0b0",
290 color: "#fff",
291 border: "none",
292 borderRadius: 6,
293 padding: "8px 28px",
294 fontWeight: 500,
295 fontSize: 16,
296 cursor: "pointer",
297 }}
298 >
299 取消
300 </button>
301 </div>
302 </form>
303 </div>
304 )}
305 </div>
306 );
307}