From ecdceeaa6117bf5a801a92a3ec4dd4c7bddbf419 Mon Sep 17 00:00:00 2001 From: lion <120344285@qq.com> Date: Wed, 6 Aug 2025 16:42:53 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A6=96=E9=A1=B5=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/dashboard/index.vue | 51 +++++++++++++++-------------------- 1 file changed, 21 insertions(+), 30 deletions(-) diff --git a/src/views/dashboard/index.vue b/src/views/dashboard/index.vue index b3de211..a43d691 100644 --- a/src/views/dashboard/index.vue +++ b/src/views/dashboard/index.vue @@ -518,45 +518,36 @@ export default { .catch((error) => {}); }, methods: { - formatResult(num) { + formatResult(originalNum) { // 1. 先处理浮点数精度问题(乘以100后四舍五入到整数,再除以100保留两位小数) - if(!num){ - return '0' + if(!originalNum){ + return 0 } - const processed = Math.round(num * 100) / 100; + const multiplied = Math.round(originalNum * 100); // 0.28 * 100 = 28 → 处理后为28 - // 2. 判断是否为整数(小数部分为0) - if (processed % 1 === 0) { - // 是整数,直接返回整数形式(不带小数位) - return processed.toString(); - } else { - // 不是整数,保留两位小数 - return processed.toFixed(2); - } + // 2. 判断是否为整数(乘以100后是否无小数) + if (multiplied % 1 === 0) { + // 是整数,直接显示整数(如28) + return multiplied; + } else { + // 不是整数,保留两位小数(如56.50) + return (multiplied / 100).toFixed(2); + } }, async getCarry () { const res = await carry(this.carrySelect); //组织数据 let setData = function(data, constData, showData) { - data.filter(function(item) { - if (item) { - constData.push(1); - showData.push(item); - } else { - constData.push(0); - showData.push({ - value: 1, - itemStyle: { - normal: { - borderColor: "rgba(0,0,0,0)", - borderWidth: 2, - color: "rgba(0,0,0,0)", - }, - }, - }); - } - }); + data.forEach(function(item) { + if (item && Number(item.value) !== 0) { + constData.push(1); + showData.push(item); + } else { + constData.push(1); // 让底部 diamond 始终有 + showData.push(null); // 顶部 diamond 不显示 + } + }); } //组织颜色 let setColor = function(colorArr) {