From 14126d07933a911f8b0bd952fb08fca0d56378ab Mon Sep 17 00:00:00 2001 From: fhysy <1149505133@qq.com> Date: Wed, 25 Dec 2024 14:34:01 +0800 Subject: [PATCH] =?UTF-8?q?=20fast(=E9=A1=B9=E7=9B=AE-=E8=83=BD=E6=BA=90?= =?UTF-8?q?=E7=AE=A1=E7=90=86):=20=E8=83=BD=E6=BA=90=E7=AE=A1=E7=90=86-?= =?UTF-8?q?=E7=94=B5=E9=87=8F=E7=BB=9F=E8=AE=A1=E6=B7=BB=E5=8A=A0=E5=88=86?= =?UTF-8?q?=E7=BB=84=E6=9F=A5=E8=AF=A2=E5=92=8C=E7=94=B5=E9=87=8F=E5=90=88?= =?UTF-8?q?=E8=AE=A1=EF=BC=8C=E8=AE=BE=E5=A4=87=E5=88=97=E8=A1=A8=E5=A1=91?= =?UTF-8?q?=E5=A3=B3=E6=96=AD=E8=B7=AF=E5=99=A8=E6=B7=BB=E5=8A=A0=E7=88=B6?= =?UTF-8?q?=E8=AE=BE=E5=A4=87=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/iot/project_new.js | 2 +- src/utils/math.js | 66 ++++++++++++++ src/views/iot/device/index.vue | 2 +- .../profileV2/EnergyManage/EElectricity.vue | 88 +++++++++++-------- 4 files changed, 119 insertions(+), 39 deletions(-) create mode 100644 src/utils/math.js diff --git a/src/api/iot/project_new.js b/src/api/iot/project_new.js index 0935d9a8..c9c98370 100644 --- a/src/api/iot/project_new.js +++ b/src/api/iot/project_new.js @@ -140,7 +140,7 @@ export function projectElectricityStatChartYear(query) { // 查询 电能 列表 export function projectElectricityTable(query) { return request({ - url: "/iot/project/monitor/electricityStatLst", + url: "/iot/project/monitor/electricityStatList", method: "get", params: query }); diff --git a/src/utils/math.js b/src/utils/math.js new file mode 100644 index 00000000..1c1aba39 --- /dev/null +++ b/src/utils/math.js @@ -0,0 +1,66 @@ +// 使用这些方法,仍然需要注意数值范围、舍入策略和比较运算等方面的问题,根据具体的应用场景进行适当的调整和处理。 +const math = { + // 加法运算 + add: function (a, b) { + const precision = Math.max(getPrecision(a), getPrecision(b)); + const multiplier = Math.pow(10, precision); + const result=(Math.round(a * multiplier) + Math.round(b * multiplier)) / multiplier; + return transferToNumber(result) + }, + + // 减法运算 + subtract: function (a, b) { + return transferToNumber(math.add(a, -b)); + }, + + // 乘法运算 + multiply: function (a, b) { + const precision = getPrecision(a) + getPrecision(b); + const multiplier = Math.pow(10, precision); + const result=(Math.round(a * multiplier) * Math.round(b * multiplier)) / (multiplier * multiplier); + return transferToNumber(result) + }, + + // 除法运算 + divide: function (num1, num2) { + var str1 = Number(num1).toString(), + str2 = Number(num2).toString(), + result, + str1Length, + str2Length; + //解决整数没有小数点方法 + try { + str1Length = str1.split(".")[1].length; + } catch (error) { + str1Length = 0; + } + try { + str2Length = str2.split(".")[1].length; + } catch (error) { + str2Length = 0; + } + var step = Math.pow(10, Math.max(str1Length, str2Length)); + result = (num1 * step) / (num2 * step); + return transferToNumber(result); + }, + + // 获取浮点数的小数位数 +}; +function getPrecision(num) { + const str = String(num); + const decimalIndex = str.indexOf("."); + return decimalIndex === -1 ? 0 : str.length - decimalIndex - 1; +} +// 处理出现科学计数法 +function transferToNumber(num) { + if (isNaN(num)) { + return num + } + num = '' + num + num = parseFloat(num) + let eformat = num.toExponential() // 转换为标准的科学计数法形式(字符串) + let tmpArray = eformat.match(/\d(?:\.(\d*))?e([+-]\d+)/) // 分离出小数值和指数值 + let number = num.toFixed(Math.max(0, (tmpArray[1] || '').length - tmpArray[2])) + return number +} +export default math; diff --git a/src/views/iot/device/index.vue b/src/views/iot/device/index.vue index dd0190c4..97f4221c 100644 --- a/src/views/iot/device/index.vue +++ b/src/views/iot/device/index.vue @@ -334,7 +334,7 @@ diff --git a/src/views/iot/project/profileV2/EnergyManage/EElectricity.vue b/src/views/iot/project/profileV2/EnergyManage/EElectricity.vue index f2eb3164..f64148ce 100644 --- a/src/views/iot/project/profileV2/EnergyManage/EElectricity.vue +++ b/src/views/iot/project/profileV2/EnergyManage/EElectricity.vue @@ -89,7 +89,7 @@ - + - +