Эх сурвалжийг харах

公式嵌套和嵌套公式的回显问题

duy 2 өдөр өмнө
parent
commit
ebfa90d816

+ 1 - 1
public/version.json

@@ -1,3 +1,3 @@
 {
-  "value": "20251215101329"
+  "value": "20251216124428"
 }

+ 9 - 9
src/views/formula/component/formulaTemplate.vue

@@ -5,8 +5,7 @@
     <div v-for="(item, index) in formulainfo.arguments" :key="index" class="mg-t-20">
       <div>
         <span>参数{{ (index + 1) }}({{ formulainfo.template.args[index].m }}):</span>
-        <span v-if="JSON.stringify(item) !== 'null'">
-
+        <span v-if="item !== null">
           <el-radio-group v-model="formulainfo.arguments[index]"
             v-if="formulainfo.template.args[index].m == '是否同行/列计算(选填)'">
             <el-radio label="y">同行</el-radio>
@@ -22,12 +21,11 @@
             </template>
           </template>
         </span>
-        <el-link type="primary" @click="changeType('text', index)" class="mg-l-10"
-          v-if="formulainfo.template.args[index].m !== '是否同行/列计算(选填)'">输入文本</el-link>
-        <el-link type="primary" @click="changeType('ele', index)" class="mg-l-10"
-          v-if="formulainfo.template.args[index].m !== '是否同行/列计算(选填)'">选择元素</el-link>
-        <el-link type="primary" @click="setCurEle(index)" class="mg-l-10"
-          v-if="formulainfo.template.args[index].m !== '是否同行/列计算(选填)'">当前元素</el-link>
+        <template v-if="formulainfo.template.args[index].m !== '是否同行/列计算(选填)'">
+          <el-link type="primary" @click="changeType('text', index)" class="mg-l-10">输入文本</el-link>
+          <el-link type="primary" @click="changeType('ele', index)" class="mg-l-10">选择元素</el-link>
+          <el-link type="primary" @click="setCurEle(index)" class="mg-l-10">当前元素</el-link>
+        </template>
       </div>
     </div>
   </div>
@@ -58,7 +56,9 @@ export default {
   },
   mounted() {
     this.template = this.formulainfo.template.ft;
-    this.formulainfo.arguments[0].tableElementKey = this.formulainfo.arguments[0].tableElementKey.replace("_key", ":key")
+    console.log("this.formulainfo", this.formulainfo.arguments)
+
+    // this.formulainfo.arguments[0].tableElementKey = this.formulainfo.arguments[0].tableElementKey.replace("_key", ":key")
     this.formulainfo.template.args.forEach(element => {
       this.template = this.template.replace(element.key, element.m)
     });

+ 1 - 1
src/views/formula/edit.vue

@@ -2150,7 +2150,7 @@ export default {
           name: ele.eName,
           id: ele.id,
           selected: false,
-          tableElementKey: ele.tableElementKey,
+          tableElementKey: ele.tableElementKey.replace('_key',':key'),
           children: [],
         }]
       })

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 451 - 561
src/views/formula/edit1-1.vue


+ 1 - 1
src/views/formula/edit1.vue

@@ -1939,7 +1939,7 @@ export default {
           name: ele.eName,
           id: ele.id,
           selected: false,
-          tableElementKey: ele.tableElementKey,
+          tableElementKey: ele.tableElementKey.replace('_key',':key'),
           children: [],
         }]
       })

+ 114 - 26
src/views/formula/formulaArrayToString.js

