blob: 088b2842bff92bb463ea5234d80de06d535e676b [file] [log] [blame]
wht47038812025-06-09 23:33:09 +08001import React, { useEffect, useState } from "react";
wht10563a82025-06-08 15:52:18 +08002import HomeIcon from "@mui/icons-material/Home";
3import MovieIcon from "@mui/icons-material/Movie";
TRM-codingfa3ffdf2025-06-09 22:47:42 +08004import TvIcon from "@mui/icons-material/Tv";
wht10563a82025-06-08 15:52:18 +08005import MusicNoteIcon from "@mui/icons-material/MusicNote";
TRM-codingfa3ffdf2025-06-09 22:47:42 +08006import AnimationIcon from "@mui/icons-material/Animation";
wht10563a82025-06-08 15:52:18 +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";
11import ForumIcon from "@mui/icons-material/Forum";
12import HelpIcon from "@mui/icons-material/Help";
13import { useNavigate } from "react-router-dom";
TRM-codingfa3ffdf2025-06-09 22:47:42 +080014import "./HomePage.css";
wht10563a82025-06-08 15:52:18 +080015
16// 导航栏
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" },
wht10563a82025-06-08 15:52:18 +080029];
30
wht10563a82025-06-08 15:52:18 +080031export default function HomePage() {
32 const navigate = useNavigate();
wht47038812025-06-09 23:33:09 +080033 const [recommendSeeds, setRecommendSeeds] = useState([]);
34 const [loading, setLoading] = useState(true);
35
36 useEffect(() => {
37 // 获取当前登录用户ID
38 const match = document.cookie.match('(^|;)\\s*userId=([^;]+)');
39 const userId = match ? match[2] : null;
40
41 if (!userId) {
42 setRecommendSeeds([]);
43 setLoading(false);
44 return;
45 }
46
47 setLoading(true);
48 fetch("http://10.126.59.25:5000/recommend", {
49 method: "POST",
50 headers: {
51 "Content-Type": "application/json"
52 },
53 body: JSON.stringify({ user_id: userId })
54 })
55 .then(res => res.json())
56 .then(data => {
57 setRecommendSeeds(Array.isArray(data.recommend) ? data.recommend : []);
58 setLoading(false);
59 })
60 .catch(() => {
61 setRecommendSeeds([]);
62 setLoading(false);
63 });
64 }, []);
wht10563a82025-06-08 15:52:18 +080065
66 return (
TRM-codingfa3ffdf2025-06-09 22:47:42 +080067 <div className="emerald-home-container">
68 {/* 流星雨背景效果 */}
69 <div className="meteor-shower">
70 <div className="meteor">💫</div>
71 <div className="meteor">⭐</div>
72 <div className="meteor">✨</div>
73 <div className="meteor">🌟</div>
74 <div className="meteor">💫</div>
75 <div className="meteor">⭐</div>
76 <div className="meteor">✨</div>
77 <div className="meteor">🌟</div>
78 <div className="meteor">💫</div>
79 <div className="meteor">⭐</div>
wht10563a82025-06-08 15:52:18 +080080 </div>
TRM-codingfa3ffdf2025-06-09 22:47:42 +080081
82 {/* 浮动园林装饰元素 */}
83 <div className="floating-garden-elements">
84 <div className="garden-element">🌿</div>
85 <div className="garden-element">🦋</div>
86 <div className="garden-element">🌺</div>
87 <div className="garden-element">🌸</div>
88 </div>
89
90 <div className="emerald-content">
91 {/* NeuraFlux用户栏 */}
92 <div className="emerald-user-bar">
93 <div className="emerald-user-avatar" onClick={() => navigate('/user')}>
94 <AccountCircleIcon style={{ fontSize: 38, color: 'white' }} />
wht10563a82025-06-08 15:52:18 +080095 </div>
TRM-codingfa3ffdf2025-06-09 22:47:42 +080096 <div className="emerald-brand-section">
97 <div className="emerald-brand-icon">⚡</div>
98 <div className="emerald-user-label">NeuraFlux</div>
99 </div>
100 <div className="emerald-user-stats">
101 <span className="emerald-stat-item">
102 魔力值: <span className="emerald-stat-value">12,345</span>
103 </span>
104 <span className="emerald-stat-item">
105 分享率: <span className="emerald-stat-value">2.56</span>
106 </span>
107 <span className="emerald-stat-item">
108 上传: <span className="emerald-stat-value">100GB</span>
109 </span>
110 <span className="emerald-stat-item">
111 下载: <span className="emerald-stat-value">50GB</span>
112 </span>
113 </div>
114 </div>
115
116 {/* NeuraFlux导航栏 */}
117 <nav className="emerald-nav-bar">
118 {navItems.map((item) => (
119 <div
120 key={item.label}
121 className={`emerald-nav-item ${item.label === "首页" ? "active" : ""}`}
122 data-type={item.type}
123 onClick={() => navigate(item.path)}
124 >
125 {item.icon}
126 <span className="emerald-nav-label">{item.label}</span>
127 </div>
128 ))}
129 </nav>
130
131 {/* NeuraFlux种子列表 */}
132 <div className="emerald-table-section">
133 <table className="emerald-table">
134 <thead>
135 <tr>
136 <th>分类标签</th>
wht47038812025-06-09 23:33:09 +0800137 <th>标题</th>
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800138 <th>发布者</th>
wht47038812025-06-09 23:33:09 +0800139 <th>大小</th>
140 <th>热度</th>
141 <th>折扣倍率</th>
wht10563a82025-06-08 15:52:18 +0800142 </tr>
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800143 </thead>
144 <tbody>
wht47038812025-06-09 23:33:09 +0800145 {loading ? (
146 <tr>
147 <td colSpan={6} style={{ textAlign: "center", color: "#888" }}>正在加载推荐种子...</td>
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800148 </tr>
wht47038812025-06-09 23:33:09 +0800149 ) : recommendSeeds.length === 0 ? (
150 <tr>
151 <td colSpan={6} style={{ textAlign: "center", color: "#888" }}>暂无推荐数据</td>
152 </tr>
153 ) : (
154 recommendSeeds.map((seed) => (
155 <tr key={seed.seed_id}>
156 <td>{seed.tags}</td>
157 <td>
158 <a href={`/torrent/${seed.seed_id}`}>
159 {seed.title}
160 </a>
161 </td>
162 <td>{seed.username}</td>
163 <td>{seed.size}</td>
164 <td>{seed.popularity}</td>
165 <td>{seed.discount == null ? 1 : seed.discount}</td>
166 </tr>
167 ))
168 )}
TRM-codingfa3ffdf2025-06-09 22:47:42 +0800169 </tbody>
170 </table>
171 </div>
wht10563a82025-06-08 15:52:18 +0800172 </div>
wht10563a82025-06-08 15:52:18 +0800173 </div>
174 );
175}