blob: b01d32480d7a5837575050a5102a27ced8a34714 [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";
2230113338fd3882025-06-06 23:33:57 +080010import ForumIcon from "@mui/icons-material/Forum";
956303669a32fc2c2025-06-02 19:45:53 +080011import { useNavigate } from "react-router-dom";
12import "./App.css";
223011330f9623f2025-06-06 00:22:05 +080013import { API_BASE_URL } from "./config";
956303669a32fc2c2025-06-02 19:45:53 +080014
15const navItems = [
16 { label: "电影", icon: <MovieIcon />, path: "/movie" },
17 { label: "剧集", icon: <EmailIcon />, path: "/tv" },
18 { label: "音乐", icon: <MusicNoteIcon />, path: "/music" },
19 { label: "动漫", icon: <EmojiPeopleIcon />, path: "/anime" },
20 { label: "游戏", icon: <SportsEsportsIcon />, path: "/game" },
21 { label: "体育", icon: <SportsMartialArtsIcon />, path: "/sport" },
22 { label: "资料", icon: <PersonIcon />, path: "/info" },
2230113338fd3882025-06-06 23:33:57 +080023 { label: "论坛", icon: <ForumIcon />, path: "/forum" },
9563036699e95ae32025-06-02 21:42:11 +080024 { label: "发布", icon: <AccountCircleIcon />, path: "/publish" }, // Added Publish option
956303669a32fc2c2025-06-02 19:45:53 +080025];
26
27const areaTabs = [
28 { label: "大陆", icon: <MovieIcon fontSize="small" /> },
29 { label: "港台", icon: <EmailIcon fontSize="small" /> },
30 { label: "欧美", icon: <PersonIcon fontSize="small" /> },
31 { label: "日韩", icon: <EmojiPeopleIcon fontSize="small" /> },
rhjc6a4ee02025-06-06 00:45:18 +080032 // { label: "其他", icon: <PersonIcon fontSize="small" /> },
956303669a32fc2c2025-06-02 19:45:53 +080033];
34
9563036699e95ae32025-06-02 21:42:11 +080035const exampleTorrents = [
36 { type: "Action", title: "实例1", id: 1 },
37 { type: "Drama", title: "实例2", id: 2 },
38 { type: "Comedy", title: "实例3", id: 3 },
39];
40
956303669a32fc2c2025-06-02 19:45:53 +080041export default function MoviePage() {
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 [movieList, setMovieList] = React.useState([]);
223011339e292152025-06-08 00:34:37 +080048
49
50 useEffect(() => {
51 const match = document.cookie.match('(^|;)\\s*userId=([^;]+)');
52 const userId = match ? match[2] : null;
53 console.log("User ID from cookie:", userId);
54 if (!userId) return;
55 fetch(`${API_BASE_URL}/api/get-userpt?userid=${encodeURIComponent(userId)}`)
56 .then(res => res.json())
57 .then(data => {
58 console.log('用户PT信息:', data);
59 setUserInfo({ avatar_url: data.user.avatar_url, username: data.user.username });
60 setUserPT({
61 magic: data.magic_value || data.magic || 0,
62 ratio: data.share_ratio || data.share || 0,
63 upload: data.upload_amount || data.upload || 0,
64 download: data.download_amount || data.download || 0,
65 });
66 })
67 .catch(err => console.error('Fetching user profile failed', err));
68 }, []);
956303669a32fc2c2025-06-02 19:45:53 +080069
70 // 每个tab对应的电影类型
71 const movieTypesList = [
72 ["华语电影(大陆)", "欧美电影", "日韩电影", "港台电影", "其他"], // 大陆
73 ["港台动作", "港台爱情", "港台喜剧", "港台其他"], // 港台
74 ["欧美动作", "欧美科幻", "欧美剧情", "欧美其他"], // 欧美
75 ["日韩动画", "日韩爱情", "日韩其他"], // 日韩
76 ["其他类型1", "其他类型2"] // 其他
77 ];
78 const movieTypes = movieTypesList[activeTab] || [];
79
rhjc6a4ee02025-06-06 00:45:18 +080080 React.useEffect(() => {
81 // 这里假设后端接口为 /api/get-seed-list-by-tag?tag=大陆
82 const area = areaTabs[activeTab].label;
223011330f9623f2025-06-06 00:22:05 +080083 fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
rhjc6a4ee02025-06-06 00:45:18 +080084 .then(res => res.json())
85 .then(data => {
86 console.log('电影区返回数据:', data);
87 setMovieList(data);
88 })
89 .catch(() => setMovieList([]));
90 }, [activeTab]);
91
223011339e292152025-06-08 00:34:37 +080092 // 搜索按钮处理
93 const handleSearch = () => {
94 const area = areaTabs[activeTab].label;
95 fetch(`${API_BASE_URL}/api/search-seeds?tag=${encodeURIComponent(area)}&keyword=${encodeURIComponent(searchText)}`)
96 .then(res => res.json())
97 .then(data => {
98 console.log('搜索返回数据:', data);
99 setMovieList(data);
100 })
101 .catch(() => setMovieList([]));
102 };
103
956303669a32fc2c2025-06-02 19:45:53 +0800104 return (
105 <div className="container">
106 {/* 顶部空白与音乐界面一致,用户栏绝对定位在页面右上角 */}
107 <div style={{ height: 80 }} />
108 <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 }}>
109 <div style={{ cursor: 'pointer', marginRight: 16 }} onClick={() => navigate('/user')}>
223011339e292152025-06-08 00:34:37 +0800110 {userInfo.avatar_url ? (
111 <img src={userInfo.avatar_url} alt="用户头像" style={{ width: 38, height: 38, borderRadius: '50%', objectFit: 'cover' }} />
112 ) : (
113 <AccountCircleIcon style={{ fontSize: 38, color: '#1a237e', background: '#e0f3ff', borderRadius: '50%' }} />
114 )}
956303669a32fc2c2025-06-02 19:45:53 +0800115 </div>
223011339e292152025-06-08 00:34:37 +0800116 <div style={{ color: '#222', fontWeight: 500, marginRight: 24 }}>{userInfo.username || '用户栏'}</div>
956303669a32fc2c2025-06-02 19:45:53 +0800117 <div style={{ display: 'flex', gap: 28, flex: 1, justifyContent: 'flex-end', alignItems: 'center' }}>
223011339e292152025-06-08 00:34:37 +0800118 <span style={{ color: '#1976d2', fontWeight: 500 }}>魔力值: <b>{userPT.magic}</b></span>
119 <span style={{ color: '#1976d2', fontWeight: 500 }}>分享率: <b>{userPT.ratio}</b></span>
120 <span style={{ color: '#1976d2', fontWeight: 500 }}>上传量: <b>{userPT.upload}</b></span>
121 <span style={{ color: '#1976d2', fontWeight: 500 }}>下载量: <b>{userPT.download}</b></span>
956303669a32fc2c2025-06-02 19:45:53 +0800122 </div>
123 </div>
124 {/* 下方内容整体下移,留出与音乐界面一致的间距 */}
125 <div style={{ height: 32 }} />
126 <nav className="nav-bar card">
127 {navItems.map((item) => (
128 <div
129 key={item.label}
130 className={item.label === "电影" ? "nav-item active" : "nav-item"}
131 onClick={() => navigate(item.path)}
132 >
133 {item.icon}
134 <span>{item.label}</span>
135 </div>
136 ))}
137 </nav>
138 <div className="search-section card">
223011339e292152025-06-08 00:34:37 +0800139 <input
140 className="search-input"
141 placeholder="输入搜索关键词"
142 value={searchText}
143 onChange={e => setSearchText(e.target.value)}
144 />
145 <button className="search-btn" onClick={handleSearch}>
956303669a32fc2c2025-06-02 19:45:53 +0800146 <span role="img" aria-label="search">🔍</span>
147 </button>
148 </div>
149 <div className="area-tabs" style={{ display: 'flex', justifyContent: 'center', gap: 24, margin: '18px 0' }}>
150 {areaTabs.map((tab, idx) => (
151 <div
152 key={tab.label}
153 className={activeTab === idx ? "area-tab active" : "area-tab"}
154 onClick={() => setActiveTab(idx)}
155 >
156 {tab.icon} <span>{tab.label}</span>
157 </div>
158 ))}
159 </div>
160 <div className="table-section">
161 <table className="movie-table">
162 <thead>
163 <tr>
164 <th>电影类型</th>
165 <th>标题</th>
166 <th>发布者</th>
167 </tr>
168 </thead>
169 <tbody>
rhjc6a4ee02025-06-06 00:45:18 +0800170 {movieList.length > 0 ? (
171 movieList.map((item, index) => (
172 <tr key={item.id || index}>
173 <td>
174 <a href={`/torrent/${item.seedid}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
175 {item.seedtag}
176 </a>
177 </td>
178 <td>
179 <a href={`/torrent/${item.seedid}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
180 {item.title}
181 </a>
182 </td>
183 <td>{item.user.username}</td>
184 </tr>
185 ))
186 ) : (
187 movieTypes.map((type, index) => (
188 <tr key={type}>
189 <td>
190 <a href={`/torrent/${type}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
191 {type}
192 </a>
193 </td>
194 <td>
195 <a href={`/torrent/${type}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
196 种子{index + 1}
197 </a>
198 </td>
199 <td>发布者{index + 1}</td>
200 </tr>
201 ))
202 )}
956303669a32fc2c2025-06-02 19:45:53 +0800203 </tbody>
204 </table>
205 </div>
206 <div style={{ height: 32 }} />
207 <Pagination />
208 </div>
209 );
210}
211
212function Pagination() {
213 const [page, setPage] = React.useState(3);
214 const total = 5;
215 return (
216 <div className="pagination">
217 <button onClick={() => setPage(p => Math.max(1, p - 1))} disabled={page === 1}>上一页</button>
218 <span className="page-num">{page}/{total}</span>
219 <button onClick={() => setPage(p => Math.min(total, p + 1))} disabled={page === total}>下一页</button>
220 <span className="page-info">第 <b>{page}</b> 页</span>
221 </div>
222 );
223}