blob: a456147d8577a82846bbd85780feb8378ba2d827 [file] [log] [blame]
whtdc90a032025-06-08 03:03:52 +08001import React, { useState } from "react";
2import HelpIcon from "@mui/icons-material/Help";
3import { useNavigate } from "react-router-dom";
4
5// 初始硬编码数据
6const initialBegSeedList = [
7 {
8 beg_id: "beg001",
9 info: "求《三体》高清资源",
10 beg_count: 5,
11 reward_magic: 100,
12 deadline: "2025-06-10T23:59:59",
13 has_match: 0,
14 },
15 {
16 beg_id: "beg002",
17 info: "求《灌篮高手》国语配音版",
18 beg_count: 3,
19 reward_magic: 50,
20 deadline: "2024-05-01T23:59:59",
21 has_match: 1,
22 },
23 {
24 beg_id: "beg003",
25 info: "求《黑暗之魂3》PC版种子",
26 beg_count: 2,
27 reward_magic: 80,
28 deadline: "2024-04-01T23:59:59",
29 has_match: 0,
30 },
31];
32
33export default function BegSeedPage() {
34 const navigate = useNavigate();
35 const now = new Date();
36 const [begSeedList, setBegSeedList] = useState(initialBegSeedList);
37 const [showForm, setShowForm] = useState(false);
38 const [formData, setFormData] = useState({
39 info: "",
40 reward_magic: "",
41 deadline: "",
42 });
43
44 // 表单输入处理
45 const handleFormChange = (e) => {
46 const { name, value } = e.target;
47 setFormData((prev) => ({
48 ...prev,
49 [name]: value,
50 }));
51 };
52
53 // 提交新求种任务
54 const handleSubmit = (e) => {
55 e.preventDefault();
56 const newBegId = "beg" + Math.floor(Math.random() * 10000);
57 setBegSeedList([
58 {
59 beg_id: newBegId,
60 info: formData.info,
61 beg_count: 1,
62 reward_magic: Number(formData.reward_magic),
63 deadline: formData.deadline,
64 has_match: 0,
65 },
66 ...begSeedList,
67 ]);
68 setShowForm(false);
69 setFormData({ info: "", reward_magic: "", deadline: "" });
70 alert("发布成功(前端演示)");
71 };
72
73 return (
74 <div className="container">
75 <h1 style={{ margin: "24px 0 32px 0", color: "#1976d2" }}>
76 <HelpIcon style={{ verticalAlign: "middle", marginRight: 8 }} />
77 求种列表
78 </h1>
79 <div style={{ margin: "0 0 32px 0", textAlign: "center" }}>
80 <button
81 onClick={() => setShowForm(true)}
82 style={{
83 fontSize: 18,
84 padding: "12px 36px",
85 background: "linear-gradient(90deg, #42a5f5 0%, #1976d2 100%)",
86 color: "#fff",
87 border: "none",
88 borderRadius: 8,
89 fontWeight: 600,
90 boxShadow: "0 2px 8px #b2d8ea",
91 cursor: "pointer",
92 transition: "background 0.2s",
93 }}
94 >
95 发布求种任务
96 </button>
97 </div>
98 {showForm && (
99 <div
100 style={{
101 background: "#fff",
102 border: "1.5px solid #b2d8ea",
103 borderRadius: 12,
104 padding: 24,
105 maxWidth: 480,
106 margin: "0 auto 32px auto",
107 boxShadow: "0 2px 8px #e0e7ff",
108 }}
109 >
110 <h3 style={{ color: "#1976d2", marginBottom: 18 }}>发布求种任务</h3>
111 <form onSubmit={handleSubmit}>
112 <div style={{ marginBottom: 16 }}>
113 <label style={{ display: "inline-block", width: 80 }}>求种信息:</label>
114 <input
115 type="text"
116 name="info"
117 value={formData.info}
118 onChange={handleFormChange}
119 required
120 style={{
121 padding: "6px 12px",
122 borderRadius: 6,
123 border: "1px solid #b2d8ea",
124 width: 260,
125 }}
126 />
127 </div>
128 <div style={{ marginBottom: 16 }}>
129 <label style={{ display: "inline-block", width: 80 }}>悬赏魔力值:</label>
130 <input
131 type="number"
132 name="reward_magic"
133 value={formData.reward_magic}
134 onChange={handleFormChange}
135 required
136 min={1}
137 style={{
138 padding: "6px 12px",
139 borderRadius: 6,
140 border: "1px solid #b2d8ea",
141 width: 120,
142 }}
143 />
144 </div>
145 <div style={{ marginBottom: 16 }}>
146 <label style={{ display: "inline-block", width: 80 }}>截止日期:</label>
147 <input
148 type="datetime-local"
149 name="deadline"
150 value={formData.deadline}
151 onChange={handleFormChange}
152 required
153 style={{
154 padding: "6px 12px",
155 borderRadius: 6,
156 border: "1px solid #b2d8ea",
157 width: 200,
158 }}
159 />
160 </div>
161 <div style={{ marginTop: 18 }}>
162 <button
163 type="submit"
164 style={{
165 background: "#1976d2",
166 color: "#fff",
167 border: "none",
168 borderRadius: 6,
169 padding: "8px 28px",
170 fontWeight: 500,
171 fontSize: 16,
172 marginRight: 18,
173 cursor: "pointer",
174 }}
175 >
176 提交
177 </button>
178 <button
179 type="button"
180 onClick={() => setShowForm(false)}
181 style={{
182 background: "#b0b0b0",
183 color: "#fff",
184 border: "none",
185 borderRadius: 6,
186 padding: "8px 28px",
187 fontWeight: 500,
188 fontSize: 16,
189 cursor: "pointer",
190 }}
191 >
192 取消
193 </button>
194 </div>
195 </form>
196 </div>
197 )}
198 <div style={{ display: "flex", flexWrap: "wrap", gap: 24 }}>
199 {begSeedList.map((beg) => {
200 const isExpired =
201 new Date(beg.deadline) < now || beg.has_match === 1;
202 return (
203 <div
204 key={beg.beg_id}
205 style={{
206 background: isExpired ? "#f0f0f0" : "#e3f7e7",
207 color: isExpired ? "#b0b0b0" : "#222",
208 border: "1.5px solid #b2d8ea",
209 borderRadius: 12,
210 padding: 18,
211 minWidth: 320,
212 maxWidth: 420,
213 boxShadow: "0 2px 8px #e0e7ff",
214 opacity: isExpired ? 0.6 : 1,
215 cursor: "pointer",
216 marginBottom: 12,
217 transition: "box-shadow 0.2s",
218 }}
219 onClick={() => navigate(`/begseed/${beg.beg_id}`)}
220 >
221 <div style={{ fontWeight: 600, fontSize: 18, marginBottom: 8 }}>
222 {beg.info}
223 </div>
224 <div>求种人数:{beg.beg_count}</div>
225 <div>悬赏魔力值:{beg.reward_magic}</div>
226 <div>
227 截止时间:{new Date(beg.deadline).toLocaleString()}
228 </div>
229 <div>
230 状态:
231 {beg.has_match === 1
232 ? "已完成"
233 : new Date(beg.deadline) < now
234 ? "已过期"
235 : "进行中"}
236 </div>
237 </div>
238 );
239 })}
240 </div>
241 </div>
242 );
243}