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" },
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 29 | ];
|
| 30 |
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 31 | const areaTabs = [
|
| 32 | { label: "出版物", icon: <MovieIcon fontSize="small" /> },
|
| 33 | { label: "学习教程", icon: <EmailIcon fontSize="small" /> },
|
| 34 | { label: "素材模板", icon: <PersonIcon fontSize="small" /> },
|
| 35 | { label: "演讲交流", icon: <EmojiPeopleIcon fontSize="small" /> },
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 36 | { label: "日常娱乐", icon: <PersonIcon fontSize="small" /> },
|
956303669 | 9e95ae3 | 2025-06-02 21:42:11 +0800 | [diff] [blame] | 37 | ];
|
| 38 |
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 39 | export default function InfoPage() {
|
| 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 });
|
| 44 | const [activeTab, setActiveTab] = useState(0);
|
| 45 | const [infoList, setInfoList] = useState([]);
|
| 46 |
|
| 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 | }, []);
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 64 |
|
| 65 | // 每个tab对应的资料类型
|
| 66 | const infoTypesList = [
|
| 67 | ["出版物A", "出版物B", "出版物C"], // 出版物
|
| 68 | ["教程A", "教程B", "教程C"], // 学习教程
|
| 69 | ["模板A", "模板B"], // 素材模板
|
| 70 | ["演讲A", "演讲B"], // 演讲交流
|
| 71 | ["娱乐A", "娱乐B"], // 日常娱乐
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 72 | ["其他类型1", "其他类型2"] // 其他
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 73 | ];
|
| 74 | const infoTypes = infoTypesList[activeTab] || [];
|
| 75 |
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 76 | useEffect(() => {
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 77 | const area = areaTabs[activeTab].label;
|
22301133 | 0f9623f | 2025-06-06 00:22:05 +0800 | [diff] [blame] | 78 | fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 79 | .then(res => res.json())
|
| 80 | .then(data => {
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 81 | setInfoList(data);
|
| 82 | })
|
| 83 | .catch(() => setInfoList([]));
|
| 84 | }, [activeTab]);
|
| 85 |
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 86 | // 搜索按钮处理
|
| 87 | const handleSearch = () => {
|
| 88 | const area = areaTabs[activeTab].label;
|
| 89 | fetch(`${API_BASE_URL}/api/search-seeds?tag=${encodeURIComponent(area)}&keyword=${encodeURIComponent(searchText)}`)
|
| 90 | .then(res => res.json())
|
| 91 | .then(data => {
|
| 92 | setInfoList(data);
|
| 93 | })
|
| 94 | .catch(() => setInfoList([]));
|
| 95 | };
|
| 96 |
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 97 | return (
|
| 98 | <div className="container">
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 99 | {/* 顶部空白与资料界面一致,用户栏绝对定位在页面右上角 */}
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 100 | <div style={{ height: 80 }} />
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 101 | <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 }}>
|
| 102 | <div style={{ cursor: 'pointer', marginRight: 16 }} onClick={() => navigate('/user')}>
|
| 103 | {userInfo.avatar_url ? (
|
| 104 | <img src={userInfo.avatar_url} alt="用户头像" style={{ width: 38, height: 38, borderRadius: '50%', objectFit: 'cover' }} />
|
| 105 | ) : (
|
| 106 | <AccountCircleIcon style={{ fontSize: 38, color: '#1a237e', background: '#e0f3ff', borderRadius: '50%' }} />
|
| 107 | )}
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 108 | </div>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 109 | <div style={{ color: '#222', fontWeight: 500, marginRight: 24 }}>{userInfo.username || '用户栏'}</div>
|
| 110 | <div style={{ display: 'flex', gap: 28, flex: 1, justifyContent: 'flex-end', alignItems: 'center' }}>
|
| 111 | <span style={{ color: '#1976d2', fontWeight: 500 }}>魔力值: <b>{userPT.magic}</b></span>
|
| 112 | <span style={{ color: '#1976d2', fontWeight: 500 }}>分享率: <b>{userPT.ratio}</b></span>
|
| 113 | <span style={{ color: '#1976d2', fontWeight: 500 }}>上传量: <b>{userPT.upload}</b></span>
|
| 114 | <span style={{ color: '#1976d2', fontWeight: 500 }}>下载量: <b>{userPT.download}</b></span>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 115 | </div>
|
| 116 | </div>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 117 | {/* 下方内容整体下移,留出与资料界面一致的间距 */}
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 118 | <div style={{ height: 32 }} />
|
| 119 | <nav className="nav-bar card">
|
| 120 | {navItems.map((item) => (
|
| 121 | <div
|
| 122 | key={item.label}
|
| 123 | className={item.label === "资料" ? "nav-item active" : "nav-item"}
|
| 124 | onClick={() => navigate(item.path)}
|
| 125 | >
|
| 126 | {item.icon}
|
| 127 | <span>{item.label}</span>
|
| 128 | </div>
|
| 129 | ))}
|
| 130 | </nav>
|
| 131 | <div className="search-section card">
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 132 | <input
|
| 133 | className="search-input"
|
| 134 | placeholder="输入搜索关键词"
|
| 135 | value={searchText}
|
| 136 | onChange={e => setSearchText(e.target.value)}
|
| 137 | />
|
| 138 | <button className="search-btn" onClick={handleSearch}>
|
| 139 | <span role="img" aria-label="search">🔍</span>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 140 | </button>
|
| 141 | </div>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 142 | <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] | 143 | {areaTabs.map((tab, idx) => (
|
| 144 | <div
|
| 145 | key={tab.label}
|
| 146 | className={activeTab === idx ? "area-tab active" : "area-tab"}
|
| 147 | onClick={() => setActiveTab(idx)}
|
| 148 | >
|
| 149 | {tab.icon} <span>{tab.label}</span>
|
| 150 | </div>
|
| 151 | ))}
|
| 152 | </div>
|
| 153 | <div className="table-section">
|
956303669 | 9e95ae3 | 2025-06-02 21:42:11 +0800 | [diff] [blame] | 154 | <table className="info-table">
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 155 | <thead>
|
| 156 | <tr>
|
956303669 | 9e95ae3 | 2025-06-02 21:42:11 +0800 | [diff] [blame] | 157 | <th>资料类型</th>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 158 | <th>标题</th>
|
| 159 | <th>发布者</th>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 160 | <th>大小</th>
|
| 161 | <th>热度</th>
|
| 162 | <th>折扣倍率</th>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 163 | </tr>
|
| 164 | </thead>
|
| 165 | <tbody>
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 166 | {infoList.length > 0 ? (
|
| 167 | infoList.map((item, index) => (
|
| 168 | <tr key={item.id || index}>
|
| 169 | <td>
|
| 170 | <a href={`/torrent/${item.seedid}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
|
| 171 | {item.seedtag}
|
| 172 | </a>
|
| 173 | </td>
|
| 174 | <td>
|
| 175 | <a href={`/torrent/${item.seedid}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
|
| 176 | {item.title}
|
| 177 | </a>
|
| 178 | </td>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 179 | <td>{item.username}</td>
|
| 180 | <td>{item.seedsize}</td>
|
| 181 | <td>{item.downloadtimes}</td>
|
| 182 | <td>{item.discount == null ? 1 : item.discount}</td>
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 183 | </tr>
|
| 184 | ))
|
| 185 | ) : (
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 186 | infoTypes.map((type, index) => (
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 187 | <tr key={type}>
|
| 188 | <td>
|
| 189 | <a href={`/torrent/${type}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
|
| 190 | {type}
|
| 191 | </a>
|
| 192 | </td>
|
| 193 | <td>
|
| 194 | <a href={`/torrent/${type}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
|
| 195 | 种子{index + 1}
|
| 196 | </a>
|
| 197 | </td>
|
| 198 | <td>发布者{index + 1}</td>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 199 | <td>--</td>
|
| 200 | <td>--</td>
|
| 201 | <td>1</td>
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 202 | </tr>
|
| 203 | ))
|
| 204 | )}
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 205 | </tbody>
|
| 206 | </table>
|
| 207 | </div>
|
| 208 | <div style={{ height: 32 }} />
|
| 209 | <Pagination />
|
| 210 | </div>
|
| 211 | );
|
| 212 | }
|
| 213 |
|
| 214 | function Pagination() {
|
| 215 | const [page, setPage] = React.useState(3);
|
| 216 | const total = 5;
|
| 217 | return (
|
| 218 | <div className="pagination">
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 219 | <button onClick={() => setPage(p => Math.max(1, p - 1))} disabled={page === 1}>上一页</button>
|
| 220 | <span className="page-num">{page}/{total}</span>
|
| 221 | <button onClick={() => setPage(p => Math.min(total, p + 1))} disabled={page === total}>下一页</button>
|
| 222 | <span className="page-info">第 <b>{page}</b> 页</span>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 223 | </div>
|
| 224 | );
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame] | 225 | } |