From c2398150b44b54a1f08e7af4b6a64f0c170046f0 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期二, 27 十月 2026 14:35:48 +0800
Subject: [PATCH] fix: 支持计算值和最终值按批注格式化
---
src/workers/InspectionWorker.worker.js | 40 +++++++++++++++++-----------------------
1 files changed, 17 insertions(+), 23 deletions(-)
diff --git a/src/workers/InspectionWorker.worker.js b/src/workers/InspectionWorker.worker.js
index 119d3ce..3334b84 100644
--- a/src/workers/InspectionWorker.worker.js
+++ b/src/workers/InspectionWorker.worker.js
@@ -1,5 +1,6 @@
// 澶氱嚎绋嬮噷闈㈤渶瑕佷繚瀛樼殑鏁版嵁
import Big from "big.js";
+import { parseInspectionValueAnnotation, formatInspectionValue } from "../utils/inspectionValueFormat";
let code = "";
// 琛ㄦ牸鏁版嵁锛堟覆鏌擄級
@@ -405,7 +406,12 @@
// 鍒ゆ柇褰撳墠琛屾槸鍚︿负褰撳墠妫�楠岄」鎵�鍦ㄨ锛屽鏋滀负褰撳墠琛岋紝鍒欑粰琛ㄦ牸鏁版嵁璧嬪��
for (var b in a) {
if (a[b].c == item.c) {
- a[b].v.v = comResult;
+ // 璁$畻鍊笺�佹渶缁堝�间篃鎸夊崟鍏冩牸鎵规敞鐨勫皬鏁颁綅鏁版牸寮忓寲锛岄伩鍏嶈绠楃粨鏋滅粫杩囧墠绔緭鍏ユ牎楠屻��
+ const annotation = a[b].v && a[b].v.ps && a[b].v.ps.value;
+ const formatConfig = parseInspectionValueAnnotation(annotation);
+ a[b].v.v = formatConfig && !formatConfig.error
+ ? formatInspectionValue(comResult, formatConfig)
+ : comResult;
hasComputedWrite = true;
break;
}
@@ -704,29 +710,17 @@
*/
function AVERAGE(...val) {
try {
- let num = null;
- let arr = [];
- if (
- val != null &&
- val != undefined &&
- val != "undefined" &&
- val != "NaN" &&
- val.length > 0
- ) {
- arr = val.filter(
- (item) => item !== null && item !== "" && item != undefined
- );
- arr.forEach((item) => {
- num += item;
- });
- if (arr.length > 0) {
- return num / arr.length;
- } else {
- return null;
+ // 鍗曞厓鏍煎�煎彲鑳芥槸瀛楃涓诧紱缁熶竴杞暟瀛楀悗鍐嶈绠楋紝鍏煎鍖洪棿鍙傛暟銆�
+ const values = [];
+ const flatten = (items) => items.forEach((item) => {
+ if (Array.isArray(item)) return flatten(item);
+ if (item !== null && item !== undefined && item !== "" && item !== " ") {
+ const number = Number(item);
+ if (Number.isFinite(number)) values.push(number);
}
- } else {
- return null;
- }
+ });
+ flatten(val || []);
+ return values.length ? values.reduce((sum, item) => sum + item, 0) / values.length : null;
} catch (error) {
console.log("error---", error);
}
--
Gitblit v1.9.3