From a3d8aa6a33a967da5e38d6f638ed92ce6dc39c9a Mon Sep 17 00:00:00 2001 From: madrays Date: Mon, 31 Mar 2025 23:24:14 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E6=9E=84=E7=AB=99=E7=82=B9=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/cards/SiteCard.vue | 976 +++++++++++++++++++++++++++--- 1 file changed, 881 insertions(+), 95 deletions(-) diff --git a/src/components/cards/SiteCard.vue b/src/components/cards/SiteCard.vue index a81086be..0aed1766 100644 --- a/src/components/cards/SiteCard.vue +++ b/src/components/cards/SiteCard.vue @@ -117,10 +117,28 @@ const statColor = computed(() => { } }) -// 计算上传量和下载量的百分比 -const getPercentage = computed(() => { - if (cardProps.data?.upload === 0) return 100 - return ((cardProps.data?.download ?? 0) / ((cardProps.data?.download ?? 0) + (cardProps.data?.upload ?? 0))) * 100 +// 数据百分比计算 +const getMaxDataValue = computed(() => { + // 获取站点数据中的最大值作为基准 + const upload = cardProps.data?.upload || 0 + const download = cardProps.data?.download || 0 + + // 避免两者都为0的情况 + if (upload === 0 && download === 0) return 1 + + return Math.max(upload, download) +}) + +// 上传百分比 +const getUploadPercent = computed(() => { + const upload = cardProps.data?.upload || 0 + return Math.min(100, Math.max(3, (upload / getMaxDataValue.value) * 100)) +}) + +// 下载百分比 +const getDownloadPercent = computed(() => { + const download = cardProps.data?.download || 0 + return Math.min(100, Math.max(3, (download / getMaxDataValue.value) * 100)) }) // 保存站点 @@ -146,102 +164,248 @@ onMounted(() => { getSiteIcon() getSiteStats() }) + +// 在 script 部分添加计算速度等级的函数 +function calcSpeedClass(speed: number) { + if (speed === undefined || speed <= 0) return 'speed-idle'; + if (speed < 50 * 1024) return 'speed-low'; + if (speed < 500 * 1024) return 'speed-medium'; + return 'speed-high'; +} + +