chenshilong 7 年之前
父节点
当前提交
4702666fbc
共有 2 个文件被更改,包括 17 次插入2 次删除
  1. 5 0
      public/web/common_util.js
  2. 12 2
      web/building_saas/main/js/models/calc_program.js

+ 5 - 0
public/web/common_util.js

@@ -13,6 +13,10 @@ String.prototype.hasSubStr = function (str) {
     return this.toLowerCase().indexOf(str.toLowerCase()) > -1;
 };
 
+String.prototype.isNumberStr = function () {
+    return this == +this;
+};
+
 // 树结点计算时,取费会出现值为NaN的情况,导致往父节点汇总(递归相加)会出现错误。
 function parseFloatPlus(value){
     let rst = parseFloat(value);
@@ -35,3 +39,4 @@ function isSubArr(sub, arr){
     }
     return true;
 };
+

+ 12 - 2
web/building_saas/main/js/models/calc_program.js

@@ -953,8 +953,18 @@ let analyzer = {
         return template.calcItems[idx];
     },
     isCycleCalc: function (expression, ID, template) {     // 这里判断expression,是ID引用: @5+@6
-        if (expression.includes(`@${ID}`))
-            return true;
+        let atID = `@${ID}`;
+        // 避免部分匹配,如:@10匹配@1
+        let idx = expression.indexOf(atID);
+        if (idx >= 0){
+            let nextPos = idx + atID.length;
+            if (nextPos >= expression.length)
+                return true;
+
+            let char = expression.charAt(nextPos);
+            if (!char.isNumberStr())
+                return true;
+        };
 
         let atIDs = analyzer.getAtIDArr(expression);
         for (let atID of atIDs) {