|
|
@@ -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 };
|
|
|
+};
|