blob: 1164816409a125cbfe8883adbfbf426859da994f [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";
TRM-codingfa3ffdf2025-06-09 22:47:42 +08004import TvIcon from "@mui/icons-material/Tv";
956303669a32fc2c2025-06-02 19:45:53 +08005import MusicNoteIcon from "@mui/icons-material/MusicNote";
TRM-codingfa3ffdf2025-06-09 22:47:42 +08006import AnimationIcon from "@mui/icons-material/Animation";
956303669a32fc2c2025-06-02 19:45:53 +08007import 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";
TRM-codingfa3ffdf2025-06-09 22:47:42 +080013import "./SharedStyles.css";
956303669a32fc2c2025-06-02 19:45:53 +080014import { 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 = [
TRM-codingfa3ffdf2025-06-09 22:47:42 +080018 { 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" },
956303669a32fc2c2025-06-02 19:45:53 +080029];
30
TRM-codingfa3ffdf2025-06-09 22:47:42 +080031// 资料地区标签
956303669a32fc2c2025-06-02 19:45:53 +080032const areaTabs = [
TRM-codingfa3ffdf2025-06-09 22:47:42 +080033 { label: "出版物", value: "publication" },
34 { label: "学习教程", value: "tutorial" },
35 { label: "素材模板", value: "template" },
36 { label: "演讲交流", value: "speech" },
37 { label: "日常娱乐", value: "entertainment" }
9563036699e95ae32025-06-02 21:42:11 +080038];
39
956303669a32fc2c2025-06-02 19:45:53 +080040export default function InfoPage() {
41 const navigate = useNavigate();
wht338fc032025-06-09 17:16:22 +080042 const [searchText, setSearchText] = useState('');
43 const [userInfo, setUserInfo] = useState({ avatar_url: '', username: '' });
44 const [userPT, setUserPT] = useState({ magic: 0, ratio: 0, upload: 0, download: 0 });
45 const [activeTab, setActiveTab] = useState(0);
46 const [infoList, setInfoList] = useState([]);
47
48 useEffect(() => {
49 const match = document.cookie.match('(^|;)\\s*userId=([^;]+)');
50 const userId = match ? match[2] : null;
51 if (!userId) return;
52 fetch(`${API_BASE_URL}/api/get-userpt?userid=${encodeURIComponent(userId)}`)
53 .then(res => res.json())
54 .then(data => {
55 setUserInfo({ avatar_url: data.user.avatar_url, username: data.user.username });
56 setUserPT({
57 magic: data.magic_value || data.magic || 0,
58 ratio: data.share_ratio || data.share || 0,
59 upload: data.upload_amount || data.upload || 0,
60 download: data.download_amount || data.download || 0,
61 });
62 })
63 .catch(err => console.error('Fetching user profile failed', err));
64 }, []);
956303669a32fc2c2025-06-02 19:45:53 +080065
66 // 每个tab对应的资料类型
67 const infoTypesList = [
68 ["出版物A", "出版物B", "出版物C"], // 出版物
69 ["教程A", "教程B", "教程C"], // 学习教程
70 ["模板A", "模板B"], // 素材模板
71 ["演讲A", "演讲B"], // 演讲交流
72 ["娱乐A", "娱乐B"], // 日常娱乐
wht338fc032025-06-09 17:16:22 +080073 ["其他类型1", "其他类型2"] // 其他
956303669a32fc2c2025-06-02 19:45:53 +080074 ];
75 const infoTypes = infoTypesList[activeTab] || [];
76
wht338fc032025-06-09 17:16:22 +080077 useEffect(() => {
rhjc6a4ee02025-06-06 00:45:18 +080078 const area = areaTabs[activeTab].label;
223011330f9623f2025-06-06 00:22:05 +080079 fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
rhjc6a4ee02025-06-06 00:45:18 +080080 .then(res => res.json())
81 .then(data => {
rhjc6a4ee02025-06-06 00:45:18 +080082 setInfoList(data);
83 })
84 .catch(() => setInfoList([]));
85 }, [activeTab]);
86
wht338fc032025-06-09 17:16:22 +080087 // 搜索按钮处理
88 const handleSearch = () => {
89 const area = areaTabs[activeTab].label;
90 fetch(`${API_BASE_URL}/api/search-seeds?tag=${encodeURIComponent(area)}&keyword=${encodeURIComponent(searchText)}`)
91 .then(res => res.json())
92 .then(data => {
93 setInfoList(data);
94 })
95 .catch(() => setInfoList([]));
96 };
956303669a32fc2c2025-06-02 19:45:53 +080097 return (
TRM-codingfa3ffdf2025-06-09 22:47:42 +080098 <div className="emerald-home-container">
99 {/* 流星雨背景效果 */}
100 <div className="meteor-shower">
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>
108 <div className="meteor">🌟</div>
109 <div className="meteor">💫</div>
110 <div className="meteor">⭐</div>
956303669a32fc2c2025-06-02 19:45:53 +0800111 </div>
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800112
113 {/* 浮动园林装饰元素 */}
114 <div className="floating-garden-elements">
115 <div className="garden-element">🌿</div>
116 <div className="garden-element">🦋</div>
117 <div className="garden-element">🌺</div>
118 <div className="garden-element">🌸</div>
956303669a32fc2c2025-06-02 19:45:53 +0800119 </div>
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800120
121 <div className="emerald-content">
122 {/* NeuraFlux用户栏 */}
123 <div className="emerald-user-bar">
124 <div className="emerald-user-avatar" onClick={() => navigate('/user')}>
125 {userInfo.avatar_url ? (
126 <img src={userInfo.avatar_url} alt="用户头像" style={{ width: 38, height: 38, borderRadius: '50%', objectFit: 'cover' }} />
rhjc6a4ee02025-06-06 00:45:18 +0800127 ) : (
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800128 <AccountCircleIcon style={{ fontSize: 38, color: 'white' }} />
rhjc6a4ee02025-06-06 00:45:18 +0800129 )}
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800130 </div>
131 <div className="emerald-brand-section">
132 <div className="emerald-brand-icon">⚡</div>
133 <div className="emerald-user-label">NeuraFlux</div>
134 </div>
135 <div className="emerald-user-stats">
136 <span className="emerald-stat-item">
137 魔力值: <span className="emerald-stat-value">{userPT.magic}</span>
138 </span>
139 <span className="emerald-stat-item">
140 分享率: <span className="emerald-stat-value">{userPT.ratio}</span>
141 </span>
142 <span className="emerald-stat-item">
143 上传: <span className="emerald-stat-value">{userPT.upload}GB</span>
144 </span>
145 <span className="emerald-stat-item">
146 下载: <span className="emerald-stat-value">{userPT.download}GB</span>
147 </span>
148 </div>
149 </div>
150
151 {/* NeuraFlux导航栏 */}
152 <nav className="emerald-nav-bar">
153 {navItems.map((item) => (
154 <div
155 key={item.label}
156 className={`emerald-nav-item ${item.label === "资料" ? "active" : ""}`}
157 data-type={item.type}
158 onClick={() => navigate(item.path)}
159 >
160 {item.icon}
161 <span className="emerald-nav-label">{item.label}</span>
162 </div>
163 ))}
164 </nav>
165
166 {/* 资料内容区域 */}
167 <div className="emerald-content-section">
168 <h1 className="emerald-page-title">📚 资料资源</h1>
169 <p style={{ textAlign: 'center', color: '#2d5016', fontSize: '18px', marginBottom: '30px' }}>
170 欢迎来到NeuraFlux资料频道,这里有最新最热门的学习和资料资源
171 </p>
172
173 {/* 搜索栏 */}
174 <div style={{
175 display: 'flex',
176 justifyContent: 'center',
177 marginBottom: '30px',
178 gap: '15px'
179 }}>
180 <input
181 type="text"
182 placeholder="搜索资料资源..."
183 value={searchText}
184 onChange={(e) => setSearchText(e.target.value)}
185 style={{
186 padding: '12px 20px',
187 borderRadius: '20px',
188 border: '2px solid rgba(144, 238, 144, 0.3)',
189 background: 'rgba(240, 255, 240, 0.5)',
190 fontSize: '16px',
191 width: '300px',
192 fontFamily: 'Lora, serif'
193 }}
194 />
195 <button
196 onClick={handleSearch}
197 style={{
198 padding: '12px 24px',
199 borderRadius: '20px',
200 border: 'none',
201 background: 'linear-gradient(135deg, #2d5016 0%, #90ee90 100%)',
202 color: 'white',
203 fontSize: '16px',
204 cursor: 'pointer',
205 fontFamily: 'Lora, serif'
206 }}
207 >
208 搜索
209 </button>
210 </div>
211
212 {/* 地区分类标签 */}
213 <div style={{
214 display: 'flex',
215 justifyContent: 'center',
216 marginBottom: '30px',
217 gap: '15px',
218 flexWrap: 'wrap'
219 }}>
220 {areaTabs.map((tab, index) => (
221 <button
222 key={tab.value}
223 onClick={() => setActiveTab(index)}
224 style={{
225 padding: '10px 20px',
226 borderRadius: '15px',
227 border: '2px solid rgba(144, 238, 144, 0.3)',
228 background: activeTab === index
229 ? 'linear-gradient(135deg, #90ee90 0%, #2d5016 100%)'
230 : 'rgba(240, 255, 240, 0.3)',
231 color: activeTab === index ? 'white' : '#2d5016',
232 fontSize: '14px',
233 cursor: 'pointer',
234 fontFamily: 'Lora, serif',
235 transition: 'all 0.3s ease'
236 }}
237 >
238 {tab.label}
239 </button>
240 ))}
241 </div>
242
243 {/* 资料列表 */}
244 <div className="emerald-table-section">
245 <table className="emerald-table">
246 <thead>
247 <tr>
248 <th>资料类型</th>
249 <th>标题</th>
250 <th>发布者</th>
251 <th>大小</th>
252 <th>热度</th>
253 <th>折扣倍率</th>
254 </tr>
255 </thead>
256 <tbody>
257 {infoList.length > 0 ? (
258 infoList.map((item, index) => (
259 <tr key={item.id || index}>
260 <td>{item.seedtag}</td>
261 <td>
262 <a href={`/torrent/${item.seedid}`}>
263 {item.title}
264 </a>
265 </td>
266 <td>{item.username}</td>
267 <td>{item.seedsize}</td>
268 <td>{item.downloadtimes}</td>
269 <td>{item.discount == null ? 1 : item.discount}</td>
270 </tr>
271 ))
272 ) : (
273 infoTypes.map((type, index) => (
274 <tr key={type}>
275 <td>{type}</td>
276 <td>
277 <a href={`/torrent/${type}`}>
278 种子{index + 1}
279 </a>
280 </td>
281 <td>发布者{index + 1}</td>
282 <td>--</td>
283 <td>--</td>
284 <td>1</td>
285 </tr>
286 ))
287 )}
288 </tbody>
289 </table>
290 </div>
291 </div>
956303669a32fc2c2025-06-02 19:45:53 +0800292 </div>
956303669a32fc2c2025-06-02 19:45:53 +0800293 </div>
294 );
295}
296
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800297// Pagination组件暂时不使用
956303669a32fc2c2025-06-02 19:45:53 +0800298function Pagination() {
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800299 const [page, setPage] = useState(3);
956303669a32fc2c2025-06-02 19:45:53 +0800300 const total = 5;
301 return (
302 <div className="pagination">
wht338fc032025-06-09 17:16:22 +0800303 <button onClick={() => setPage(p => Math.max(1, p - 1))} disabled={page === 1}>上一页</button>
304 <span className="page-num">{page}/{total}</span>
305 <button onClick={() => setPage(p => Math.min(total, p + 1))} disabled={page === total}>下一页</button>
306 <span className="page-info">第 <b>{page}</b> 页</span>
956303669a32fc2c2025-06-02 19:45:53 +0800307 </div>
308 );
wht338fc032025-06-09 17:16:22 +0800309}