TRM-coding | fa3ffdf | 2025-06-09 22:47:42 +0800 | [diff] [blame^] | 1 | import React, { useState, useEffect } from "react"; |
| 2 | import HomeIcon from "@mui/icons-material/Home"; |
| 3 | import MovieIcon from "@mui/icons-material/Movie"; |
| 4 | import TvIcon from "@mui/icons-material/Tv"; |
| 5 | import MusicNoteIcon from "@mui/icons-material/MusicNote"; |
| 6 | import AnimationIcon from "@mui/icons-material/Animation"; |
| 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"; |
| 14 | import "./SharedStyles.css"; |
| 15 | import { API_BASE_URL } from "./config"; |
| 16 | |
| 17 | // 导航栏 |
| 18 | const navItems = [ |
| 19 | { label: "首页", icon: <HomeIcon className="emerald-nav-icon" />, path: "/home", type: "home" }, |
| 20 | { label: "电影", icon: <MovieIcon className="emerald-nav-icon" />, path: "/movie", type: "movie" }, |
| 21 | { label: "剧集", icon: <TvIcon className="emerald-nav-icon" />, path: "/tv", type: "tv" }, |
| 22 | { label: "音乐", icon: <MusicNoteIcon className="emerald-nav-icon" />, path: "/music", type: "music" }, |
| 23 | { label: "动漫", icon: <AnimationIcon className="emerald-nav-icon" />, path: "/anime", type: "anime" }, |
| 24 | { label: "游戏", icon: <SportsEsportsIcon className="emerald-nav-icon" />, path: "/game", type: "game" }, |
| 25 | { label: "体育", icon: <SportsMartialArtsIcon className="emerald-nav-icon" />, path: "/sport", type: "sport" }, |
| 26 | { label: "资料", icon: <PersonIcon className="emerald-nav-icon" />, path: "/info", type: "info" }, |
| 27 | { label: "论坛", icon: <ForumIcon className="emerald-nav-icon" />, path: "/forum", type: "forum" }, |
| 28 | { label: "发布", icon: <AccountCircleIcon className="emerald-nav-icon" />, path: "/publish", type: "publish" }, |
| 29 | { label: "求种", icon: <HelpIcon className="emerald-nav-icon" />, path: "/begseed", type: "help" }, |
| 30 | ]; |
| 31 | |
| 32 | // 剧集地区标签 |
| 33 | const areaTabs = [ |
| 34 | { label: "华语剧集", value: "chinese" }, |
| 35 | { label: "港台剧集", value: "hk_tw" }, |
| 36 | { label: "欧美剧集", value: "western" }, |
| 37 | { label: "日韩剧集", value: "jp_kr" }, |
| 38 | { label: "其他剧集", value: "others" } |
| 39 | ]; |
| 40 | |
| 41 | export default function TvPage() { |
| 42 | const navigate = useNavigate(); |
| 43 | const [searchText, setSearchText] = React.useState(''); |
| 44 | const [userInfo, setUserInfo] = useState({ avatar_url: '', username: '' }); |
| 45 | const [userPT, setUserPT] = useState({ magic: 0, ratio: 0, upload: 0, download: 0 }); |
| 46 | const [activeTab, setActiveTab] = React.useState(0); |
| 47 | const [tvList, setTvList] = React.useState([]); |
| 48 | |
| 49 | useEffect(() => { |
| 50 | const match = document.cookie.match('(^|;)\\s*userId=([^;]+)'); |
| 51 | const userId = match ? match[2] : null; |
| 52 | if (!userId) return; |
| 53 | fetch(`${API_BASE_URL}/api/get-userpt?userid=${encodeURIComponent(userId)}`) |
| 54 | .then(res => res.json()) |
| 55 | .then(data => { |
| 56 | setUserInfo({ avatar_url: data.user.avatar_url, username: data.user.username }); |
| 57 | setUserPT({ |
| 58 | magic: data.magic_value || data.magic || 0, |
| 59 | ratio: data.share_ratio || data.share || 0, |
| 60 | upload: data.upload_amount || data.upload || 0, |
| 61 | download: data.download_amount || data.download || 0, |
| 62 | }); |
| 63 | }) |
| 64 | .catch(err => console.error('Fetching user profile failed', err)); |
| 65 | }, []); |
| 66 | |
| 67 | // 每个tab对应的剧集类型 |
| 68 | const tvTypesList = [ |
| 69 | ["华语电视剧", "华语综艺", "华语纪录片", "华语其他"], // 华语 |
| 70 | ["港台电视剧", "港台综艺", "港台其他"], // 港台 |
| 71 | ["欧美电视剧", "欧美综艺", "欧美纪录片", "欧美其他"], // 欧美 |
| 72 | ["日韩电视剧", "日韩综艺", "日韩其他"], // 日韩 |
| 73 | ["其他类型1", "其他类型2"] // 其他 |
| 74 | ]; |
| 75 | const tvTypes = tvTypesList[activeTab] || []; |
| 76 | |
| 77 | React.useEffect(() => { |
| 78 | const area = areaTabs[activeTab].label; |
| 79 | fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`) |
| 80 | .then(res => res.json()) |
| 81 | .then(data => { |
| 82 | setTvList(data); |
| 83 | }) |
| 84 | .catch(() => setTvList([])); |
| 85 | }, [activeTab]); |
| 86 | |
| 87 | // 搜索按钮处理 |
| 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 | setTvList(data); |
| 94 | }) |
| 95 | .catch(() => setTvList([])); |
| 96 | }; |
| 97 | |
| 98 | return ( |
| 99 | <div className="emerald-home-container"> |
| 100 | {/* 流星雨背景效果 */} |
| 101 | <div className="meteor-shower"> |
| 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> |
| 111 | <div className="meteor">⭐</div> |
| 112 | </div> |
| 113 | |
| 114 | {/* 浮动园林装饰元素 */} |
| 115 | <div className="floating-garden-elements"> |
| 116 | <div className="garden-element">🌿</div> |
| 117 | <div className="garden-element">🦋</div> |
| 118 | <div className="garden-element">🌺</div> |
| 119 | <div className="garden-element">🌸</div> |
| 120 | </div> |
| 121 | |
| 122 | <div className="emerald-content"> |
| 123 | {/* NeuraFlux用户栏 */} |
| 124 | <div className="emerald-user-bar"> |
| 125 | <div className="emerald-user-avatar" onClick={() => navigate('/user')}> |
| 126 | <AccountCircleIcon style={{ fontSize: 38, color: 'white' }} /> |
| 127 | </div> |
| 128 | <div className="emerald-brand-section"> |
| 129 | <div className="emerald-brand-icon">⚡</div> |
| 130 | <div className="emerald-user-label">NeuraFlux</div> |
| 131 | </div> |
| 132 | <div className="emerald-user-stats"> |
| 133 | <span className="emerald-stat-item"> |
| 134 | 魔力值: <span className="emerald-stat-value">{userPT.magic}</span> |
| 135 | </span> |
| 136 | <span className="emerald-stat-item"> |
| 137 | 分享率: <span className="emerald-stat-value">{userPT.ratio}</span> |
| 138 | </span> |
| 139 | <span className="emerald-stat-item"> |
| 140 | 上传: <span className="emerald-stat-value">{userPT.upload}GB</span> |
| 141 | </span> |
| 142 | <span className="emerald-stat-item"> |
| 143 | 下载: <span className="emerald-stat-value">{userPT.download}GB</span> |
| 144 | </span> |
| 145 | </div> |
| 146 | </div> |
| 147 | |
| 148 | {/* NeuraFlux导航栏 */} |
| 149 | <nav className="emerald-nav-bar"> |
| 150 | {navItems.map((item) => ( |
| 151 | <div |
| 152 | key={item.label} |
| 153 | className={`emerald-nav-item ${item.label === "剧集" ? "active" : ""}`} |
| 154 | data-type={item.type} |
| 155 | onClick={() => navigate(item.path)} |
| 156 | > |
| 157 | {item.icon} |
| 158 | <span className="emerald-nav-label">{item.label}</span> |
| 159 | </div> |
| 160 | ))} |
| 161 | </nav> |
| 162 | |
| 163 | {/* 剧集内容区域 */} |
| 164 | <div className="emerald-content-section"> |
| 165 | <h1 className="emerald-page-title">📺 剧集资源</h1> |
| 166 | <p style={{ textAlign: 'center', color: '#2d5016', fontSize: '18px', marginBottom: '30px' }}> |
| 167 | 欢迎来到NeuraFlux剧集频道,这里有最新最热门的电视剧、综艺、纪录片资源 |
| 168 | </p> |
| 169 | |
| 170 | {/* 搜索栏 */} |
| 171 | <div style={{ |
| 172 | display: 'flex', |
| 173 | justifyContent: 'center', |
| 174 | marginBottom: '30px', |
| 175 | gap: '15px' |
| 176 | }}> |
| 177 | <input |
| 178 | type="text" |
| 179 | placeholder="搜索剧集资源..." |
| 180 | value={searchText} |
| 181 | onChange={(e) => setSearchText(e.target.value)} |
| 182 | style={{ |
| 183 | padding: '12px 20px', |
| 184 | borderRadius: '20px', |
| 185 | border: '2px solid rgba(144, 238, 144, 0.3)', |
| 186 | background: 'rgba(240, 255, 240, 0.5)', |
| 187 | fontSize: '16px', |
| 188 | width: '300px', |
| 189 | fontFamily: 'Lora, serif' |
| 190 | }} |
| 191 | /> |
| 192 | <button |
| 193 | onClick={handleSearch} |
| 194 | style={{ |
| 195 | padding: '12px 24px', |
| 196 | borderRadius: '20px', |
| 197 | border: 'none', |
| 198 | background: 'linear-gradient(135deg, #2d5016 0%, #90ee90 100%)', |
| 199 | color: 'white', |
| 200 | fontSize: '16px', |
| 201 | cursor: 'pointer', |
| 202 | fontFamily: 'Lora, serif' |
| 203 | }} |
| 204 | > |
| 205 | 搜索 |
| 206 | </button> |
| 207 | </div> |
| 208 | |
| 209 | {/* 地区分类标签 */} |
| 210 | <div style={{ |
| 211 | display: 'flex', |
| 212 | justifyContent: 'center', |
| 213 | marginBottom: '30px', |
| 214 | gap: '15px', |
| 215 | flexWrap: 'wrap' |
| 216 | }}> |
| 217 | {areaTabs.map((tab, index) => ( |
| 218 | <button |
| 219 | key={tab.value} |
| 220 | onClick={() => setActiveTab(index)} |
| 221 | style={{ |
| 222 | padding: '10px 20px', |
| 223 | borderRadius: '15px', |
| 224 | border: '2px solid rgba(144, 238, 144, 0.3)', |
| 225 | background: activeTab === index |
| 226 | ? 'linear-gradient(135deg, #90ee90 0%, #2d5016 100%)' |
| 227 | : 'rgba(240, 255, 240, 0.3)', |
| 228 | color: activeTab === index ? 'white' : '#2d5016', |
| 229 | fontSize: '14px', |
| 230 | cursor: 'pointer', |
| 231 | fontFamily: 'Lora, serif', |
| 232 | transition: 'all 0.3s ease' |
| 233 | }} |
| 234 | > |
| 235 | {tab.label} |
| 236 | </button> |
| 237 | ))} |
| 238 | </div> |
| 239 | |
| 240 | {/* 剧集列表 */} |
| 241 | <div className="emerald-table-section"> |
| 242 | <table className="emerald-table"> |
| 243 | <thead> |
| 244 | <tr> |
| 245 | <th>分类标签</th> |
| 246 | <th>剧集标题</th> |
| 247 | <th>热门指数</th> |
| 248 | <th>发布者</th> |
| 249 | </tr> |
| 250 | </thead> |
| 251 | <tbody> |
| 252 | {tvList.length > 0 ? ( |
| 253 | tvList.map((tv, index) => ( |
| 254 | <tr key={tv.id || index}> |
| 255 | <td>{tv.tags || areaTabs[activeTab].label}</td> |
| 256 | <td> |
| 257 | <a href={`/torrent/${tv.id || index}`}> |
| 258 | {tv.title || `剧集资源 ${index + 1}`} |
| 259 | </a> |
| 260 | </td> |
| 261 | <td>{tv.popularity || Math.floor(Math.random() * 100) + 1}</td> |
| 262 | <td>{tv.user?.username || '匿名用户'}</td> |
| 263 | </tr> |
| 264 | )) |
| 265 | ) : ( |
| 266 | <tr> |
| 267 | <td colspan="4" style={{ |
| 268 | textAlign: 'center', |
| 269 | color: '#666', |
| 270 | fontStyle: 'italic', |
| 271 | padding: '40px 20px' |
| 272 | }}> |
| 273 | 暂无{areaTabs[activeTab].label}资源,请稍后再试 |
| 274 | </td> |
| 275 | </tr> |
| 276 | )} |
| 277 | </tbody> |
| 278 | </table> |
| 279 | </div> |
| 280 | </div> |
| 281 | </div> |
| 282 | </div> |
| 283 | ); |
| 284 | } |