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";
|
| 4 | import EmailIcon from "@mui/icons-material/Email";
|
| 5 | import MusicNoteIcon from "@mui/icons-material/MusicNote";
|
| 6 | import EmojiPeopleIcon from "@mui/icons-material/EmojiPeople";
|
| 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";
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 13 | import "./App.css";
|
| 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 = [
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 18 | { label: "首页", icon: <HomeIcon />, path: "/home" },
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 19 | { 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" },
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 26 | { label: "论坛", icon: <ForumIcon />, path: "/forum" },
|
| 27 | { label: "发布", icon: <AccountCircleIcon />, path: "/publish" },
|
| 28 | { label: "求种", icon: <HelpIcon />, path: "/begseed" },
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 29 | ];
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 30 |
|
| 31 | const areaTabs = [
|
| 32 | { label: "PC", icon: <MovieIcon fontSize="small" /> },
|
| 33 | { label: "主机", icon: <EmailIcon fontSize="small" /> },
|
| 34 | { label: "移动", icon: <PersonIcon fontSize="small" /> },
|
| 35 | { label: "掌机", icon: <EmojiPeopleIcon fontSize="small" /> },
|
| 36 | { label: "视频", icon: <PersonIcon fontSize="small" /> },
|
| 37 | ];
|
| 38 |
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 39 | // 每个tab对应的游戏类型
|
| 40 | const gameTypesList = [
|
| 41 | ["PC单机", "PC网络", "PC独立", "PC其他"], // PC
|
| 42 | ["主机动作", "主机RPG", "主机其他"], // 主机
|
| 43 | ["移动休闲", "移动竞技", "移动其他"], // 移动
|
| 44 | ["掌机冒险", "掌机其他"], // 掌机
|
| 45 | ["游戏视频", "赛事视频", "其他视频"], // 视频
|
| 46 | ["其他类型1", "其他类型2"] // 其他
|
| 47 | ];
|
| 48 |
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 49 | export default function GamePage() {
|
| 50 | const navigate = useNavigate();
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 51 | const [searchText, setSearchText] = useState('');
|
| 52 | const [userInfo, setUserInfo] = useState({ avatar_url: '', username: '' });
|
| 53 | const [userPT, setUserPT] = useState({ magic: 0, ratio: 0, upload: 0, download: 0 });
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 54 | const [activeTab, setActiveTab] = useState(0);
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 55 | const [gameList, setGameList] = useState([]);
|
| 56 |
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 57 | useEffect(() => {
|
| 58 | const match = document.cookie.match('(^|;)\\s*userId=([^;]+)');
|
| 59 | const userId = match ? match[2] : null;
|
| 60 | if (!userId) return;
|
| 61 | fetch(`${API_BASE_URL}/api/get-userpt?userid=${encodeURIComponent(userId)}`)
|
| 62 | .then(res => res.json())
|
| 63 | .then(data => {
|
| 64 | setUserInfo({ avatar_url: data.user.avatar_url, username: data.user.username });
|
| 65 | setUserPT({
|
| 66 | magic: data.magic_value || data.magic || 0,
|
| 67 | ratio: data.share_ratio || data.share || 0,
|
| 68 | upload: data.upload_amount || data.upload || 0,
|
| 69 | download: data.download_amount || data.download || 0,
|
| 70 | });
|
| 71 | })
|
| 72 | .catch(err => console.error('Fetching user profile failed', err));
|
| 73 | }, []);
|
| 74 |
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 75 | const gameTypes = gameTypesList[activeTab] || [];
|
| 76 |
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 77 | useEffect(() => {
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 78 | const area = areaTabs[activeTab].label;
|
22301133 | 0f9623f | 2025-06-06 00:22:05 +0800 | [diff] [blame] | 79 | fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 80 | .then(res => res.json())
|
| 81 | .then(data => setGameList(data))
|
| 82 | .catch(() => setGameList([]));
|
| 83 | }, [activeTab]);
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 84 |
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 85 | // 搜索按钮处理
|
| 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 => {
|
| 91 | setGameList(data);
|
| 92 | })
|
| 93 | .catch(() => setGameList([]));
|
| 94 | };
|
| 95 |
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 96 | return (
|
| 97 | <div className="container">
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 98 | {/* 顶部空白与游戏界面一致,用户栏绝对定位在页面右上角 */}
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 99 | <div style={{ height: 80 }} />
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 100 | <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 }}>
|
| 101 | <div style={{ cursor: 'pointer', marginRight: 16 }} onClick={() => navigate('/user')}>
|
| 102 | {userInfo.avatar_url ? (
|
| 103 | <img src={userInfo.avatar_url} alt="用户头像" style={{ width: 38, height: 38, borderRadius: '50%', objectFit: 'cover' }} />
|
| 104 | ) : (
|
| 105 | <AccountCircleIcon style={{ fontSize: 38, color: '#1a237e', background: '#e0f3ff', borderRadius: '50%' }} />
|
| 106 | )}
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 107 | </div>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 108 | <div style={{ color: '#222', fontWeight: 500, marginRight: 24 }}>{userInfo.username || '用户栏'}</div>
|
| 109 | <div style={{ display: 'flex', gap: 28, flex: 1, justifyContent: 'flex-end', alignItems: 'center' }}>
|
| 110 | <span style={{ color: '#1976d2', fontWeight: 500 }}>魔力值: <b>{userPT.magic}</b></span>
|
| 111 | <span style={{ color: '#1976d2', fontWeight: 500 }}>分享率: <b>{userPT.ratio}</b></span>
|
| 112 | <span style={{ color: '#1976d2', fontWeight: 500 }}>上传量: <b>{userPT.upload}</b></span>
|
| 113 | <span style={{ color: '#1976d2', fontWeight: 500 }}>下载量: <b>{userPT.download}</b></span>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 114 | </div>
|
| 115 | </div>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 116 | {/* 下方内容整体下移,留出与游戏界面一致的间距 */}
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 117 | <div style={{ height: 32 }} />
|
| 118 | <nav className="nav-bar card">
|
| 119 | {navItems.map((item) => (
|
| 120 | <div
|
| 121 | key={item.label}
|
| 122 | className={item.label === "游戏" ? "nav-item active" : "nav-item"}
|
| 123 | onClick={() => navigate(item.path)}
|
| 124 | >
|
| 125 | {item.icon}
|
| 126 | <span>{item.label}</span>
|
| 127 | </div>
|
| 128 | ))}
|
| 129 | </nav>
|
| 130 | <div className="search-section card">
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 131 | <input
|
| 132 | className="search-input"
|
| 133 | placeholder="输入搜索关键词"
|
| 134 | value={searchText}
|
| 135 | onChange={e => setSearchText(e.target.value)}
|
| 136 | />
|
| 137 | <button className="search-btn" onClick={handleSearch}>
|
| 138 | <span role="img" aria-label="search">🔍</span>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 139 | </button>
|
| 140 | </div>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 141 | <div className="area-tabs" style={{ display: 'flex', justifyContent: 'center', gap: 24, margin: '18px 0' }}>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 142 | {areaTabs.map((tab, idx) => (
|
| 143 | <div
|
| 144 | key={tab.label}
|
| 145 | className={activeTab === idx ? "area-tab active" : "area-tab"}
|
| 146 | onClick={() => setActiveTab(idx)}
|
| 147 | >
|
| 148 | {tab.icon} <span>{tab.label}</span>
|
| 149 | </div>
|
| 150 | ))}
|
| 151 | </div>
|
| 152 | <div className="table-section">
|
956303669 | 9e95ae3 | 2025-06-02 21:42:11 +0800 | [diff] [blame] | 153 | <table className="game-table">
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 154 | <thead>
|
| 155 | <tr>
|
| 156 | <th>游戏类型</th>
|
| 157 | <th>标题</th>
|
| 158 | <th>发布者</th>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 159 | <th>大小</th>
|
| 160 | <th>热度</th>
|
| 161 | <th>折扣倍率</th>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 162 | </tr>
|
| 163 | </thead>
|
| 164 | <tbody>
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 165 | {gameList.length > 0 ? (
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 166 | gameList.map((item, index) => (
|
| 167 | <tr key={item.id || index}>
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 168 | <td>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 169 | <a href={`/torrent/${item.seedid}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 170 | {item.seedtag}
|
| 171 | </a>
|
| 172 | </td>
|
| 173 | <td>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 174 | <a href={`/torrent/${item.seedid}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 175 | {item.title}
|
| 176 | </a>
|
| 177 | </td>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 178 | <td>{item.username}</td>
|
| 179 | <td>{item.seedsize}</td>
|
| 180 | <td>{item.downloadtimes}</td>
|
| 181 | <td>{item.discount == null ? 1 : item.discount}</td>
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 182 | </tr>
|
| 183 | ))
|
| 184 | ) : (
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 185 | gameTypes.map((type, index) => (
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 186 | <tr key={type}>
|
| 187 | <td>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 188 | <a href={`/torrent/${type}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 189 | {type}
|
| 190 | </a>
|
| 191 | </td>
|
| 192 | <td>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 193 | <a href={`/torrent/${type}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
|
| 194 | 种子{index + 1}
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 195 | </a>
|
| 196 | </td>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 197 | <td>发布者{index + 1}</td>
|
| 198 | <td>--</td>
|
| 199 | <td>--</td>
|
| 200 | <td>1</td>
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 201 | </tr>
|
| 202 | ))
|
| 203 | )}
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 204 | </tbody>
|
| 205 | </table>
|
| 206 | </div>
|
| 207 | <div style={{ height: 32 }} />
|
| 208 | <Pagination />
|
| 209 | </div>
|
| 210 | );
|
| 211 | }
|
| 212 |
|
| 213 | function Pagination() {
|
| 214 | const [page, setPage] = React.useState(3);
|
| 215 | const total = 5;
|
| 216 | return (
|
| 217 | <div className="pagination">
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 218 | <button onClick={() => setPage(p => Math.max(1, p - 1))} disabled={page === 1}>上一页</button>
|
| 219 | <span className="page-num">{page}/{total}</span>
|
| 220 | <button onClick={() => setPage(p => Math.min(total, p + 1))} disabled={page === total}>下一页</button>
|
| 221 | <span className="page-info">第 <b>{page}</b> 页</span>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 222 | </div>
|
| 223 | );
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 224 | } |