From 7e7a8e3b15df991b9c3fbd22b94534b1d1984e29 Mon Sep 17 00:00:00 2001
From: gaoluyang <2820782392@qq.com>
Date: 星期一, 14 九月 2026 19:54:28 +0800
Subject: [PATCH] 新疆——新聚lims 1.检验任务详情逻辑重构,不需要判断结论逻辑,添加复杂运算逻辑
---
src/workers/InspectionWorker.worker.js | 634 +++++++++++++++++---------------------------------------
1 files changed, 195 insertions(+), 439 deletions(-)
diff --git a/src/workers/InspectionWorker.worker.js b/src/workers/InspectionWorker.worker.js
index 5cd696e..a8756a7 100644
--- a/src/workers/InspectionWorker.worker.js
+++ b/src/workers/InspectionWorker.worker.js
@@ -26,6 +26,8 @@
let param = null;
// 褰撳墠鐨勬ā鏉�
let currentTable = "";
+// 褰撳墠妯℃澘鐨勭粨鏋勭鍚�(琛屽垪鍧愭爣+鍗犱綅绗�),鐢ㄤ簬鍒ゆ柇妯℃澘鍐呭鏄惁琚敼杩�
+let currentTemplateSig = "";
// 浼樺寲鏁伴噰杈冨鏁版嵁鏃�-璁板綍鏈�鍚庝竴涓楠岄」鐨刬d
let getDataTypeId = null;
//褰撳墠妫�楠岄」
@@ -33,15 +35,51 @@
// 褰撳墠杩欐杈撳叆瀵瑰簲鐨勫師濮嬫楠岄」銆傝绠楄繃绋嬩腑 pId 浼氬垏鎹㈠埌涓嬫父璁$畻椤癸紝
// 淇濆瓨鏃跺繀椤诲悓鏃跺甫鍥炲師濮嬫楠岄」锛屽惁鍒欏彧浼氫繚瀛樿绠楃粨鏋溿��
let sourceInsItemId = null;
+
+/**
+ * 鐢熸垚妯℃澘缁撴瀯绛惧悕
+ * 鍙寘鍚鍒楀潗鏍囦笌鍗犱綅绗�,涓嶅惈鍊�,鎵�浠ョ敤鎴峰~鍊间笉浼氳Е鍙戠鍚嶅彉鍖�
+ *
+ * @param list 涓荤嚎绋嬩紶杩囨潵鐨勮〃鏍兼暟鎹�
+ * @returns 缁撴瀯绛惧悕瀛楃涓�
+ */
+function buildTemplateSig(list) {
+ if (!list || !list.length) {
+ return "";
+ }
+ return list
+ .map((table) => {
+ const tpl = table && table.template;
+ if (!tpl || !tpl.length) {
+ return `${table && table.templateId}:0`;
+ }
+ const cells = tpl
+ .map((cell) => {
+ const ps = cell.v && cell.v.ps ? cell.v.ps.value : "";
+ return `${cell.r}-${cell.c}-${ps}`;
+ })
+ .join("|");
+ return `${table.templateId}:${tpl.length}:${cells}`;
+ })
+ .join(";");
+}
+
// 鎺ユ敹鍒颁富绾跨▼澶勭悊閫昏緫鐨勬秷鎭�
self.onmessage = function (event) {
// 淇濆瓨涓荤嚎绋嬩紶杩囨潵鐨勫��
const data = JSON.parse(event.data);
- if (currentTable != data.currentTable) {
- // 妫�楠屾ā鏉挎敼鍙樺悗闇�瑕佸埛鏂拌〃鏍�
+ // 妯℃澘鍐呭鍙樹簡(涓嶅彧鏄ā鏉縤d鍙樹簡)涔熻鍒锋柊琛ㄦ牸,鍚﹀垯鏀瑰畬妯$増鍚� Worker 浠嶇敤鏃фā鏉胯绠楀苟鎶婃棫鐗堝紡鍥炲啓椤甸潰
+ const nextTemplateSig = buildTemplateSig(data.tableList);
+ if (
+ currentTable != data.currentTable ||
+ (nextTemplateSig && nextTemplateSig != currentTemplateSig)
+ ) {
tableList = data.tableList;
}
currentTable = data.currentTable;
+ if (nextTemplateSig) {
+ currentTemplateSig = nextTemplateSig;
+ }
if (data.type && data.type == "saveData") {
// 鏇存柊琛ㄦ牸鏁版嵁鍜屼紶閫掑埌鍚庣鐨勫弬鏁�
tableList = data.tableList;
@@ -85,10 +123,9 @@
tableList = data.tableList;
}
if (param) {
- // 濡傛灉浼犻�掑埌鍚庣鐨勫弬鏁板瓨鍦紝鍒欐洿鏂板綋鍓嶄慨鏀规楠岄」鐨勪紶閫掑埌鍚庣鐨勫弬鏁�
+ // 鍙傛暟鎸夆�滄ā鏉縤d + 鍗曞厓鏍煎潗鏍団�濆瓨,妯℃澘id鍗� code 鐨勭涓�娈�
let str = code.split("-");
- let pId = str[3];
- param[pId] = data.param[pId];
+ param[str[0]] = data.param[str[0]];
} else {
// 鍒濆鍖栦紶閫掑埌鍚庣鐨勫弬鏁�
param = data.param;
@@ -105,12 +142,64 @@
changeInput("", code);
};
+/**
+ * 鍒ゆ柇鍏紡鏄惁涓烘暟鍊煎叕寮�(鍚畻鏈繍绠楁垨 Excel 鍑芥暟)
+ * 杩欑被鍏紡蹇呴』璧版暟鍊艰绠楀垎鏀�,鍚﹀垯鍙細鎶婄畻寮忓綋鏂囨湰鍘熸牱鏄剧ず
+ *
+ * @param f 鍏紡瀛楃涓�
+ * @returns 鏄惁鎸夋暟鍊艰绠�
+ */
+function isNumericFormula(f) {
+ if (typeof f !== "string") {
+ return false;
+ }
+ // 鍘绘帀鍙屽紩鍙峰唴鐨勬枃鏈�,閬垮厤鎶� "A-B" 杩欑被鏂囨湰瀛楅潰閲忚鍒や负绠楁湳
+ const probe = f.replace(/"[^"]*"/g, "");
+ // 鍙鏀寔鐨勭畻鏈繍绠楃鍜� Excel 鍑芥暟,鎷彿鍗曠嫭鍑虹幇涓嶈涓烘暟鍊煎叕寮�,
+ // 浠ュ厤 IF 绛変笉鏀寔鐨勫嚱鏁拌璇垽
+ if (
+ /[+\-*/^%]/.test(probe) ||
+ /SUM|MAX|MIN|AVERAGE|ABS|MEDIAN/.test(probe)
+ ) {
+ return true;
+ }
+ // 绾崟鍏冩牸寮曠敤涔熸槸鏁板�煎叕寮忋�傛ā鐗堥噷"鏈�缁堝��"甯稿啓鎴� =F4 杩欑褰㈠紡,
+ // 涓嶈鐨勮瘽浼氭帀杩涙枃鏈垎鏀�,鎶婃渶缁堝�煎彉鎴愬甫绌烘牸鐨勫瓧绗︿覆
+ return /^[A-Za-z]{1,3}\d{1,7}$/.test(f.replace(/[=\s]/g, ""));
+}
+
+/**
+ * 鎸夋楠岄」id鍙栧綋鍓嶆牱鍝佷笅鐨勬楠岄」淇℃伅,鍙栦笉鍒版椂杩斿洖绌哄璞�,閬垮厤鍏紡璁$畻鍥犵己椤逛腑鏂�
+ *
+ * @param id 妫�楠岄」id
+ * @returns 妫�楠岄」淇℃伅
+ */
+function findInsItem(id) {
+ if (!currentSample || !currentSample.insProduct) {
+ return {};
+ }
+ return currentSample.insProduct.find((m) => m.id == id) || {};
+}
+
+/**
+ * 鍒ゆ柇璁$畻缁撴灉鏄惁鍙互鍐欏洖鍗曞厓鏍�
+ *
+ * @param r 璁$畻缁撴灉
+ * @returns 缁撴灉鏈夋晥杩斿洖 true
+ */
+function isValidComputedResult(r) {
+ if (r === "" || r === null || r === undefined) {
+ return false;
+ }
+ return !(typeof r === "number" && isNaN(r));
+}
+
function changeInput(m, code) {
let str = code.split("-");
let r = str[1]; //褰撳墠琛�
let c = str[2]; //褰撳墠鍒�
let id = str[0];
- let pId = str[3]; //褰撳墠妫�楠岄」id锛宲aram[pId]涓哄綋鍓嶆楠岄」鐨勬墍鏈夊�硷紝鍖呭惈锛氳繃绋嬪�糹nsValue銆佽绠楀�糲omValue銆佽澶囩紪鐮乪quipValue銆佽澶囧悕绉癳quipName銆佹渶缁堝�紃esValue銆佺粨璁篿nsResult
+ let pId = str[3]; //褰撳墠妫�楠岄」id锛岀敤浜庤绠楀畬鎴愬悗鎶婄粨鏋滃啓鍥炶妫�楠岄」鎵�鍦ㄨ
var list = []; //涓�涓弻灞傛暟缁勶紝閲岄潰淇濆瓨鏈夊綋鍓嶉〉闈㈡覆鏌撶殑鎵�鏈夋暟鎹�
// 璧嬪�煎綋鍓嶆ā鏉跨殑琛ㄦ牸鏁版嵁
for (let a in tableList) {
@@ -157,7 +246,8 @@
list2.push(c.v.v);
// 缁勮鍙傛暟鐨勫璞¢泦鍚堝苟璧嬪�硷紝鍒楀{A3:12,B4:15}
if (
- getInspectionValueType(item.i) == 1 &&
+ (getInspectionValueType(item.i) == 1 ||
+ isNumericFormula(item.v.f)) &&
!isNaN(parseFloat(c.v.v))
) {
// 濡傛灉鏄暟瀛楄緭鍏ユ
@@ -177,362 +267,26 @@
}
});
});
- // 濡傛灉姝xcel鏂规硶鏄粨璁哄垽鏂柟娉曪紝鍒欐墽琛屾鏂规硶
- // console.log('item.v.ps.value---', item.v.ps.value)
- if (item.v.ps != undefined && item.v.ps.value == "缁撹") {
- try {
- if (currentSample.insProduct.find((m) => m.id == item.i)) {
- // 濡傛灉褰撳墠妫�楠岄」鏄骇鍝佹楠岄」锛屽垯鎵ц姝ゆ柟娉曪紝鎵惧埌姝ゆ楠岄」鐨勮姹傚��
- let ask = currentSample.insProduct.find((m) => m.id == item.i).ask
- ? currentSample.insProduct
- .find((m) => m.id == item.i)
- .ask.split("&")
- : null;
- // 鑾峰彇褰撳墠缁撹鐨勫弬鏁帮紝涔熷氨鏄綋鍓嶆楠岄」鐨勬渶缁堝��
- let res = Object.values(comValue)[0];
- if (typeof res == "string" && res.includes(">")) {
- res = res.replace(">", "");
- }
- if (typeof res == "string" && res.includes("鈮�")) {
- res = res.replace("鈮�", "");
- }
- if (typeof res == "string" && res.includes("鈮�")) {
- res = res.replace("鈮�", "");
- }
- if (typeof res == "string" && res.includes("<")) {
- res = res.replace("<", "");
- }
- if (typeof res == "string" && res.includes("锛�")) {
- res = res.replace("锛�", "");
- }
- if (typeof res == "string" && res.includes("锛�")) {
- res = res.replace("锛�", "");
- }
- if (
- typeof res == "string" &&
- (res === "鏂" || res === "鑴嗗寲" || res === "鏂鑴嗗寲")
- ) {
- item.v.v = 0;
- list.forEach((a) => {
- if (a[0].r == item.r) {
- for (let b = 0; b < a.length; b++) {
- if (a[b].c == item.c) {
- a[b].v.v = 0;
- break;
- }
- }
- }
- });
- }
- let comp = [];
- // 鍒ゆ柇褰撳墠缁撹鐨勫弬鏁帮紙褰撳墠妫�楠岄」鐨勬渶缁堝�硷級鏄惁涓虹┖锛屽鏋滀负绌猴紝鍒欑洿鎺ヨ祴鍊�
- if (
- res === "" ||
- res === null ||
- res === undefined ||
- res === "Infinity"
- ) {
- item.v.v = null;
- list.forEach((a) => {
- if (a[0].r == item.r) {
- for (let b = 0; b < a.length; b++) {
- if (a[b].c == item.c) {
- a[b].v.v = null;
- break;
- }
- }
- }
- });
- } else {
- // 濡傛灉涓嶄负绌猴紝鍒欏垽鏂綋鍓嶇粨璁哄氨闇�瑕佽繘琛屽垽鏂�
- //瑕佹眰鍊间负-锛�/锛屸�旓紝鍒欑粨璁鸿缃负涓嶅垽瀹氾紝缁撹璧嬪�间负3
- if (
- ask == null ||
- ask[0] == "-" ||
- ask[0] == "/" ||
- ask[0] == "鈥�"
- ) {
- item.v.v = 3;
- list.forEach((a) => {
- if (a[0].r == item.r) {
- for (let b = 0; b < a.length; b++) {
- if (a[b].c == item.c) {
- a[b].v.v = 3;
- break;
- }
- }
- }
- });
- } else {
- // 瑕佹眰鍊间笉涓�-锛�/锛屸�旓紝鍒欒繘琛屽垽鏂�
- if (ask) {
- // 寰幆瑕佹眰鍊煎垪琛紝鍒ゆ柇褰撳墠缁撹鐨勫弬鏁版槸鍚︾鍚堣姹�
- comp = ask.map((m, i) => {
- // 濡傛灉瑕佹眰鍊煎寘鍚�=锛屽垯鍒ゆ柇褰撳墠缁撹鐨勫弬鏁版槸鍚︾瓑浜庤姹傚�硷紝
- // 浠ヤ笅鍒ゆ柇鍩烘湰涓�鑷达紝鍙槸鍒ゆ柇绫诲瀷涓嶄竴鏍凤紝灏变笉鍋氭敞閲婁簡
- if (m.includes("=")) {
- // 澶勭悊瑕佹眰鍊�
- let str = handleFraction(m.split("=")[1]);
- if (typeof res == "string" && typeof str == "string") {
- // 濡傛灉瑕佹眰鍊煎拰褰撳墠缁撹鐨勫弬鏁伴兘鏄瓧绗︿覆锛屽垯鎵ц
- if (res.includes("/")) {
- // 濡傛灉缁撹鐨勫弬鏁版槸鍒嗘暟锛屽垯鍒ゆ柇
- if (m.includes("/")) {
- // 濡傛灉瑕佹眰鍊兼槸鍒嗘暟锛屽垯鍒ゆ柇
- return eval(res) == eval(str);
- } else {
- // 濡傛灉瑕佹眰鍊间笉鏄垎鏁帮紝鍒欏垽鏂�
- return handleMoreParam(res, m.split("=")[1], "=");
- }
- } else {
- // 濡傛灉缁撹鐨勫弬鏁颁笉鏄垎鏁帮紝鍒欏垽鏂�
- return (
- res.trim().replace(/[.,銆傘�侊紱锛�'";?锛熲�滐紝]/g, "") ==
- str.trim().replace(/[.,銆傘�侊紱锛�'";?锛熲�滐紝]/g, "")
- );
- }
- } else {
- // 濡傛灉瑕佹眰鍊煎拰褰撳墠缁撹鐨勫弬鏁版湁涓�涓槸鏁板瓧锛屽垯鎵ц
- return eval(res) == eval(str);
- }
- } else if (m.includes("鈮�")) {
- if (typeof res == "string" && res.includes("/")) {
- if (m.includes("/")) {
- let str = handleFraction(m.split("鈮�")[1]);
- return eval(res) >= eval(str);
- } else {
- return handleMoreParam(res, m.split("鈮�")[1], "鈮�");
- }
- } else {
- let str = handleFraction(m.split("鈮�")[1]);
- return eval(res) >= eval(str);
- }
- } else if (m.includes("鈮�")) {
- if (typeof res == "string" && res.includes("/")) {
- if (m.includes("/")) {
- let str = handleFraction(m.split("鈮�")[1]);
- return eval(res) <= eval(str);
- } else {
- return handleMoreParam(res, m.split("鈮�")[1], "鈮�");
- }
- } else {
- let str = handleFraction(m.split("鈮�")[1]);
- if (typeof str == "string" && str.includes("A")) {
- str = str.replace("A", "");
- }
- if (typeof str == "string" && str.includes("D")) {
- str = str.replace("D", "");
- }
- if (typeof res == "string" && res.includes("A")) {
- res = res.replace("A", "");
- }
- if (typeof res == "string" && res.includes("D")) {
- res = res.replace("D", "");
- }
- return eval(res) <= eval(str);
- }
- } else if (m.includes("<")) {
- if (typeof res == "string" && res.includes("/")) {
- if (m.includes("/")) {
- let str = handleFraction(m.split("<")[1]);
- return eval(res) < eval(str);
- } else {
- return handleMoreParam(res, m.split("<")[1], "<");
- }
- } else {
- let str = handleFraction(m.split("<")[1]);
- return eval(res) < eval(str);
- }
- } else if (m.includes(">")) {
- if (typeof res == "string" && res.includes("/")) {
- if (m.includes("/")) {
- let str = handleFraction(m.split(">")[1]);
- return eval(res) > eval(str);
- } else {
- return handleMoreParam(res, m.split(">")[1], ">");
- }
- } else {
- let str = handleFraction(m.split(">")[1]);
- return eval(res) > eval(str);
- }
- } else if (m.includes("~")) {
- if (typeof res == "string" && res.includes("/")) {
- if (m.includes("/")) {
- let k = m.split("~");
- return (
- eval(res) >= eval(handleFraction(k[0])) &&
- eval(res) <= eval(handleFraction(k[1]))
- );
- } else {
- return handleMoreParam(res, m, "~");
- }
- } else {
- let k = m.split("~");
- return (
- eval(res) >= eval(handleFraction(k[0])) &&
- eval(res) <= eval(handleFraction(k[1]))
- );
- }
- } else if (m.includes("-")) {
- if (typeof res == "string" && res.includes("/")) {
- if (m.includes("/")) {
- let k = m.split("-");
- return (
- eval(res) >= eval(handleFraction(k[0])) &&
- eval(res) <= eval(handleFraction(k[1]))
- );
- } else {
- return handleMoreParam(res, m, "-");
- }
- } else {
- let k = m.split("-");
- return (
- eval(res) >= eval(handleFraction(k[0])) &&
- eval(res) <= eval(handleFraction(k[1]))
- );
- }
- } else if (m.includes("卤")) {
- if (modelType.includes("蠁-")) {
- if (m.indexOf("卤") == 0) {
- m =
- modelType.substring(modelType.indexOf("-") + 1) + m;
- }
- }
- if (typeof res == "string" && res.includes("/")) {
- if (m.includes("/")) {
- let k = m.split("卤");
- return (
- eval(res) >=
- eval(
- handleFraction(k[0]) - handleFraction(k[1])
- ) &&
- eval(res) <=
- eval(
- Number(handleFraction(k[0])) +
- Number(handleFraction(k[1]))
- )
- );
- } else {
- return handleMoreParam(res, m, "卤");
- }
- } else {
- let k = m.split("卤");
- return (
- eval(res) >=
- eval(handleFraction(k[0]) - handleFraction(k[1])) &&
- eval(res) <=
- eval(
- Number(handleFraction(k[0])) +
- Number(handleFraction(k[1]))
- )
- );
- }
- } else if (m.includes("锛�")) {
- if (typeof res == "string" && res.includes("/")) {
- if (m.includes("/")) {
- let str = handleFraction(m.split("锛�")[1]);
- return eval(res) > eval(str);
- } else {
- return handleMoreParam(res, m.split("锛�")[1], ">");
- }
- } else {
- let str = handleFraction(m.split("锛�")[1]);
- return eval(res) > eval(str);
- }
- } else if (m.includes("锛�")) {
- if (typeof res == "string" && res.includes("/")) {
- if (m.includes("/")) {
- let str = handleFraction(m.split("锛�")[1]);
- return eval(res) < eval(str);
- } else {
- return handleMoreParam(res, m.split("锛�")[1], "<");
- }
- } else {
- let str = handleFraction(m.split("锛�")[1]);
- return eval(res) < eval(str);
- }
- }
- });
- }
- // 濡傛灉瑕佹眰鍊肩殑姣忎釜鏉′欢閮界鍚堬紝鍒欑粰缁撹璧嬪�间负1锛屽悎鏍�
- if (comp.every((m) => m)) {
- item.v.v = 1;
- list.forEach((a) => {
- if (a[0].r == item.r) {
- for (let b = 0; b < a.length; b++) {
- if (a[b].c == item.c) {
- a[b].v.v = 1;
- break;
- }
- }
- }
- });
- } else {
- // 鍚﹀垯缁欑粨璁鸿祴鍊间负0锛屼笉鍚堟牸
- item.v.v = 0;
- list.forEach((a) => {
- if (a[0].r == item.r) {
- for (let b = 0; b < a.length; b++) {
- if (a[b].c == item.c) {
- a[b].v.v = 0;
- break;
- }
- }
- }
- });
- }
- }
- }
- let getDataType0 = false;
- // 浼樺寲鏁伴噰杈冨鏁版嵁鏃�-璁板綍鏈�鍚庝竴涓楠岄」鐨刬d锛屽鏋滃綋鍓嶆楠岄」鐨刬d涓庤褰曠殑id鐩稿悓锛屽垯澶氫紶涓�涓弬鏁板埌涓荤嚎绋嬶紝杩涜鏁版嵁淇濆瓨锛屽惁鍒欐暟閲囧氨涓嶈繘琛屼繚瀛�
- if (item.i == getDataTypeId) {
- getDataType0 = true;
- }
- // 璧嬪�间紶閫掑埌涓荤嚎绋嬬殑鏁版嵁锛宮ethod锛歴aveInsContext琛ㄧず姝ゆ秷鎭渶瑕佷繚瀛樻暟鎹�
- currentInsItemId = item.i;
- // 璧嬪�间紶閫掑埌涓荤嚎绋嬬殑鏁版嵁锛宮ethod锛歴aveInsContext琛ㄧず姝ゆ秷鎭渶瑕佷繚瀛樻暟鎹�
- result = {
- method: "saveInsContext",
- value: {
- tableList, // 琛ㄦ牸鏁版嵁
- param: getParam(), //浼犵粰鍚庣鐨勫弬鏁�
- getDataTypeId: getDataTypeId,
- currentInsItemId: item.i,
- sourceInsItemId: sourceInsItemId,
- },
- };
- // 鍙戞秷鎭粰涓荤嚎绋�
- self.postMessage(JSON.stringify(result));
- }
- } catch (error) {
- console.log("error---", error);
- }
- } else {
// 濡傛灉鏄嚱鏁版柟娉曪紝鍒欐墽琛屾鏂规硶
let comResult = ""; //鍒濆鍖栬绠楃粨鏋�
try {
- if (getInspectionValueType(item.i) == 1) {
- // 濡傛灉妫�楠屽�肩被鍨嬫槸鏁板瓧杈撳叆妗�
- let tell = currentSample.insProduct.find((m) => m.id == item.i).tell
- ? currentSample.insProduct
- .find((m) => m.id == item.i)
- .tell.split("&")
- : null;
+ if (
+ getInspectionValueType(item.i) == 1 ||
+ isNumericFormula(item.v.f)
+ ) {
+ // 濡傛灉妫�楠屽�肩被鍨嬫槸鏁板瓧杈撳叆妗�,鎴栧叕寮忔湰韬惈绠楁湳杩愮畻/Excel鍑芥暟
+ const itemInfo = findInsItem(item.i);
+ let tell =
+ typeof itemInfo.tell == "string" ? itemInfo.tell.split("&") : null;
isPoint =
tell &&
tell.length > 0 &&
typeof tell[0] == "string" &&
tell[0].includes("/") &&
tell[0] !== "/"; // 鍒ゆ柇瑕佹眰鍊兼槸鍚︿负鍒嗘暟
- const inspectionItemClass = currentSample.insProduct.find(
- (m) => m.id == item.i
- ).inspectionItemClass; // 妫�楠岄」鍒嗙被
- const inspectionItem = currentSample.insProduct.find(
- (m) => m.id == item.i
- ).inspectionItem; // 妫�楠岄」
- const inspectionItemSubclass = currentSample.insProduct.find(
- (m) => m.id == item.i
- ).inspectionItemSubclass; // 妫�楠屽瓙椤�
+ const inspectionItemClass = itemInfo.inspectionItemClass; // 妫�楠岄」鍒嗙被
+ const inspectionItem = itemInfo.inspectionItem; // 妫�楠岄」
+ const inspectionItemSubclass = itemInfo.inspectionItemSubclass; // 妫�楠屽瓙椤�
let isHaveSymbol = false;
let symbol = "";
for (var a in comValue) {
@@ -585,7 +339,12 @@
) {
comResult = comResult + "";
}
- if (inspectionItem === "閭垫皬纭害" && tell[0].includes("A")) {
+ if (
+ inspectionItem === "閭垫皬纭害" &&
+ tell &&
+ tell[0] &&
+ tell[0].includes("A")
+ ) {
// 瑕佹眰鍊煎鏋滄湁鍖呭惈瀛楁瘝锛屾渶缁堢粨鏋滆灞曠ず鍑哄瓧姣�
comResult = comResult + "A";
}
@@ -593,6 +352,8 @@
inspectionItemClass === "缁濈紭鏈烘鐗╃悊鎬ц兘" &&
inspectionItem === "寮洸鎬ц兘" &&
inspectionItemSubclass === "鏈�灏忓集鏇插崐寰�" &&
+ tell &&
+ tell[0] &&
tell[0].includes("D")
) {
// 瑕佹眰鍊煎鏋滄湁鍖呭惈瀛楁瘝锛屾渶缁堢粨鏋滆灞曠ず鍑哄瓧姣�
@@ -644,7 +405,7 @@
try {
// 寰幆琛ㄦ牸鏁版嵁锛岀粰琛ㄦ牸鏁版嵁杩涜璧嬪��
list.forEach((a) => {
- if (a[0].r == item.r && comResult !== "") {
+ if (a[0].r == item.r && isValidComputedResult(comResult)) {
// 鍒ゆ柇褰撳墠琛屾槸鍚︿负褰撳墠妫�楠岄」鎵�鍦ㄨ锛屽鏋滀负褰撳墠琛岋紝鍒欑粰琛ㄦ牸鏁版嵁璧嬪��
for (var b in a) {
if (a[b].c == item.c) {
@@ -672,9 +433,7 @@
// 鍒ゆ柇璁$畻缁撴灉鏄惁涓虹瀛﹁鏁版硶锛屽鏋滀负绉戝璁℃暟娉曪紝鍒欑粰琛ㄦ牸鏁版嵁璧嬪�间负绉戝璁℃暟娉�
a[b].v.v = comResult;
} else {
- const inspectionItem = currentSample.insProduct.find(
- (m) => m.id == item.i
- ).inspectionItem;
+ const inspectionItem = findInsItem(item.i).inspectionItem;
// 鍒ゆ柇璁$畻缁撴灉鏄惁涓烘暟瀛楋紝濡傛灉涓烘暟瀛楋紝鍒欑粰琛ㄦ牸鏁版嵁璧嬪�间负鏁板瓧
if (inspectionItem == "閾滅嚎鐢甸樆鐜囅�20鏈�澶у��") {
let val = parseFloat(Number(comResult).toFixed(5));
@@ -695,12 +454,14 @@
}
});
// 濡傛灉姝よ绠楃粨鏋滄墍灞炲崟鍏冩牸锛屽悓鏃朵篃鏄彟涓�涓猠xcel鍑芥暟鐨勫弬鏁帮紝閭d箞灏遍渶瑕侀�掑綊杩涜璁$畻
- changeInput(comResult, `${id}-${item.r}-${item.c}-${pId}`); //鏀瑰彉鏈�缁堝��
+ // 鍙湁绠楀嚭鏈夋晥缁撴灉鎵嶇户缁悜涓嬫父鍏紡浼犻��,閬垮厤鎶婄┖鍊�/NaN 浼犳煋缁欏叾瀹冨崟鍏冩牸
+ if (isValidComputedResult(comResult)) {
+ changeInput(comResult, `${id}-${item.r}-${item.c}-${pId}`); //鏀瑰彉鏈�缁堝��
+ }
currentInsItemId = item.i;
} catch (error) {
console.log("error---", error);
}
- }
}
});
if (index === -1 || (inputType === undefined && isSave === "true")) {
@@ -726,17 +487,6 @@
};
// 鍙戦�佷富绾跨▼鏁版嵁
self.postMessage(JSON.stringify(result));
- try {
- // 璧嬪�煎绾跨▼浼犺緭鏁版嵁
- result = {
- method: "getCurrentInsProduct",
- value: pId,
- };
- // 鍙戦�佷富绾跨▼鏁版嵁
- self.postMessage(JSON.stringify(result));
- } catch (error) {
- console.log("error---", error);
- }
}
/**
* 鑾峰彇妫�娴嬪�肩被鍨�
@@ -835,68 +585,33 @@
* @returns 杩斿洖澶勭悊鍚庣殑鍙傛暟瀵硅薄
*/
function getParam() {
- tableList[0].arr.forEach((a) => {
- a.forEach((b) => {
- // 鍒濆鍖栦紶閫掑埌鍚庣鐨勫弬鏁�
- if (param[b.i]) {
- param[b.i].insValue = [];
- param[b.i].comValue = [];
- param[b.i].equipValue = [];
- param[b.i].equipName = [];
- param[b.i].resValue = null;
- param[b.i].insResult = null;
- }
- });
- });
- tableList[0].arr.forEach((a) => {
- a.forEach((b) => {
- // 鏍规嵁琛ㄦ牸鏁版嵁锛岃祴鍊间紶閫掑埌鍚庣鐨勫弬鏁�
- if (
- b.v.ps != undefined &&
- typeof b.v.ps.value == "string" &&
- b.v.ps.value.includes("妫�楠屽��")
- ) {
- // 璧嬪�兼楠屽��
- b.i &&
- b.v.v !== "" &&
- b.v.v !== null &&
- b.v.v !== undefined &&
- param[b.i].insValue.push(b);
- }
- if (b.v.ps != undefined && b.v.ps.value === "璁$畻鍊�") {
- // 璧嬪�艰绠楀��
- b.i &&
- b.v.v &&
- b.valueList &&
- b.valueList.length > 0 &&
- param[b.i].comValue.push(b);
- }
- if (b.v.ps != undefined && b.v.ps.value === "璁惧缂栫爜") {
- // 璧嬪�艰澶囩紪鐮�
- b.i && b.v && param[b.i].equipValue.push(b);
- }
- if (b.v.ps != undefined && b.v.ps.value === "璁惧鍚嶇О") {
- // 璧嬪�艰澶囧悕绉�
- b.i && b.v && param[b.i].equipName.push(b);
- }
- if (b.v.ps != undefined && b.v.ps.value === "鏈�缁堝��") {
- // 璧嬪�兼渶缁堝��
- b.i &&
- b.v &&
- b.valueList &&
- b.valueList.length > 0 &&
- (param[b.i].resValue = b);
- }
- if (b.v.ps != undefined && b.v.ps.value === "缁撹") {
- if (b.i && (b.v.v || b.v.v === 0 || b.v.v === "0")) {
- if (b.v.v != "鍚堟牸" && b.v.v != "涓嶅悎鏍�") {
- // 璧嬪�肩粨璁�
- param[b.i].insResult = b;
- }
+ // 鎸夆�滄ā鏉縤d + 鍗曞厓鏍煎潗鏍�(r-c)鈥濅粠褰撳墠妯℃澘蹇収鍑哄緟淇濆瓨鍙傛暟
+ const resultParam = {};
+ tableList.forEach((t) => {
+ resultParam[t.templateId] = {};
+ (t.arr || []).forEach((a) => {
+ a.forEach((b) => {
+ const isEditable =
+ b.v.ps != undefined &&
+ typeof b.v.ps.value == "string" &&
+ (b.v.ps.value.includes("妫�楠屽��") ||
+ b.v.ps.value === "璁$畻鍊�" ||
+ b.v.ps.value === "鏈�缁堝��" ||
+ b.v.ps.value === "璁惧鍚嶇О");
+ if (!isEditable) {
+ return;
}
- }
+ if (
+ b.v.ps.value.includes("妫�楠屽��") &&
+ (b.v.v === "" || b.v.v === null || b.v.v === undefined)
+ ) {
+ return;
+ }
+ resultParam[t.templateId][`${b.r}-${b.c}`] = { v: b.v.v, u: b.u };
+ });
});
});
+ param = resultParam;
return param;
}
@@ -1191,6 +906,7 @@
*/
function getIdFromColumnName(id, arr) {
try {
+ id = String(id).replace(/\$/g, "");
// Get the letters
var t = /^[a-zA-Z]+/.exec(id);
if (t) {
@@ -1271,6 +987,9 @@
*/
function getABCList(f) {
try {
+ if (typeof f !== "string") {
+ return [];
+ }
let regex = /[=\+\-\*\%\(\)\/\^\s]/g;
// 涓婇潰璁$畻鍑芥暟鏂板鍚庯紝杩欓噷涔熻鍚屾澧炲姞
let fouList = [
@@ -1284,8 +1003,12 @@
"IF",
"LOG",
];
- // 鏇挎崲鐗规畩瀛楃
+ // 鏇挎崲鐗规畩瀛楃,鍘绘帀 Excel 缁濆寮曠敤绗﹀彿($D$14 涓� D14 绛変环)
f = f
+ .replace(/\$/g, "")
+ // 鍖洪棿鍐欐硶閲岀殑绌烘牸(AVERAGE( D14 : D15 ))浼氳涓嬮潰鐨勭┖鐧芥浛鎹㈠悆鎺夊啋鍙�,
+ // 瀵艰嚧鍖洪棿琚媶鎴愪袱涓嫭绔嬪崟鍏冩牸,鍏堟妸鍖洪棿瑙勬暣鎴� D14:D15
+ .replace(/\s*:\s*/g, ":")
.replace(regex, ",")
.replace(new RegExp('"&', "g"), "")
.replace(new RegExp('&"', "g"), "");
@@ -1322,6 +1045,22 @@
}
/**
+ * 鎶婂崟鍏冩牸鍊艰浆鎴愬彲鍙備笌 eval 鐨勫瓧闈㈤噺,绌虹櫧鍗曞厓鏍兼寜 0 澶勭悊(涓� Excel 涓�鑷�)
+ *
+ * @param value 鍗曞厓鏍肩殑鍊�
+ * @returns 鏁板��/鍘熷鍊�,绌哄�艰繑鍥� 0
+ */
+function toNumberLiteral(value) {
+ if (value === null || value === undefined) {
+ return 0;
+ }
+ if (typeof value === "string" && value.trim() === "") {
+ return 0;
+ }
+ return value;
+}
+
+/**
* 璁$畻鍑芥暟
*
* @param f 瀛楃涓茬被鍨嬶紝琛ㄧず寰呰绠楃殑鍏紡
@@ -1330,7 +1069,9 @@
*/
function compute(f, comValue, isPoint) {
try {
- let str = f;
+ // 鍘绘帀 Excel 缁濆寮曠敤绗﹀彿,$D$14 涓� D14 绛変环;
+ // 鍖洪棿閲岀殑绌烘牸涔熻涓�骞跺幓鎺�,鍚﹀垯涓嬮潰鎶� ":" 鎹㈡垚 "-" 鍚� D14-D15 浼氬洜绌烘牸鍖归厤涓嶄笂鑰屽睍寮�澶辫触
+ let str = f.replace(/\$/g, "").replace(/\s*:\s*/g, ":");
// 鑾峰彇鍗曞厓鏍煎搴斿��
let arr = getAllCell(f);
for (var a in comValue) {
@@ -1397,9 +1138,18 @@
for (var a in obj) {
str = str.replace(new RegExp(a, "g"), obj[a]);
}
- // 璁$畻
- for (var a in arr) {
- str = str.replace(new RegExp(a, "g"), arr[a]);
+ // 璁$畻:涓�娆℃�ф浛鎹㈡墍鏈夊弬鏁�,閬垮厤 D1 涓� D14 杩欑被鍓嶇紑浜掔浉姹℃煋;
+ // 绌虹櫧鍗曞厓鏍兼寜 0 澶勭悊,閬垮厤鎶� null/undefined 甯﹁繘琛ㄨ揪寮忓鑷存暣鏉″叕寮忕畻涓嶅嚭鏉�
+ const cellKeys = Object.keys(arr);
+ if (cellKeys.length > 0) {
+ const pattern = new RegExp(
+ cellKeys
+ .sort((x, y) => y.length - x.length)
+ .map((k) => k.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"))
+ .join("|"),
+ "g"
+ );
+ str = str.replace(pattern, (m) => String(toNumberLiteral(arr[m])));
}
if (str.includes(",,")) {
str = str.replace(new RegExp(",,", "g"), ",");
@@ -1421,8 +1171,9 @@
return str
.replace(new RegExp('&"/"&', "g"), "/")
.replace(new RegExp("//", "g"), "");
- } else if (isPoint) {
- // 璁$畻甯﹀皬鏁扮偣鐨�
+ } else if (isPoint && !/SUM|MAX|MIN|AVERAGE|ABS|MEDIAN/.test(str)) {
+ // 鍒嗘暟褰㈠紡鐨勮緭鍏�(濡� 3/4)鎸夊師鏂囪繑鍥炲睍绀�;
+ // 浣嗗惈 Excel 鍑芥暟鍚嶇殑鍏紡涓嶈兘璧拌繖閲�,鍚﹀垯浼氭妸 "AVERAGE(...)" 杩欑绠楀紡鏂囨湰褰撴垚缁撴灉鍐欏洖鍗曞厓鏍�
return str.replace("ABS", "").replace(/\(|\)/g, "");
} else {
if (str.includes("IF")) {
@@ -1449,7 +1200,12 @@
}
}
// 璁$畻甯歌鐨�
- return eval(str);
+ const value = eval(str);
+ // 闄ら浂绛夐潪鏈夐檺缁撴灉涓嶅啓鍥炲崟鍏冩牸(涓� Excel 鐨� #DIV/0! 涓�鑷�:涓嶅嚭鍊�)
+ if (typeof value === "number" && !isFinite(value)) {
+ return undefined;
+ }
+ return value;
}
} catch (error) {
console.log("error", error);
--
Gitblit v1.9.3