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'; +} + +