blob: 7e33a87f0c9cc581cb51aca92d8a7a97ff9d41ed [file] [log] [blame]
223011339e292152025-06-08 00:34:37 +08001import React, { useState, useEffect } from "react";
956303669a32fc2c2025-06-02 19:45:53 +08002import MovieIcon from "@mui/icons-material/Movie";
3import EmailIcon from "@mui/icons-material/Email";
4import MusicNoteIcon from "@mui/icons-material/MusicNote";
5import EmojiPeopleIcon from "@mui/icons-material/EmojiPeople";
6import SportsEsportsIcon from "@mui/icons-material/SportsEsports";
7import SportsMartialArtsIcon from "@mui/icons-material/SportsMartialArts";
8import PersonIcon from "@mui/icons-material/Person";
9import AccountCircleIcon from "@mui/icons-material/AccountCircle";
10import { useNavigate } from "react-router-dom";
11import "./App.css";
223011330f9623f2025-06-06 00:22:05 +080012import { API_BASE_URL } from "./config";
956303669a32fc2c2025-06-02 19:45:53 +080013
14const navItems = [
15 { label: "电影", icon: <MovieIcon />, path: "/movie" },
16 { label: "剧集", icon: <EmailIcon />, path: "/tv" },
17 { label: "音乐", icon: <MusicNoteIcon />, path: "/music" },
18 { label: "动漫", icon: <EmojiPeopleIcon />, path: "/anime" },
19 { label: "游戏", icon: <SportsEsportsIcon />, path: "/game" },
20 { label: "体育", icon: <SportsMartialArtsIcon />, path: "/sport" },
21 { label: "资料", icon: <PersonIcon />, path: "/info" },
9563036699e95ae32025-06-02 21:42:11 +080022 { label: "发布", icon: <AccountCircleIcon />, path: "/publish" }, // Added Publish option
956303669a32fc2c2025-06-02 19:45:53 +080023];
24
rhjc6a4ee02025-06-06 00:45:18 +080025const tvTypesList = [
26 ["华语剧集(大陆)", "欧美剧集", "日韩剧集", "港台剧集", "其他"], // 大陆
27 ["港台都市", "港台爱情", "港台悬疑", "港台其他"], // 港台
28 ["欧美悬疑", "欧美历史", "欧美其他"], // 欧美
29 ["日韩青春", "日韩家庭", "日韩其他"], // 日韩
30 ["其他类型1", "其他类型2"] // 其他
956303669a32fc2c2025-06-02 19:45:53 +080031];
32
33const areaTabs = [
rhjc6a4ee02025-06-06 00:45:18 +080034 { label: "国产电视剧", icon: <MovieIcon fontSize="small" /> },
35 { label: "港剧", icon: <EmailIcon fontSize="small" /> },
36 { label: "欧美剧", icon: <PersonIcon fontSize="small" /> },
37 { label: "日韩剧", icon: <EmojiPeopleIcon fontSize="small" /> },
38 // { label: "其他", icon: <PersonIcon fontSize="small" /> },
9563036699e95ae32025-06-02 21:42:11 +080039];
40
956303669a32fc2c2025-06-02 19:45:53 +080041export default function TVPage() {
42 const navigate = useNavigate();
223011339e292152025-06-08 00:34:37 +080043 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 });
956303669a32fc2c2025-06-02 19:45:53 +080046 const [activeTab, setActiveTab] = React.useState(0);
rhjc6a4ee02025-06-06 00:45:18 +080047 const [tvList, setTvList] = React.useState([]);
48
223011339e292152025-06-08 00:34:37 +080049 useEffect(() => {
50 const match = document.cookie.match('(^|;)\\s*userId=([^;]+)');
51 const userId = match ? match[2] : null;
52 console.log("User ID from cookie:", userId);
53 if (!userId) return;
54 fetch(`${API_BASE_URL}/api/get-userpt?userid=${encodeURIComponent(userId)}`)
55 .then(res => res.json())
56 .then(data => {
57 console.log('用户PT信息:', data);
58 setUserInfo({ avatar_url: data.user.avatar_url, username: data.user.username });
59 setUserPT({
60 magic: data.magic_value || data.magic || 0,
61 ratio: data.share_ratio || data.share || 0,
62 upload: data.upload_amount || data.upload || 0,
63 download: data.download_amount || data.download || 0,
64 });
65 })
66 .catch(err => console.error('Fetching user profile failed', err));
67 }, []);
68
rhjc6a4ee02025-06-06 00:45:18 +080069 React.useEffect(() => {
70 // 假设后端接口为 /api/tvs?area=大陆
71 const area = areaTabs[activeTab].label;
223011330f9623f2025-06-06 00:22:05 +080072 fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
rhjc6a4ee02025-06-06 00:45:18 +080073 .then(res => res.json())
74 .then(data => setTvList(data))
75 .catch(() => setTvList([]));
76 }, [activeTab]);
956303669a32fc2c2025-06-02 19:45:53 +080077
223011339e292152025-06-08 00:34:37 +080078 // 搜索按钮处理
79 const handleSearch = () => {
80 const area = areaTabs[activeTab].label;
81 fetch(`${API_BASE_URL}/api/search-seeds?tag=${encodeURIComponent(area)}&keyword=${encodeURIComponent(searchText)}`)
82 .then(res => res.json())
83 .then(data => {
84 console.log('搜索返回数据:', data);
85 setTvList(data);
86 })
87 .catch(() => setTvList([]));
88 };
89
956303669a32fc2c2025-06-02 19:45:53 +080090 // 每个tab对应的剧集类型
956303669a32fc2c2025-06-02 19:45:53 +080091 const tvTypes = tvTypesList[activeTab] || [];
92
93 return (
94 <div className="container">
95 {/* 顶部空白与音乐界面一致,用户栏绝对定位在页面右上角 */}
96 <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')}>
223011339e292152025-06-08 00:34:37 +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>
223011339e292152025-06-08 00:34:37 +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' }}>
223011339e292152025-06-08 00:34:37 +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>
113 {/* 下方内容整体下移,留出与音乐界面一致的间距 */}
114 <div style={{ height: 32 }} />
115 <nav className="nav-bar card">
116 {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">
223011339e292152025-06-08 00:34:37 +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">
150 <table className="movie-table">
151 <thead>
152 <tr>
153 <th>剧集类型</th>
154 <th>标题</th>
155 <th>发布者</th>
156 </tr>
157 </thead>
158 <tbody>
rhjc6a4ee02025-06-06 00:45:18 +0800159 {tvList.length > 0 ? (
160 tvList.map((item, index) => (
161 <tr key={item.id || index}>
162 <td>
163 <a href={`/torrent/${item.seedid}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
164 {item.seedtag}
165 </a>
166 </td>
167 <td>
168 <a href={`/torrent/${item.seedid}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
169 {item.title}
170 </a>
171 </td>
172 <td>{item.user.username}</td>
173 </tr>
174 ))
175 ) : (
176 tvTypes.map((type, index) => (
177 <tr key={type}>
178 <td>
179 <a href={`/torrent/${type}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
180 {type}
181 </a>
182 </td>
183 <td>
184 <a href={`/torrent/${type}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
185 种子{index + 1}
186 </a>
187 </td>
188 <td>发布者{index + 1}</td>
189 </tr>
190 ))
191 )}
956303669a32fc2c2025-06-02 19:45:53 +0800192 </tbody>
193 </table>
194 </div>
195 <div style={{ height: 32 }} />
196 <Pagination />
197 </div>
198 );
199}
200
201function Pagination() {
202 const [page, setPage] = React.useState(3);
203 const total = 5;
204 return (
205 <div className="pagination">
206 <button onClick={() => setPage(p => Math.max(1, p - 1))} disabled={page === 1}>上一页</button>
207 <span className="page-num">{page}/{total}</span>
208 <button onClick={() => setPage(p => Math.min(total, p + 1))} disabled={page === total}>下一页</button>
209 <span className="page-info">第 <b>{page}</b> 页</span>
210 </div>
211 );
212}