修改前端页面

Change-Id: I344849fc3dfca5725e0ef2a107e2c89a14fce8da
diff --git a/front/src/SportPage.js b/front/src/SportPage.js
index 7dc452d..2874495 100644
--- a/front/src/SportPage.js
+++ b/front/src/SportPage.js
@@ -1,4 +1,5 @@
 import React, { useState, useEffect } from "react";

+import HomeIcon from "@mui/icons-material/Home";

 import MovieIcon from "@mui/icons-material/Movie";

 import EmailIcon from "@mui/icons-material/Email";

 import MusicNoteIcon from "@mui/icons-material/MusicNote";

@@ -7,12 +8,14 @@
 import SportsMartialArtsIcon from "@mui/icons-material/SportsMartialArts";

 import PersonIcon from "@mui/icons-material/Person";

 import AccountCircleIcon from "@mui/icons-material/AccountCircle";

+import ForumIcon from "@mui/icons-material/Forum";

+import HelpIcon from "@mui/icons-material/Help";

 import "./App.css";

 import { useNavigate } from "react-router-dom";

 import { API_BASE_URL } from "./config";

-import ForumIcon from "@mui/icons-material/Forum";

 

 const navItems = [

+  { label: "首页", icon: <HomeIcon />, path: "/home" },

   { label: "电影", icon: <MovieIcon />, path: "/movie" },

   { label: "剧集", icon: <EmailIcon />, path: "/tv" },

   { label: "音乐", icon: <MusicNoteIcon />, path: "/music" },

@@ -21,65 +24,56 @@
   { label: "体育", icon: <SportsMartialArtsIcon />, path: "/sport" },

   { label: "资料", icon: <PersonIcon />, path: "/info" },

   { label: "论坛", icon: <ForumIcon />, path: "/forum" },

-  { label: "发布", icon: <AccountCircleIcon />, path: "/publish" }, // Added Publish option

+  { label: "发布", icon: <AccountCircleIcon />, path: "/publish" },

+  { label: "求种", icon: <HelpIcon />, path: "/begseed" },

 ];

 

-const sportTypes = [""];

-

 const areaTabs = [

   { label: "篮球", icon: <MovieIcon fontSize="small" /> },

   { label: "足球", icon: <EmailIcon fontSize="small" /> },

   { label: "羽毛球", icon: <EmojiPeopleIcon fontSize="small" /> },

   { label: "排球", icon: <PersonIcon fontSize="small" /> },

-  { label: "电竞", icon: <PersonIcon fontSize="small" />, active: true },

-];

-