@@ -117,12 +117,14 @@ function isFormulaItem(ele) {
 //   return fcText;
 // }
 function transformArguments(children, curEle, eleMap) {
-  // debugger
+  // debugger;
   let fcReg = /(FC\.\S+\()(.+)\)/;
   let fcText = "";
   for (let i = children.length - 1; i >= 0; i--) {
     let ele = children[i];
 
+    console.log("transformArguments==ele", ele);
+
     if (ele.isOn === false) {
       //点击了开关关闭的,跳过
       continue;
@@ -244,9 +246,10 @@ export const formulaArrayToString = (processFormula, resultFormula) => {
   let text = "";
   let eleMap = {}; //元素字典,为了回显的时候查询信息
   let preIsOp = false; //前一个参数是否是四则运算(+-*/)
+  // debugger
 
   console.log("processFormula", processFormula);
-  processFormula.forEach((item, index) => {
+  processFormula.forEach((item) => {
     if (isFormulaItem(item)) {
       //item.type == "Element" || item.type == "ParamData";
       //console.log(item)
@@ -258,7 +261,9 @@ export const formulaArrayToString = (processFormula, resultFormula) => {
             tableElementKey: item.tableElementKey,
             type: "Element",
           };
-          text += `E[${item.tableElementKey}],`;
+          text += `${
+            isStrictNumber(item.argIndex) ? "#" + item.argIndex + "~" : ""
+          }E[${item.tableElementKey}],`;
         } else if (item.type == "ParamData") {
           eleMap[item.k] = {
             id: item.id,
@@ -270,9 +275,20 @@ export const formulaArrayToString = (processFormula, resultFormula) => {
           text += `WP[${item.k}]`;
         }
       } else {
-        text +=
-          (index > 0 && !preIsOp ? "," : "") +
-          transformArguments(item.children, item, eleMap);
+        text += `${
+          isStrictNumber(item.argIndex) ? "#" + item.argIndex + "~" : ""
+        }${transformArguments(item.children, item, eleMap)},`;
+        // text += `${index > 0 && !preIsOp ? "," : ""}${
+        //   item.argIndex || item.argIndex === 0 ? "#" + item.argIndex + "-" : ""
+        // }${transformArguments(item.children, item, eleMap)},`;
+        // (index > 0 && !preIsOp ? "," : "") +
+        // "#" +
+        // item.argIndex +
+        // "-" +
+        // transformArguments(item.children, item, eleMap) +
+        // ",";
+        console.log(text, "中间1111111");
+
         preIsOp = false;
       }
     } else if (item.type == "Element") {
@@ -280,10 +296,11 @@ export const formulaArrayToString = (processFormula, resultFormula) => {
     } else if (item.type == "Operator") {
       //在运算符前后加上空格
       preIsOp = true;
-      text += " " + item.name + " ";
+      text += `${item.name},`;
+      // text += item.name + ",";
       //console.log(fcText)
     } else {
-      text += item.name;
+      text += item.name + ",";
     }
   });
 
@@ -299,31 +316,102 @@ export const formulaArrayToString = (processFormula, resultFormula) => {
     console.log(resText, "等号左侧");
 
     //等号左侧元素不需要,左侧的公式嵌套右侧所有结果
-    // let fcReg = /(FC\.\S+\()(.+)\)/;
     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){
-    // if (text && !resText.includes(text) && leftArr.length) {
-    //   console.log(leftArr[2], "左侧匹配结果");
+    if (!!text && !resText.includes(text) && !!leftArr) {
+      let reg = leftArr[2].replace("OPTION,", "");
 
-    //   const toReplace = leftArr[2].replace('OPTION,', '')
-    //   console.log("替换内容", toReplace);
-    //   text = resText.replace(toReplace, text)
+      console.log("resultFormula替换111", reg, "processFormula替换222", text);
 
-    // } else {
-    //   text = resText;
-    // }
+      const textArr = splitSharpSegments(text);
+      console.log("resultFormula替换333", textArr);
+      const map = reg.split(",").map((el, index) => {
+        const idx = textArr.findIndex((item) => item.idx === index);
+        if (idx > -1) {
+          return textArr[idx].after;
+        } else {
+          return el;
+        }
+      });
+      console.log("resultFormula替换444", map);
+      text = leftArr[1] + map.join(",") + ")";
+    } else {
+      text = resText;
+    }
   } else {
-    if (!fcReg.test(text)) {
-      text = text.replaceAll(",", "");
+    // 判断字符串是否以 FC.xxx(...) 开头
+    const textArr = splitSharpSegments(text);
+    console.log("resultFormula替换555", textArr);
+    const fcRegStart = /^FC\.\w+\([^)]*\)/;
+    if (!fcRegStart.test(text)) {
+      text = cleanExpr(text).replace(/#\d+~/g, "");
     }
   }
-
-  console.log(text, "最终");
-  //console.log(eleMap)
+  text = text.replace(
+    /(FC\.\w+)(\(([^]*?)\))(?=[^()]*$)/,
+    (_, fn, __, inner) => fn + "(" + inner.replace(/,\s*$/, "") + ")"
+  );
+  console.log(text, eleMap, "最终");
   return { text, eleMap };
 };
+
+const isStrictNumber = (v) => typeof v === "number" && !Number.isNaN(v);
+/**
+ * 按规则拆分,并保留 #数字- 前缀
+ * @param {string} str 原始字符串
+ * @returns {string[]} 形如 ["#1- FC.quantity(...)", "#2- E[...]", ...]
+ */
+function splitSharpSegments(str) {
+  const re = /(#(\d+)~)([^#]*?)(?=,#\d+|$)/g;
+  const res = [];
+  let m;
+
+  while ((m = re.exec(str)) !== null) {
+    const idx = Number(m[2]); // 数字部分
+    let raw = m[3]; // "#数字-" 后面的原始片段
+
+    if (raw.includes("(")) {
+      const close = raw.lastIndexOf(")");
+      res.push({ idx, after: raw.slice(0, close + 1) });
+    } else {
+      const close = raw.lastIndexOf("]");
+      res.push({ idx, after: raw.slice(0, close + 1) });
+    }
+  }
+  return res;
+}
+
+/**
+ * 清洗表达式
+ * @param {string} raw 原始字符串
+ * @returns {string} 清洗后的字符串
+ */
+function cleanExpr(raw) {
+
+  raw = raw.replace(/\s+/g, ''); // 去掉所有空格
+
+  // 1. 把 FC.xx(...) 整体保护起来
+  const bucket = [];
+  const protected_ = raw.replace(
+    /FC\.[^(]+\([^)]*\)/g,          // 匹配 FC.xx(任意非右括号)
+    m => (bucket.push(m), `__${bucket.length - 1}__`)  // 占位符
+  );
+
+  // 2. 在“非函数区”做逗号清理
+  let cleaned = protected_.replace(/,([#+\-*/()\d])/g, '$1');
+
+  // 3. 还原占位符
+  cleaned = cleaned.replace(/__(\d+)__/g, (_, i) => bucket[i]);
+
+  // 去掉末尾逗号
+  cleaned = cleaned.replace(/,$/, '');
+
+  // 3. 保证运算符左右各有一个空格
+  //    先给所有运算符前后强制插入一个空格
+  cleaned = cleaned.replace(/([+\-*/])/g, ' $1 ');
+  //    再把连续空格压成一个
+  cleaned = cleaned.replace(/\s+/g, ' ');
+  //    去掉行首行尾空格
+  return cleaned.trim();
+}

+ 254 - 226
src/views/formula/formulaStringToArray.js

@@ -1,236 +1,265 @@
-
-function isFormulaItem(ele){
-  return ele.type == 'Element' || ele.type == 'ParamData'
+function isFormulaItem(ele) {
+  return ele.type == "Element" || ele.type == "ParamData";
 }
 
-function parseFormula(arr,resultFormula,processFormula,isAllFun){
-  let tmpArr = [];//放置这一层的数组
+function parseFormula(arr, resultFormula, processFormula, isAllFun) {
+  let tmpArr = []; //放置这一层的数组
+  // debugger
+  console.log("parseFormula555555555", arr);
   for (let i = 0; i < arr.length; i++) {
     tmpArr.push(arr[i]);
-    if(arr[i].type != "Function"){
+    if (arr[i].type != "Function") {
       isAllFun = false;
     }
   }
-  if(isAllFun){
+  console.log(
+    "parseFormula====isAllFun",
+    isAllFun,
+    tmpArr,
+    resultFormula,
+    processFormula
+  );
+  // debugger;
+  if (isAllFun) {
     for (let i = 0; i < tmpArr.length; i++) {
-      parseArguments(resultFormula[0],tmpArr[i]);
-      parseFormula(arr[i].children,resultFormula,processFormula,isAllFun);
+      parseArguments(resultFormula[0], tmpArr[i]);
+      parseFormula(arr[i].children, resultFormula, processFormula, isAllFun);
     }
-  }else{
+  } else {
+    let argIndex = 0;
     for (let j = 0; j < tmpArr.length; j++) {
       let data = tmpArr[j];
-      if(data.type == 'Function'){
+      if (data.type == "Function") {
         let obj = {
-          children:[],
-          name:"临时占位",
-          selected:false,
-          type:"Element",
-        }
-        parseProcessFormula(arr[j],obj);
-        processFormula.push(Object.assign({},obj))
+          children: [],
+          name: "临时占位",
+          selected: false,
+          type: "Element",
+        };
+        parseProcessFormula(arr[j], obj);
+        processFormula.push(Object.assign({}, obj));
         delete obj.children;
-      }else if(data.name){
-        processFormula.push(data);
+      } else if (data.name || data.type === "Text") {
+        if (data.name) {
+          // if (data.type !== "Operator") {
+            processFormula.push({ ...data, argIndex });
+          // } else {
+            // processFormula.push({ ...data });
+          // }
+        }
+        // if (data.type !== "Operator") {
+          argIndex++;
+        // }
       }
     }
   }
 }
 
 //解析方法里面的参数
-function parseArguments(ele,funObj){
+function parseArguments(ele, funObj) {
   let fcReg = /(FC\.\S+\()(.+)\)/;
   let fun = {
-    example:funObj.example,
-    name:funObj.name,
-    template:funObj.template,
+    example: funObj.example,
+    name: funObj.name,
+    template: funObj.template,
   };
   //console.log(funObj)
   //特殊公式需要number
-  if(funObj.number){
+  if (funObj.number) {
     fun.number = funObj.number;
   }
-  let argTextArr = funObj.children;//放参数文本的数组
+  let argTextArr = funObj.children; //放参数文本的数组
+  console.log("argTextArr", argTextArr);
 
   //根据逗号位置分割参数
   let index = 0;
   let argSpliceArr = [[]];
   while (index < argTextArr.length) {
-    if(argTextArr[index].type =='Comma'){
+    if (argTextArr[index].type == "Comma") {
       argSpliceArr.push([]);
-    }else{
-      argSpliceArr[argSpliceArr.length-1].push(argTextArr[index])
+    } else {
+      argSpliceArr[argSpliceArr.length - 1].push(argTextArr[index]);
     }
-    index++
+    index++;
   }
-
+  console.log("argSpliceArr88888888888888", argSpliceArr);
   fun.arguments = [];
 
   if (funObj.template != null && funObj.template != undefined) {
     let tmpArr = fcReg.exec(funObj.template.ft);
-    let argList = tmpArr[2].split(",");//括号里面参数部分#1,#2..
-
-    argList.forEach((argText,index)=>{
-        //只用动态的
-        if(argText.indexOf('#')>-1||/^[A-Z]+$/.test(argText)){
-          if(argSpliceArr[index].length>1){
-            if(fun.name == '判断'){
-              fun.arguments.push(ifFunArgumentsHandle(argSpliceArr[index]))
-            }else{
-              //是前面的计算结果
-              fun.arguments.push(ele)
-            }
-
-          }else{
-            let arg = argSpliceArr[index][0];
-            if(!arg){
-              fun.arguments.push(undefined)
-            }else if( arg.type == 'Element'){
-              fun.arguments.push(arg)
-            }else if( arg.type == 'ParamData'){
-              fun.arguments.push(arg)
-            }else if(arg.type == 'Function'){
-              fun.arguments.push(ele)
-            }else if(arg.type == 'Text'){
-              fun.arguments.push(arg.tag)
-            }else{
-              fun.arguments.push(undefined)
-            }
+    let argList = tmpArr[2].split(","); //括号里面参数部分#1,#2..
+    console.log("argList", argList);
+    argList.forEach((argText, index) => {
+      //只用动态的
+      if (argText.indexOf("#") > -1 || /^[A-Z]+$/.test(argText)) {
+        console.log(
+          "argSpliceArr.index",
+          argSpliceArr[index],
+          fun.arguments,
+          ele
+        );
+        if (argSpliceArr[index].length > 1) {
+          if (fun.name == "判断") {
+            fun.arguments.push(ifFunArgumentsHandle(argSpliceArr[index]));
+          } else {
+            //是前面的计算结果
+            fun.arguments.push(ele);
+          }
+        } else {
+          let arg = argSpliceArr[index][0];
+          if (!arg) {
+            fun.arguments.push(undefined);
+          } else if (arg.type == "Element") {
+            fun.arguments.push(arg);
+          } else if (arg.type == "ParamData") {
+            fun.arguments.push(arg);
+          } else if (arg.type == "Function") {
+            fun.arguments.push(ele);
+          } else if (arg.type == "Text") {
+            fun.arguments.push(arg.tag);
+          } else {
+            fun.arguments.push(undefined);
           }
         }
-      })
+      }
+    });
   }
 
   ele.children.push(fun);
 }
 
-function parseProcessFormula(funObj,ele){
-  parseArguments(ele,funObj);
-  let inFun = false;//是不是有Function
-  let endEle = null;//认为最下面一层第一个元素是显示的元素
+function parseProcessFormula(funObj, ele) {
+  console.log(
+    "666666666666parseProcessFormula===========666666666666",
+    funObj,
+    ele
+  );
+  parseArguments(ele, funObj);
+  let inFun = false; //是不是有Function
+  let endEle = null; //认为最下面一层第一个元素是显示的元素
   for (let i = 0; i < funObj.children.length; i++) {
-    if(funObj.children[i].type == 'Function'){
-      parseProcessFormula(funObj.children[i],ele);
+    if (funObj.children[i].type == "Function") {
+      parseProcessFormula(funObj.children[i], ele);
       inFun = true;
-    }else if(isFormulaItem(funObj.children[i]) && !endEle){
-      endEle = funObj.children[i];
+    } else if (isFormulaItem(funObj.children[i]) && !endEle) {
+      endEle = { ...funObj.children[i], argIndex: i };
     }
   }
-  if(!inFun){
+  if (!inFun) {
     //console.log(endEle)
     //把临时的属性改为最终找到的
-    if(endEle.type == 'Element'){
+    if (endEle.type == "Element") {
       ele.id = endEle.id;
       ele.name = endEle.name;
       ele.tableElementKey = endEle.tableElementKey;
-    }else if(endEle.type == 'ParamData'){
+    } else if (endEle.type == "ParamData") {
       ele.id = endEle.id;
       ele.name = endEle.name;
       ele.v = endEle.v;
       ele.k = endEle.k;
       ele.type = "ParamData";
     }
-
   }
-
 }
 
 //处理if方法的参数
-function ifFunArgumentsHandle(argArr){
+function ifFunArgumentsHandle(argArr) {
   let arr = [];
 
-  argArr.forEach((Element)=>{
-    if(Element.type == 'Text' || Element.type == 'Logical'){
-      arr.push(Element.tag)
-    }else{
-      if(Element.type == 'Function'){
-                let rootObj = {root:null};
-        getRootElement(Element.children,rootObj)
-        arr.push(rootObj.root)
-      }else{
+  argArr.forEach((Element) => {
+    if (Element.type == "Text" || Element.type == "Logical") {
+      arr.push(Element.tag);
+    } else {
+      if (Element.type == "Function") {
+        let rootObj = { root: null };
+        getRootElement(Element.children, rootObj);
+        arr.push(rootObj.root);
+      } else {
         arr.push(Element);
       }
     }
-  })
+  });
 
   return arr;
 }
 
 //获取嵌套里面根节点元素,认为是if显示的元素
-function getRootElement(children,rootObj){
-  let inFun = false;//是不是有Function
-  let endEle = null;//认为最下面一层第一个元素是显示的元素
-  children.forEach((Element)=>{
-    if(Element.type == 'Function'){
-      getRootElement(Element.children,rootObj);
+function getRootElement(children, rootObj) {
+  let inFun = false; //是不是有Function
+  let endEle = null; //认为最下面一层第一个元素是显示的元素
+  children.forEach((Element) => {
+    if (Element.type == "Function") {
+      getRootElement(Element.children, rootObj);
       inFun = true;
-    }else if(isFormulaItem(Element) && !endEle){
+    } else if (isFormulaItem(Element) && !endEle) {
       endEle = Element;
     }
-  })
-  if(!inFun){
+  });
+  if (!inFun) {
     //把临时的属性改为最终找到的
-    rootObj.root = Object.assign({},endEle);
+    rootObj.root = Object.assign({}, endEle);
   }
 }
 
-export const formulaStringToArray = (text,elemap,formulaMap) => {
-// debugger
+export const formulaStringToArray = (text, elemap, formulaMap) => {
+  // debugger
   // 匹配开始的FC.xxx(
   const startFCRegExp = /^FC\.([a-zA-Z0-9]+)\(/;
-  const startBracketsReg = /^\(/;//左括号
-  const endBracketsReg = /^\)/;//右括号
+  const startBracketsReg = /^\(/; //左括号
+  const endBracketsReg = /^\)/; //右括号
   //const elementReg = /^E\[(.[^\]]+_.[^\]]+)\]/;//元素
-  const elementReg = /^E\[([^\]]+)\]/;//元素
-  const paramReg = /^WP\[(.[^\]]+)\]/;//节点参数
-  const commaReg = /^,/;//逗号
-  const operatorReg = /^ (\+|-|\*|%|\/) /;//加减乘除
+  const elementReg = /^E\[([^\]]+)\]/; //元素
+  const paramReg = /^WP\[(.[^\]]+)\]/; //节点参数
+  const commaReg = /^,/; //逗号
+  const operatorReg = /^ (\+|-|\*|%|\/) /; //加减乘除
   // const wordReg = /^[\u4e00-\u9fa5\w0-9'"-]+/;//文本
   // const wordReg = /^[\u4e00-\u9fa5\{\}\w\\.0-9'"-]+/;//文本
   // const wordReg = /^[\u4e00-\u9fa5\{\}\w\\.0-9'"-]+/;//文本
   const wordReg = /^[±\u4e00-\u9fa5\{\}\w\\.0-9'"-]+/; // 新增±符号到文本匹配正则
 
- const sxReg = /^[|]/; // 匹配字符串开头竖线
+  const sxReg = /^[|]/; // 匹配字符串开头竖线
 
   // const logicalReg = /^(>=|<=|>|<|=|&&)/;//逻辑符号
   const logicalReg = /^(>=|<=|>|<|=|&&|\|)/;
 
-  let elementMap = JSON.parse(elemap);//元素字典
+  let elementMap = JSON.parse(elemap); //元素字典
   //console.log(formulaMap)
 
-  let resArr = [];//结果数组
-  let strIndex = 0;//位置索引
-  let nuText = text;//未处理的字符串
+  let resArr = []; //结果数组
+  let strIndex = 0; //位置索引
+  let nuText = text; //未处理的字符串
   //let startStack = [];//方法体开始部分和左括号 放进来的栈
-  let contentStack = [];//内容放进来的栈
+  let contentStack = []; //内容放进来的栈
 
   while (strIndex < text.length) {
     nuText = text.substring(strIndex);
-    if(startFCRegExp.test(nuText)){
+    // console.log(nuText, "未处理的字符串");
+    if (startFCRegExp.test(nuText)) {
       //console.log('匹配FC开始部分')
       //匹配FC开始部分FC.xxx(
       let regRes = nuText.match(startFCRegExp);
-      let startText = regRes[0];//匹配到的文本
+      let startText = regRes[0]; //匹配到的文本
 
       let obj = {};
-      if(formulaMap[startText]){
-        Object.assign(obj,formulaMap[startText]);
-        Object.assign(obj,{
-          type:'Function',
-          children:[],
-          tag:startText
+      if (formulaMap[startText]) {
+        Object.assign(obj, formulaMap[startText]);
+        Object.assign(obj, {
+          type: "Function",
+          children: [],
+          tag: startText,
         });
-      }else{
+      } else {
         obj = {
-          type:'Function',
-          children:[],
-          tag:startText
-        }
+          type: "Function",
+          children: [],
+          tag: startText,
+        };
       }
       //startStack.push(startText);
       contentStack.push(obj);
 
-      strIndex += startText.length;//索引移动
-    }else if(endBracketsReg.test(nuText)){
+      strIndex += startText.length; //索引移动
+    } else if (endBracketsReg.test(nuText)) {
       //console.log('匹配右括号')
       //匹配右括号
       let endBrackets = nuText.match(endBracketsReg)[0];
@@ -238,205 +267,204 @@ export const formulaStringToArray = (text,elemap,formulaMap) => {
       let popObj = contentStack.pop();
       let arrType = [];
 
-      if(contentStack.length > 0){
-        let content =contentStack[contentStack.length - 1];
+      if (contentStack.length > 0) {
+        let content = contentStack[contentStack.length - 1];
         content.children.push(popObj);
         arrType = content.children;
-      }else{
+      } else {
         //匹配完成最顶层的一整个方法体,或括号
         resArr.push(popObj);
         arrType = resArr;
       }
 
-      if(popObj.type =='Brackets'){
+      if (popObj.type == "Brackets") {
         let brackArr = [];
         //如果是括号,把括号里面的提出一层
-        popObj.children.forEach((ele)=>{
+        popObj.children.forEach((ele) => {
           brackArr.push(ele);
-        })
+        });
         //补个右括号
         brackArr.push({
-          type:'Brackets',
-          selected:false,
-          name:')',
+          type: "Brackets",
+          selected: false,
+          name: ")",
         });
         arrType.push(...brackArr);
-        delete popObj.children
+        delete popObj.children;
       }
       //console.log(popObj,'pop')
 
-      strIndex += endBrackets.length;//索引移动
-    }else if(startBracketsReg.test(nuText)){
+      strIndex += endBrackets.length; //索引移动
+    } else if (startBracketsReg.test(nuText)) {
       //console.log('匹配左括号')
       //匹配左括号
       let startBrackets = nuText.match(startBracketsReg)[0];
 
       contentStack.push({
-        type:'Brackets',
-        children:[],
-        selected:false,
-        name:startBrackets,
-        tag:startBrackets
+        type: "Brackets",
+        children: [],
+        selected: false,
+        name: startBrackets,
+        tag: startBrackets,
       });
 
-      strIndex += startBrackets.length;//索引移动
-    }else if(elementReg.test(nuText)){
+      strIndex += startBrackets.length; //索引移动
+    } else if (elementReg.test(nuText)) {
       //console.log('匹配元素')
       //匹配元素
       let eleArr = nuText.match(elementReg);
       let obj = {};
-      if(elementMap[eleArr[1]]){
-        Object.assign(obj,elementMap[eleArr[1]]);
-        Object.assign(obj,{
-          selected:false,
-          children:[],
-          tag:eleArr[0]
+      if (elementMap[eleArr[1]]) {
+        Object.assign(obj, elementMap[eleArr[1]]);
+        Object.assign(obj, {
+          selected: false,
+          children: [],
+          tag: eleArr[0],
         });
-      }else{
+      } else {
         obj = {
-          type:'Element',
-          name:eleArr[1].split('_')[1],
-          tableElementKey:eleArr[1],
-          children:[],
-          selected:false,
-          tag:eleArr[0]
-        }
+          type: "Element",
+          name: eleArr[1].split("_")[1],
+          tableElementKey: eleArr[1],
+          children: [],
+          selected: false,
+          tag: eleArr[0],
+        };
       }
 
-      let content =contentStack[contentStack.length - 1];
-      if(content){
+      let content = contentStack[contentStack.length - 1];
+      if (content) {
         content.children.push(obj);
-      }else{
+      } else {
         //如果没有,那就是在最上层
         resArr.push(obj);
       }
 
-      strIndex += eleArr[0].length;//索引移动
-    }else if(paramReg.test(nuText)){
+      strIndex += eleArr[0].length; //索引移动
+    } else if (paramReg.test(nuText)) {
       //console.log('匹配节点参数')
       //匹配节点参数
       let eleArr = nuText.match(paramReg);
       let obj = {};
-      if(elementMap[eleArr[1]]){
-        Object.assign(obj,elementMap[eleArr[1]]);
-        Object.assign(obj,{
-          selected:false,
-          children:[],
-          tag:"paramData"
+      if (elementMap[eleArr[1]]) {
+        Object.assign(obj, elementMap[eleArr[1]]);
+        Object.assign(obj, {
+          selected: false,
+          children: [],
+          tag: "paramData",
         });
-      }else{
+      } else {
         obj = {
-          type:'ParamData',
-          name:elementMap[eleArr[1]].name,
-          v:elementMap[eleArr[1]].v,
-          k:elementMap[eleArr[1]].k,
-          children:[],
-          selected:false,
-          tag:"paramData"
-        }
+          type: "ParamData",
+          name: elementMap[eleArr[1]].name,
+          v: elementMap[eleArr[1]].v,
+          k: elementMap[eleArr[1]].k,
+          children: [],
+          selected: false,
+          tag: "paramData",
+        };
       }
 
-      let content =contentStack[contentStack.length - 1];
-      if(content){
+      let content = contentStack[contentStack.length - 1];
+      if (content) {
         content.children.push(obj);
-      }else{
+      } else {
         //如果没有,那就是在最上层
         resArr.push(obj);
       }
 
-      strIndex += eleArr[0].length;//索引移动
-    }else if(commaReg.test(nuText)){
+      strIndex += eleArr[0].length; //索引移动
+    } else if (commaReg.test(nuText)) {
       //console.log('匹配逗号')
       //匹配逗号
       let comma = nuText.match(commaReg)[0];
 
       contentStack[contentStack.length - 1].children.push({
-        type:'Comma',
-        tag:comma
+        type: "Comma",
+        tag: comma,
       });
 
-      strIndex += comma.length;//索引移动
-    }else if(logicalReg.test(nuText)){
-      console.log('逻辑符号','')
+      strIndex += comma.length; //索引移动
+    } else if (logicalReg.test(nuText)) {
+      console.log("逻辑符号", "");
       let logical = nuText.match(logicalReg)[0];
 
       contentStack[contentStack.length - 1].children.push({
-        type:'Logical',
-        tag:logical
+        type: "Logical",
+        tag: logical,
       });
 
-      strIndex += logical.length;//索引移动
-
-    }else if(operatorReg.test(nuText)){
+      strIndex += logical.length; //索引移动
+    } else if (operatorReg.test(nuText)) {
       //console.log('匹配加减乘除')
       //匹配加减乘除
       let operator = nuText.match(operatorReg)[0];
       let obj = {
-        type:'Operator',
-        name:operator,
-        selected:false,
-        tag:operator,
+        type: "Operator",
+        name: operator,
+        selected: false,
+        tag: operator,
       };
-      if(formulaMap[operator]){
+      if (formulaMap[operator]) {
         obj.example = formulaMap[operator].example;
         obj.template = formulaMap[operator].template;
       }
 
-      if(contentStack.length > 0){
+      if (contentStack.length > 0) {
         //不然就在方法体或括号里面
         contentStack[contentStack.length - 1].children.push(obj);
-      }else{
+      } else {
         //如果没有,那就是在最上层
         resArr.push(obj);
       }
 
-      strIndex += operator.length;//索引移动
+      strIndex += operator.length; //索引移动
       //console.log(operator.length)
-    }else if(wordReg.test(nuText)){
+    } else if (wordReg.test(nuText)) {
       //匹配文本
       let word = nuText.match(wordReg)[0];
-      console.log('匹配文本',word)
-      if(word == "''"){
+      console.log("匹配文本", word);
+      if (word == "''") {
         word = "";
       }
 
       let obj = {
-        type:'Text',
-        tag:word
+        type: "Text",
+        tag: word,
       };
-
-      let content =contentStack[contentStack.length - 1];
-      if(content){
+      let content = contentStack[contentStack.length - 1];
+      if (content) {
         content.children.push(obj);
-      }else{
+      } else {
         //如果没有,那就是在最上层
         obj.name = word;
         obj.selected = false;
         resArr.push(obj);
       }
 
-      strIndex += word.length?word.length:2;//索引移动
-    }
-
-    else{
-      console.log('匹配不到:',nuText)
+      strIndex += word.length ? word.length : 2; //索引移动
+    } else {
+      console.log("匹配不到:", nuText);
       //匹配不到
-      strIndex++
+      strIndex++;
     }
   }
 
-  let resultFormula = [{
-    children:[],
-    name:"临时占位",
-    selected:false,
-    type:"Element",
-  }]
+  let resultFormula = [
+    {
+      children: [],
+      name: "临时占位",
+      selected: false,
+      type: "Element",
+    },
+  ];
 
-  let processFormula = []
-  let isAllFun = true;//一层全是方法,有其他说明到了显示层
+  let processFormula = [];
+  let isAllFun = true; //一层全是方法,有其他说明到了显示层
 
+  console.log("公式转换开始", resArr);
   //从顶层开始
-  parseFormula(resArr,resultFormula,processFormula,isAllFun);
+  parseFormula(resArr, resultFormula, processFormula, isAllFun);
 
   //console.log(contentStack)
   console.log(resArr, "--------- resArr -------");
@@ -444,7 +472,7 @@ export const formulaStringToArray = (text,elemap,formulaMap) => {
   console.log(processFormula, "--------- processFormula -------");
 
   return {
-    processFormula:processFormula,
-    resultFormula:resultFormula,
+    processFormula: processFormula,
+    resultFormula: resultFormula,
   };
-}
+};

+ 1 - 1
src/views/formula/project/globalEdit.vue

@@ -1897,7 +1897,7 @@ export default {
           name: ele.eName,
           id: ele.id,
           selected: false,
-          tableElementKey: ele.tableElementKey,
+          tableElementKey: ele.tableElementKey.replace('_key',':key'),
           children: [],
         }]
       })

+ 4 - 3
src/views/formula/project/nodeEdit.vue

@@ -1424,7 +1424,7 @@ export default {
             let obj = Object.assign({}, expression);
             //obj.template = JSON.parse(obj.template);
             obj.arguments = new Array(obj.template.args.length);
-
+            console.log(this.equationSelectEle, "equationSelectEle11111111111111");
             let ele = {};
             if (this.equationSelectEle.type == "ParamData") {
                 ele = {
@@ -1531,6 +1531,7 @@ export default {
 
         //显示选择元素弹窗
         showChooseEle(argumenObj) {
+            console.log("999999999999999", argumenObj);
             const { item } = argumenObj;
 
             if (item) {
@@ -2000,7 +2001,7 @@ export default {
                     detail.map,
                     this.formulaMap
                 );
-                console.log("formula99999999999", formula);
+                console.log("formula99999999999", formula, this.formulaMap);
 
                 this.processFormula = formula.processFormula;
                 formula.resultFormula[0].id = this.resultFormula[0].id;
@@ -2126,7 +2127,7 @@ export default {
                         name: ele.eName,
                         id: ele.id,
                         selected: false,
-                        tableElementKey: ele.tableElementKey,
+                        tableElementKey: ele.tableElementKey.replace('_key',':key'),
                         children: [],
                     },
                 ];

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно