|
@@ -39,7 +39,7 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="box-dashed">
|
|
|
- <div class="mg-b-20">函数公式..</div>
|
|
|
+ <div class="mg-b-20">函数公式..(节点公式)</div>
|
|
|
<div class="edit-text">
|
|
|
<span>
|
|
|
<formula-item
|
|
@@ -48,7 +48,7 @@
|
|
|
>
|
|
|
</formula-item>
|
|
|
</span>
|
|
|
- <span>=</span>
|
|
|
+ <span style="margin-left: 5px;margin-right: 5px;">=</span>
|
|
|
<span v-for="(item,index) in processFormula" :key="index">
|
|
|
<el-tooltip class="item" effect="light" placement="top-start" :disabled="item.type!=='Element'">
|
|
|
<div slot="content">{{item.tableName }}</div>
|
|
@@ -205,7 +205,17 @@
|
|
|
<template v-else>
|
|
|
<div class="flex" >
|
|
|
<div class=" flex-d-c" style="width:40%">
|
|
|
- <component ref="dynamiccomponent" v-bind:is="componentMap[item.name]" :formulainfo="item" :curele="equationSelectEle" :formulamap="formulaMap" @uncheck="unCheckEleComp" class="flex1"></component>
|
|
|
+ <component ref="dynamiccomponent"
|
|
|
+ v-bind:is="componentMap[item.name]"
|
|
|
+ :formulainfo="item"
|
|
|
+ :curele="equationSelectEle"
|
|
|
+ :formulamap="formulaMap"
|
|
|
+ :map="formulaDetailMap"
|
|
|
+ @uncheck="unCheckEleComp"
|
|
|
+ class="flex1"
|
|
|
+ :moreConditions="moreConditions"
|
|
|
+ :isMore="isMore">
|
|
|
+ </component>
|
|
|
<div class="flex1" v-show="item.showSelectEle" style="margin-top:10px;margin-bottom:30px">
|
|
|
<el-scrollbar style="height: 400px">
|
|
|
<el-tree
|
|
@@ -439,7 +449,6 @@ import datasReme from "./component/funComponent/datasReme"
|
|
|
import datasGetlist from "./component/funComponent/datasGetlist"
|
|
|
import datasJoin from "./component/funComponent/datasJoin"
|
|
|
import ifelse from "./component/funComponent/ifelse"
|
|
|
-import dataChange from "./component/funComponent/dataChange"
|
|
|
|
|
|
import deviationRange from "./component/deviationRange/deviationRange"
|
|
|
import {rangeToString} from "./component/deviationRange/rangeToString"
|
|
@@ -466,8 +475,7 @@ export default {
|
|
|
datasJoin,
|
|
|
ifelse,
|
|
|
|
|
|
- deviationRange,
|
|
|
- dataChange
|
|
|
+ deviationRange
|
|
|
},
|
|
|
props: {
|
|
|
wbsid:{
|
|
@@ -563,7 +571,6 @@ export default {
|
|
|
'下标取数':'datas-getlist',
|
|
|
// '数组转字符串':"datas-join",
|
|
|
'判断':'ifelse',
|
|
|
- '数据自变':'data-change'
|
|
|
|
|
|
},
|
|
|
|
|
@@ -591,6 +598,10 @@ export default {
|
|
|
version:1,//版本号,以后可能会有不兼容旧公式的改动,留作以后可能用来判断
|
|
|
input3:'',//搜索元素字段
|
|
|
eleListable:false,
|
|
|
+ isMore:false,//是否是多条件判断
|
|
|
+ moreConditions:[],//多条件判断数组
|
|
|
+ formulaDetailMap:{},//公式详情map
|
|
|
+
|
|
|
};
|
|
|
},
|
|
|
computed: {
|
|
@@ -1167,6 +1178,8 @@ export default {
|
|
|
},
|
|
|
//获取当前元素的表名
|
|
|
getItemTableName(item){
|
|
|
+
|
|
|
+
|
|
|
if(item.type==="Element"){
|
|
|
this.rightDict.forEach((ele)=>{
|
|
|
if(ele.ekey===item.tableElementKey){
|
|
@@ -1359,11 +1372,284 @@ export default {
|
|
|
|
|
|
return true;
|
|
|
},
|
|
|
+ formatArrayMore(inputArray) {
|
|
|
+ console.log(inputArray,'inputArray');
|
|
|
+
|
|
|
+ // 定义字段映射关系
|
|
|
+ const fieldMappings = {
|
|
|
+ 'tag2': 'parameter1',
|
|
|
+ 'tag3': 'parameter2',
|
|
|
+ 'symbol1': 'symbol',
|
|
|
+ 'logicSymbol': 'groupTerm',
|
|
|
+ 'tag4': 'trueData',
|
|
|
+ 'tag5': 'falseData'
|
|
|
+ };
|
|
|
+
|
|
|
+ // 处理值的格式化,将特定格式字符串包裹在E[]中
|
|
|
+ function formatValue(value) {
|
|
|
+ // 检查是否是符合格式的字符串(包含:key_)
|
|
|
+ if (typeof value === 'string' && value.includes(':key_')) {
|
|
|
+ return `E[${value}]`;
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ }
|
|
|
|
|
|
+ // 处理单个对象的函数
|
|
|
+ function processObject(obj) {
|
|
|
+ const result = {};
|
|
|
+
|
|
|
+ // 处理formulaIfElse(如果存在)
|
|
|
+ if (obj.formulaIfElse && Array.isArray(obj.formulaIfElse)) {
|
|
|
+ result.formulaIfElse = obj.formulaIfElse.map(item => processObject(item));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理其他字段映射
|
|
|
+ Object.keys(obj).forEach(key => {
|
|
|
+ // 特殊处理tags2、tags3、tags4和tags5
|
|
|
+ if (key === 'tags2' && Array.isArray(obj.tags2) && obj.tags2.length > 0) {
|
|
|
+ // 如果tags2有值,取第一个对象的tableElementKey作为parameter1的值,并格式化
|
|
|
+ const value = obj.tags2[0].tableElementKey || '';
|
|
|
+ result.parameter1 = formatValue(value);
|
|
|
+ }
|
|
|
+ else if (key === 'tags3' && Array.isArray(obj.tags3) && obj.tags3.length > 0) {
|
|
|
+ // 如果tags3有值,取第一个对象的tableElementKey作为parameter2的值,并格式化
|
|
|
+ const value = obj.tags3[0].tableElementKey || '';
|
|
|
+ result.parameter2 = formatValue(value);
|
|
|
+ }
|
|
|
+ else if (key === 'tags4' && Array.isArray(obj.tags4) && obj.tags4.length > 0) {
|
|
|
+ // 如果tags4有值,取第一个对象的tableElementKey作为trueData的值,并格式化
|
|
|
+ const value = obj.tags4[0].tableElementKey || '';
|
|
|
+ result.trueData = formatValue(value);
|
|
|
+ }
|
|
|
+ else if (key === 'tags5' && Array.isArray(obj.tags5) && obj.tags5.length > 0) {
|
|
|
+ // 如果tags5有值,取第一个对象的tableElementKey作为falseData的值,并格式化
|
|
|
+ const value = obj.tags5[0].tableElementKey || '';
|
|
|
+ result.falseData = formatValue(value);
|
|
|
+ }
|
|
|
+ // 处理其他映射字段
|
|
|
+ else if (fieldMappings[key]) {
|
|
|
+ // 只有当对应的tags数组没有提供值时,才使用原始字段值
|
|
|
+ if ((key === 'tag2' && !result.parameter1) ||
|
|
|
+ (key === 'tag3' && !result.parameter2) ||
|
|
|
+ (key === 'tag4' && !result.trueData) ||
|
|
|
+ (key === 'tag5' && !result.falseData) ||
|
|
|
+ !['tag2', 'tag3', 'tag4', 'tag5'].includes(key)) {
|
|
|
+ // 对原始字段值也进行格式化处理
|
|
|
+ result[fieldMappings[key]] = formatValue(obj[key]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理整个数组
|
|
|
+ return inputArray.map(item => processObject(item));
|
|
|
+ },
|
|
|
+restoreArrayMore(processedArray) {
|
|
|
+ // 定义反转的字段映射关系(与原方法相反)
|
|
|
+ const reverseMappings = {
|
|
|
+ 'parameter1': 'tag2',
|
|
|
+ 'parameter2': 'tag3',
|
|
|
+ 'symbol': 'symbol1',
|
|
|
+ 'groupTerm': 'logicSymbol',
|
|
|
+ 'trueData': 'tag4',
|
|
|
+ 'falseData': 'tag5'
|
|
|
+ };
|
|
|
+
|
|
|
+ // 从this.map获取完整元素信息并构建tags对象
|
|
|
+ const getTagElement = (tableElementKey) => {
|
|
|
+ const objTargetData = JSON.parse(this.formulaDetailMap);
|
|
|
+ const baseData = objTargetData[tableElementKey] || {};
|
|
|
+ // 返回完整的tags元素结构
|
|
|
+ return {
|
|
|
+ "type": baseData.type || "Element",
|
|
|
+ "name": baseData.name || "",
|
|
|
+ "id": baseData.id || "",
|
|
|
+ "selected": false,
|
|
|
+ "tableElementKey": tableElementKey,
|
|
|
+ "children": [],
|
|
|
+ "text": baseData.name || "", // text与name保持一致
|
|
|
+ "style": "background-color: #409EFF" // 保持示例中的样式
|
|
|
+ };
|
|
|
+ };
|
|
|
+
|
|
|
+ // 还原值的格式化,去掉E[]包裹
|
|
|
+ function restoreValue(value) {
|
|
|
+ if (typeof value === 'string' && value.startsWith('E[') && value.endsWith(']')) {
|
|
|
+ const innerValue = value.slice(2, -1);
|
|
|
+ if (innerValue.includes(':key_')) {
|
|
|
+ return innerValue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 还原单个对象的函数
|
|
|
+ function restoreObject(obj) {
|
|
|
+ const result = {};
|
|
|
+
|
|
|
+ // 递归还原formulaIfElse(如果存在)
|
|
|
+ if (obj.formulaIfElse && Array.isArray(obj.formulaIfElse)) {
|
|
|
+ result.formulaIfElse = obj.formulaIfElse.map(item => restoreObject(item));
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理参数与tags数组的还原
|
|
|
+ Object.keys(obj).forEach(key => {
|
|
|
+ const restoredValue = restoreValue(obj[key]);
|
|
|
+
|
|
|
+ // parameter1对应tags2和tag2
|
|
|
+ if (key === 'parameter1') {
|
|
|
+ result.tags2 = [getTagElement(restoredValue)];
|
|
|
+ result[reverseMappings[key]] = restoredValue;
|
|
|
+ }
|
|
|
+ // parameter2对应tags3和tag3
|
|
|
+ else if (key === 'parameter2') {
|
|
|
+ result.tags3 = [getTagElement(restoredValue)];
|
|
|
+ result[reverseMappings[key]] = restoredValue;
|
|
|
+ }
|
|
|
+ // trueData对应tags4和tag4
|
|
|
+ else if (key === 'trueData') {
|
|
|
+ result.tags4 = [getTagElement(restoredValue)];
|
|
|
+ result[reverseMappings[key]] = restoredValue;
|
|
|
+ }
|
|
|
+ // falseData对应tags5和tag5
|
|
|
+ else if (key === 'falseData') {
|
|
|
+ result.tags5 = [getTagElement(restoredValue)];
|
|
|
+ result[reverseMappings[key]] = restoredValue;
|
|
|
+ }
|
|
|
+ // 处理其他映射字段
|
|
|
+ else if (reverseMappings[key]) {
|
|
|
+ result[reverseMappings[key]] = restoredValue;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 还原整个数组
|
|
|
+ return processedArray.map(item => restoreObject(item));
|
|
|
+},
|
|
|
+ generateResult(input) {
|
|
|
+ // 检查输入是否有效
|
|
|
+ if (!Array.isArray(input) || input.length === 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建结果对象
|
|
|
+ const result = {};
|
|
|
+
|
|
|
+ // 处理标签的通用函数
|
|
|
+ const processTags = (tags) => {
|
|
|
+ if (tags && Array.isArray(tags)) {
|
|
|
+ tags.forEach(tag => {
|
|
|
+ const key = tag.tableElementKey;
|
|
|
+ if (key) {
|
|
|
+ // 如果存在相同的key,这里会覆盖之前的值
|
|
|
+ // 如有需要,可以修改为数组或其他处理方式
|
|
|
+ result[key] = {
|
|
|
+ id: tag.id,
|
|
|
+ name: tag.name,
|
|
|
+ tableElementKey: key,
|
|
|
+ type: tag.type
|
|
|
+ };
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ // 遍历输入数组中的每一个对象元素
|
|
|
+ input.forEach(data => {
|
|
|
+ // 处理当前对象中的所有formulaIfElse元素
|
|
|
+ if (data.formulaIfElse && Array.isArray(data.formulaIfElse)) {
|
|
|
+ data.formulaIfElse.forEach(formulaItem => {
|
|
|
+ // 处理每个formulaIfElse元素中的标签
|
|
|
+ processTags(formulaItem.tags2);
|
|
|
+ processTags(formulaItem.tags3);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 处理当前对象根级别的标签
|
|
|
+ processTags(data.tags4);
|
|
|
+ processTags(data.tags5);
|
|
|
+ });
|
|
|
+
|
|
|
+ // 检查是否有数据
|
|
|
+ if (Object.keys(result).length === 0) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ return result;
|
|
|
+},
|
|
|
//保存公式
|
|
|
saveFormula(){
|
|
|
console.log('保存',this.pid);
|
|
|
console.log(this.processFormula,'this.processFormula1111111112333');
|
|
|
+ console.log(this.resultFormula,'this.resultFormula1111111112333');
|
|
|
+ console.log(this.$refs.dynamiccomponent,'this.$refs.dynamiccomponent');
|
|
|
+
|
|
|
+ if(this.$refs.dynamiccomponent&&this.$refs.dynamiccomponent.length>0&&this.$refs.dynamiccomponent[0]&& this.$refs.dynamiccomponent[0].symbol=='more'){
|
|
|
+ //多条件保存公式
|
|
|
+
|
|
|
+ console.log('this.$refs.dynamiccomponent[0]',this.$refs.dynamiccomponent[0].conditionList);
|
|
|
+ let resMore=this.formatArrayMore(this.$refs.dynamiccomponent[0].conditionList);
|
|
|
+ const resJson=this.generateResult(this.$refs.dynamiccomponent[0].conditionList);
|
|
|
+
|
|
|
+ if(this.formulaid){
|
|
|
+ updateFormula({
|
|
|
+ id:this.formulaid,
|
|
|
+ formula:'',
|
|
|
+ formulas:resMore,
|
|
|
+ remark:'',
|
|
|
+ nodeId:this.nodeid,
|
|
|
+ elementId:this.eleid,
|
|
|
+ scale:this.isRetain?this.retainNum:'',
|
|
|
+ number:number,
|
|
|
+ map:JSON.stringify(resJson),
|
|
|
+ scope:this.globaltype,
|
|
|
+ // projectId:this.curProjiect.id||this.projectId,
|
|
|
+ projectId:this.curProjiect.id||this.pid,
|
|
|
+ dev:deviationRangeText
|
|
|
+ }).then(()=>{
|
|
|
+ this.formulaStringToArray();
|
|
|
+ this.$message({
|
|
|
+ type: "success",
|
|
|
+ message: "修改成功"
|
|
|
+ });
|
|
|
+ })
|
|
|
+ }else{
|
|
|
+ saveFormula({
|
|
|
+ formula:'',
|
|
|
+ formulas:resMore,
|
|
|
+ remark:'',
|
|
|
+ nodeId:this.nodeid,
|
|
|
+ elementId:this.eleid,
|
|
|
+ scale:this.isRetain?this.retainNum:'',
|
|
|
+ number:number,
|
|
|
+ map:JSON.stringify(resJson),
|
|
|
+ scope:this.globaltype,
|
|
|
+ dev:deviationRangeText,
|
|
|
+ // projectId:this.curProjiect.id||this.projectId,
|
|
|
+ projectId:this.curProjiect.id||this.pid,
|
|
|
+ ver:this.version
|
|
|
+ }).then((res)=>{
|
|
|
+ if(res.data.data){
|
|
|
+ this.formulaid = res.data.data;
|
|
|
+ }
|
|
|
+ this.formulaStringToArray();
|
|
|
+ this.$message({
|
|
|
+ type: "success",
|
|
|
+ message: "保存成功"
|
|
|
+ });
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ return;
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
let arr=JSON.parse(JSON.stringify(this.processFormula));
|
|
|
let filteredArr = arr.filter(item => item.id ===this.checkGsId);
|
|
|
let obj
|
|
@@ -1465,6 +1751,20 @@ export default {
|
|
|
async formulaStringToArray(){
|
|
|
let detail = (await formulaDetail({elementId:this.eleid,scope:this.globaltype,nodeId:this.nodeid,projectId:this.curProjiect.id||this.pid})).data.data;
|
|
|
console.log(detail,'detail');
|
|
|
+ if(detail&&detail.formula.includes('FC.ifelseMulti')){
|
|
|
+ detail.formula = detail.formula.replace('FC.ifelseMulti','FC.ifelse');
|
|
|
+ this.isMore = true;
|
|
|
+ this.formulaDetailMap = detail.map;
|
|
|
+ this.moreConditions = this.restoreArrayMore(detail.formulas)
|
|
|
+
|
|
|
+ }else{
|
|
|
+ this.isMore = false;
|
|
|
+ this.moreConditions = []
|
|
|
+ this.formulaDetailMap ={}
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
if(detail&&detail.id){
|
|
|
//获取右边元素的字典
|
|
|
let dictMap=detail.dict
|
|
@@ -1475,8 +1775,12 @@ export default {
|
|
|
|
|
|
}
|
|
|
this.rightDict=dictArr
|
|
|
+ console.log( this.rightDict,' this.rightDict');
|
|
|
+
|
|
|
this.formulaid = detail.id;
|
|
|
//let formula = formulaStringToArray('FC.sum(FC.repeat(E[测试测试_222]))+FC.ifelse(3<E[测试测试_333]&&E[测试测试_333]<10,E[测试测试_222]+E[测试测试_333],E[测试测试_333])',detail.map,this.formulaMap);
|
|
|
+ console.log(this.formulaMap,'this.formulaMap');
|
|
|
+
|
|
|
let formula = formulaStringToArray(detail.formula,detail.map,this.formulaMap);
|
|
|
this.processFormula = formula.processFormula;
|
|
|
formula.resultFormula[0].id = this.resultFormula[0].id;
|
|
@@ -1834,7 +2138,7 @@ export default {
|
|
|
}
|
|
|
|
|
|
.icon-box .el-link{
|
|
|
- font-size: 24px;
|
|
|
+ font-size: 14px;
|
|
|
margin-right: 10px;
|
|
|
}
|
|
|
</style>
|
|
@@ -1847,4 +2151,31 @@ export default {
|
|
|
height: 100%;
|
|
|
}
|
|
|
}
|
|
|
+.operation-box-inset{
|
|
|
+ display: flex;
|
|
|
+ flex-direction: column;
|
|
|
+}
|
|
|
</style>
|
|
|
+<style scoped>
|
|
|
+.operation-symbol-box{
|
|
|
+ display: flex;
|
|
|
+ align-items: center;
|
|
|
+ border: 1px solid rgb(229, 231, 235);
|
|
|
+ background-color: #F9FAFB;
|
|
|
+ padding: 10px 10px;
|
|
|
+ border-radius: 5px 5px 0px 0px;
|
|
|
+ margin-top: 10px;
|
|
|
+
|
|
|
+}
|
|
|
+.sele-ele-box1{
|
|
|
+ padding: 10px;
|
|
|
+ border: 1px solid rgb(229, 231, 235);
|
|
|
+ border-radius: 0px 0px 5px 5px;
|
|
|
+
|
|
|
+ height: 50px;
|
|
|
+}
|
|
|
+.text-sm{
|
|
|
+ font-size: 14px;
|
|
|
+ margin-right: 10px;
|
|
|
+}
|
|
|
+</style>
|