From 81f85b9e461fdf83be06d3f1e45ed1f6749344b2 Mon Sep 17 00:00:00 2001 From: jxxghp Date: Sat, 29 Mar 2025 08:11:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E4=BC=98=E5=8C=96=E6=90=9C=E7=B4=A2?= =?UTF-8?q?=E7=BB=93=E6=9E=9C=E7=95=8C=E9=9D=A2UI=EF=BC=8C=E6=84=9F?= =?UTF-8?q?=E8=B0=A2=20@madrays?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/cards/TorrentCard.vue | 645 ++++++++++++++++---- src/components/cards/TorrentItem.vue | 510 +++++++++++++--- src/pages/resource.vue | 424 +++++++++++-- src/views/torrent/TorrentCardListView.vue | 565 ++++++++++++++++-- src/views/torrent/TorrentRowListView.vue | 693 +++++++++++++++++----- 5 files changed, 2405 insertions(+), 432 deletions(-) diff --git a/src/components/cards/TorrentCard.vue b/src/components/cards/TorrentCard.vue index 0108825e..da156a3a 100644 --- a/src/components/cards/TorrentCard.vue +++ b/src/components/cards/TorrentCard.vue @@ -78,12 +78,13 @@ async function downloadTorrentFile() { window.open(torrent.value?.enclosure, '_blank') } -// 促销Chip类 -function getVolumeFactorClass(downloadVolume: number, uploadVolume: number) { - if (downloadVolume === 0) return 'text-white bg-lime-500' - else if (downloadVolume < 1) return 'text-white bg-green-500' - else if (uploadVolume !== 1) return 'text-white bg-sky-500' - else return 'text-white bg-gray-500' +// 获取优惠类型样式 +function getPromotionClass(downloadVolumeFactor: number | undefined, uploadVolumeFactor: number | undefined) { + if (!downloadVolumeFactor) return 'free-discount' + if (downloadVolumeFactor === 0) return 'free-discount' + else if (downloadVolumeFactor < 1) return 'percent-discount' + else if (uploadVolumeFactor !== undefined && uploadVolumeFactor > 1) return 'upload-bonus' + else return '' } // 装载时查询站点图标 @@ -95,124 +96,153 @@ onMounted(() => { + + diff --git a/src/components/cards/TorrentItem.vue b/src/components/cards/TorrentItem.vue index 5441c60f..6efd4665 100644 --- a/src/components/cards/TorrentItem.vue +++ b/src/components/cards/TorrentItem.vue @@ -25,6 +25,10 @@ const meta = ref(props.torrent?.meta_info) // 站点图标 const siteIcon = ref('') +// 站点图标加载状态 +const iconLoading = ref(false) +const iconError = ref(false) + // 存储是否已经下载过的记录 const downloaded = ref([]) @@ -33,11 +37,65 @@ const addDownloadDialog = ref(false) // 查询站点图标 async function getSiteIcon() { - try { - siteIcon.value = (await api.get(`site/icon/${torrent?.value?.site}`)).data.icon - } catch (error) { - console.error(error) + if (!torrent?.value?.site || iconLoading.value) { + return } + + iconLoading.value = true + iconError.value = false + + try { + const response = await api.get(`site/icon/${torrent.value.site}`) + if (response && response.data && response.data.icon) { + siteIcon.value = response.data.icon + } else { + iconError.value = true + } + } catch (error) { + console.error('Failed to load site icon:', error) + iconError.value = true + } finally { + iconLoading.value = false + } +} + +// 获取站点颜色 +function getSiteColor(siteId: string | number | undefined) { + if (!siteId) return '#3F51B5' + + // 根据站点ID生成不同颜色 + const colors = [ + '#3F51B5', + '#673AB7', + '#9C27B0', + '#E91E63', + '#F44336', + '#FF5722', + '#FF9800', + '#FFC107', + '#4CAF50', + '#009688', + '#00BCD4', + '#03A9F4', + ] + + // 简单哈希函数 + let hash = 0 + const idStr = String(siteId) + for (let i = 0; i < idStr.length; i++) { + hash = idStr.charCodeAt(i) + ((hash << 5) - hash) + } + + return colors[Math.abs(hash) % colors.length] +} + +// 获取优惠类型样式 +function getPromotionClass(downloadVolumeFactor: number | undefined, uploadVolumeFactor: number | undefined) { + if (!downloadVolumeFactor) return 'free-discount' + if (downloadVolumeFactor === 0) return 'free-discount' + else if (downloadVolumeFactor < 1) return 'percent-discount' + else if (uploadVolumeFactor !== undefined && uploadVolumeFactor > 1) return 'upload-bonus' + else return '' } // 询问并添加下载 @@ -69,10 +127,11 @@ async function downloadTorrentFile() { } // 促销Chip类 -function getVolumeFactorClass(downloadVolume: number, uploadVolume: number) { +function getVolumeFactorClass(downloadVolume: number | undefined, uploadVolume: number | undefined) { + if (!downloadVolume) return 'text-white bg-gray-500' if (downloadVolume === 0) return 'text-white bg-lime-500' else if (downloadVolume < 1) return 'text-white bg-green-500' - else if (uploadVolume !== 1) return 'text-white bg-sky-500' + else if (uploadVolume !== undefined && uploadVolume !== 1) return 'text-white bg-sky-500' else return 'text-white bg-gray-500' } @@ -83,96 +142,88 @@ onMounted(() => {