blob: 6fed422287e37fd21bf5d7e361bfa0af3a0469fc [file] [log] [blame]
223011339e292152025-06-08 00:34:37 +08001import React, { useState, useEffect } from "react";
wht338fc032025-06-09 17:16:22 +08002import HomeIcon from "@mui/icons-material/Home";
956303669a32fc2c2025-06-02 19:45:53 +08003import MovieIcon from "@mui/icons-material/Movie";
TRM-codingfa3ffdf2025-06-09 22:47:42 +08004import TvIcon from "@mui/icons-material/Tv";
956303669a32fc2c2025-06-02 19:45:53 +08005import MusicNoteIcon from "@mui/icons-material/MusicNote";
TRM-codingfa3ffdf2025-06-09 22:47:42 +08006import AnimationIcon from "@mui/icons-material/Animation";
956303669a32fc2c2025-06-02 19:45:53 +08007import SportsEsportsIcon from "@mui/icons-material/SportsEsports";
8import SportsMartialArtsIcon from "@mui/icons-material/SportsMartialArts";
9import PersonIcon from "@mui/icons-material/Person";
10import AccountCircleIcon from "@mui/icons-material/AccountCircle";
wht338fc032025-06-09 17:16:22 +080011import ForumIcon from "@mui/icons-material/Forum";
12import HelpIcon from "@mui/icons-material/Help";
TRM-codingfa3ffdf2025-06-09 22:47:42 +080013import "./SharedStyles.css";
956303669a32fc2c2025-06-02 19:45:53 +080014import { useNavigate } from "react-router-dom";
223011330f9623f2025-06-06 00:22:05 +080015import { API_BASE_URL } from "./config";
956303669a32fc2c2025-06-02 19:45:53 +080016
17const navItems = [
TRM-codingfa3ffdf2025-06-09 22:47:42 +080018 { label: "首页", icon: <HomeIcon className="emerald-nav-icon" />, path: "/home", type: "home" },
19 { label: "电影", icon: <MovieIcon className="emerald-nav-icon" />, path: "/movie", type: "movie" },
20 { label: "剧集", icon: <TvIcon className="emerald-nav-icon" />, path: "/tv", type: "tv" },
21 { label: "音乐", icon: <MusicNoteIcon className="emerald-nav-icon" />, path: "/music", type: "music" },
22 { label: "动漫", icon: <AnimationIcon className="emerald-nav-icon" />, path: "/anime", type: "anime" },
23 { label: "游戏", icon: <SportsEsportsIcon className="emerald-nav-icon" />, path: "/game", type: "game" },
24 { label: "体育", icon: <SportsMartialArtsIcon className="emerald-nav-icon" />, path: "/sport", type: "sport" },
25 { label: "资料", icon: <PersonIcon className="emerald-nav-icon" />, path: "/info", type: "info" },
26 { label: "论坛", icon: <ForumIcon className="emerald-nav-icon" />, path: "/forum", type: "forum" },
27 { label: "发布", icon: <AccountCircleIcon className="emerald-nav-icon" />, path: "/publish", type: "publish" },
28 { label: "求种", icon: <HelpIcon className="emerald-nav-icon" />, path: "/begseed", type: "help" },
956303669a32fc2c2025-06-02 19:45:53 +080029];
30
TRM-codingfa3ffdf2025-06-09 22:47:42 +080031// 体育地区标签
956303669a32fc2c2025-06-02 19:45:53 +080032const areaTabs = [
TRM-codingfa3ffdf2025-06-09 22:47:42 +080033 { label: "篮球", value: "basketball" },
34 { label: "足球", value: "football" },
35 { label: "羽毛球", value: "badminton" },
36 { label: "排球", value: "volleyball" },
37 { label: "电竞", value: "esports" }
9563036699e95ae32025-06-02 21:42:11 +080038];
39
956303669a32fc2c2025-06-02 19:45:53 +080040export default function SportPage() {
41 const navigate = useNavigate();
wht338fc032025-06-09 17:16:22 +080042 const [searchText, setSearchText] = useState('');
43 const [userInfo, setUserInfo] = useState({ avatar_url: '', username: '' });
44 const [userPT, setUserPT] = useState({ magic: 0, ratio: 0, upload: 0, download: 0 });
45 const [activeTab, setActiveTab] = useState(0);
46 const [sportList, setSportList] = useState([]);
956303669a32fc2c2025-06-02 19:45:53 +080047
wht338fc032025-06-09 17:16:22 +080048 useEffect(() => {
49 const match = document.cookie.match('(^|;)\\s*userId=([^;]+)');
50 const userId = match ? match[2] : null;
51 if (!userId) return;
52 fetch(`${API_BASE_URL}/api/get-userpt?userid=${encodeURIComponent(userId)}`)
53 .then(res => res.json())
54 .then(data => {
55 setUserInfo({ avatar_url: data.user.avatar_url, username: data.user.username });
56 setUserPT({
57 magic: data.magic_value || data.magic || 0,
58 ratio: data.share_ratio || data.share || 0,
59 upload: data.upload_amount || data.upload || 0,
60 download: data.download_amount || data.download || 0,
61 });
62 })
63 .catch(err => console.error('Fetching user profile failed', err));
64 }, []);
223011339e292152025-06-08 00:34:37 +080065
wht338fc032025-06-09 17:16:22 +080066 // 每个tab对应的体育类型
956303669a32fc2c2025-06-02 19:45:53 +080067 const sportTypesList = [
68 ["篮球赛事", "篮球技巧", "篮球明星"], // 篮球
69 ["足球赛事", "足球技巧", "足球明星"], // 足球
70 ["羽毛球赛事", "羽毛球技巧"], // 羽毛球
71 ["排球赛事", "排球技巧"], // 排球
72 ["电竞赛事", "电竞技巧"], // 电竞
wht338fc032025-06-09 17:16:22 +080073 ["其他类型1", "其他类型2"] // 其他
956303669a32fc2c2025-06-02 19:45:53 +080074 ];
75 const sportTypes = sportTypesList[activeTab] || [];
wht338fc032025-06-09 17:16:22 +080076 useEffect(() => {
TRM-codingfa3ffdf2025-06-09 22:47:42 +080077 // 根据选中的标签获取体育列表
rhjc6a4ee02025-06-06 00:45:18 +080078 const area = areaTabs[activeTab].label;
223011330f9623f2025-06-06 00:22:05 +080079 fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
rhjc6a4ee02025-06-06 00:45:18 +080080 .then(res => res.json())
81 .then(data => setSportList(data))
82 .catch(() => setSportList([]));
83 }, [activeTab]);
84
wht338fc032025-06-09 17:16:22 +080085 // 搜索按钮处理
86 const handleSearch = () => {
87 const area = areaTabs[activeTab].label;
88 fetch(`${API_BASE_URL}/api/search-seeds?tag=${encodeURIComponent(area)}&keyword=${encodeURIComponent(searchText)}`)
89 .then(res => res.json())
90 .then(data => {
TRM-codingfa3ffdf2025-06-09 22:47:42 +080091 console.log('搜索返回数据:', data);
wht338fc032025-06-09 17:16:22 +080092 setSportList(data);
93 })
94 .catch(() => setSportList([]));
95 };
956303669a32fc2c2025-06-02 19:45:53 +080096 return (
TRM-codingfa3ffdf2025-06-09 22:47:42 +080097 <div className="emerald-home-container">
98 {/* 流星雨背景效果 */}
99 <div className="meteor-shower">
100 <div className="meteor">💫</div>
101 <div className="meteor">⭐</div>
102 <div className="meteor">✨</div>
103 <div className="meteor">🌟</div>
104 <div className="meteor">💫</div>
105 <div className="meteor">⭐</div>
106 <div className="meteor">✨</div>
107 <div className="meteor">🌟</div>
108 <div className="meteor">💫</div>
109 <div className="meteor">⭐</div>
956303669a32fc2c2025-06-02 19:45:53 +0800110 </div>
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800111
112 {/* 浮动园林装饰元素 */}
113 <div className="floating-garden-elements">
114 <div className="garden-element">🌿</div>
115 <div className="garden-element">🦋</div>
116 <div className="garden-element">🌺</div>
117 <div className="garden-element">🌸</div>
956303669a32fc2c2025-06-02 19:45:53 +0800118 </div>
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800119
120 <div className="emerald-content">
121 {/* NeuraFlux用户栏 */}
122 <div className="emerald-user-bar">
123 <div className="emerald-user-avatar" onClick={() => navigate('/user')}>
124 {userInfo.avatar_url ? (
125 <img src={userInfo.avatar_url} alt="用户头像" style={{ width: 38, height: 38, borderRadius: '50%', objectFit: 'cover' }} />
rhjc6a4ee02025-06-06 00:45:18 +0800126 ) : (
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800127 <AccountCircleIcon style={{ fontSize: 38, color: 'white' }} />
rhjc6a4ee02025-06-06 00:45:18 +0800128 )}
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800129 </div>
130 <div className="emerald-brand-section">
131 <div className="emerald-brand-icon">⚡</div>
132 <div className="emerald-user-label">NeuraFlux</div>
133 </div>
134 <div className="emerald-user-stats">
135 <span className="emerald-stat-item">
136 魔力值: <span className="emerald-stat-value">{userPT.magic}</span>
137 </span>
138 <span className="emerald-stat-item">
139 分享率: <span className="emerald-stat-value">{userPT.ratio}</span>
140 </span>
141 <span className="emerald-stat-item">
142 上传: <span className="emerald-stat-value">{userPT.upload}GB</span>
143 </span>
144 <span className="emerald-stat-item">
145 下载: <span className="emerald-stat-value">{userPT.download}GB</span>
146 </span>
147 </div>
148 </div>
149
150 {/* NeuraFlux导航栏 */}
151 <nav className="emerald-nav-bar">
152 {navItems.map((item) => (
153 <div
154 key={item.label}
155 className={`emerald-nav-item ${item.label === "体育" ? "active" : ""}`}
156 data-type={item.type}
157 onClick={() => navigate(item.path)}
158 >
159 {item.icon}
160 <span className="emerald-nav-label">{item.label}</span>
161 </div>
162 ))}
163 </nav>
164
165 {/* 体育内容区域 */}
166 <div className="emerald-content-section">
167 <h1 className="emerald-page-title">⚽ 体育资源</h1>
168 <p style={{ textAlign: 'center', color: '#2d5016', fontSize: '18px', marginBottom: '30px' }}>
169 欢迎来到NeuraFlux体育频道,这里有最新最热门的体育资源
170 </p>
171
172 {/* 搜索栏 */}
173 <div style={{
174 display: 'flex',
175 justifyContent: 'center',
176 marginBottom: '30px',
177 gap: '15px'
178 }}>
179 <input
180 type="text"
181 placeholder="搜索体育资源..."
182 value={searchText}
183 onChange={(e) => setSearchText(e.target.value)}
184 style={{
185 padding: '12px 20px',
186 borderRadius: '20px',
187 border: '2px solid rgba(144, 238, 144, 0.3)',
188 background: 'rgba(240, 255, 240, 0.5)',
189 fontSize: '16px',
190 width: '300px',
191 fontFamily: 'Lora, serif'
192 }}
193 />
194 <button
195 onClick={handleSearch}
196 style={{
197 padding: '12px 24px',
198 borderRadius: '20px',
199 border: 'none',
200 background: 'linear-gradient(135deg, #2d5016 0%, #90ee90 100%)',
201 color: 'white',
202 fontSize: '16px',
203 cursor: 'pointer',
204 fontFamily: 'Lora, serif'
205 }}
206 >
207 搜索
208 </button>
209 </div>
210
211 {/* 地区分类标签 */}
212 <div style={{
213 display: 'flex',
214 justifyContent: 'center',
215 marginBottom: '30px',
216 gap: '15px',
217 flexWrap: 'wrap'
218 }}>
219 {areaTabs.map((tab, index) => (
220 <button
221 key={tab.value}
222 onClick={() => setActiveTab(index)}
223 style={{
224 padding: '10px 20px',
225 borderRadius: '15px',
226 border: '2px solid rgba(144, 238, 144, 0.3)',
227 background: activeTab === index
228 ? 'linear-gradient(135deg, #90ee90 0%, #2d5016 100%)'
229 : 'rgba(240, 255, 240, 0.3)',
230 color: activeTab === index ? 'white' : '#2d5016',
231 fontSize: '14px',
232 cursor: 'pointer',
233 fontFamily: 'Lora, serif',
234 transition: 'all 0.3s ease'
235 }}
236 >
237 {tab.label}
238 </button>
239 ))}
240 </div>
241
242 {/* 体育列表 */}
243 <div className="emerald-table-section">
244 <table className="emerald-table">
245 <thead>
246 <tr>
247 <th>体育类型</th>
248 <th>标题</th>
249 <th>发布者</th>
250 <th>大小</th>
251 <th>热度</th>
252 <th>折扣倍率</th>
253 </tr>
254 </thead>
255 <tbody>
256 {sportList.length > 0 ? (
257 sportList.map((item, index) => (
258 <tr key={item.id || index}>
259 <td>{item.seedtag}</td>
260 <td>
261 <a href={`/torrent/${item.seedid}`}>
262 {item.title}
263 </a>
264 </td>
265 <td>{item.username}</td>
266 <td>{item.seedsize}</td>
267 <td>{item.downloadtimes}</td>
268 <td>{item.discount == null ? 1 : item.discount}</td>
269 </tr>
270 ))
271 ) : (
272 sportTypes.map((type, index) => (
273 <tr key={type}>
274 <td>{type}</td>
275 <td>
276 <a href={`/torrent/${type}`}>
277 种子{index + 1}
278 </a>
279 </td>
280 <td>发布者{index + 1}</td>
281 <td>--</td>
282 <td>--</td>
283 <td>1</td>
284 </tr>
285 ))
286 )}
287 </tbody>
288 </table>
289 </div>
290 </div>
956303669a32fc2c2025-06-02 19:45:53 +0800291 </div>
956303669a32fc2c2025-06-02 19:45:53 +0800292 </div>
293 );
294}
295
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800296// Pagination组件暂时不使用
956303669a32fc2c2025-06-02 19:45:53 +0800297function Pagination() {
298 const [page, setPage] = React.useState(3);
299 const total = 5;
300 return (
301 <div className="pagination">
wht338fc032025-06-09 17:16:22 +0800302 <button onClick={() => setPage(p => Math.max(1, p - 1))} disabled={page === 1}>上一页</button>
303 <span className="page-num">{page}/{total}</span>
304 <button onClick={() => setPage(p => Math.min(total, p + 1))} disabled={page === total}>下一页</button>
305 <span className="page-info">第 <b>{page}</b> 页</span>
956303669a32fc2c2025-06-02 19:45:53 +0800306 </div>
307 );
wht338fc032025-06-09 17:16:22 +0800308}