Browse Source

合格点数判断,保存更新问题

duy 1 week ago
parent
commit
2e3b62d625
2 changed files with 145 additions and 114 deletions
  1. 34 24
      src/views/formula/edit.vue
  2. 111 90
      src/views/formula/formulaArrayToString.js

+ 34 - 24
src/views/formula/edit.vue

@@ -20,8 +20,9 @@
                 <template slot="title">
                   <span>{{ key }}</span>
                 </template>
-                <el-menu-item v-for="(item2, index2) in value" :key="index2"
-                  :index="(index + 1) + '-' + (index2 + 1)">{{ item2.name }}</el-menu-item>
+                <el-menu-item v-for="(item2, index2) in value" :key="index2" :index="(index + 1) + '-' + (index2 + 1)">
+                  {{ item2.name }}
+                </el-menu-item>
               </el-submenu>
             </el-menu>
           </div>
@@ -87,7 +88,7 @@
                         <span v-else>{{ item.eName }}</span>
 
 
-                        <el-checkbox v-model="item.checked" @change="value => eleChang(value,item)"></el-checkbox>
+                        <el-checkbox v-model="item.checked" @change="value => eleChang(value, item)"></el-checkbox>
                       </div>
                     </el-col>
                   </el-row>
@@ -107,8 +108,9 @@
                 </div>
                 <div>
 
-                  <el-link :underline="false" type="primary" class="mg-r-10" @click="addBrackets('(', false)">(</el-link>
-                  <el-link :underline="false" type="primary" class="mg-r-10" @click="addBrackets(')',true)">)</el-link>
+                  <el-link :underline="false" type="primary" class="mg-r-10"
+                    @click="addBrackets('(', false)">(</el-link>
+                  <el-link :underline="false" type="primary" class="mg-r-10" @click="addBrackets(')', true)">)</el-link>
 
                   <el-link :underline="false" type="primary" @click="addText">输入值</el-link>
                 </div>
@@ -116,7 +118,7 @@
               <div class="border-grey sele-ele-box">
                 <draggable v-model="selectEleFormula">
                   <formula-item v-for="(item, index) in selectEleFormula" :key="index" :item="item"
-                    @click="obj => eleFormulaClick(obj,index)">
+                    @click="obj => eleFormulaClick(obj, index)">
                   </formula-item>
                 </draggable>
               </div>
@@ -192,7 +194,7 @@
             </el-col>
           </el-row>
           <div class="text-align-c">
-            <el-button size="small" @click="canceloperationVisible ">取消</el-button>
+            <el-button size="small" @click="canceloperationVisible">取消</el-button>
             <el-button size="small" @click="operationHandle" type="primary">保存</el-button>
           </div>
         </div>
@@ -378,7 +380,7 @@
                 <template>
 
                   <el-option v-for="item in eleTableList" :key="item.id" :label="item.tableName"
-                    :value="(item.pkeyId !== null && item.pkeyId!==-1)?item.pkeyId:item.id"></el-option>
+                    :value="(item.pkeyId !== null && item.pkeyId !== -1) ? item.pkeyId : item.id"></el-option>
                 </template>
 
               </el-select>
@@ -390,7 +392,7 @@
               <el-scrollbar style="height: 460px">
                 <tableFormWrite :pkeyId="eleTableId" :multiple-select="true"
                   @element-selected="(obj, val, list) => handleElementSelectedList(obj, val, list)"
-                  :initTableName="initTableNameComp" :key="tableKey" :container-id="'excel-container-'+tableKey"
+                  :initTableName="initTableNameComp" :key="tableKey" :container-id="'excel-container-' + tableKey"
                   :selectedTableKey="selectedTableKeyList"></tableFormWrite>
               </el-scrollbar>
 
