wht | 4703881 | 2025-06-09 23:33:09 +0800 | [diff] [blame^] | 1 | import React, { useEffect, useState } from "react"; |
wht | 10563a8 | 2025-06-08 15:52:18 +0800 | [diff] [blame] | 2 | import HomeIcon from "@mui/icons-material/Home"; |
| 3 | import MovieIcon from "@mui/icons-material/Movie"; |
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 4 | import TvIcon from "@mui/icons-material/Tv"; |
wht | 10563a8 | 2025-06-08 15:52:18 +0800 | [diff] [blame] | 5 | import MusicNoteIcon from "@mui/icons-material/MusicNote"; |
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 6 | import AnimationIcon from "@mui/icons-material/Animation"; |
wht | 10563a8 | 2025-06-08 15:52:18 +0800 | [diff] [blame] | 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"; |
| 11 | import ForumIcon from "@mui/icons-material/Forum"; |
| 12 | import HelpIcon from "@mui/icons-material/Help"; |
| 13 | import { useNavigate } from "react-router-dom"; |
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 14 | import "./HomePage.css"; |
wht | 10563a8 | 2025-06-08 15:52:18 +0800 | [diff] [blame] | 15 | |
| 16 | // 导航栏 |
| 17 | const navItems = [ |
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 18 | { 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" }, |
wht | 10563a8 | 2025-06-08 15:52:18 +0800 | [diff] [blame] | 29 | ]; |
| 30 | |
wht | 10563a8 | 2025-06-08 15:52:18 +0800 | [diff] [blame] | 31 | export default function HomePage() { |
| 32 | const navigate = useNavigate(); |
wht | 4703881 | 2025-06-09 23:33:09 +0800 | [diff] [blame^] | 33 | 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 | }, []); |
wht | 10563a8 | 2025-06-08 15:52:18 +0800 | [diff] [blame] | 65 | |
| 66 | return ( |
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 67 | <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> |
wht | 10563a8 | 2025-06-08 15:52:18 +0800 | [diff] [blame] | 80 | </div> |
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 81 | |
| 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' }} /> |
wht | 10563a8 | 2025-06-08 15:52:18 +0800 | [diff] [blame] | 95 | </div> |
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 96 | <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> |
wht | 4703881 | 2025-06-09 23:33:09 +0800 | [diff] [blame^] | 137 | <th>标题</th> |
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 138 | <th>发布者</th> |
wht | 4703881 | 2025-06-09 23:33:09 +0800 | [diff] [blame^] | 139 | <th>大小</th> |
| 140 | <th>热度</th> |
| 141 | <th>折扣倍率</th> |
wht | 10563a8 | 2025-06-08 15:52:18 +0800 | [diff] [blame] | 142 | </tr> |
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 143 | </thead> |
| 144 | <tbody> |
wht | 4703881 | 2025-06-09 23:33:09 +0800 | [diff] [blame^] | 145 | {loading ? ( |
| 146 | <tr> |
| 147 | <td colSpan={6} style={{ textAlign: "center", color: "#888" }}>正在加载推荐种子...</td> |
TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 148 | </tr> |
wht | 4703881 | 2025-06-09 23:33:09 +0800 | [diff] [blame^] | 149 | ) : 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-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame] | 169 | </tbody> |
| 170 | </table> |
| 171 | </div> |
wht | 10563a8 | 2025-06-08 15:52:18 +0800 | [diff] [blame] | 172 | </div> |
wht | 10563a8 | 2025-06-08 15:52:18 +0800 | [diff] [blame] | 173 | </div> |
| 174 | ); |
| 175 | } |