blob: 2874495277c6f164ccd51f91e62b36ff787140f8 [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";
4import EmailIcon from "@mui/icons-material/Email";
5import MusicNoteIcon from "@mui/icons-material/MusicNote";
6import EmojiPeopleIcon from "@mui/icons-material/EmojiPeople";
7import 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";
956303669a32fc2c2025-06-02 19:45:53 +080013import "./App.css";
14import { 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 = [
wht338fc032025-06-09 17:16:22 +080018 { label: "首页", icon: <HomeIcon />, path: "/home" },
956303669a32fc2c2025-06-02 19:45:53 +080019 { label: "电影", icon: <MovieIcon />, path: "/movie" },
20 { label: "剧集", icon: <EmailIcon />, path: "/tv" },
21 { label: "音乐", icon: <MusicNoteIcon />, path: "/music" },
22 { label: "动漫", icon: <EmojiPeopleIcon />, path: "/anime" },
23 { label: "游戏", icon: <SportsEsportsIcon />, path: "/game" },
24 { label: "体育", icon: <SportsMartialArtsIcon />, path: "/sport" },
25 { label: "资料", icon: <PersonIcon />, path: "/info" },
2230113338fd3882025-06-06 23:33:57 +080026 { label: "论坛", icon: <ForumIcon />, path: "/forum" },
wht338fc032025-06-09 17:16:22 +080027 { label: "发布", icon: <AccountCircleIcon />, path: "/publish" },
28 { label: "求种", icon: <HelpIcon />, path: "/begseed" },
956303669a32fc2c2025-06-02 19:45:53 +080029];
30
956303669a32fc2c2025-06-02 19:45:53 +080031const areaTabs = [
32 { label: "篮球", icon: <MovieIcon fontSize="small" /> },
33 { label: "足球", icon: <EmailIcon fontSize="small" /> },
34 { label: "羽毛球", icon: <EmojiPeopleIcon fontSize="small" /> },
35 { label: "排球", icon: <PersonIcon fontSize="small" /> },
wht338fc032025-06-09 17:16:22 +080036 { label: "电竞", icon: <PersonIcon fontSize="small" /> },
9563036699e95ae32025-06-02 21:42:11 +080037];
38
956303669a32fc2c2025-06-02 19:45:53 +080039export default function SportPage() {
40 const navigate = useNavigate();
wht338fc032025-06-09 17:16:22 +080041 const [searchText, setSearchText] = useState('');
42 const [userInfo, setUserInfo] = useState({ avatar_url: '', username: '' });
43 const [userPT, setUserPT] = useState({ magic: 0, ratio: 0, upload: 0, download: 0 });
44 const [activeTab, setActiveTab] = useState(0);
45 const [sportList, setSportList] = useState([]);
956303669a32fc2c2025-06-02 19:45:53 +080046
wht338fc032025-06-09 17:16:22 +080047 useEffect(() => {
48 const match = document.cookie.match('(^|;)\\s*userId=([^;]+)');
49 const userId = match ? match[2] : null;
50 if (!userId) return;
51 fetch(`${API_BASE_URL}/api/get-userpt?userid=${encodeURIComponent(userId)}`)
52 .then(res => res.json())
53 .then(data => {
54 setUserInfo({ avatar_url: data.user.avatar_url, username: data.user.username });
55 setUserPT({
56 magic: data.magic_value || data.magic || 0,
57 ratio: data.share_ratio || data.share || 0,
58 upload: data.upload_amount || data.upload || 0,
59 download: data.download_amount || data.download || 0,
60 });
61 })
62 .catch(err => console.error('Fetching user profile failed', err));
63 }, []);
223011339e292152025-06-08 00:34:37 +080064
wht338fc032025-06-09 17:16:22 +080065 // 每个tab对应的体育类型
956303669a32fc2c2025-06-02 19:45:53 +080066 const sportTypesList = [
67 ["篮球赛事", "篮球技巧", "篮球明星"], // 篮球
68 ["足球赛事", "足球技巧", "足球明星"], // 足球
69 ["羽毛球赛事", "羽毛球技巧"], // 羽毛球
70 ["排球赛事", "排球技巧"], // 排球
71 ["电竞赛事", "电竞技巧"], // 电竞
wht338fc032025-06-09 17:16:22 +080072 ["其他类型1", "其他类型2"] // 其他
956303669a32fc2c2025-06-02 19:45:53 +080073 ];
74 const sportTypes = sportTypesList[activeTab] || [];
75
wht338fc032025-06-09 17:16:22 +080076 useEffect(() => {
rhjc6a4ee02025-06-06 00:45:18 +080077 const area = areaTabs[activeTab].label;
223011330f9623f2025-06-06 00:22:05 +080078 fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
rhjc6a4ee02025-06-06 00:45:18 +080079 .then(res => res.json())
80 .then(data => setSportList(data))
81 .catch(() => setSportList([]));
82 }, [activeTab]);
83
wht338fc032025-06-09 17:16:22 +080084 // 搜索按钮处理
85 const handleSearch = () => {
86 const area = areaTabs[activeTab].label;
87 fetch(`${API_BASE_URL}/api/search-seeds?tag=${encodeURIComponent(area)}&keyword=${encodeURIComponent(searchText)}`)
88 .then(res => res.json())
89 .then(data => {
90 setSportList(data);
91 })
92 .catch(() => setSportList([]));
93 };
223011339e292152025-06-08 00:34:37 +080094
956303669a32fc2c2025-06-02 19:45:53 +080095 return (
96 <div className="container">
wht338fc032025-06-09 17:16:22 +080097 {/* 顶部空白与体育界面一致,用户栏绝对定位在页面右上角 */}
956303669a32fc2c2025-06-02 19:45:53 +080098 <div style={{ height: 80 }} />
223011339e292152025-06-08 00:34:37 +080099 <div className="user-bar" style={{ position: 'fixed', top: 18, right: 42, zIndex: 100, display: 'flex', alignItems: 'center', background: '#e0f3ff', borderRadius: 12, padding: '6px 18px', boxShadow: '0 2px 8px #b2d8ea', minWidth: 320, minHeight: 48, width: 420 }}>
100 <div style={{ cursor: 'pointer', marginRight: 16 }} onClick={() => navigate('/user')}>
101 {userInfo.avatar_url ? (
102 <img src={userInfo.avatar_url} alt="用户头像" style={{ width: 38, height: 38, borderRadius: '50%', objectFit: 'cover' }} />
103 ) : (
104 <AccountCircleIcon style={{ fontSize: 38, color: '#1a237e', background: '#e0f3ff', borderRadius: '50%' }} />
105 )}
956303669a32fc2c2025-06-02 19:45:53 +0800106 </div>
223011339e292152025-06-08 00:34:37 +0800107 <div style={{ color: '#222', fontWeight: 500, marginRight: 24 }}>{userInfo.username || '用户栏'}</div>
108 <div style={{ display: 'flex', gap: 28, flex: 1, justifyContent: 'flex-end', alignItems: 'center' }}>
109 <span style={{ color: '#1976d2', fontWeight: 500 }}>魔力值: <b>{userPT.magic}</b></span>
110 <span style={{ color: '#1976d2', fontWeight: 500 }}>分享率: <b>{userPT.ratio}</b></span>
111 <span style={{ color: '#1976d2', fontWeight: 500 }}>上传量: <b>{userPT.upload}</b></span>
112 <span style={{ color: '#1976d2', fontWeight: 500 }}>下载量: <b>{userPT.download}</b></span>
956303669a32fc2c2025-06-02 19:45:53 +0800113 </div>
114 </div>
wht338fc032025-06-09 17:16:22 +0800115 {/* 下方内容整体下移,留出与体育界面一致的间距 */}
956303669a32fc2c2025-06-02 19:45:53 +0800116 <div style={{ height: 32 }} />
117 <nav className="nav-bar card">
118 {navItems.map((item) => (
119 <div
120 key={item.label}
121 className={item.label === "体育" ? "nav-item active" : "nav-item"}
122 onClick={() => navigate(item.path)}
123 >
124 {item.icon}
125 <span>{item.label}</span>
126 </div>
127 ))}
128 </nav>
129 <div className="search-section card">
223011339e292152025-06-08 00:34:37 +0800130 <input
131 className="search-input"
132 placeholder="输入搜索关键词"
133 value={searchText}
134 onChange={e => setSearchText(e.target.value)}
135 />
136 <button className="search-btn" onClick={handleSearch}>
137 <span role="img" aria-label="search">🔍</span>
956303669a32fc2c2025-06-02 19:45:53 +0800138 </button>
139 </div>
wht338fc032025-06-09 17:16:22 +0800140 <div className="area-tabs" style={{ display: 'flex', justifyContent: 'center', gap: 24, margin: '18px 0' }}>
956303669a32fc2c2025-06-02 19:45:53 +0800141 {areaTabs.map((tab, idx) => (
142 <div
143 key={tab.label}
144 className={activeTab === idx ? "area-tab active" : "area-tab"}
145 onClick={() => setActiveTab(idx)}
146 >
147 {tab.icon} <span>{tab.label}</span>
148 </div>
149 ))}
150 </div>
151 <div className="table-section">
9563036699e95ae32025-06-02 21:42:11 +0800152 <table className="sport-table">
956303669a32fc2c2025-06-02 19:45:53 +0800153 <thead>
154 <tr>
9563036699e95ae32025-06-02 21:42:11 +0800155 <th>体育类型</th>
956303669a32fc2c2025-06-02 19:45:53 +0800156 <th>标题</th>
157 <th>发布者</th>
wht338fc032025-06-09 17:16:22 +0800158 <th>大小</th>
159 <th>热度</th>
160 <th>折扣倍率</th>
956303669a32fc2c2025-06-02 19:45:53 +0800161 </tr>
162 </thead>
163 <tbody>
rhjc6a4ee02025-06-06 00:45:18 +0800164 {sportList.length > 0 ? (
165 sportList.map((item, index) => (
166 <tr key={item.id || index}>
167 <td>
168 <a href={`/torrent/${item.seedid}`} style={{ color: "#1a237e", textDecoration: "none" }}>
169 {item.seedtag}
170 </a>
171 </td>
172 <td>
173 <a href={`/torrent/${item.seedid}`} style={{ color: "#1a237e", textDecoration: "none" }}>
174 {item.title}
175 </a>
176 </td>
wht338fc032025-06-09 17:16:22 +0800177 <td>{item.username}</td>
178 <td>{item.seedsize}</td>
179 <td>{item.downloadtimes}</td>
180 <td>{item.discount == null ? 1 : item.discount}</td>
rhjc6a4ee02025-06-06 00:45:18 +0800181 </tr>
182 ))
183 ) : (
184 sportTypes.map((type, index) => (
185 <tr key={type}>
186 <td>
187 <a href={`/torrent/${type}`} style={{ color: "#1a237e", textDecoration: "none" }}>
188 {type}
189 </a>
190 </td>
191 <td>
192 <a href={`/torrent/${type}`} style={{ color: "#1a237e", textDecoration: "none" }}>
193 种子{index + 1}
194 </a>
195 </td>
196 <td>发布者{index + 1}</td>
wht338fc032025-06-09 17:16:22 +0800197 <td>--</td>
198 <td>--</td>
199 <td>1</td>
rhjc6a4ee02025-06-06 00:45:18 +0800200 </tr>
201 ))
202 )}
956303669a32fc2c2025-06-02 19:45:53 +0800203 </tbody>
204 </table>
205 </div>
206 <div style={{ height: 32 }} />
207 <Pagination />
208 </div>
209 );
210}
211
212function Pagination() {
213 const [page, setPage] = React.useState(3);
214 const total = 5;
215 return (
216 <div className="pagination">
wht338fc032025-06-09 17:16:22 +0800217 <button onClick={() => setPage(p => Math.max(1, p - 1))} disabled={page === 1}>上一页</button>
218 <span className="page-num">{page}/{total}</span>
219 <button onClick={() => setPage(p => Math.min(total, p + 1))} disabled={page === total}>下一页</button>
220 <span className="page-info">第 <b>{page}</b> 页</span>
956303669a32fc2c2025-06-02 19:45:53 +0800221 </div>
222 );
wht338fc032025-06-09 17:16:22 +0800223}