From 22e2ecb71931291bb32ee2e4b897a44d1aca4f44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=8A=B2=E6=9D=BE?= Date: Thu, 24 Dec 2020 18:45:12 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E5=9B=BE=E8=A1=A8?= =?UTF-8?q?=E5=B8=A6=E6=9C=89e=E6=97=B6total=E6=97=A0=E6=B3=95=E6=98=BE?= =?UTF-8?q?=E7=A4=BA=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/charts/chartPreview.vue | 4 +-- .../components/charts/line-chart-block.vue | 7 ++--- .../common/project/popData/lineChart.vue | 6 ++-- nezha-fronted/src/main.js | 28 ++++++++++++++++++- 4 files changed, 35 insertions(+), 10 deletions(-) diff --git a/nezha-fronted/src/components/charts/chartPreview.vue b/nezha-fronted/src/components/charts/chartPreview.vue index 31cbecd0a..c987d3a8a 100644 --- a/nezha-fronted/src/components/charts/chartPreview.vue +++ b/nezha-fronted/src/components/charts/chartPreview.vue @@ -830,7 +830,7 @@ if(val===0){ val = Number(item.data[1]).toExponential(2); } - sum +=val; + sum += self.numberWithEConvent(val); str += `
`; str += `
${tip?(tip.alias?tip.alias:tip.name):item.seriesName}
`; str += `
`; @@ -1004,7 +1004,7 @@ if(val===0){ val = Number(item.data[1]).toExponential(2); } - sum +=val; + sum += self.numberWithEConvent(val); str += `
`; str += `
${tip?(tip.alias?tip.alias:tip.name):item.seriesName}
`; str += `
`; diff --git a/nezha-fronted/src/components/charts/line-chart-block.vue b/nezha-fronted/src/components/charts/line-chart-block.vue index 4777e87b4..f5a018892 100644 --- a/nezha-fronted/src/components/charts/line-chart-block.vue +++ b/nezha-fronted/src/components/charts/line-chart-block.vue @@ -737,7 +737,7 @@ if(val===0){ val = Number(item.data[1]).toExponential(2); } - sum +=val; + sum += self.numberWithEConvent(val); str += `
`; str += `
${tip?(tip.alias?tip.alias:tip.name):item.seriesName}
`; str += `
`; @@ -969,7 +969,7 @@ if(val===0){ val = Number(item.data[1]).toExponential(2); } - sum +=val; + sum += self.numberWithEConvent(val); str += `
`; str += `
${tip?(tip.alias?tip.alias:tip.name):item.seriesName}
`; str += `
`; @@ -1132,7 +1132,7 @@ if(val===0){ val = Number(item.data[1]).toExponential(2); } - sum +=val; + sum += self.numberWithEConvent(val); str += `
`; str += `
${tip?(tip.alias?tip.alias:tip.name):item.seriesName}
`; str += `
`; @@ -1803,7 +1803,6 @@ let copy=JSON.parse(JSON.stringify(data.data)); copy = copy.map(t=>parseFloat(t[1])) let sum = eval(copy.join('+')); - item['total'] = sum; } }) diff --git a/nezha-fronted/src/components/common/project/popData/lineChart.vue b/nezha-fronted/src/components/common/project/popData/lineChart.vue index 5c27d35f2..f86f9fd65 100644 --- a/nezha-fronted/src/components/common/project/popData/lineChart.vue +++ b/nezha-fronted/src/components/common/project/popData/lineChart.vue @@ -636,7 +636,7 @@ if(val===0){ val = Number(item.data[1]).toExponential(2); } - sum +=val; + sum += self.numberWithEConvent(val); str += `
`; str += `
${tip?(tip.alias?tip.alias:tip.name):item.seriesName}
`; str += `
`; @@ -894,7 +894,7 @@ if(val===0){ val = Number(item.data[1]).toExponential(2); } - sum +=val; + sum += self.numberWithEConvent(val); str += `
`; str += `
${tip?(tip.alias?tip.alias:tip.name):item.seriesName}
`; str += `
`; @@ -1051,7 +1051,7 @@ if(val===0){ val = Number(item.data[1]).toExponential(2); } - sum +=val; + sum += self.numberWithEConvent(val); str += `
`; str += `
${tip?(tip.alias?tip.alias:tip.name):item.seriesName}
`; str += `
`; diff --git a/nezha-fronted/src/main.js b/nezha-fronted/src/main.js index 1045ccf5a..6170d34d8 100644 --- a/nezha-fronted/src/main.js +++ b/nezha-fronted/src/main.js @@ -156,7 +156,33 @@ Vue.mixin({ vm.tools.showTopBtn = wrap.scrollTop > 50; vm.tools.tableHover = wrap.scrollTop > 50; }, 100)); - } + }, + numberWithEConvent(num) { + if (num) { + if ((("" + num).indexOf('E') != -1) || (("" + num).indexOf('e') != -1)) { + let regExp = new RegExp('^((\\d+.?\\d+)[Ee]{1}(\\d+))$', 'ig'); + let result = regExp.exec(num); + let resultValue = ""; + let power = ""; + if (result != null) { + resultValue = result[2]; + power = result[3]; + result = regExp.exec(num); + } + + if (resultValue != "") { + if (power != "") { + let powVer = Math.pow(10, power); + resultValue = resultValue * powVer; + return resultValue; + } + } + } else { + return num; + } + } + return 0; + }, }, computed: { getMenuList() {