Browse Source

行引用主导模式换成ID引用主导模式,由ID引用解析成行引用显示。

chenshilong 7 years ago
parent
commit
85622544e6

+ 1 - 1
test/calculation/test_analyzer.js

@@ -213,5 +213,5 @@ let calcTemplate = {
 let expr = "F2+F5+F6+F10";
 let arr = analyzer.getFArr(expr);
 console.log(JSON.stringify(arr));
-let id = analyzer.getFID('F10', calcTemplate);
+let id = analyzer.getID('F10', calcTemplate);
 console.log(JSON.stringify(id));

+ 31 - 4
web/building_saas/main/js/models/calc_program.js

@@ -719,12 +719,20 @@ let analyzer = {
         return arrBase ? arrBase : [];
     },
 
-    getFID: function (FName, calcTemplate) {          // F3、F22 → 4、99
+    getID: function (FName, calcTemplate) {          // F13 → 4
         let idx = FName.slice(1) - 1;
         let id = calcTemplate.calcItems[idx] ? calcTemplate.calcItems[idx].ID : null;
         return id;
     },
-    getFItem: function (FName, calcTemplate){      // F3 → calcItems[2] → {Object}
+    getFName: function (atID, calcTemplate) {          // @3 → F7
+        for (var i = 0; i < calcTemplate.calcItems.length; i++) {
+            if (calcTemplate.calcItems[i].ID == atID.slice(1)) {
+                return 'F'+ (i + 1);
+            }
+        }
+        return null;
+    },
+    getItem: function (FName, calcTemplate){      // F3 → calcItems[2] → {Object}
         let idx = FName.slice(1) - 1;
         return calcTemplate.calcItems[idx];
     },
@@ -797,13 +805,31 @@ let analyzer = {
 
         return true;  // 表达式合法
     },
+    getDispExpr: function (expression, calcTemplate) {
+        function refIDToLine(expr, template) {
+            let rst = expr;
+            let IDArr = analyzer.getAtIDArr(rst);
+            let fArr = [];
+            for (let atID of IDArr){
+                let FN = analyzer.getFName(atID, template);
+                fArr.push(FN);
+            };
+            for (let i = 0; i < IDArr.length; i++) {
+                let patt = new RegExp(IDArr[i]);
+                let val = fArr[i];
+                rst = rst.replace(patt, val);
+            };
+            return rst;
+        };
+        return refIDToLine(expression, calcTemplate);
+    },
     getExpression: function (dispExpr, calcTemplate) {
         function refLineToID(expr, template) {
             let rst = expr;
             let fArr = me.getFArr(rst);
             let IDArr = [];
             for (let F of fArr){
-                let ID = me.getFID(F, template);
+                let ID = me.getID(F, template);
                 IDArr.push(ID);
             };
             for (let i = 0; i < fArr.length; i++) {
@@ -1083,7 +1109,8 @@ class CalcProgram {
 
             for (let i = 0; i < template.calcItems.length; i++) {
                 let item = template.calcItems[i];
-                item.expression = analyzer.getExpression(item.dispExpr, template);
+                // item.expression = analyzer.getExpression(item.dispExpr, template);
+                item.dispExpr = analyzer.getDispExpr(item.expression, template);
                 template.compiledCalcItems[item.ID] = item;
                 template.compiledCalcItems[item.ID + "_idx"] = i;
             }

+ 2 - 2
web/building_saas/main/js/views/calc_program_manage.js

@@ -116,9 +116,9 @@ let calcProgramManage = {
         }
     },
     onEnterCell: function (sender, args) {
-       /* let t = calcProgramManage.getSelectionInfo().template;
+/*        let t = calcProgramManage.getSelectionInfo().template;
         let c = calcProgramManage.getSelectionInfo().calcItem;
-        c.expression = analyzer.getExpression(c.dispExpr, t);
+        c.dispExpr = analyzer.getDispExpr(c.expression, t);
         let lc = 0;
         if (c.labourCoeID) lc = projectObj.project.calcProgram.compiledLabourCoes[c.labourCoeID].coe.toString();
         c.compiledExpr = analyzer.getCompiledExpr(c.expression, lc);