-const exampleTorrents = [

-  { type: "Soccer", title: "实例1", id: 1 },

-  { type: "Basketball", title: "实例2", id: 2 },

-  { type: "Tennis", title: "实例3", id: 3 },

+  { label: "电竞", icon: <PersonIcon fontSize="small" /> },

 ];

 

 export default function SportPage() {

   const navigate = useNavigate();

-    const [searchText, setSearchText] = React.useState('');

-    const [userInfo, setUserInfo] = useState({ avatar_url: '', username: '' });

-    const [userPT, setUserPT] = useState({ magic: 0, ratio: 0, upload: 0, download: 0 });

-  const [activeTab, setActiveTab] = React.useState(0);

-  const [sportList, setSportList] = React.useState([]);

+  const [searchText, setSearchText] = useState('');

+  const [userInfo, setUserInfo] = useState({ avatar_url: '', username: '' });

+  const [userPT, setUserPT] = useState({ magic: 0, ratio: 0, upload: 0, download: 0 });

+  const [activeTab, setActiveTab] = useState(0);

+  const [sportList, setSportList] = useState([]);

 

-    useEffect(() => {

-      const match = document.cookie.match('(^|;)\\s*userId=([^;]+)');

-      const userId = match ? match[2] : null;

-      console.log("User ID from cookie:", userId);

-      if (!userId) return;

-      fetch(`${API_BASE_URL}/api/get-userpt?userid=${encodeURIComponent(userId)}`)

-        .then(res => res.json())

-        .then(data => {

-          console.log('用户PT信息:', data); 

-          setUserInfo({ avatar_url: data.user.avatar_url, username: data.user.username });

-          setUserPT({

-            magic: data.magic_value || data.magic || 0,

-            ratio: data.share_ratio || data.share || 0,

-            upload: data.upload_amount || data.upload || 0,

-            download: data.download_amount || data.download || 0,

-          });

-        })

-        .catch(err => console.error('Fetching user profile failed', err));

-    }, []);

+  useEffect(() => {

+    const match = document.cookie.match('(^|;)\\s*userId=([^;]+)');

+    const userId = match ? match[2] : null;

+    if (!userId) return;

+    fetch(`${API_BASE_URL}/api/get-userpt?userid=${encodeURIComponent(userId)}`)

+      .then(res => res.json())

+      .then(data => {

+        setUserInfo({ avatar_url: data.user.avatar_url, username: data.user.username });

+        setUserPT({

+          magic: data.magic_value || data.magic || 0,

+          ratio: data.share_ratio || data.share || 0,

+          upload: data.upload_amount || data.upload || 0,

+          download: data.download_amount || data.download || 0,

+        });

+      })

+      .catch(err => console.error('Fetching user profile failed', err));

+  }, []);

 

-  // 每个tab对应的运动类型

+  // 每个tab对应的体育类型

   const sportTypesList = [

     ["篮球赛事", "篮球技巧", "篮球明星"], // 篮球

     ["足球赛事", "足球技巧", "足球明星"], // 足球

     ["羽毛球赛事", "羽毛球技巧"], // 羽毛球

     ["排球赛事", "排球技巧"], // 排球

     ["电竞赛事", "电竞技巧"], // 电竞

+    ["其他类型1", "其他类型2"] // 其他

   ];

   const sportTypes = sportTypesList[activeTab] || [];

 

-  React.useEffect(() => {

-    // 假设后端接口为 /api/sports?area=篮球

+  useEffect(() => {

     const area = areaTabs[activeTab].label;

     fetch(`${API_BASE_URL}/api/get-seed-list-by-tag?tag=${encodeURIComponent(area)}`)

       .then(res => res.json())

@@ -87,21 +81,20 @@
       .catch(() => setSportList([]));

   }, [activeTab]);

 

-    // 搜索按钮处理

-    const handleSearch = () => {

-      const area = areaTabs[activeTab].label;

-      fetch(`${API_BASE_URL}/api/search-seeds?tag=${encodeURIComponent(area)}&keyword=${encodeURIComponent(searchText)}`)

-        .then(res => res.json())

-        .then(data => {

-          console.log('搜索返回数据:', data);

-          setSportList(data);

-        })

-        .catch(() => setSportList([]));

-    };

+  // 搜索按钮处理

+  const handleSearch = () => {

+    const area = areaTabs[activeTab].label;

+    fetch(`${API_BASE_URL}/api/search-seeds?tag=${encodeURIComponent(area)}&keyword=${encodeURIComponent(searchText)}`)

+      .then(res => res.json())

+      .then(data => {

+        setSportList(data);

+      })

+      .catch(() => setSportList([]));

+  };

 

   return (

     <div className="container">

-      {/* 顶部空白与音乐界面一致,用户栏绝对定位在页面右上角 */}

+      {/* 顶部空白与体育界面一致,用户栏绝对定位在页面右上角 */}

       <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')}>

@@ -119,7 +112,7 @@
           <span style={{ color: '#1976d2', fontWeight: 500 }}>下载量: <b>{userPT.download}</b></span>

         </div>

       </div>

-      {/* 下方内容整体下移,留出与音乐界面一致的间距 */}

+      {/* 下方内容整体下移,留出与体育界面一致的间距 */}

       <div style={{ height: 32 }} />

       <nav className="nav-bar card">

         {navItems.map((item) => (

@@ -144,15 +137,7 @@
           <span role="img" aria-label="search">🔍</span>

         </button>

       </div>

-      <div

-        className="area-tabs"

-        style={{

-          display: "flex",

-          justifyContent: "center",

-          gap: 24,

-          margin: "18px 0",

-        }}

-      >

+      <div className="area-tabs" style={{ display: 'flex', justifyContent: 'center', gap: 24, margin: '18px 0' }}>

         {areaTabs.map((tab, idx) => (

           <div

             key={tab.label}

@@ -170,6 +155,9 @@
               <th>体育类型</th>

               <th>标题</th>

               <th>发布者</th>

+              <th>大小</th>

+              <th>热度</th>

+              <th>折扣倍率</th>

             </tr>

           </thead>

           <tbody>

@@ -186,7 +174,10 @@
                       {item.title}

                     </a>

                   </td>

-                  <td>{item.user.username}</td>

+                  <td>{item.username}</td>

+                  <td>{item.seedsize}</td>

+                  <td>{item.downloadtimes}</td>

+                  <td>{item.discount == null ? 1 : item.discount}</td>

                 </tr>

               ))

             ) : (

@@ -203,6 +194,9 @@
                     </a>

                   </td>

                   <td>发布者{index + 1}</td>

+                  <td>--</td>

+                  <td>--</td>

+                  <td>1</td>

                 </tr>

               ))

             )}

@@ -220,24 +214,10 @@
   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>

+      <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>

   );

-}

+}
\ No newline at end of file