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