From ad373961e43f1e5cf6653b28ddb8237ea1141f1e Mon Sep 17 00:00:00 2001 From: TsMask <340112800@qq.com> Date: Wed, 23 Jul 2025 10:56:59 +0800 Subject: [PATCH] =?UTF-8?q?fix::=20=E8=87=AA=E5=AE=9A=E4=B9=89=E6=8C=87?= =?UTF-8?q?=E6=A0=87=E6=95=B0=E5=80=BC=E6=A0=BC=E5=BC=8F=E5=A4=84=E7=90=86?= =?UTF-8?q?=EF=BC=8C=E5=AF=BC=E5=87=BA=E8=A1=A8=E6=A0=BC=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/perfManage/kpiCReport/index.vue | 90 ++++++++++++++++++++--- 1 file changed, 78 insertions(+), 12 deletions(-) diff --git a/src/views/perfManage/kpiCReport/index.vue b/src/views/perfManage/kpiCReport/index.vue index 51711b39..2913466a 100644 --- a/src/views/perfManage/kpiCReport/index.vue +++ b/src/views/perfManage/kpiCReport/index.vue @@ -307,7 +307,21 @@ function fnRecordExport() { for (const key of keys) { if (tableColumnsKeyArr[i] === key) { const title = tableColumnsTitleArr[i]; - kpiData[title] = item[key]; + if (key == 'timeGroup') { + kpiData[title] = parseDateToStr(item[key]); + } else if (key === 'neName' || key === 'startIndex') { + kpiData[title] = item[key]; + } else { + const v = parseFloat(item[key]); + let kpiV = v.toFixed(3); // 有小数部分,保留 3 位小数 + // 判断数字是否有小数部分 + if (Math.abs(v) < 0.001) { + kpiV = '0'; // 如果数字非常小,返回 0 + } else if (v % 1 === 0) { + kpiV = v.toFixed(0); // 没有小数部分,保留 0 位小数 + } + kpiData[title] = kpiV; + } } } } @@ -368,8 +382,15 @@ function fnGetListTitle() { width: 100, minWidth: 150, maxWidth: 300, - customRender: (opt:any) => { - return parseFloat(opt.text).toFixed(3); + customRender: (opt: any) => { + const num = parseFloat(opt.text); + // 判断数字是否有小数部分 + if (Math.abs(num) < 0.001) { + return '0'; // 如果数字非常小,返回 0 + } else if (num % 1 === 0) { + return num.toFixed(0); // 没有小数部分,保留 0 位小数 + } + return num.toFixed(3); // 有小数部分,保留 3 位小数 }, }); } @@ -388,6 +409,9 @@ function fnGetListTitle() { key: 'timeGroup', sorter: true, width: 100, + customRender: (opt: any) => { + return parseDateToStr(opt.text); + }, }); nextTick(() => { @@ -456,20 +480,53 @@ function fnGetList() { }); // 计算总值 - const total = Number( - values.reduce((sum, val) => sum + val, 0).toFixed(2) - ); + const totalV = values.reduce((sum, val) => sum + val, 0); + let total = totalV.toFixed(3); + // 判断数字是否有小数部分 + if (Math.abs(totalV) < 0.001) { + total = '0'; // 如果数字非常小,返回 0 + } else if (totalV % 1 === 0) { + total = totalV.toFixed(0); // 没有小数部分,保留 0 位小数 + } + // 计算平均值 - const avg = - values.length > 0 ? Number((total / values.length).toFixed(2)) : 0; + const avgV = values.length > 0 ? totalV / values.length : 0; + let avg = avgV.toFixed(3); + // 判断数字是否有小数部分 + if (Math.abs(avgV) < 0.001) { + avg = '0'; // 如果数字非常小,返回 0 + } else if (avgV % 1 === 0) { + avg = avgV.toFixed(0); // 没有小数部分,保留 0 位小数 + } + + // 计算最大值 + const maxV = values.length > 0 ? Math.max(...values) : 0; + let max = maxV.toFixed(3); + // 判断数字是否有小数部分 + if (Math.abs(maxV) < 0.001) { + max = '0'; // 如果数字非常小,返回 0 + } else if (maxV % 1 === 0) { + max = maxV.toFixed(0); // 没有小数部分,保留 0 位小数 + } + + // 计算最小值 + const minV = values.length > 0 ? Math.min(...values) : 0; + let min = minV.toFixed(3); + // 判断数字是否有小数部分 + if (Math.abs(minV) < 0.001) { + min = '0'; // 如果数字非常小,返回 0 + } else if (minV % 1 === 0) { + min = minV.toFixed(0); // 没有小数部分,保留 0 位小数 + } + kpiStats.value.push({ kpiId: columns.key, title: columns.title, unit: columns.unit, - max: values.length > 0 ? Math.max(...values).toFixed(3) : 0, - min: values.length > 0 ? Math.min(...values).toFixed(3) : 0, + max, + min, avg, - total: total, + total, }); } } else { @@ -642,7 +699,16 @@ function fnRanderChartData() { for (const y of chartDataYSeriesData) { for (const key of keys) { if (y.key === key) { - y.data.push(parseFloat(item[key]).toFixed(3)); + // 计算最小值 + const v = parseFloat(item[key]); + let kpiV = v.toFixed(3); + // 判断数字是否有小数部分 + if (Math.abs(v) < 0.001) { + kpiV = '0'; // 如果数字非常小,返回 0 + } else if (v % 1 === 0) { + kpiV = v.toFixed(0); // 没有小数部分,保留 0 位小数 + } + y.data.push(kpiV); chartDataXAxisData.push(parseDateToStr(item['timeGroup'])); } }