Bläddra i källkod

清单模板ID引用相关

zhongzewei 6 år sedan
förälder
incheckning
229f65ce9a

+ 30 - 0
modules/pm/controllers/new_proj_controller.js

@@ -15,6 +15,31 @@ import EngineeringLibModel from "../../users/models/engineering_lib_model";
 
 module.exports = {
     copyTemplateData: async function (property, newProjID, callback) {
+        //转换ID引用,原本@ID ID为原ID,需要替换为新的uuid
+        function parseCalcBase(calcBase, uuidMapping) {
+            let rst = '';
+            let reg = /@\d+/g,
+                numberData = Array.from(new Set(calcBase.match(reg))); //eg: @1
+            let regForOpr = /[+,\-,*,/]/g,
+                oprData = calcBase.match(regForOpr); //eg: +
+            let regForID = /\d+/g;
+            let uuidArr = [];
+            for (let data of numberData) {
+                let orgID = data.match(regForID);
+                if (orgID && orgID[0] && uuidMapping[orgID[0]]) {
+                    uuidArr.push(uuidMapping[orgID[0]]);
+                }
+            }
+            for (let i = 0; i < uuidArr.length; i++) {
+                let uid = uuidArr[i],
+                    opr = oprData[i - 1];
+                if (opr) {
+                    rst += opr;
+                }
+                rst += `@${uid}`;
+            }
+            return rst;
+        }
         async.parallel([
             async function (cb) {
                 // 获取清单模板数据
@@ -27,11 +52,16 @@ module.exports = {
                 for(let bill of billsDatas){
                     uuidMaping[bill.ID] = uuidV1();
                 }
+                let needParseReg = /@/g;
                 billsDatas.forEach(function (template) {
                     template.projectID = newProjID;
                     template.ID = uuidMaping[template.ID] ? uuidMaping[template.ID] : -1;
                     template.ParentID = uuidMaping[template.ParentID] ? uuidMaping[template.ParentID] : -1;
                     template.NextSiblingID = uuidMaping[template.NextSiblingID] ? uuidMaping[template.NextSiblingID] : -1;
+                    //需要转换ID引用
+                    if (template.calcBase && needParseReg.test(template.calcBase)) {
+                        template.calcBase = parseCalcBase(template.calcBase, uuidMaping);
+                    }
                 });
                 billsData.insertData(billsDatas, callback);
             },

+ 8 - 0
web/building_saas/main/js/models/cache_tree.js

@@ -294,6 +294,14 @@ var cacheTree = {
             }
             return success;
         };
+        //获取节点的祖先节点(最顶父节点)
+        Node.prototype.getAncestor = function () {
+            let node = this;
+            while (node.parent) {
+                node = node.parent;
+            }
+            return node;
+        };
 
         var Tree = function (owner) {
             this.owner = owner;