import React from "react"; | |
import MovieIcon from "@mui/icons-material/Movie"; | |
import EmailIcon from "@mui/icons-material/Email"; | |
import MusicNoteIcon from "@mui/icons-material/MusicNote"; | |
import EmojiPeopleIcon from "@mui/icons-material/EmojiPeople"; | |
import SportsEsportsIcon from "@mui/icons-material/SportsEsports"; | |
import SportsMartialArtsIcon from "@mui/icons-material/SportsMartialArts"; | |
import PersonIcon from "@mui/icons-material/Person"; | |
import AccountCircleIcon from "@mui/icons-material/AccountCircle"; | |
import "./App.css"; | |
import { useNavigate } from "react-router-dom"; | |
import { API_BASE_URL } from "./config"; | |
const navItems = [ | |
{ label: "电影", icon: <MovieIcon />, path: "/movie" }, | |
{ label: "剧集", icon: <EmailIcon />, path: "/tv" }, | |
{ label: "音乐", icon: <MusicNoteIcon />, path: "/music" }, | |
{ label: "动漫", icon: <EmojiPeopleIcon />, path: "/anime" }, | |
{ label: "游戏", icon: <SportsEsportsIcon />, path: "/game" }, | |
{ label: "体育", icon: <SportsMartialArtsIcon />, path: "/sport" }, | |
{ label: "资料", icon: <PersonIcon />, path: "/info" }, | |
{ label: "发布", icon: <AccountCircleIcon />, path: "/publish" }, // Added Publish option | |
]; | |
const areaTabs = [ | |
{ label: "古典音乐", icon: <MovieIcon fontSize="small" /> }, | |
{ label: "流行音乐", icon: <EmailIcon fontSize="small" /> }, | |
{ label: "摇滚", icon: <PersonIcon fontSize="small" /> }, | |
{ label: "电子音乐", icon: <EmojiPeopleIcon fontSize="small" /> }, | |
{ label: "说唱", icon: <PersonIcon fontSize="small" /> }, | |
]; | |
const exampleTorrents = [ | |
{ type: "Pop", title: "实例1", id: 1 }, | |
{ type: "Rock", title: "实例2", id: 2 }, | |
{ type: "Jazz", title: "实例3", id: 3 }, | |
]; | |
export default function MusicPage() { | |
const navigate = useNavigate(); | |
const [activeTab, setActiveTab] = React.useState(0); | |
const [musicList, setMusicList] = React.useState([]); | |
// 每个tab对应的音乐类型 | |
const musicTypesList = [ | |
["华语音乐(大陆)", "欧美音乐", "日韩音乐", "港台音乐", "其他"], // 大陆 | |
["港台流行", "港台摇滚", "港台其他"], // 港台 | |
["欧美流行", "欧美摇滚", "欧美其他"], // 欧美 | |
["日韩流行", "日韩其他"], // 日韩 | |
["其他类型1", "其他类型2"] // 其他 | |
]; | |
const musicTypes = musicTypesList[activeTab] || []; | |
React.useEffect(() => { | |
// 假设后端接口为 /api/musics?area=大陆 | |
const area = areaTabs[activeTab].label; | |
fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`) | |
.then(res => res.json()) | |
.then(data => setMusicList(data)) | |
.catch(() => setMusicList([])); | |
}, [activeTab]); | |
return ( | |
<div className="container music-bg"> | |
{/* 顶部空白与音乐界面一致,用户栏绝对定位在页面右上角 */} | |
<div style={{ height: 80 }} /> | |
<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 }}> | |
<div style={{ cursor: 'pointer', marginRight: 16 }} onClick={() => navigate('/user')}> | |
<AccountCircleIcon style={{ fontSize: 38, color: '#1a237e', background: '#e0f3ff', borderRadius: '50%' }} /> | |
</div> | |
<div style={{ color: '#222', fontWeight: 500, marginRight: 24 }}>用户栏</div> | |
<div style={{ display: 'flex', gap: 28, flex: 1, justifyContent: 'flex-end', alignItems: 'center' }}> | |
<span style={{ color: '#1976d2', fontWeight: 500 }}>魔力值: <b>12345</b></span> | |
<span style={{ color: '#1976d2', fontWeight: 500 }}>分享率: <b>2.56</b></span> | |
<span style={{ color: '#1976d2', fontWeight: 500 }}>上传量: <b>100GB</b></span> | |
<span style={{ color: '#1976d2', fontWeight: 500 }}>下载量: <b>50GB</b></span> | |
</div> | |
</div> | |
{/* 下方内容整体下移,留出与其他页面一致的间距 */} | |
<div style={{ height: 32 }} /> | |
<nav className="nav-bar card"> | |
{navItems.map((item) => ( | |
<div | |
key={item.label} | |
className={item.label === "音乐" ? "nav-item active" : "nav-item"} | |
onClick={() => navigate(item.path)} | |
> | |
{item.icon} | |
<span>{item.label}</span> | |
</div> | |
))} | |
</nav> | |
<div className="search-section card"> | |
<input className="search-input" placeholder="输入搜索关键词" /> | |
<button className="search-btn"> | |
<span role="img" aria-label="search">🔍</span> | |
</button> | |
</div> | |
<div className="area-tabs card" style={{ display: 'flex', justifyContent: 'center', gap: 24, margin: '18px 0' }}> | |
{areaTabs.map((tab, idx) => ( | |
<div | |
key={tab.label} | |
className={activeTab === idx ? "area-tab active" : "area-tab"} | |
onClick={() => setActiveTab(idx)} | |
> | |
{tab.icon} <span>{tab.label}</span> | |
</div> | |
))} | |
</div> | |
<div className="table-section"> | |
<table className="music-table"> | |
<thead> | |
<tr> | |
<th>音乐类型</th> | |
<th>标题</th> | |
<th>发布者</th> | |
</tr> | |
</thead> | |
<tbody> | |
{musicList.length > 0 ? ( | |
musicList.map((item, index) => ( | |
<tr key={item.id || index}> | |
<td> | |
<a href={`/torrent/${item.seedid}`} style={{ color: '#1a237e', textDecoration: 'none' }}> | |
{item.seedtag} | |
</a> | |
</td> | |
<td> | |
<a href={`/torrent/${item.seedid}`} style={{ color: '#1a237e', textDecoration: 'none' }}> | |
{item.title} | |
</a> | |
</td> | |
<td>{item.user.username}</td> | |
</tr> | |
)) | |
) : ( | |
musicTypes.map((type, index) => ( | |
<tr key={type}> | |
<td> | |
<a href={`/torrent/${type}`} style={{ color: '#1a237e', textDecoration: 'none' }}> | |
{type} | |
</a> | |
</td> | |
<td> | |
<a href={`/torrent/${type}`} style={{ color: '#1a237e', textDecoration: 'none' }}> | |
种子{index + 1} | |
</a> | |
</td> | |
<td>发布者{index + 1}</td> | |
</tr> | |
)) | |
)} | |
</tbody> | |
</table> | |
</div> | |
<div style={{ height: 32 }} /> | |
<Pagination /> | |
</div> | |
); | |
} | |
function Pagination() { | |
const [page, setPage] = React.useState(3); | |
const total = 5; | |
return ( | |
<div className="pagination"> | |
<button onClick={() => setPage(p => Math.max(1, p - 1))} disabled={page === 1}>上一页</button> | |
<span className="page-num">{page}/{total}</span> | |
<button onClick={() => setPage(p => Math.min(total, p + 1))} disabled={page === total}>下一页</button> | |
<span className="page-info">第 <b>{page}</b> 页</span> | |
</div> | |
); | |
} |