@@ -647,6 +649,7 @@ export default {
     //等式中选中的元素
     equationSelectEle: function () {
       if (this.processType) {
+        console.log(this[this.processType])
         return this[this.processType][this.processSelectIndex];
       } else {
         return null;
@@ -759,8 +762,8 @@ export default {
 
     //选择公式处理
     handleSelect(index, indexPath) {
-      //console.log(index,'index')
-      //console.log(indexPath,'indexPath')
+      console.log(index, 'index')
+      console.log(indexPath, 'indexPath', this.operationVisible)
       if (this.operationVisible) {
         this.openerationSelect(index, indexPath)
       } else {
@@ -1356,6 +1359,8 @@ export default {
     equationClick({ selected, item }, index, arrName) {
       this.checkGsId = item.id
 
+      console.log(item, selected)
+
       if (selected) {
         this.resultFormula.forEach((ele) => {
           ele.selected = false;
@@ -1753,11 +1758,15 @@ export default {
 
 
       let arr = JSON.parse(JSON.stringify(this.processFormula));
+      console.log("aaaaaaaaaaaaaaaa===processFormula", arr,);
       let filteredArr = arr.filter(item => item.id === this.checkGsId);
+      console.log("bbbbbbbbbbbbbbbb===filteredArr", filteredArr,);
       let obj
       let obj2
       obj = formulaArrayToString(this.processFormula, this.resultFormula);
+      console.log("ccccccccccccccccc===obj", obj,);
       obj2 = formulaArrayToString(filteredArr, this.resultFormula);
+      console.log("ccccccccccccccccc===obj2", obj2,);
       // 判断 obj2.text 是否包含 FC.ifelse
       if (obj2.text && (obj2.text.includes('FC.ifelse')) || obj2.text.includes("''")) {
         obj = obj2; // 如果包含 FC.ifelse,使用 obj2
@@ -1798,8 +1807,7 @@ export default {
           }
         }
       }
-
-      //console.log(text);
+      // console.log("55555555555", obj, obj.text);
       if (this.formulaid) {
         updateFormula({
           id: this.formulaid,
@@ -1878,8 +1886,7 @@ export default {
         this.dataForm = detail.formula
         console.log(this.dataForm, ' this.dataListGet');
 
-      }
-      else {
+      } else {
         this.isMore = false;
         this.moreConditions = []
         this.formulaDetailMap = {}
@@ -1890,6 +1897,7 @@ export default {
 
       }
 
+      console.log('detail', detail);
 
       if (detail && detail.id) {
         //获取右边元素的字典
@@ -1909,7 +1917,7 @@ export default {
 
 
         let formula = formulaStringToArray(detail.formula, detail.map, this.formulaMap);
-        console.log(formula, 'formula');
+        console.log('formula99999999999', formula);
 
         this.processFormula = formula.processFormula;
         formula.resultFormula[0].id = this.resultFormula[0].id;
@@ -1917,6 +1925,8 @@ export default {
         formula.resultFormula[0].tableElementKey = this.resultFormula[0].tableElementKey;
         this.resultFormula[0].children = formula.resultFormula[0].children;
 
+        console.log("this.resultFormula", this.resultFormula);
+
         //允许偏差值范围
         let mapObj = JSON.parse(detail.map);
         if (mapObj.deviationRangeJson) {
@@ -2394,14 +2404,14 @@ export default {
 
     },
     //逻辑判断回显元素
-    handleClickTagElse(item){
-  
+    handleClickTagElse(item) {
+
       this.selectedTableKeyComp = null;
-  
-              const keyParts =  item.tableElementKey.split('key');
-              this.selectedTableKeyComp = keyParts.length > 1 ? 'key'+keyParts[1] : null;
-  },
-}
+
+      const keyParts = item.tableElementKey.split('key');
+      this.selectedTableKeyComp = keyParts.length > 1 ? 'key' + keyParts[1] : null;
+    },
+  }
 
 };
 </script>
@@ -2475,7 +2485,7 @@ export default {
 
 .operation-box-inset {
   display: flex;
-  flex-direction:column;
+  flex-direction: column;
 }
 </style>
 <style scoped>

+ 111 - 90
src/views/formula/formulaArrayToString.js

@@ -1,6 +1,5 @@
-
-function isFormulaItem(ele){
-  return ele.type == 'Element' || ele.type == 'ParamData'
+function isFormulaItem(ele) {
+  return ele.type == "Element" || ele.type == "ParamData";
 }
 
 //转换公式的参数
@@ -34,7 +33,7 @@ function isFormulaItem(ele){
 //           }
 //         }
 //         let arg = ele.arguments[argIndex];
-        
+
 //         if(arg && isFormulaItem(arg)){
 //           if(!isNestEle && !isNestEle2 && i != (children.length-1) && curEle.id == arg.id){
 //             //不是第一个嵌套的公式,且和当前挂载的是同一个元素
@@ -59,7 +58,7 @@ function isFormulaItem(ele){
 //               };
 //               fcText += `WP[${arg.k}]`;
 //             }
-            
+
 //           }
 //         }else if(Array.isArray(arg)){
 //           //ifsles方法会进来
@@ -117,46 +116,51 @@ function isFormulaItem(ele){
 
 //   return fcText;
 // }
-function transformArguments(children,curEle,eleMap){
+function transformArguments(children, curEle, eleMap) {
   // debugger
   let fcReg = /(FC\.\S+\()(.+)\)/;
-  let fcText = '';
-  for (let i = (children.length-1); i >= 0; i--) {
+  let fcText = "";
+  for (let i = children.length - 1; i >= 0; i--) {
     let ele = children[i];
 
-    if(ele.isOn === false){
+    if (ele.isOn === false) {
       //点击了开关关闭的,跳过
       continue;
     }
     if (ele.template != null && ele.template != undefined) {
       let tmpArr = fcReg.exec(ele.template.ft);
-      fcText = tmpArr[1] + fcText;//fc.XX( 左括号部分
-      let argList = tmpArr[2].split(",");//括号里面参数部分#1,#2..
-      let isNestEle = false;//是否有过嵌套的元素了
+      fcText = tmpArr[1] + fcText; //fc.XX( 左括号部分
+      let argList = tmpArr[2].split(","); //括号里面参数部分#1,#2..
+      let isNestEle = false; //是否有过嵌套的元素了
       let isNestEle2 = false;
       //console.log(argList)
       //console.log(text)
-      argList.forEach((argText,index)=>{
-        if(argText.indexOf('#')>-1){
+      argList.forEach((argText, index) => {
+        if (argText.indexOf("#") > -1) {
           //#动态参数
           let argIndex = index;
           for (let j = 0; j < ele.template.args.length; j++) {
-            if(ele.template.args[j].key == argText){
+            if (ele.template.args[j].key == argText) {
               //找到相同的#编码
               argIndex = j;
               break;
             }
           }
           let arg = ele.arguments[argIndex];
-          
-          if(arg && isFormulaItem(arg)){
-            if(!isNestEle && !isNestEle2 && i != (children.length-1) && curEle.id == arg.id){
+
+          if (arg && isFormulaItem(arg)) {
+            if (
+              !isNestEle &&
+              !isNestEle2 &&
+              i != children.length - 1 &&
+              curEle.id == arg.id
+            ) {
               //不是第一个嵌套的公式,且和当前挂载的是同一个元素
               //认为这个参数是之前公式计算的结果,不再写入元素
               isNestEle = true;
-            }else{
+            } else {
               // let atbkey=arg.tableElementKey.replace('_key',':key')
-              if(arg.type == 'Element'){
+              if (arg.type == "Element") {
                 eleMap[arg.tableElementKey] = {
                   id: arg.id,
                   name: arg.name,
@@ -164,28 +168,31 @@ function transformArguments(children,curEle,eleMap){
                   type: "Element",
                 };
                 fcText += `E[${arg.tableElementKey}]`;
-              }else if(arg.type == 'ParamData'){
+              } else if (arg.type == "ParamData") {
                 eleMap[arg.k] = {
                   id: arg.id,
                   name: arg.name,
-                  v:arg.v,
-                  k:arg.k,
+                  v: arg.v,
+                  k: arg.k,
                   type: "ParamData",
                 };
                 fcText += `WP[${arg.k}]`;
               }
-              
             }
-          }else if(Array.isArray(arg)){
+          } else if (Array.isArray(arg)) {
             //ifsles方法会进来
-            arg.forEach((a)=>{
-              if(a && isFormulaItem(a)){
-                if(!isNestEle2 && i != (children.length-1) && curEle.id == a.id){
+            arg.forEach((a) => {
+              if (a && isFormulaItem(a)) {
+                if (
+                  !isNestEle2 &&
+                  i != children.length - 1 &&
+                  curEle.id == a.id
+                ) {
                   //不是第一个嵌套的公式,且和当前挂载的是同一个元素
                   //认为这个参数是之前公式计算的结果,不再写入元素
-                  isNestEle2 = true
-                }else{
-                  if(a.type == 'Element'){
+                  isNestEle2 = true;
+                } else {
+                  if (a.type == "Element") {
                     eleMap[a.tableElementKey] = {
                       id: a.id,
                       name: a.name,
@@ -193,111 +200,125 @@ function transformArguments(children,curEle,eleMap){
                       type: "Element",
                     };
                     fcText += `E[${a.tableElementKey}]`;
-                  }else if(a.type == 'ParamData'){
+                  } else if (a.type == "ParamData") {
                     eleMap[a.k] = {
                       id: a.id,
                       name: a.name,
-                      v:a.v,
-                      k:a.k,
+                      v: a.v,
+                      k: a.k,
                       type: "ParamData",
                     };
                     fcText += `WP[${a.k}]`;
                   }
                 }
-              }else if(a && a.type == 'Operator'){
+              } else if (a && a.type == "Operator") {
                 //在运算符前后加上空格
-                fcText += ' '+a.name+' ';
+                fcText += " " + a.name + " ";
                 //console.log(fcText)
-              }else if(a && a.type){
+              } else if (a && a.type) {
                 fcText += a.name;
-              }else{
-                fcText += a?a:"''";
+              } else {
+                fcText += a ? a : "''";
               }
-            })
-  
-          }else{
-            fcText += arg?arg:"''";
+            });
+          } else {
+            fcText += arg ? arg : "''";
           }
-  
-        }else{
+        } else {
           //已有参数
-          fcText += argText?argText:'';
+          fcText += argText ? argText : "";
         }
-        if(index != argList.length-1){
-          fcText += ',';
+        if (index != argList.length - 1) {
+          fcText += ",";
         }
-      })
-    
-      fcText += ')';
-    
-    }
-    console.log(fcText,'ele.name')
+      });
 
-  
+      fcText += ")";
+    }
+    console.log(fcText, "ele.name");
   }
 
   return fcText;
 }
-export const formulaArrayToString = (processFormula,resultFormula) => {
-  let text = '';
-  let eleMap = {};//元素字典,为了回显的时候查询信息
-  let preIsOp=false;//前一个参数是否是四则运算(+-*/)
-  processFormula.forEach((item,index) => {
-    if(isFormulaItem(item)){
+export const formulaArrayToString = (processFormula, resultFormula) => {
+  let text = "";
+  let eleMap = {}; //元素字典,为了回显的时候查询信息
+  let preIsOp = false; //前一个参数是否是四则运算(+-*/)
+
+  console.log("processFormula",processFormula);
+  processFormula.forEach((item, index) => {
+    if (isFormulaItem(item)) {
       //console.log(item)
-      if(item.children.length <1){
-        if(item.type == 'Element'){
+      if (item.children.length < 1) {
+        if (item.type == "Element") {
           eleMap[item.tableElementKey] = {
             id: item.id,
             name: item.name,
             tableElementKey: item.tableElementKey,
             type: "Element",
           };
-          text += `E[${item.tableElementKey}]`;
-        }else if(item.type == 'ParamData'){
+          text += `E[${item.tableElementKey}],`;
+        } else if (item.type == "ParamData") {
           eleMap[item.k] = {
             id: item.id,
             name: item.name,
-            v:item.v,
-            k:item.k,
+            v: item.v,
+            k: item.k,
             type: "ParamData",
           };
           text += `WP[${item.k}]`;
         }
-        
-      }else{
-        text += (index>0&&!preIsOp?',':'')+transformArguments(item.children,item,eleMap);
-        preIsOp=false;
+      } else {
+        text +=
+          (index > 0 && !preIsOp ? "," : "") +
+          transformArguments(item.children, item, eleMap);
+        preIsOp = false;
       }
-    }else if(item.type == 'Element'){
+    } else if (item.type == "Element") {
       text += item.template.ft;
-    }else if(item.type == 'Operator'){
+    } else if (item.type == "Operator") {
       //在运算符前后加上空格
-      preIsOp=true;
-      text += ' '+item.name+' ';
+      preIsOp = true;
+      text += " " + item.name + " ";
       //console.log(fcText)
-    }else{
+    } else {
       text += item.name;
     }
   });
-  if(resultFormula[0].children.length){
+
+  console.log(text, "sssssss");
+
+  if (resultFormula[0].children.length) {
     //等号左侧部分
-    let resText = transformArguments(resultFormula[0].children,resultFormula[0],eleMap);
+    let resText = transformArguments(
+      resultFormula[0].children,
+      resultFormula[0],
+      eleMap
+    );
+    console.log(resText, "等号左侧");
+
     //等号左侧元素不需要,左侧的公式嵌套右侧所有结果
     let fcReg = /(FC\.\S+\()(.+)\)/;
-    let leftArr=fcReg.exec(resText);
+    let leftArr = fcReg.exec(resText);
+    console.log(leftArr, "左侧匹配", resText);
+    text = resText;
+
+    // 有问题!!!
     //text = resText.replace(`E[${resultFormula[0].tableElementKey}]`,text);
-    if(!!text&&!resText.includes(text)&&!!leftArr){
-       let reg = leftArr[2].replace('OPTION,','');
-      text = resText.replace(reg,text);
-    }else{
-      text = resText;
-    }
-   
-  
+    // if(!!text&&!resText.includes(text)&&!!leftArr){
+    // if (text && !resText.includes(text) && leftArr.length) {
+    //   console.log(leftArr[2], "左侧匹配结果");
+
+    //   const toReplace = leftArr[2].replace('OPTION,', '')
+    //   console.log("替换内容", toReplace);
+    //   text = resText.replace(toReplace, text)
+
+    // } else {
+    //   text = resText;
+    // }
   }
 
-  console.log(text,'最终');
+  console.log(text, "最终");
   //console.log(eleMap)
-  return {text,eleMap};
-}
+  return { text, eleMap };
+};