22301133 | 9e29215 | 2025-06-08 00:34:37 +0800 | [diff] [blame] | 1 | import React, { useState, useEffect } from "react";
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame^] | 2 | import HomeIcon from "@mui/icons-material/Home";
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 3 | import MovieIcon from "@mui/icons-material/Movie";
|
| 4 | import EmailIcon from "@mui/icons-material/Email";
|
| 5 | import MusicNoteIcon from "@mui/icons-material/MusicNote";
|
| 6 | import EmojiPeopleIcon from "@mui/icons-material/EmojiPeople";
|
| 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";
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame^] | 11 | import ForumIcon from "@mui/icons-material/Forum";
|
| 12 | import HelpIcon from "@mui/icons-material/Help";
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 13 | import "./App.css";
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame^] | 14 | import { useNavigate } from "react-router-dom";
|
22301133 | 0f9623f | 2025-06-06 00:22:05 +0800 | [diff] [blame] | 15 | import { API_BASE_URL } from "./config";
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 16 |
|
| 17 | const navItems = [
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame^] | 18 | { label: "首页", icon: <HomeIcon />, path: "/home" },
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 19 | { label: "电影", icon: <MovieIcon />, path: "/movie" },
|
| 20 | { label: "剧集", icon: <EmailIcon />, path: "/tv" },
|
| 21 | { label: "音乐", icon: <MusicNoteIcon />, path: "/music" },
|
| 22 | { label: "动漫", icon: <EmojiPeopleIcon />, path: "/anime" },
|
| 23 | { label: "游戏", icon: <SportsEsportsIcon />, path: "/game" },
|
| 24 | { label: "体育", icon: <SportsMartialArtsIcon />, path: "/sport" },
|
| 25 | { label: "资料", icon: <PersonIcon />, path: "/info" },
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame^] | 26 | { label: "论坛", icon: <ForumIcon />, path: "/forum" },
|
| 27 | { label: "发布", icon: <AccountCircleIcon />, path: "/publish" },
|
| 28 | { label: "求种", icon: <HelpIcon />, path: "/begseed" },
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 29 | ];
|
| 30 |
|
| 31 | const areaTabs = [
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 32 | { label: "国产电视剧", icon: <MovieIcon fontSize="small" /> },
|
| 33 | { label: "港剧", icon: <EmailIcon fontSize="small" /> },
|
| 34 | { label: "欧美剧", icon: <PersonIcon fontSize="small" /> },
|
| 35 | { label: "日韩剧", icon: <EmojiPeopleIcon fontSize="small" /> },
|
956303669 | 9e95ae3 | 2025-06-02 21:42:11 +0800 | [diff] [blame] | 36 | ];
|
| 37 |
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 38 | export default function TVPage() {
|
| 39 | const navigate = useNavigate();
|
22301133 | 9e29215 | 2025-06-08 00:34:37 +0800 | [diff] [blame] | 40 | const [searchText, setSearchText] = React.useState('');
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame^] | 41 | const [userInfo, setUserInfo] = useState({ avatar_url: '', username: '' });
|
| 42 | const [userPT, setUserPT] = useState({ magic: 0, ratio: 0, upload: 0, download: 0 });
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 43 | const [activeTab, setActiveTab] = React.useState(0);
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 44 | const [tvList, setTvList] = React.useState([]);
|
| 45 |
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame^] | 46 | useEffect(() => {
|
| 47 | const match = document.cookie.match('(^|;)\\s*userId=([^;]+)');
|
| 48 | const userId = match ? match[2] : null;
|
| 49 | if (!userId) return;
|
| 50 | fetch(`${API_BASE_URL}/api/get-userpt?userid=${encodeURIComponent(userId)}`)
|
| 51 | .then(res => res.json())
|
| 52 | .then(data => {
|
| 53 | setUserInfo({ avatar_url: data.user.avatar_url, username: data.user.username });
|
| 54 | setUserPT({
|
| 55 | magic: data.magic_value || data.magic || 0,
|
| 56 | ratio: data.share_ratio || data.share || 0,
|
| 57 | upload: data.upload_amount || data.upload || 0,
|
| 58 | download: data.download_amount || data.download || 0,
|
| 59 | });
|
| 60 | })
|
| 61 | .catch(err => console.error('Fetching user profile failed', err));
|
| 62 | }, []);
|
22301133 | 9e29215 | 2025-06-08 00:34:37 +0800 | [diff] [blame] | 63 |
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 64 | React.useEffect(() => {
|
| 65 | // 假设后端接口为 /api/tvs?area=大陆
|
| 66 | const area = areaTabs[activeTab].label;
|
22301133 | 0f9623f | 2025-06-06 00:22:05 +0800 | [diff] [blame] | 67 | fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 68 | .then(res => res.json())
|
| 69 | .then(data => setTvList(data))
|
| 70 | .catch(() => setTvList([]));
|
| 71 | }, [activeTab]);
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 72 |
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame^] | 73 | // 搜索按钮处理
|
| 74 | const handleSearch = () => {
|
| 75 | const area = areaTabs[activeTab].label;
|
| 76 | fetch(`${API_BASE_URL}/api/search-seeds?tag=${encodeURIComponent(area)}&keyword=${encodeURIComponent(searchText)}`)
|
| 77 | .then(res => res.json())
|
| 78 | .then(data => {
|
| 79 | console.log('搜索返回数据:', data);
|
| 80 | setTvList(data);
|
| 81 | })
|
| 82 | .catch(() => setTvList([]));
|
| 83 | };
|
22301133 | 9e29215 | 2025-06-08 00:34:37 +0800 | [diff] [blame] | 84 |
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame^] | 85 | const tvTypesList = [
|
| 86 | ["华语剧集(大陆)", "欧美剧集", "日韩剧集", "港台剧集", "其他"], // 大陆
|
| 87 | ["港台都市", "港台爱情", "港台悬疑", "港台其他"], // 港台
|
| 88 | ["欧美悬疑", "欧美历史", "欧美其他"], // 欧美
|
| 89 | ["日韩青春", "日韩家庭", "日韩其他"], // 日韩
|
| 90 | ["其他类型1", "其他类型2"] // 其他
|
| 91 | ];
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 92 | const tvTypes = tvTypesList[activeTab] || [];
|
| 93 |
|
| 94 | return (
|
| 95 | <div className="container">
|
| 96 | {/* 顶部空白与音乐界面一致,用户栏绝对定位在页面右上角 */}
|
| 97 | <div style={{ height: 80 }} />
|
| 98 | <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 }}>
|
| 99 | <div style={{ cursor: 'pointer', marginRight: 16 }} onClick={() => navigate('/user')}>
|
22301133 | 9e29215 | 2025-06-08 00:34:37 +0800 | [diff] [blame] | 100 | {userInfo.avatar_url ? (
|
| 101 | <img src={userInfo.avatar_url} alt="用户头像" style={{ width: 38, height: 38, borderRadius: '50%', objectFit: 'cover' }} />
|
| 102 | ) : (
|
| 103 | <AccountCircleIcon style={{ fontSize: 38, color: '#1a237e', background: '#e0f3ff', borderRadius: '50%' }} />
|
| 104 | )}
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 105 | </div>
|
22301133 | 9e29215 | 2025-06-08 00:34:37 +0800 | [diff] [blame] | 106 | <div style={{ color: '#222', fontWeight: 500, marginRight: 24 }}>{userInfo.username || '用户栏'}</div>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 107 | <div style={{ display: 'flex', gap: 28, flex: 1, justifyContent: 'flex-end', alignItems: 'center' }}>
|
22301133 | 9e29215 | 2025-06-08 00:34:37 +0800 | [diff] [blame] | 108 | <span style={{ color: '#1976d2', fontWeight: 500 }}>魔力值: <b>{userPT.magic}</b></span>
|
| 109 | <span style={{ color: '#1976d2', fontWeight: 500 }}>分享率: <b>{userPT.ratio}</b></span>
|
| 110 | <span style={{ color: '#1976d2', fontWeight: 500 }}>上传量: <b>{userPT.upload}</b></span>
|
| 111 | <span style={{ color: '#1976d2', fontWeight: 500 }}>下载量: <b>{userPT.download}</b></span>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 112 | </div>
|
| 113 | </div>
|
| 114 | {/* 下方内容整体下移,留出与音乐界面一致的间距 */}
|
| 115 | <div style={{ height: 32 }} />
|
| 116 | <nav className="nav-bar card">
|
| 117 | {navItems.map((item) => (
|
| 118 | <div
|
| 119 | key={item.label}
|
| 120 | className={item.label === "剧集" ? "nav-item active" : "nav-item"}
|
| 121 | onClick={() => navigate(item.path)}
|
| 122 | >
|
| 123 | {item.icon}
|
| 124 | <span>{item.label}</span>
|
| 125 | </div>
|
| 126 | ))}
|
| 127 | </nav>
|
| 128 | <div className="search-section card">
|
22301133 | 9e29215 | 2025-06-08 00:34:37 +0800 | [diff] [blame] | 129 | <input
|
| 130 | className="search-input"
|
| 131 | placeholder="输入搜索关键词"
|
| 132 | value={searchText}
|
| 133 | onChange={e => setSearchText(e.target.value)}
|
| 134 | />
|
| 135 | <button className="search-btn" onClick={handleSearch}>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 136 | <span role="img" aria-label="search">🔍</span>
|
| 137 | </button>
|
| 138 | </div>
|
| 139 | <div className="area-tabs" style={{ display: 'flex', justifyContent: 'center', gap: 24, margin: '18px 0' }}>
|
| 140 | {areaTabs.map((tab, idx) => (
|
| 141 | <div
|
| 142 | key={tab.label}
|
| 143 | className={activeTab === idx ? "area-tab active" : "area-tab"}
|
| 144 | onClick={() => setActiveTab(idx)}
|
| 145 | >
|
| 146 | {tab.icon} <span>{tab.label}</span>
|
| 147 | </div>
|
| 148 | ))}
|
| 149 | </div>
|
| 150 | <div className="table-section">
|
| 151 | <table className="movie-table">
|
| 152 | <thead>
|
| 153 | <tr>
|
| 154 | <th>剧集类型</th>
|
| 155 | <th>标题</th>
|
| 156 | <th>发布者</th>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame^] | 157 | <th>大小</th>
|
| 158 | <th>热度</th>
|
| 159 | <th>折扣倍率</th>
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 160 | </tr>
|
| 161 | </thead>
|
| 162 | <tbody>
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 163 | {tvList.length > 0 ? (
|
| 164 | tvList.map((item, index) => (
|
| 165 | <tr key={item.id || index}>
|
| 166 | <td>
|
| 167 | <a href={`/torrent/${item.seedid}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
|
| 168 | {item.seedtag}
|
| 169 | </a>
|
| 170 | </td>
|
| 171 | <td>
|
| 172 | <a href={`/torrent/${item.seedid}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
|
| 173 | {item.title}
|
| 174 | </a>
|
| 175 | </td>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame^] | 176 | <td>{item.username}</td>
|
| 177 | <td>{item.seedsize}</td>
|
| 178 | <td>{item.downloadtimes}</td>
|
| 179 | <td>{item.discount == null ? 1 : item.discount}</td>
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 180 | </tr>
|
| 181 | ))
|
| 182 | ) : (
|
| 183 | tvTypes.map((type, index) => (
|
| 184 | <tr key={type}>
|
| 185 | <td>
|
| 186 | <a href={`/torrent/${type}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
|
| 187 | {type}
|
| 188 | </a>
|
| 189 | </td>
|
| 190 | <td>
|
| 191 | <a href={`/torrent/${type}`} style={{ color: '#1a237e', textDecoration: 'none' }}>
|
| 192 | 种子{index + 1}
|
| 193 | </a>
|
| 194 | </td>
|
| 195 | <td>发布者{index + 1}</td>
|
wht | 338fc03 | 2025-06-09 17:16:22 +0800 | [diff] [blame^] | 196 | <td>--</td>
|
| 197 | <td>--</td>
|
| 198 | <td>1</td>
|
rhj | c6a4ee0 | 2025-06-06 00:45:18 +0800 | [diff] [blame] | 199 | </tr>
|
| 200 | ))
|
| 201 | )}
|
956303669 | a32fc2c | 2025-06-02 19:45:53 +0800 | [diff] [blame] | 202 | </tbody>
|
| 203 | </table>
|
| 204 | </div>
|
| 205 | <div style={{ height: 32 }} />
|
| 206 | <Pagination />
|
| 207 | </div>
|
| 208 | );
|
| 209 | }
|
| 210 |
|
| 211 | function Pagination() {
|
| 212 | const [page, setPage] = React.useState(3);
|
| 213 | const total = 5;
|
| 214 | return (
|
| 215 | <div className="pagination">
|
| 216 | <button onClick={() => setPage(p => Math.max(1, p - 1))} disabled={page === 1}>上一页</button>
|
| 217 | <span className="page-num">{page}/{total}</span>
|
| 218 | <button onClick={() => setPage(p => Math.min(total, p + 1))} disabled={page === total}>下一页</button>
|
| 219 | <span className="page-info">第 <b>{page}</b> 页</span>
|
| 220 | </div>
|
| 221 | );
|
| 222 | }
|