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