Browse Source

判断条件逻辑修改

kukuasir@vip.qq.com 1 year ago
parent
commit
e7c6ab8d69
1 changed files with 23 additions and 18 deletions
  1. 23 18
      src/js/common.js

+ 23 - 18
src/js/common.js

@@ -543,46 +543,51 @@ function runCodeInArgsList(runMode, row, prop, argsList) {
   argsList = argsList.filter((a) => a.En === prop);
 
   var colorVal = 0;
-  var evalString = "";
+
   if (argsList.length <= 0) {
-    return evalString;
+    return 0;
   }
 
   // 对于换热站设备,先判断水泵状态,如果为0时标底颜色不可能出现黄色
   if (prop.indexOf("hex_") >= 0 && row.hex_pump_status == 0) {
-    evalString = "colorVal=0";
-    eval(evalString);
-    return colorVal;
+    return 0;
   }
 
-  // 先找出条件中有模式的数组跟无模式的数组
-  // 先拼接带有模式的数组, 再组合一下无模式的数组
   const val = row[prop];
-  const runModeArgs = argsList.filter((args) => args.RunMode > 0);
+  var result1 = 0;
+  var result2 = 0;
+
   const noneRunModeArgs = argsList.filter((args) => args.RunMode <= 0);
   if (noneRunModeArgs.length > 0) {
-    let tmp = "if (";
+    let evalString = "if (";
     noneRunModeArgs.forEach((args) => {
-      tmp += `${val}${args.Action}${args.Threshold}`;
-      tmp += "||";
+      evalString += `${val}${args.Action}${args.Threshold}`;
+      evalString += "||";
     });
-    tmp = tmp.substring(0, tmp.length - 2);
-    tmp += `) {colorVal=1} else {colorVal=0}`;
-    evalString += tmp;
-  } else {
+    evalString = evalString.substring(0, evalString.length - 2);
+    evalString += `) {colorVal=1} else {colorVal=0}`;
+    eval(evalString);
+    result1 = colorVal;
+  }
+
+  const runModeArgs = argsList.filter((args) => args.RunMode > 0);
+  if (runModeArgs.length > 0) {
+    let evalString = "";
     runModeArgs.forEach((args) => {
       evalString += `if (${runMode}==${args.RunMode} && ${row.available_modes}==true) {colorVal=(${val}${args.Action}${args.Threshold}`;
       if (args.Action2.length) {
         evalString += `||${val}${args.Action2}${args.Threshold2})`;
       } else {
-        evalString += ')';
+        evalString += ")";
       }
       evalString += `?1:0} else `;
     });
     evalString = evalString.substring(0, evalString.length - 5);
+    eval(evalString);
+    result2 = colorVal;
   }
-  eval(evalString);
-  return colorVal;
+  
+  return result1 || result2;
 }
 
 /**