From 1100c8c13cd931802edfcffcb2dee29d06b5f04c Mon Sep 17 00:00:00 2001 From: zhangyu Date: Wed, 28 Feb 2024 10:28:41 +0800 Subject: [PATCH] =?UTF-8?q?NEZ-3417=20fix:=20=E4=BF=AE=E5=A4=8D=20?= =?UTF-8?q?=E5=9B=BE=E8=A1=A8=20=E6=95=B0=E5=80=BC=E5=BE=88=E5=B0=8F?= =?UTF-8?q?=E5=B0=8F=E4=BA=8E1024=E6=97=B6=20=E5=8D=95=E4=BD=8D=E7=B2=BE?= =?UTF-8?q?=E5=BA=A6=E4=B8=8D=E6=AD=A3=E7=A1=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/chart/chartDataFormat.js | 65 +++++++------------ nezha-fronted/static/config.json | 2 +- 2 files changed, 24 insertions(+), 43 deletions(-) diff --git a/nezha-fronted/src/components/chart/chartDataFormat.js b/nezha-fronted/src/components/chart/chartDataFormat.js index c90d9e99f..c8e7d33f3 100644 --- a/nezha-fronted/src/components/chart/chartDataFormat.js +++ b/nezha-fronted/src/components/chart/chartDataFormat.js @@ -58,35 +58,21 @@ function localFormat (value, index, type = 1, dot = 2) { return result } function bits (value, index, type = 1, dot = 0) { - const num = value / 8 - if (value < 8) { - return value + 'b' - } - if (num < 1024) { - return num + 'B' - } if (type == 1) { - return asciiCompute(num, 1024, ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], 0) + return asciiCompute(value, 1024, ['b', 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], 0, true) } else if (type == -1) { - return asciiCompute(num, 1024, ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], dot) + return asciiCompute(value, 1024, ['b', 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], dot, true) } else { - return asciiCompute(num, 1024, ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], 2) + return asciiCompute(value, 1024, ['b', 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], 2, true) } } function bitsSI (value, index, type = 1, dot = 0) { - const num = value / 8 - if (value < 8) { - return value + 'b' - } - if (num < 1000) { - return num + 'B' - } if (type == 1) { - return asciiCompute(num, 1000, ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], 0) + return asciiCompute(value, 1000, ['b', 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], 0, true) } else if (type == -1) { - return asciiCompute(num, 1000, ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], dot) + return asciiCompute(value, 1000, ['b', 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], dot, true) } else { - return asciiCompute(num, 1000, ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], 2) + return asciiCompute(value, 1000, ['b', 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'], 2, true) } } function bytes (value, index, type = 1, dot) { @@ -207,19 +193,12 @@ function packetsSec (value, index, type = 1, dot) { } } function bitsSec (value, index, type = 1, dot) { - const num = value / 8 - if (value < 8) { - return value + 'b' - } - if (num < 1024) { - return num + 'B' - } if (type == 1) { - return asciiCompute(value, 1024, ['bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Epps', 'Zpps', 'Ypps'], 1) + return asciiCompute(value, 1024, ['bps', 'Bbps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Epps', 'Zpps', 'Ypps'], 1, true) } else if (type == -1) { - return asciiCompute(value, 1024, ['bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Epps', 'Zpps', 'Ypps'], dot) + return asciiCompute(value, 1024, ['bps', 'Bbps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Epps', 'Zpps', 'Ypps'], dot, true) } else { - return asciiCompute(value, 1024, ['bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Epps', 'Zpps', 'Ypps'], 2) + return asciiCompute(value, 1024, ['bps', 'Bbps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Epps', 'Zpps', 'Ypps'], 2, true) } } function bytesSec (value, index, type = 1, dot) { @@ -322,19 +301,12 @@ function petabitsSec (value, index, type = 1, dot) { } } function bitsSecSI (value, index, type = 1, dot) { - const num = value / 8 - if (value < 8) { - return value + 'b' - } - if (num < 1000) { - return num + 'B' - } if (type == 1) { - return asciiCompute(value, 1000, ['bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Epps', 'Zpps', 'Ypps'], 1) + return asciiCompute(value, 1000, ['bps', 'Bbps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Epps', 'Zpps', 'Ypps'], 1, true) } else if (type == -1) { - return asciiCompute(value, 1000, ['bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Epps', 'Zpps', 'Ypps'], dot) + return asciiCompute(value, 1000, ['bps', 'Bbps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Epps', 'Zpps', 'Ypps'], dot, true) } else { - return asciiCompute(value, 1000, ['bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Epps', 'Zpps', 'Ypps'], 2) + return asciiCompute(value, 1000, ['bps', 'Bbps', 'Kbps', 'Mbps', 'Gbps', 'Tbps', 'Pbps', 'Epps', 'Zpps', 'Ypps'], 2, true) } } function bytesSecSI (value, index, type = 1, dot) { @@ -545,18 +517,27 @@ function numberWithEConvent (num) { * units:单位列表 * dot:保留的小数位, * */ -function asciiCompute (num, ascii, units, dot = 2) { +function asciiCompute (num, ascii, units, dot = 2, isBits = false) { if (isNaN(num) || num === null) { return num } const scientificNotationValue = formatScientificNotation(num, dot) if (!numberWithEConvent(scientificNotationValue)) { - return scientificNotationValue + return scientificNotationValue + ' ' + units[0] } if (!num && num !== 0 && num !== '0') { return '' } num = Number(num) + if (isBits) { + num = num / 8 + if (num < 8) { + return num.toFixed(dot) + ' ' + units[0] + } + if (num < ascii) { + return num.toFixed(dot) + ' ' + units[1] + } + } const SIGN = num > 0 ? 1 : -1 num = Math.abs(num) let carry = 0 diff --git a/nezha-fronted/static/config.json b/nezha-fronted/static/config.json index 3d45d84b8..2b4166482 100644 --- a/nezha-fronted/static/config.json +++ b/nezha-fronted/static/config.json @@ -1 +1 @@ -{"baseUrl":"http://192.168.44.22/", "version": "23.06"} +{"baseUrl":"http://192.168.44.36/", "version": "23.06"}