通知与推荐功能,css样式优化

Change-Id: I33d934bfdca88b7a8e6742be2a3c7323d28ffbcf
diff --git a/src/components/Dashboard.jsx b/src/components/Dashboard.jsx
index 61111f3..e393fcd 100644
--- a/src/components/Dashboard.jsx
+++ b/src/components/Dashboard.jsx
@@ -72,6 +72,9 @@
     const [recommendations, setRecommendations] = useState([]);

     const [recommendLoading, setRecommendLoading] = useState(false);

     const [recommendError, setRecommendError] = useState(null);

+    const [isRecommend, setIsRecommend] = useState(true);

+    const [needNewRecommend, setNeedNewRecommend] = useState(false);

+

 

 

 

@@ -101,18 +104,28 @@
     }

     };

 

+   // 修改 useEffect 钩子

     useEffect(() => {

         if (activeTab === 'announcement') {

             fetchAnnouncements();

             fetchDiscountsForCarousel();

-            fetchRecommendations();

+            

+            // 只在需要时获取推荐

+            if (isRecommend || needNewRecommend) {

+                fetchRecommendations();

+            }

         }

-    }, [activeTab]);

+    }, [activeTab, isRecommend, needNewRecommend]);

+

+    // 添加刷新推荐的功能

+    const handleRefreshRecommendations = () => {

+        setNeedNewRecommend(true);

+    };

 

     const fetchDiscountsForCarousel = async () => {

         try {

             const all = await getAllDiscounts();

-            console.log("返回的折扣数据:", all);

+            // console.log("返回的折扣数据:", all);

             const now = new Date();

 

             // ⚠️ 使用 Date.parse 确保兼容 ISO 格式

@@ -353,19 +366,10 @@
     setIsDownloading(true);

     setDownloadProgress(0);

 

-    try {

-        // 标准化路径

-        const cleanPath = downloadPath

-        .replace(/\\/g, '/')  // 统一使用正斜杠

-        .replace(/\/+/g, '/') // 去除多余斜杠

-        .trim();

-

-        // 确保路径以斜杠结尾

-        const finalPath = cleanPath.endsWith('/') ? cleanPath : cleanPath + '/';

-

+    try {      

         // 发起下载请求

-        await downloadTorrent(selectedTorrent.id, finalPath);

-        

+        await downloadTorrent(selectedTorrent.id, downloadPath);

+        message.success("下载任务已提交");

         // 开始轮询进度

         const interval = setInterval(async () => {

             try {

@@ -374,7 +378,7 @@
                 

                 if (progresses) {

                     // 使用完整的 torrent 文件路径作为键

-                    const torrentPath = selectedTorrent.filePath.replace(/\\/g, '/');

+                    const torrentPath = selectedTorrent.downloadPath.replace(/\\/g, '/');

                     const torrentHash = selectedTorrent.hash;

                     // 查找匹配的进度

                     let foundProgress = null;

@@ -404,7 +408,7 @@
                 } catch (error) {

                     console.error('获取进度失败:', error);

                     // 如果获取进度失败但文件已存在,也视为完成

-                    const filePath = `${finalPath}${selectedTorrent.torrentName || 'downloaded_file'}`;

+                    const filePath = `${downloadPath}${selectedTorrent.torrentName || 'downloaded_file'}`;

                     try {

                     const exists = await checkFileExists(filePath);

                     if (exists) {

@@ -640,24 +644,37 @@
         }

     };

 

-    const fetchRecommendations = async () => {

-        try {

-            setRecommendLoading(true);

-            const response = await getRecommendations(5);

-            if (response.code === 200) {

-            setRecommendations(response.data || []);

+    // 修改 fetchRecommendations 函数

+const fetchRecommendations = async () => {

+    try {

+        setRecommendLoading(true);

+        const response = await getRecommendations(5);

+        

+        if (Array.isArray(response)) {

+            setRecommendations(response);

             

-            // 标记这些推荐为已显示

-            response.data.forEach(torrent => {

-                markRecommendationShown(torrent.id);

-            });

+            if (response.length === 0) {

+                console.warn('暂无推荐内容');

+            } else {

+                // 标记这些推荐为已显示

+                response.forEach(torrent => {

+                    markRecommendationShown(torrent.id);

+                });

             }

-        } catch (error) {

-            setRecommendError(error.message || '获取推荐失败');

-        } finally {

-            setRecommendLoading(false);

+            

+            // 获取成功后重置标志

+            setIsRecommend(false);

+            setNeedNewRecommend(false);

+        } else {

+            console.warn('返回格式异常:', response);

+            setRecommendations([]);

         }

-    };

+    } catch (error) {

+        setRecommendError(error.message || '获取推荐失败');

+    } finally {

+        setRecommendLoading(false);

+    }

+};

 

 

     useEffect(() => {

@@ -798,7 +815,7 @@
         try {

           setLoading(true);

           const backendData = await getUserInfo(); // 调用修改后的方法

-          console.log('后端返回的用户数据:', backendData); // 调试用

+        //   console.log('后端返回的用户数据:', backendData); // 调试用

           

           setUserInfo({

             name: backendData.username || '演示用户',

@@ -902,11 +919,20 @@
                         </div>

                         {/* 新增的为你推荐区域 */}

                         <div className="recommend-section">

-                            <h2 className="section-title">为你推荐</h2>

+                            <div className="section-header">

+                                <h2 className="section-title">为你推荐</h2>

+                                <button 

+                                    className="refresh-btn"

+                                    onClick={handleRefreshRecommendations}

+                                    disabled={recommendLoading}

+                                >

+                                    {recommendLoading ? '刷新中...' : '刷新推荐'}

+                                </button>

+                            </div>

                             

                             {recommendLoading && <div className="loading">加载推荐中...</div>}

                             {recommendError && <div className="error">{recommendError}</div>}

-                            

+    

                             <div className="recommend-grid">

                             {recommendations.map(torrent => (

                                 <div 

@@ -1225,11 +1251,11 @@
             case 'request':

                 return (

                     <div className="content-area" data-testid="request-section">

-                        {/* 求助区搜索框 */}

+                        {/* 求种区搜索框 */}

                         <div className="section-search-container">

                             <input

                                 type="text"

-                                placeholder="搜索求助..."

+                                placeholder="搜索求种..."

                                 value={requestSearch}

                                 onChange={(e) => setRequestSearch(e.target.value)}

                                 className="section-search-input"