blob: 03ad8b2e7ab51ec62394d8f776b7dd56d29eef71 [file] [log] [blame]
wht338fc032025-06-09 17:16:22 +08001import React, { useState, useEffect } from "react";
2import 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" },
wht338fc032025-06-09 17:16:22 +080026 { label: "论坛", icon: <ForumIcon />, path: "/forum" },
27 { label: "发布", icon: <AccountCircleIcon />, path: "/publish" },
28 { label: "求种", icon: <HelpIcon />, path: "/begseed" },
956303669a32fc2c2025-06-02 19:45:53 +080029];
30
31const areaTabs = [
rhjc6a4ee02025-06-06 00:45:18 +080032 { label: "国创", icon: <EmojiPeopleIcon fontSize="small" /> },
33 { label: "日漫", icon: <EmailIcon fontSize="small" /> },
34 { label: "欧美动漫", icon: <PersonIcon fontSize="small" /> },
35 { label: "韩漫", icon: <EmojiPeopleIcon fontSize="small" /> },
956303669a32fc2c2025-06-02 19:45:53 +080036];
37
38export default function AnimePage() {
39 const navigate = useNavigate();
wht338fc032025-06-09 17:16:22 +080040 const [searchText, setSearchText] = useState('');
41 const [userInfo, setUserInfo] = useState({ avatar_url: '', username: '' });
42 const [userPT, setUserPT] = useState({ magic: 0, ratio: 0, upload: 0, download: 0 });
43 const [activeTab, setActiveTab] = useState(0);
44 const [animeList, setAnimeList] = useState([]);
45
46 useEffect(() => {
47 const match = document.cookie.match('(^|;)\\s*userId=([^;]+)');
48 const userId = match ? match[2] : null;
49 if (!userId) return;
50 fetch(`${API_BASE_URL}/api/get-userpt?userid=${encodeURIComponent(userId)}`)
51 .then(res => res.json())
52 .then(data => {
53 setUserInfo({ avatar_url: data.user.avatar_url, username: data.user.username });
54 setUserPT({
55 magic: data.magic_value || data.magic || 0,
56 ratio: data.share_ratio || data.share || 0,
57 upload: data.upload_amount || data.upload || 0,
58 download: data.download_amount || data.download || 0,
59 });
60 })
61 .catch(err => console.error('Fetching user profile failed', err));
62 }, []);
956303669a32fc2c2025-06-02 19:45:53 +080063
64 // 每个tab对应的动漫类型
65 const animeTypesList = [
wht338fc032025-06-09 17:16:22 +080066 ["华语动漫(大陆)", "欧美动漫", "日韩动漫", "港台动漫", "其他"], // 国创
67 ["日漫热血", "日漫搞笑", "日漫其他"], // 日漫
68 ["欧美冒险", "欧美科幻", "欧美其他"], // 欧美动漫
69 ["韩漫爱情", "韩漫奇幻", "韩漫其他"], // 韩漫
956303669a32fc2c2025-06-02 19:45:53 +080070 ["其他类型1", "其他类型2"] // 其他
71 ];
72 const animeTypes = animeTypesList[activeTab] || [];
73
wht338fc032025-06-09 17:16:22 +080074 useEffect(() => {
rhjc6a4ee02025-06-06 00:45:18 +080075 const area = areaTabs[activeTab].label;
223011330f9623f2025-06-06 00:22:05 +080076 fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
rhjc6a4ee02025-06-06 00:45:18 +080077 .then(res => res.json())
78 .then(data => setAnimeList(data))
79 .catch(() => setAnimeList([]));
80 }, [activeTab]);
81
wht338fc032025-06-09 17:16:22 +080082 // 搜索按钮处理
83 const handleSearch = () => {
84 const area = areaTabs[activeTab].label;
85 fetch(`${API_BASE_URL}/api/search-seeds?tag=${encodeURIComponent(area)}&keyword=${encodeURIComponent(searchText)}`)
86 .then(res => res.json())
87 .then(data => {
88 setAnimeList(data);
89 })
90 .catch(() => setAnimeList([]));
91 };
92
956303669a32fc2c2025-06-02 19:45:53 +080093 return (
94 <div className="container">
wht338fc032025-06-09 17:16:22 +080095 {/* 顶部空白与动漫界面一致,用户栏绝对定位在页面右上角 */}
956303669a32fc2c2025-06-02 19:45:53 +080096 <div style={{ height: 80 }} />
97 <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 }}>
98 <div style={{ cursor: 'pointer', marginRight: 16 }} onClick={() => navigate('/user')}>
wht338fc032025-06-09 17:16:22 +080099 {userInfo.avatar_url ? (
100 <img src={userInfo.avatar_url} alt="用户头像" style={{ width: 38, height: 38, borderRadius: '50%', objectFit: 'cover' }} />
101 ) : (
102 <AccountCircleIcon style={{ fontSize: 38, color: '#1a237e', background: '#e0f3ff', borderRadius: '50%' }} />
103 )}
956303669a32fc2c2025-06-02 19:45:53 +0800104 </div>
wht338fc032025-06-09 17:16:22 +0800105 <div style={{ color: '#222', fontWeight: 500, marginRight: 24 }}>{userInfo.username || '用户栏'}</div>
956303669a32fc2c2025-06-02 19:45:53 +0800106 <div style={{ display: 'flex', gap: 28, flex: 1, justifyContent: 'flex-end', alignItems: 'center' }}>
wht338fc032025-06-09 17:16:22 +0800107 <span style={{ color: '#1976d2', fontWeight: 500 }}>魔力值: <b>{userPT.magic}</b></span>
108 <span style={{ color: '#1976d2', fontWeight: 500 }}>分享率: <b>{userPT.ratio}</b></span>
109 <span style={{ color: '#1976d2', fontWeight: 500 }}>上传量: <b>{userPT.upload}</b></span>
110 <span style={{ color: '#1976d2', fontWeight: 500 }}>下载量: <b>{userPT.download}</b></span>
956303669a32fc2c2025-06-02 19:45:53 +0800111 </div>
112 </div>
wht338fc032025-06-09 17:16:22 +0800113 {/* 下方内容整体下移,留出与动漫界面一致的间距 */}
956303669a32fc2c2025-06-02 19:45:53 +0800114 <div style={{ height: 32 }} />
wht338fc032025-06-09 17:16:22 +0800115 <nav className="nav-bar card">
956303669a32fc2c2025-06-02 19:45:53 +0800116 {navItems.map((item) => (
117 <div
118 key={item.label}
119 className={item.label === "动漫" ? "nav-item active" : "nav-item"}
120 onClick={() => navigate(item.path)}
121 >
122 {item.icon}
123 <span>{item.label}</span>
124 </div>
125 ))}
126 </nav>
127 <div className="search-section card">
wht338fc032025-06-09 17:16:22 +0800128 <input
129 className="search-input"
130 placeholder="输入搜索关键词"
131 value={searchText}
132 onChange={e => setSearchText(e.target.value)}
133 />
134 <button className="search-btn" onClick={handleSearch}>
956303669a32fc2c2025-06-02 19:45:53 +0800135 <span role="img" aria-label="search">🔍</span>
136 </button>
137 </div>
138 <div className="area-tabs" style={{ display: 'flex', justifyContent: 'center', gap: 24, margin: '18px 0' }}>
139 {areaTabs.map((tab, idx) => (
140 <div
141 key={tab.label}
142 className={activeTab === idx ? "area-tab active" : "area-tab"}
143 onClick={() => setActiveTab(idx)}
144 >
145 {tab.icon} <span>{tab.label}</span>
146 </div>
147 ))}
148 </div>
149 <div className="table-section">
9563036699e95ae32025-06-02 21:42:11 +0800150 <table className="anime-table">
956303669a32fc2c2025-06-02 19:45:53 +0800151 <thead>
152 <tr>
153 <th>动漫类型</th>
154 <th>标题</th>
155 <th>发布者</th>
wht338fc032025-06-09 17:16:22 +0800156 <th>大小</th>
157 <th>热度</th>
158 <th>折扣倍率</th>
956303669a32fc2c2025-06-02 19:45:53 +0800159 </tr>
160 </thead>
161 <tbody>
rhjc6a4ee02025-06-06 00:45:18 +0800162 {animeList.length > 0 ? (
163 animeList.map((item, index) => (
164 <tr key={item.id || index}>
165 <td>
166 <a href={`/torrent/${item.seedid}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
167 {item.seedtag}
168 </a>
169 </td>
170 <td>
171 <a href={`/torrent/${item.seedid}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
172 {item.title}
173 </a>
174 </td>
wht338fc032025-06-09 17:16:22 +0800175 <td>{item.username}</td>
176 <td>{item.seedsize}</td>
177 <td>{item.downloadtimes}</td>
178 <td>{item.discount == null ? 1 : item.discount}</td>
rhjc6a4ee02025-06-06 00:45:18 +0800179 </tr>
180 ))
181 ) : (
182 animeTypes.map((type, index) => (
183 <tr key={type}>
184 <td>
185 <a href={`/torrent/${type}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
186 {type}
187 </a>
188 </td>
189 <td>
190 <a href={`/torrent/${type}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
191 种子{index + 1}
192 </a>
193 </td>
194 <td>发布者{index + 1}</td>
wht338fc032025-06-09 17:16:22 +0800195 <td>--</td>
196 <td>--</td>
197 <td>1</td>
rhjc6a4ee02025-06-06 00:45:18 +0800198 </tr>
199 ))
200 )}
956303669a32fc2c2025-06-02 19:45:53 +0800201 </tbody>
202 </table>
203 </div>
204 <div style={{ height: 32 }} />
205 <Pagination />
206 </div>
207 );
208}
209
210function Pagination() {
211 const [page, setPage] = React.useState(3);
212 const total = 5;
213 return (
214 <div className="pagination">
215 <button onClick={() => setPage(p => Math.max(1, p - 1))} disabled={page === 1}>上一页</button>
216 <span className="page-num">{page}/{total}</span>
217 <button onClick={() => setPage(p => Math.min(total, p + 1))} disabled={page === total}>下一页</button>
218 <span className="page-info">第 <b>{page}</b> 页</span>
219 </div>
220 );
wht338fc032025-06-09 17:16:22 +0800221}