22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 1 | // export default SeedList; |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 2 | import React, { useState, useEffect } from 'react'; |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 3 | import { Link } from 'wouter'; |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 4 | import axios from 'axios'; |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 5 | import Recommend from './Recommend/Recommend'; |
22301009 | f9641c5 | 2025-04-15 21:14:56 +0800 | [diff] [blame] | 6 | import Header from '../../components/Header'; // 引入 Header 组件 |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 7 | import './SeedList.css'; |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 8 | import { useUser } from '../../context/UserContext'; |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 9 | |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 10 | const SeedList = () => { |
| 11 | const [seeds, setSeeds] = useState([]); |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 12 | const [loading, setLoading] = useState(true); |
| 13 | const [searchTerm, setSearchTerm] = useState(''); |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 14 | const [sortOption, setSortOption] = useState('最新'); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 15 | const [activeTab, setActiveTab] = useState('种子列表'); |
| 16 | const [filters, setFilters] = useState({}); |
| 17 | const [selectedFilters, setSelectedFilters] = useState({}); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 18 | const [tagMode, setTagMode] = useState('any'); // 与接口对应,any / all |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 19 | const [errorMsg, setErrorMsg] = useState(''); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 20 | const { user } = useUser(); |
| 21 | |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 22 | const TAGS = ['猜你喜欢', '电影', '电视剧', '动漫', '音乐', '游戏', '综艺', '软件', '体育', '学习', '纪录片', '其他']; |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 23 | |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 24 | const CATEGORY_MAP = { |
| 25 | '电影': 'movie', |
| 26 | '电视剧': 'tv', |
| 27 | '动漫': 'anime', |
| 28 | '音乐': 'music', |
| 29 | '游戏': 'game', |
| 30 | '综艺': 'variety', |
| 31 | '软件': 'software', |
| 32 | '体育': 'sports', |
| 33 | '学习': 'study', |
| 34 | '纪录片': 'documentary', |
| 35 | '其他': 'other', |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 36 | '猜你喜欢': '', |
| 37 | '种子列表': '', |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 38 | }; |
| 39 | |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 40 | |
| 41 | const buildQueryParams = () => { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 42 | const category = CATEGORY_MAP[activeTab] || ''; |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 43 | const orderKey = sortOption === '最新' ? 'upload_time' : (sortOption === '最热' ? 'downloads' : 'upload_time'); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 44 | const params = { |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 45 | page: 1, |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 46 | size: 20, |
| 47 | orderKey, |
| 48 | orderDesc: true, |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 49 | }; |
| 50 | |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 51 | if (searchTerm.trim()) { |
| 52 | params.title = searchTerm.trim(); |
| 53 | } |
| 54 | if (category) { |
| 55 | params.category = category; |
| 56 | } |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 57 | |
| 58 | const tags = Object.entries(selectedFilters) |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 59 | .filter(([_, value]) => value !== '不限') |
| 60 | .map(([_, value]) => value); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 61 | |
| 62 | if (tags.length > 0) { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 63 | params.tags = tags; |
| 64 | params.tagMode = tagMode; // any 或 all |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 65 | } |
| 66 | |
| 67 | return params; |
| 68 | }; |
| 69 | |
| 70 | const fetchSeeds = async () => { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 71 | if (activeTab === '猜你喜欢') return; |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 72 | setLoading(true); |
| 73 | setErrorMsg(''); |
| 74 | try { |
| 75 | const params = buildQueryParams(); |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 76 | const response = await axios.get('/seeds/list', { params }); |
Krishya | 6bf199c | 2025-06-06 21:14:23 +0800 | [diff] [blame] | 77 | |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 78 | const data = response.data; |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 79 | |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 80 | if (data.code !== 0) { |
| 81 | throw new Error(data.msg || '获取失败'); |
| 82 | } |
| 83 | |
| 84 | setSeeds(data.data || []); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 85 | } catch (error) { |
| 86 | console.error('获取种子列表失败:', error); |
| 87 | setErrorMsg(error.message || '获取失败,请稍后再试。'); |
| 88 | setSeeds([]); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 89 | } finally { |
| 90 | setLoading(false); |
| 91 | } |
| 92 | }; |
| 93 | |
| 94 | const fetchFilterOptions = async () => { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 95 | if (activeTab === '猜你喜欢' || !CATEGORY_MAP[activeTab]) return; |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 96 | const category = CATEGORY_MAP[activeTab]; |
| 97 | try { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 98 | const res = await axios.get(`/seed-filters?category=${category}`); |
22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame] | 99 | const filterData = res.data || {}; |
| 100 | setFilters(filterData); |
| 101 | |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 102 | const defaultSelections = {}; |
22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame] | 103 | for (const key in filterData) { |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 104 | defaultSelections[key] = '不限'; |
| 105 | } |
| 106 | setSelectedFilters(defaultSelections); |
| 107 | } catch (err) { |
| 108 | console.error('获取筛选项失败:', err); |
| 109 | setFilters({}); |
| 110 | setSelectedFilters({}); |
| 111 | } |
| 112 | }; |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 113 | |
| 114 | useEffect(() => { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 115 | fetchFilterOptions(); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 116 | }, [activeTab]); |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 117 | |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 118 | useEffect(() => { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 119 | fetchSeeds(); |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 120 | }, [activeTab, sortOption, selectedFilters, tagMode, searchTerm]); |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 121 | |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 122 | const handleDownload = async (seedId) => { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 123 | if (!user || !user.userId) { |
| 124 | alert('请先登录再下载种子文件'); |
| 125 | return; |
| 126 | } |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 127 | |
| 128 | try { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 129 | const response = await axios.get(`/seeds/${seedId}/download`, { |
| 130 | params: { |
| 131 | passkey: user.userId, |
| 132 | }, |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 133 | responseType: 'blob' |
| 134 | }); |
| 135 | |
| 136 | const blob = new Blob([response.data], { type: 'application/x-bittorrent' }); |
| 137 | const downloadUrl = URL.createObjectURL(blob); |
| 138 | const a = document.createElement('a'); |
| 139 | a.href = downloadUrl; |
| 140 | a.download = `${seedId}.torrent`; |
| 141 | a.click(); |
| 142 | URL.revokeObjectURL(downloadUrl); |
| 143 | } catch (error) { |
| 144 | console.error('下载失败:', error); |
| 145 | alert('下载失败,请稍后再试。'); |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 146 | } |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 147 | }; |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 148 | |
22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame] | 149 | const handleFilterChange = (key, value) => { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 150 | setSelectedFilters(prev => ({ |
| 151 | ...prev, |
22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame] | 152 | [key]: value |
| 153 | })); |
| 154 | }; |
| 155 | |
| 156 | const clearFilter = (key) => { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 157 | setSelectedFilters(prev => ({ |
| 158 | ...prev, |
22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame] | 159 | [key]: '不限' |
| 160 | })); |
| 161 | }; |
| 162 | |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 163 | return ( |
Krishya | f1d0ea8 | 2025-05-03 17:01:58 +0800 | [diff] [blame] | 164 | <div className="seed-list-container"> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 165 | <Header /> |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 166 | |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 167 | <div className="controls"> |
| 168 | <input |
| 169 | type="text" |
| 170 | placeholder="搜索种子..." |
| 171 | value={searchTerm} |
| 172 | onChange={(e) => setSearchTerm(e.target.value)} |
| 173 | className="search-input" |
| 174 | /> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 175 | <select |
| 176 | value={sortOption} |
| 177 | onChange={(e) => setSortOption(e.target.value)} |
| 178 | className="sort-select" |
| 179 | > |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 180 | <option value="最新">最新</option> |
| 181 | <option value="最热">最热</option> |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 182 | </select> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 183 | <select |
| 184 | value={tagMode} |
| 185 | onChange={(e) => setTagMode(e.target.value)} |
| 186 | className="tag-mode-select" |
| 187 | > |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 188 | <option value="any">包含任意标签</option> |
| 189 | <option value="all">包含所有标签</option> |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 190 | </select> |
| 191 | </div> |
| 192 | |
| 193 | <div className="tag-filters"> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 194 | {TAGS.map(tag => ( |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 195 | <button |
| 196 | key={tag} |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 197 | className={`tag-button ${activeTab === tag ? 'active-tag' : ''}`} |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 198 | onClick={() => { |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 199 | setActiveTab(tag); |
| 200 | setFilters({}); |
| 201 | setSelectedFilters({}); |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 202 | }} |
| 203 | > |
| 204 | {tag} |
| 205 | </button> |
| 206 | ))} |
| 207 | </div> |
| 208 | |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 209 | {activeTab !== '猜你喜欢' && Object.keys(filters).length > 0 && ( |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 210 | <div className="filter-bar"> |
| 211 | {Object.entries(filters).map(([key, options]) => ( |
| 212 | <div className="filter-group" key={key}> |
| 213 | <label>{key}:</label> |
| 214 | <select |
| 215 | value={selectedFilters[key]} |
22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame] | 216 | onChange={(e) => handleFilterChange(key, e.target.value)} |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 217 | > |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 218 | {options.map(opt => ( |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 219 | <option key={opt} value={opt}>{opt}</option> |
| 220 | ))} |
| 221 | </select> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 222 | {selectedFilters[key] !== '不限' && ( |
| 223 | <button |
| 224 | className="clear-filter-btn" |
| 225 | onClick={() => clearFilter(key)} |
| 226 | > |
| 227 | ✕ |
| 228 | </button> |
22301009 | 5b28c67 | 2025-04-10 20:12:45 +0800 | [diff] [blame] | 229 | )} |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 230 | </div> |
| 231 | ))} |
| 232 | </div> |
| 233 | )} |
| 234 | |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 235 | <div className="seed-list-content"> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 236 | {activeTab === '猜你喜欢' ? ( |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 237 | <Recommend /> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 238 | ) : loading ? ( |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 239 | <p>加载中...</p> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 240 | ) : errorMsg ? ( |
22301009 | afbcf4b | 2025-04-10 16:08:39 +0800 | [diff] [blame] | 241 | <p className="error-text">{errorMsg}</p> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 242 | ) : seeds.length === 0 ? ( |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 243 | <p>未找到符合条件的种子。</p> |
| 244 | ) : ( |
Krishya | 25590de | 2025-04-21 19:03:49 +0800 | [diff] [blame] | 245 | <div className="seed-list-card"> |
| 246 | <div className="seed-list-header"> |
| 247 | <div className="seed-header-cover"></div> |
| 248 | <div className="seed-header-title">种子名称</div> |
| 249 | <div className="seed-header-size">大小</div> |
| 250 | <div className="seed-header-upload-time">上传时间</div> |
| 251 | <div className="seed-header-downloads">下载次数</div> |
| 252 | <div className="seed-header-actions">操作</div> |
| 253 | </div> |
| 254 | <div className="seed-list-body"> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 255 | {seeds.map((seed, index) => { |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 256 | let tagsArray = []; |
| 257 | if (seed.tags) { |
| 258 | if (Array.isArray(seed.tags)) { |
| 259 | tagsArray = seed.tags; |
| 260 | } else if (typeof seed.tags === 'string') { |
| 261 | try { |
| 262 | tagsArray = JSON.parse(seed.tags); |
| 263 | if (!Array.isArray(tagsArray)) { |
22301111 | a289e26 | 2025-06-07 22:38:46 +0800 | [diff] [blame^] | 264 | tagsArray = seed.tags.split(',').map(t => t.trim()).filter(t => t); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 265 | } |
| 266 | } catch { |
22301111 | a289e26 | 2025-06-07 22:38:46 +0800 | [diff] [blame^] | 267 | tagsArray = seed.tags.split(',').map(t => t.trim()).filter(t => t); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 268 | } |
| 269 | } |
| 270 | } |
| 271 | |
| 272 | return ( |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 273 | <Link to={`/seed/${seed.id}`} key={index} className="seed-item-link"> |
| 274 | <div className="seed-item"> |
22301009 | 4158f3a | 2025-06-06 19:59:10 +0800 | [diff] [blame] | 275 | {seed.imageUrl && ( |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 276 | <img |
22301009 | 4158f3a | 2025-06-06 19:59:10 +0800 | [diff] [blame] | 277 | src={seed.imageUrl} |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 278 | alt={seed.title} |
| 279 | className="seed-item-cover" |
| 280 | /> |
| 281 | )} |
22301009 | 4158f3a | 2025-06-06 19:59:10 +0800 | [diff] [blame] | 282 | |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 283 | <div className="seed-item-title"> |
| 284 | <div className="seed-title-row"> |
| 285 | <h3 className="seed-title">{seed.title}</h3> |
| 286 | <div className="seed-tags"> |
| 287 | {tagsArray.map((tag, i) => ( |
| 288 | <span key={i} className="tag-label">{tag}</span> |
| 289 | ))} |
| 290 | </div> |
Krishya | 25590de | 2025-04-21 19:03:49 +0800 | [diff] [blame] | 291 | </div> |
| 292 | </div> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 293 | <div className="seed-item-size">{seed.size || '未知'}</div> |
| 294 | <div className="seed-item-upload-time">{seed.upload_time?.split('T')[0] || '未知'}</div> |
| 295 | <div className="seed-item-downloads">{seed.downloads ?? 0} 次下载</div> |
| 296 | <div |
| 297 | className="seed-item-actions" |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 298 | onClick={e => e.stopPropagation()} |
Krishya | 25590de | 2025-04-21 19:03:49 +0800 | [diff] [blame] | 299 | > |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 300 | <button |
| 301 | className="btn-primary" |
| 302 | onClick={e => { |
| 303 | e.preventDefault(); |
| 304 | e.stopPropagation(); |
| 305 | handleDownload(seed.id); |
| 306 | }} |
| 307 | > |
| 308 | 下载 |
| 309 | </button> |
| 310 | <button |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 311 | className="btn-outline" |
| 312 | onClick={async (e) => { |
| 313 | e.preventDefault(); |
| 314 | e.stopPropagation(); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 315 | |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 316 | if (!user || !user.userId) { |
| 317 | alert('请先登录再收藏'); |
| 318 | return; |
| 319 | } |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 320 | |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 321 | try { |
| 322 | const res = await axios.post(`/seeds/${seed.id}/favorite-toggle`, null, { |
| 323 | params: { user_id: user.userId }, |
| 324 | }); |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 325 | |
22301009 | 01d3ff9 | 2025-06-07 16:16:26 +0800 | [diff] [blame] | 326 | if (res.data.code === 0) { |
| 327 | alert('操作成功'); |
| 328 | } else { |
| 329 | alert(res.data.msg || '操作失败'); |
| 330 | } |
| 331 | } catch (err) { |
| 332 | console.error('收藏失败:', err); |
| 333 | alert('收藏失败,请稍后再试。'); |
| 334 | } |
| 335 | }} |
| 336 | > |
| 337 | 收藏 |
| 338 | </button> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 339 | </div> |
Krishya | 25590de | 2025-04-21 19:03:49 +0800 | [diff] [blame] | 340 | </div> |
22301009 | 80aaf0d | 2025-06-05 23:20:05 +0800 | [diff] [blame] | 341 | </Link> |
| 342 | ); |
| 343 | })} |
Krishya | 25590de | 2025-04-21 19:03:49 +0800 | [diff] [blame] | 344 | </div> |
22301009 | ecc1c1c | 2025-04-09 21:56:23 +0800 | [diff] [blame] | 345 | </div> |
| 346 | )} |
| 347 | </div> |
| 348 | </div> |
| 349 | ); |
| 350 | }; |
| 351 | |
| 352 | export default SeedList; |