wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 1 | import React, { useState, useEffect } from "react";
|
| 2 | import HomeIcon from "@mui/icons-material/Home";
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 3 | import MovieIcon from "@mui/icons-material/Movie";
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 4 | import TvIcon from "@mui/icons-material/Tv";
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 5 | import MusicNoteIcon from "@mui/icons-material/MusicNote";
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 6 | import AnimationIcon from "@mui/icons-material/Animation";
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 7 | import SportsEsportsIcon from "@mui/icons-material/SportsEsports";
|
| 8 | import SportsMartialArtsIcon from "@mui/icons-material/SportsMartialArts";
|
| 9 | import PersonIcon from "@mui/icons-material/Person";
|
| 10 | import AccountCircleIcon from "@mui/icons-material/AccountCircle";
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 11 | import ForumIcon from "@mui/icons-material/Forum";
|
| 12 | import HelpIcon from "@mui/icons-material/Help";
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 13 | import "./SharedStyles.css";
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 14 | import { useNavigate } from "react-router-dom";
|
22301133 | 0f9623f | 2025-06-06 00:22:05 +0800 | [diff] [blame] | 15 | import { API_BASE_URL } from "./config";
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 16 |
|
| 17 | const navItems = [
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 18 | { 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" },
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 29 | ];
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 30 |
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 31 | // 游戏平台标签
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 32 | const areaTabs = [
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 33 | { label: "PC游戏", value: "pc" },
|
| 34 | { label: "主机游戏", value: "console" },
|
| 35 | { label: "移动游戏", value: "mobile" },
|
| 36 | { label: "掌机游戏", value: "handheld" },
|
| 37 | { label: "游戏视频", value: "video" }
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 38 | ];
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 39 | export default function GamePage() {
|
| 40 | const navigate = useNavigate();
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 41 | 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 });
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 44 | const [activeTab, setActiveTab] = useState(0);
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 45 | const [gameList, setGameList] = useState([]);
|
| 46 |
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 47 | 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 | }, []);
|
| 64 |
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 65 | useEffect(() => {
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 66 | // 根据选中的标签获取游戏列表
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 67 | const area = areaTabs[activeTab].label;
|
22301133 | 0f9623f | 2025-06-06 00:22:05 +0800 | [diff] [blame] | 68 | fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 69 | .then(res => res.json())
|
| 70 | .then(data => setGameList(data))
|
| 71 | .catch(() => setGameList([]));
|
| 72 | }, [activeTab]);
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 73 |
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 74 | // 搜索按钮处理
|
| 75 | const handleSearch = () => {
|
| 76 | const area = areaTabs[activeTab].label;
|
| 77 | fetch(`${API_BASE_URL}/api/search-seeds?tag=${encodeURIComponent(area)}&keyword=${encodeURIComponent(searchText)}`)
|
| 78 | .then(res => res.json())
|
| 79 | .then(data => {
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 80 | console.log('搜索返回数据:', data);
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 81 | setGameList(data);
|
| 82 | })
|
| 83 | .catch(() => setGameList([]));
|
| 84 | };
|
| 85 |
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 86 | const gameTypesList = [
|
| 87 | ["PC单机", "PC网络", "PC独立", "PC其他"], // PC游戏
|
| 88 | ["主机动作", "主机RPG", "主机竞速", "主机其他"], // 主机游戏
|
| 89 | ["移动休闲", "移动竞技", "移动策略", "移动其他"], // 移动游戏
|
| 90 | ["掌机冒险", "掌机RPG", "掌机其他"], // 掌机游戏
|
| 91 | ["游戏实况", "赛事视频", "攻略教学", "其他视频"] // 游戏视频
|
| 92 | ];
|
| 93 | const gameTypes = gameTypesList[activeTab] || [];
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 94 | return (
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 95 | <div className="emerald-home-container">
|
| 96 | {/* 流星雨背景效果 */}
|
| 97 | <div className="meteor-shower">
|
| 98 | <div className="meteor">💫</div>
|
| 99 | <div className="meteor">⭐</div>
|
| 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>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 108 | </div>
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 109 |
|
| 110 | {/* 浮动园林装饰元素 */}
|
| 111 | <div className="floating-garden-elements">
|
| 112 | <div className="garden-element">🌿</div>
|
| 113 | <div className="garden-element">🦋</div>
|
| 114 | <div className="garden-element">🌺</div>
|
| 115 | <div className="garden-element">🌸</div>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 116 | </div>
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 117 |
|
| 118 | <div className="emerald-content">
|
| 119 | {/* NeuraFlux用户栏 */}
|
| 120 | <div className="emerald-user-bar">
|
| 121 | <div className="emerald-user-avatar" onClick={() => navigate('/user')}>
|
| 122 | {userInfo.avatar_url ? (
|
| 123 | <img src={userInfo.avatar_url} alt="用户头像" style={{ width: 38, height: 38, borderRadius: '50%', objectFit: 'cover' }} />
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 124 | ) : (
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 125 | <AccountCircleIcon style={{ fontSize: 38, color: 'white' }} />
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 126 | )}
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 127 | </div>
|
| 128 | <div className="emerald-brand-section">
|
| 129 | <div className="emerald-brand-icon">⚡</div>
|
| 130 | <div className="emerald-user-label">NeuraFlux</div>
|
| 131 | </div>
|
| 132 | <div className="emerald-user-stats">
|
| 133 | <span className="emerald-stat-item">
|
| 134 | 魔力值: <span className="emerald-stat-value">{userPT.magic}</span>
|
| 135 | </span>
|
| 136 | <span className="emerald-stat-item">
|
| 137 | 分享率: <span className="emerald-stat-value">{userPT.ratio}</span>
|
| 138 | </span>
|
| 139 | <span className="emerald-stat-item">
|
| 140 | 上传: <span className="emerald-stat-value">{userPT.upload}GB</span>
|
| 141 | </span>
|
| 142 | <span className="emerald-stat-item">
|
| 143 | 下载: <span className="emerald-stat-value">{userPT.download}GB</span>
|
| 144 | </span>
|
| 145 | </div>
|
| 146 | </div>
|
| 147 |
|
| 148 | {/* NeuraFlux导航栏 */}
|
| 149 | <nav className="emerald-nav-bar">
|
| 150 | {navItems.map((item) => (
|
| 151 | <div
|
| 152 | key={item.label}
|
| 153 | className={`emerald-nav-item ${item.label === "游戏" ? "active" : ""}`}
|
| 154 | data-type={item.type}
|
| 155 | onClick={() => navigate(item.path)}
|
| 156 | >
|
| 157 | {item.icon}
|
| 158 | <span className="emerald-nav-label">{item.label}</span>
|
| 159 | </div>
|
| 160 | ))}
|
| 161 | </nav>
|
| 162 |
|
| 163 | {/* 游戏内容区域 */}
|
| 164 | <div className="emerald-content-section">
|
| 165 | <h1 className="emerald-page-title">🎮 游戏资源</h1>
|
| 166 | <p style={{ textAlign: 'center', color: '#2d5016', fontSize: '18px', marginBottom: '30px' }}>
|
| 167 | 欢迎来到NeuraFlux游戏频道,这里有最新最热门的游戏资源
|
| 168 | </p>
|
| 169 |
|
| 170 | {/* 搜索栏 */}
|
| 171 | <div style={{
|
| 172 | display: 'flex',
|
| 173 | justifyContent: 'center',
|
| 174 | marginBottom: '30px',
|
| 175 | gap: '15px'
|
| 176 | }}>
|
| 177 | <input
|
| 178 | type="text"
|
| 179 | placeholder="搜索游戏资源..."
|
| 180 | value={searchText}
|
| 181 | onChange={(e) => setSearchText(e.target.value)}
|
| 182 | style={{
|
| 183 | padding: '12px 20px',
|
| 184 | borderRadius: '20px',
|
| 185 | border: '2px solid rgba(144, 238, 144, 0.3)',
|
| 186 | background: 'rgba(240, 255, 240, 0.5)',
|
| 187 | fontSize: '16px',
|
| 188 | width: '300px',
|
| 189 | fontFamily: 'Lora, serif'
|
| 190 | }}
|
| 191 | />
|
| 192 | <button
|
| 193 | onClick={handleSearch}
|
| 194 | style={{
|
| 195 | padding: '12px 24px',
|
| 196 | borderRadius: '20px',
|
| 197 | border: 'none',
|
| 198 | background: 'linear-gradient(135deg, #2d5016 0%, #90ee90 100%)',
|
| 199 | color: 'white',
|
| 200 | fontSize: '16px',
|
| 201 | cursor: 'pointer',
|
| 202 | fontFamily: 'Lora, serif'
|
| 203 | }}
|
| 204 | >
|
| 205 | 搜索
|
| 206 | </button>
|
| 207 | </div>
|
| 208 |
|
| 209 | {/* 平台分类标签 */}
|
| 210 | <div style={{
|
| 211 | display: 'flex',
|
| 212 | justifyContent: 'center',
|
| 213 | marginBottom: '30px',
|
| 214 | gap: '15px',
|
| 215 | flexWrap: 'wrap'
|
| 216 | }}>
|
| 217 | {areaTabs.map((tab, index) => (
|
| 218 | <button
|
| 219 | key={tab.value}
|
| 220 | onClick={() => setActiveTab(index)}
|
| 221 | style={{
|
| 222 | padding: '10px 20px',
|
| 223 | borderRadius: '15px',
|
| 224 | border: '2px solid rgba(144, 238, 144, 0.3)',
|
| 225 | background: activeTab === index
|
| 226 | ? 'linear-gradient(135deg, #90ee90 0%, #2d5016 100%)'
|
| 227 | : 'rgba(240, 255, 240, 0.3)',
|
| 228 | color: activeTab === index ? 'white' : '#2d5016',
|
| 229 | fontSize: '14px',
|
| 230 | cursor: 'pointer',
|
| 231 | fontFamily: 'Lora, serif',
|
| 232 | transition: 'all 0.3s ease'
|
| 233 | }}
|
| 234 | >
|
| 235 | {tab.label}
|
| 236 | </button>
|
| 237 | ))}
|
| 238 | </div>
|
| 239 |
|
| 240 | {/* 游戏列表 */}
|
| 241 | <div className="emerald-table-section">
|
| 242 | <table className="emerald-table">
|
| 243 | <thead>
|
| 244 | <tr>
|
| 245 | <th>游戏类型</th>
|
| 246 | <th>标题</th>
|
| 247 | <th>发布者</th>
|
| 248 | <th>大小</th>
|
| 249 | <th>热度</th>
|
| 250 | <th>折扣倍率</th>
|
| 251 | </tr>
|
| 252 | </thead>
|
| 253 | <tbody>
|
| 254 | {gameList.length > 0 ? (
|
| 255 | gameList.map((item, index) => (
|
| 256 | <tr key={item.id || index}>
|
| 257 | <td>{item.seedtag}</td>
|
| 258 | <td>
|
| 259 | <a href={`/torrent/${item.seedid}`}>
|
| 260 | {item.title}
|
| 261 | </a>
|
| 262 | </td>
|
| 263 | <td>{item.username}</td>
|
| 264 | <td>{item.seedsize}</td>
|
| 265 | <td>{item.downloadtimes}</td>
|
| 266 | <td>{item.discount == null ? 1 : item.discount}</td>
|
| 267 | </tr>
|
| 268 | ))
|
| 269 | ) : (
|
| 270 | gameTypes.map((type, index) => (
|
| 271 | <tr key={type}>
|
| 272 | <td>{type}</td>
|
| 273 | <td>
|
| 274 | <a href={`/torrent/${type}`}>
|
| 275 | 种子{index + 1}
|
| 276 | </a>
|
| 277 | </td>
|
| 278 | <td>发布者{index + 1}</td>
|
| 279 | <td>--</td>
|
| 280 | <td>--</td>
|
| 281 | <td>1</td>
|
| 282 | </tr>
|
| 283 | ))
|
| 284 | )}
|
| 285 | </tbody>
|
| 286 | </table>
|
| 287 | </div>
|
| 288 | </div>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 289 | </div>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 290 | </div>
|
| 291 | );
|
| 292 | }
|
| 293 |
|
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 294 | // Pagination组件暂时不使用
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 295 | function Pagination() {
|
| 296 | const [page, setPage] = React.useState(3);
|
| 297 | const total = 5;
|
| 298 | return (
|
| 299 | <div className="pagination">
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 300 | <button onClick={() => setPage(p => Math.max(1, p - 1))} disabled={page === 1}>上一页</button>
|
| 301 | <span className="page-num">{page}/{total}</span>
|
| 302 | <button onClick={() => setPage(p => Math.min(total, p + 1))} disabled={page === total}>下一页</button>
|
| 303 | <span className="page-info">第 <b>{page}</b> 页</span>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 304 | </div>
|
| 305 | );
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 306 | } |