Kaynağa Gözat

数据获取公式修改

duy 6 gün önce
ebeveyn
işleme
288e9197c7

+ 544 - 44
src/views/formula/component/funComponent/ifelse.vue

@@ -12,17 +12,22 @@
         <el-option label="小于等于且大于等于" value="<=&&<="></el-option>
         <el-option label="试验判断" value="|"></el-option>
         <el-option label="多条件" value="more"></el-option>
+        <el-option label="数据获取" value="getData"></el-option>
       </el-select>
       <span class="mg-l-20 mg-r-10" v-if="symbol!=='|'">执行结果</span>
-      <el-select v-model="result" @change="setTF()" size="medium" placeholder="请选择" v-if="symbol!=='|'">
+      <el-select v-model="result" @change="setTF()" size="medium" placeholder="请选择" v-if="symbol!=='|'&&symbol!=='getData'" >
         <el-option label="真假值" value="1"></el-option>
         <el-option label="运算" value="2"></el-option>
+      </el-select>
+        <el-select v-model="result" size="medium" placeholder="请选择"    v-if="symbol=='getData'">
+        <el-option label="数据获取" value="3"></el-option>
+      
       </el-select>
       <el-button class="mg-l-10" size="small" type="info" @click="showSelectEle">选择参数</el-button>
     </div>
 
     <!-- 多条件其他的 -->
-    <template v-if="symbol !== 'more'"> 
+    <template v-if="symbol !== 'more'&&symbol !== 'getData'"> 
         <div class="mg-t-20 flex jc-al-c">
             <span class="textblod mg-r-20"  v-if="symbol!=='|'">IF</span>
             <div class="flex jc-al-c" v-if="symbol == '<&&<' || symbol == '<=&&<='">
@@ -105,7 +110,8 @@
         </div>
     </template>
     <!-- 多条件 -->
-     <template v-else>
+     <template v-if="symbol == 'more'"> 
+
       <div v-for="(item, conditionIndex) in conditionList" :key="conditionIndex">
         <!-- 从第二个条件开始显示“条件X”和删除按钮 -->
         <div v-if="conditionIndex >= 1" class="condition-header flex al-c  mg-t-20">
@@ -258,6 +264,111 @@
       
       </div>
      </template>
+     <!-- 数据获取配置框 - 修改部分 -->
+     <template v-if="symbol==='getData'">
+        <div class="mg-t-10">
+              <div v-for="(item, index) in getDataList" :key="index"  class="mg-t-10">
+                <div class="flex jc-al-c">
+                  <div class="textblod mg-r-10" :style="{ opacity: index === 0 ? 1 : 0 }">
+                    当
+                  </div>
+                  <div class="mg-r-10" :style="{ opacity: index === 0 ? 1 : 0 }">
+                    <vue-tags-input 
+                      v-model="item.tagWhenLeft" 
+                      :tags="item.tagsWhenLeft" 
+                      @focus="setDataFocus(index, 'tagWhenLeft')" 
+                      @blur="dataInputBlur(index, 'tagWhenLeft')" 
+                      placeholder="输入/参数" 
+                      @before-adding-tag="beforeAddingTag" 
+                      @keyup.native="btKeyUp"
+
+                    />
+                  </div>
+                  <div  class="mg-r-10">
+                      <el-select 
+                      v-model="item.condition" 
+                      @change="setDataCondition(index)" 
+                      size="medium" 
+                      placeholder="请选择"  
+                      style="width:120px"
+                    >
+                          <el-option label=">=" value=">="></el-option>
+                          <el-option label="<=" value="<="></el-option>
+                          <el-option label="=" value="="></el-option>
+                          <el-option label=">" value=">"></el-option>
+                          <el-option label="<" value="<"></el-option>
+                          <el-option label="≠" value="≠"></el-option>
+                          <el-option label="包含" value="包含"></el-option>
+                          <el-option label="不包含" value="不包含"></el-option>
+                    </el-select>
+                  </div>
+                  <div  class="mg-r-10">
+                    <vue-tags-input 
+                      v-model="item.tagWhenRight" 
+                      :tags="item.tagsWhenRight" 
+                      @focus="setDataFocus(index, 'tagWhenRight')" 
+                      @blur="dataInputBlur(index, 'tagWhenRight')" 
+                      placeholder="输入/参数" 
+                      @before-adding-tag="beforeAddingTag" 
+                      @keyup.native="btKeyUp"
+                    />
+                  </div>
+                  
+                  <div  class="mg-r-10 textblod">则</div>
+                    <vue-tags-input 
+                      v-model="item.tagThenLeft" 
+                      :tags="item.tagsThenLeft" 
+                      @focus="setDataFocus(index, 'tagThenLeft')" 
+                      @blur="dataInputBlur(index, 'tagThenLeft')" 
+                      placeholder="输入/参数" 
+                      @before-adding-tag="beforeAddingTag" 
+                      @keyup.native="btKeyUp"
+                    />
+                    <span  class="mg-r-10 mg-l-10">=</span>
+                    <div class="mg-r-10">
+                        <vue-tags-input 
+                          v-model="item.tagThenRight" 
+                          :tags="item.tagsThenRight" 
+                          @focus="setDataFocus(index, 'tagThenRight')" 
+                          @blur="dataInputBlur(index, 'tagThenRight')" 
+                          placeholder="输入/参数" 
+                          @before-adding-tag="beforeAddingTag" 
+                          @keyup.native="btKeyUp"
+                        />
+                    </div>
+                      <i class="el-icon-circle-plus-outline mg-l-20" style="color: #409EFF;cursor: pointer;" @click="addDataItem(index)"></i>
+                    <i class="el-icon-delete mg-l-20" style="color: red;cursor: pointer;" @click="removeDataItem(index)" v-if="getDataList.length > 1"></i>
+                </div>
+               
+              </div>
+              <div class="mg-t-10  ">
+                  <div class="textblod "  >否则</div>
+                  <div class="flex jc-al-c "  style="float: right; margin-top: -28px;" >
+                    <vue-tags-input 
+                      v-model="elseTagLeft" 
+                      :tags="elseTagsLeft" 
+                      @focus="setElseFocus('left')" 
+                      @blur="elseInputBlur('left')" 
+                      placeholder="请选择参数" 
+                      @before-adding-tag="beforeAddingTag" 
+                      @keyup.native="btKeyUp"
+                      class="mg-r-10"
+                    />
+                    <span class="mg-r-10">=</span>
+                    <vue-tags-input 
+                      v-model="elseTagRight" 
+                      :tags="elseTagsRight" 
+                      @focus="setElseFocus('right')" 
+                      @blur="elseInputBlur('right')" 
+                      placeholder="请选择/输入参数" 
+                      @before-adding-tag="beforeAddingTag" 
+                      @keyup.native="btKeyUp"
+                    />
+                  </div>
+                </div>
+            </div>
+      </template>
+
 
     <el-dialog title="输入值" :visible.sync="inputVisible" width="300px" append-to-body :close-on-click-modal="false">
       <el-input v-model="inputText" placeholder="请输入内容"></el-input>
@@ -273,6 +384,7 @@
 import VueTagsInput from '@johmun/vue-tags-input';
 import formulaItem from "../formulaItem";
 import draggable from 'vuedraggable';
+import {transformData,generateElementMap,restoreData} from './multiIfElseTools'
 
 export default {
   name: "ifelse",
@@ -314,7 +426,21 @@ export default {
     conditionIndex:{//当前是多条件中的哪一个
       type: Number,
       default: 0
-    }
+    },
+    isGetData:{
+      type: Boolean,
+      default: false
+    },
+    dataListGet:{
+      type: String,
+      default:''
+      },
+      map:{
+        type: String,
+        default:''
+      }
+    
+
   },
   data(){
     return{
@@ -332,6 +458,11 @@ export default {
         innerIndex: -1,
         field: ''
       },
+      // 数据获取部分的焦点信息
+      dataFocus: {
+        index: -1,
+        field: ''
+      },
       symbolReg:/(\+|-|\*|\/)(.+)/,
       inputVisible:false,
       inputText:'',
@@ -367,9 +498,60 @@ export default {
           formula1: [],
           formula2: []
         }
-      ]//多条件的条件列表
+      ],//多条件的条件列表
+      // 修改getDataList结构,为每个项添加独立属性
+      getDataList:[
+        {
+          tagWhenLeft: '',
+          tagsWhenLeft: [],
+          condition: '',
+          tagWhenRight: '',
+          tagsWhenRight: [],
+          tagThenLeft: '',
+          tagsThenLeft: [],
+          tagThenRight: '',
+          tagsThenRight: []
+        }
+      ],//数据获取列表
+        // 否则部分的属性
+      elseTagLeft: '',
+      elseTagsLeft: [],
+      elseTagRight: '',
+      elseTagsRight: [],
+      elseFocus: '' // 用于跟踪否则部分的焦点
+
     }
   },
+  watch: {
+  // 监视getDataList的变化
+  getDataList: {
+    deep: true,
+    handler(newVal) {
+      // 只有当数组中有至少一个元素时才处理
+      if (newVal.length > 0) {
+        // 获取第一个元素的tagWhenLeft值
+        const firstTagWhenLeft = newVal[0].tagWhenLeft;
+        const firstTagsWhenLeft = newVal[0].tagsWhenLeft;
+        
+        // 如果第一个元素有值,同步到其他元素
+        if ((firstTagWhenLeft && firstTagWhenLeft.trim() !== '') || 
+            (firstTagsWhenLeft && firstTagsWhenLeft.length > 0)) {
+          
+          // 遍历从第二个元素开始的所有元素
+          for (let i = 1; i < newVal.length; i++) {
+            // 避免触发不必要的watch循环
+            if (newVal[i].tagWhenLeft !== firstTagWhenLeft || 
+                JSON.stringify(newVal[i].tagsWhenLeft) !== JSON.stringify(firstTagsWhenLeft)) {
+              
+              this.$set(newVal[i], 'tagWhenLeft', firstTagWhenLeft);
+              this.$set(newVal[i], 'tagsWhenLeft', [...firstTagsWhenLeft]);
+            }
+          }
+        }
+      }
+    }
+  }
+},
   mounted(){
     console.log(this.formulainfo,'this.formulainfo333333');
     
@@ -394,12 +576,146 @@ export default {
 
        
       
-    }else{
+    }else if(this.isGetData){
+      this.symbol = 'getData';
+      this.result = '3';
+       console.log(this.dataListGet,'dataListGet');
+       const str=this.dataListGet;
+        let resultStr=''
+          // 找到第一个左括号的位置
+          const startIndex = str.indexOf('(');
+          // 找到最后一个右括号的位置
+          const endIndex = str.lastIndexOf(')');
+
+          // 提取括号内的内容
+          if (startIndex !== -1 && endIndex !== -1 && startIndex < endIndex) {
+            const result = str.substring(startIndex + 1, endIndex);
+            resultStr=result
+            console.log(result);
+          } else {
+            console.log("未找到有效的括号对");
+          }
+   
+          const resObj=restoreData(resultStr,JSON.parse(this.map))
+          console.log(resObj,'resObj');
+          this.getDataList=resObj.getDataList
+          this.elseTagLeft = resObj.elseTagLeft;
+          this.elseTagsLeft = resObj.elseTagsLeft;
+          this.elseTagRight = resObj.elseTagRight;
+          this.elseTagsRight = resObj.elseTagsRight;
+
+          
+          
+    }
+    else{
       // this.conditionList=[]
     }
     
+    // // 初始化数据获取列表
+    // if (this.symbol === 'getData' && this.formulainfo.arguments && this.formulainfo.arguments.length > 0) {
+    //   console.log(this.dataListGet,'dataListGet');
+      
+    //   // this.initGetDataList(this.formulainfo.arguments[0]);
+    // }
   },
   methods:{
+    // 初始化数据获取列表
+    initGetDataList(data) {
+      if (Array.isArray(data)) {
+        this.getDataList = data.map(item => ({
+          tagWhenLeft: item.tagWhenLeft || '',
+          tagsWhenLeft: item.tagsWhenLeft || [],
+          condition: item.condition || '',
+          tagWhenRight: item.tagWhenRight || '',
+          tagsWhenRight: item.tagsWhenRight || [],
+          tagThenLeft: item.tagThenLeft || '',
+          tagsThenLeft: item.tagsThenLeft || [],
+          tagThenRight: item.tagThenRight || '',
+          tagsThenRight: item.tagsThenRight || []
+        }));
+      }
+    },
+    
+    // 设置数据获取部分的焦点
+    setDataFocus(index, field) {
+      this.elseFocus=false
+      this.dataFocus = { index, field };
+    },
+    
+    // 数据获取部分输入框失焦处理
+    dataInputBlur(index, field) {
+      const item = this.getDataList[index];
+      const tagNumber = field.replace('tag', '');
+      
+      if (item[field]) {
+        if (item[`tags${tagNumber}`] && item[`tags${tagNumber}`][0]) {
+          this.$emit('uncheck', item[`tags${tagNumber}`][0].id);
+        }
+        item[`tags${tagNumber}`] = [];
+      }
+      
+      this.setGetDataCondition();
+    },
+    
+    // 添加数据获取项
+    addDataItem(index) {
+          // 获取第一个元素的值作为模板
+        const firstItem = this.getDataList[0];
+        
+        const newItem = {
+          // 新添加的项直接使用第一个元素的tagWhenLeft相关值
+          tagWhenLeft: firstItem.tagWhenLeft,
+          tagsWhenLeft: [...firstItem.tagsWhenLeft],
+          condition: '',
+          tagWhenRight: '',
+          tagsWhenRight: [],
+          tagThenLeft: '',
+          tagsThenLeft: [],
+          tagThenRight: '',
+          tagsThenRight: []
+        };
+        
+        this.getDataList.splice(index + 1, 0, newItem);
+        this.setGetDataCondition();
+          },
+    
+    // 删除数据获取项
+    removeDataItem(index) {
+      if (this.getDataList.length > 1) {
+        this.getDataList.splice(index, 1);
+        this.setGetDataCondition();
+      } else {
+        this.$message({ type: "warning", message: "至少保留一个数据获取条件" });
+      }
+    },
+    
+    // 设置数据获取条件
+    setDataCondition(index) {
+      this.setGetDataCondition();
+    },
+    
+    // 保存数据获取条件到公式信息
+    setGetDataCondition() {
+      this.formulainfo.arguments[0] = {
+        conditions: this.getDataList.map(item => ({
+          tagWhenLeft: item.tagWhenLeft,
+          tagsWhenLeft: item.tagsWhenLeft,
+          condition: item.condition,
+          tagWhenRight: item.tagWhenRight,
+          tagsWhenRight: item.tagsWhenRight,
+          tagThenLeft: item.tagThenLeft,
+          tagsThenLeft: item.tagsThenLeft,
+          tagThenRight: item.tagThenRight,
+          tagsThenRight: item.tagsThenRight
+        })),
+        elseCase: {
+          tagLeft: this.elseTagLeft,
+          tagsLeft: this.elseTagsLeft,
+          tagRight: this.elseTagRight,
+          tagsRight: this.elseTagsRight
+        }
+      };
+    },
 
     clearTagsIfHasValue(obj) {
            // 复制对象以避免修改原对象
@@ -860,6 +1176,48 @@ export default {
         this.inputVisible = false;
         this.inputText = '';
         return;
+      }else if(this.symbol === 'getData' && this.dataFocus.index !== -1) {
+        // 数据获取部分处理
+        const { index, field } = this.dataFocus;
+        const item = this.getDataList[index];
+        const formulaType = field;
+        
+        //简单语法判断
+        if(item[formulaType] && item[formulaType].length != 0){
+          let lastEle = item[formulaType][item[formulaType].length-1];
+          if(lastEle.type == 'Element'){
+            this.$message({ type: "warning", message: "输入值无法连续出现在元素后面" });
+            this.inputVisible = false;
+            return;
+          }
+          if(lastEle.type == 'Text'){
+            this.$message({ type: "warning", message: "输入值无法连续出现在输入值后面" });
+            this.inputVisible = false;
+            return;
+          }
+          if(lastEle.type == 'Brackets' && lastEle.name == ')'){
+            this.$message({ type: "warning", message: "输入值无法连续出现在右括号后面" });
+            this.inputVisible = false;
+            return;
+          }
+        }
+
+        // 添加输入值到相应字段
+        const tagField = field;
+        const tagsField = `tags${field.replace('tag', '')}`;
+        
+        item[tagsField].push({
+          type: 'Text',
+          name: this.inputText,
+          text: this.inputText,
+          style: 'background-color: #409EFF'
+        });
+        item[tagField] = '';
+        
+        this.setGetDataCondition();
+        this.inputVisible = false;
+        this.inputText = '';
+        return;
       }else{
         return;
       }
@@ -906,6 +1264,92 @@ export default {
     },
     
     setELe(ele){
+
+      if (this.symbol === 'getData' && this.elseFocus) {
+        let obj = {};
+        if(ele.k){
+          obj = {
+            type:'ParamData',
+            name:ele.name,
+            id:ele.id,
+            selected:false,
+            v:ele.v,
+            k:ele.k,
+            children:[],
+          }
+        }else{
+          obj = {
+            type:'Element',
+            name:ele.eName,
+            id:ele.id,
+            selected:false,
+            tableElementKey:ele.tableElementKey,
+            children:[],
+          }
+        }
+        
+        // 根据当前焦点位置设置对应的标签
+        const position = this.elseFocus;
+        const tagField = `elseTag${position.charAt(0).toUpperCase() + position.slice(1)}`;
+        const tagsField = `elseTags${position.charAt(0).toUpperCase() + position.slice(1)}`;
+        
+        // 清除之前选择的元素
+        if (this[tagsField] && this[tagsField][0]) {
+          this.$emit('uncheck', this[tagsField][0].id);
+        }
+        
+        // 设置新选择的元素
+        obj.text = obj.name;
+        obj.style = 'background-color: #409EFF';
+        this[tagsField] = [obj];
+        this[tagField] = '';
+        
+        this.setGetDataCondition();
+        return;
+      }
+      // 处理数据获取情况
+      if (this.symbol === 'getData' && this.dataFocus.index !== -1) {
+        const { index, field } = this.dataFocus;
+        const item = this.getDataList[index];
+        
+        let obj = {};
+        if(ele.k){
+          obj = {
+            type:'ParamData',
+            name:ele.name,
+            id:ele.id,
+            selected:false,
+            v:ele.v,
+            k:ele.k,
+            children:[],
+          }
+        }else{
+          obj = {
+            type:'Element',
+            name:ele.eName,
+            id:ele.id,
+            selected:false,
+            tableElementKey:ele.tableElementKey,
+            children:[],
+          }
+        }
+        
+        // 清除之前选择的元素
+        const tagsField = `tags${field.replace('tag', '')}`;
+        if (item[tagsField] && item[tagsField][0]) {
+          this.$emit('uncheck', item[tagsField][0].id);
+        }
+        
+        // 设置新选择的元素
+        obj.text = obj.name;
+        obj.style = 'background-color: #409EFF';
+        item[tagsField] = [obj];
+        item[field] = '';
+        
+        this.setGetDataCondition();
+        return;
+      }
+      
       // 处理多条件情况
       if (this.symbol === 'more' && this.multiFocus.conditionIndex !== -1) {
         const { conditionIndex, innerIndex, field } = this.multiFocus;
@@ -1146,45 +1590,48 @@ export default {
 
     //写入参数真假值判断if(xxx)部分
     setCondition(){
-      if(this.symbol == '<&&<' || this.symbol == '<=&&<='){
-        let arr = new Array(7).fill('');
-        let symbolArr = this.symbol.split('&&');
-        if(this.tags1.length == 0){
-          arr[0] = this.tag1;
-        }else{
-          arr[0] = this.tags1[0];
-        }
-        arr[1] = symbolArr[0];
-        if(this.tags2.length == 0){
-          arr[2] = this.tag2;
-          arr[4] = this.tag2;
-        }else{
-          arr[2] = this.tags2[0];
-          arr[4] = this.tags2[0];
-        }
-        arr[3] = '&&';
-        arr[5] = symbolArr[1];
-        if(this.tags3.length == 0){
-          arr[6] = this.tag3;
-        }else{
-          arr[6] = this.tags3[0];
-        }
-        this.formulainfo.arguments[0] = arr;
-      }else if(this.symbol !== 'more'){
-        let arr = new Array(3).fill('');
-        if(this.tags2.length == 0){
-          arr[0] = this.tag2;
-        }else{
-          arr[0] = this.tags2[0];
-        }
-        arr[1] = this.symbol;
-        if(this.tags3.length == 0){
-          arr[2] = this.tag3;
+      if(this.symbol == '<&&<' || this.symbol == '<=&&<=' || this.symbol !== 'more' && this.symbol !== 'getData') {
+        // 处理单条件情况
+        if(this.symbol == '<&&<' || this.symbol == '<=&&<='){
+          let arr = new Array(7).fill('');
+          let symbolArr = this.symbol.split('&&');
+          if(this.tags1.length == 0){
+            arr[0] = this.tag1;
+          }else{
+            arr[0] = this.tags1[0];
+          }
+          arr[1] = symbolArr[0];
+          if(this.tags2.length == 0){
+            arr[2] = this.tag2;
+            arr[4] = this.tag2;
+          }else{
+            arr[2] = this.tags2[0];
+            arr[4] = this.tags2[0];
+          }
+          arr[3] = '&&';
+          arr[5] = symbolArr[1];
+          if(this.tags3.length == 0){
+            arr[6] = this.tag3;
+          }else{
+            arr[6] = this.tags3[0];
+          }
+          this.formulainfo.arguments[0] = arr;
         }else{
-          arr[2] = this.tags3[0];
+          let arr = new Array(3).fill('');
+          if(this.tags2.length == 0){
+            arr[0] = this.tag2;
+          }else{
+            arr[0] = this.tags2[0];
+          }
+          arr[1] = this.symbol;
+          if(this.tags3.length == 0){
+            arr[2] = this.tag3;
+          }else{
+            arr[2] = this.tags3[0];
+          }
+          this.formulainfo.arguments[0] = arr;
         }
-        this.formulainfo.arguments[0] = arr;
-      } else {
+      } else if(this.symbol == 'more'){
         // 处理多条件情况
         this.formulainfo.arguments[0] = this.conditionList.map(condition => ({
           formulaIfElse: condition.formulaIfElse.map(inner => ({
@@ -1202,6 +1649,9 @@ export default {
           formula1: condition.formula1,
           formula2: condition.formula2
         }));
+      } else if(this.symbol == 'getData'){
+        this.result='3'
+        // 数据获取情况已在setGetDataCondition中处理
       }
     },
 
@@ -1282,7 +1732,7 @@ export default {
 
     //写入参数真假值
     setTF(){
-      if(this.symbol !== 'more') {
+      if(this.symbol !== 'more' && this.symbol !== 'getData') {
         if(this.result == 1){
           if(this.tags4.length == 0){
             this.formulainfo.arguments[1] = this.tag4;
@@ -1366,7 +1816,57 @@ export default {
       } else {
         this.$message({ type: "warning", message: "至少保留一个条件项" });
       }
+    },
+    // 设置否则部分的焦点
+  setElseFocus(position) {
+    this.elseFocus = position;
+  },
+  
+  // 否则部分输入框失焦处理
+  elseInputBlur(position) {
+    const tagField = `elseTag${position.charAt(0).toUpperCase() + position.slice(1)}`;
+    const tagsField = `elseTags${position.charAt(0).toUpperCase() + position.slice(1)}`;
+    
+    if (this[tagField]) {
+      if (this[tagsField] && this[tagsField][0]) {
+        this.$emit('uncheck', this[tagsField][0].id);
+      }
+      this[tagsField] = [];
+    }
+    
+    this.setGetDataCondition();
+  },
+  //返回数据获取相关的数据
+  getDataConditionData() {
+    const inputData = {
+      // 获取数据列表的函数
+        getDataList: this.getDataList,
+      // 左侧else标签
+        elseTagLeft: this.elseTagLeft,
+          elseTagsLeft: this.elseTagsLeft,
+      // 左侧else标签集合
+      elseTagRight:this.elseTagRight,
+      elseTagsRight:this.elseTagsRight,
     }
+    console.log(inputData,'inputData');
+    
+    const result = transformData(inputData);
+    const mapEle=generateElementMap(inputData)
+    return {
+      // 获取数据列表的函数
+        getDataList: this.getDataList,
+        elseTagsLeft: this.elseTagsLeft,
+      // 左侧else标签
+        elseTagLeft: this.elseTagLeft,
+      // 左侧else标签集合
+      elseTagRight:this.elseTagRight,
+      elseTagsRight:this.elseTagsRight,
+      result,
+      mapEle
+    
+
+    };
+  }
 
   }
 }

+ 222 - 0
src/views/formula/component/funComponent/multiIfElseTools.js

@@ -379,3 +379,225 @@ export function generateResult(input) {
   
   return result;
 }
+
+
+
+export function transformData(data) {
+    // 辅助函数:获取值并根据类型决定是否用E[]包裹
+    const getValue = (directValue, arrayValues) => {
+        if (directValue) {
+            return directValue;
+        }
+        
+        // 检查数组中第一个元素
+        if (arrayValues && arrayValues.length > 0) {
+            const firstItem = arrayValues[0];
+            // 如果类型是Element,用E[]包裹tableElementKey
+            if (firstItem.type === "Element" && firstItem.tableElementKey) {
+                return `E[${firstItem.tableElementKey}]`;
+            }
+            return firstItem.tableElementKey || '';
+        }
+        
+        return '';
+    };
+    
+    // 处理getDataList中的每个对象
+    const conditions = data.getDataList.map(item => {
+        // 获取左侧值 a
+        const leftValue = getValue(item.tagWhenLeft, item.tagsWhenLeft);
+        // 获取条件符号
+        const condition = item.condition || '';
+        // 获取右侧值 x
+        const rightValue = getValue(item.tagWhenRight, item.tagsWhenRight);
+        // 获取结果左侧 b
+        const thenLeft = getValue(item.tagThenLeft, item.tagsThenLeft);
+        // 获取结果右侧
+        const thenRight = getValue(item.tagThenRight, item.tagsThenRight);
+        
+        return `${leftValue}${condition}${rightValue},${thenLeft}=${thenRight}`;
+    });
+    
+    // 处理else部分
+    const elseLeft = getValue(data.elseTagLeft, data.elseTagsLeft);
+    const elseRight = getValue(data.elseTagRight, data.elseTagsRight);
+    const elsePart = `else,${elseLeft}=${elseRight}`;
+    
+    // 组合所有部分
+    return [...conditions, elsePart].join(',');
+}
+
+ export function generateElementMap(originalData) {
+    const elementMap = {};
+    
+    // 提取Element的工具函数
+    const extractElements = (elements) => {
+        if (elements && Array.isArray(elements)) {
+            elements.forEach(element => {
+                if (element.type === "Element" && element.tableElementKey) {
+                    elementMap[element.tableElementKey] = {
+                        id: element.id,
+                        name: element.name,
+                        tableElementKey: element.tableElementKey,
+                        type: element.type
+                    };
+                }
+            });
+        }
+    };
+    
+    // 处理getDataList中的元素
+    if (originalData.getDataList && Array.isArray(originalData.getDataList)) {
+        originalData.getDataList.forEach(item => {
+            // 处理tagsWhenLeft(新增)
+            extractElements(item.tagsWhenLeft);
+            // 处理tagsWhenRight
+            extractElements(item.tagsWhenRight);
+            // 处理tagsThenLeft(新增)
+            extractElements(item.tagsThenLeft);
+            // 处理tagsThenRight(新增)
+            extractElements(item.tagsThenRight);
+        });
+    }
+    
+    // 处理elseTagsLeft中的元素
+    extractElements(originalData.elseTagsLeft);
+    
+    // 处理elseTagsRight中的元素
+    extractElements(originalData.elseTagsRight);
+    
+
+    
+    return elementMap;
+
+
+}
+export function restoreData(str,map) {
+    // 辅助函数:创建元素对象
+    const createElement = (tableElementKey, text) => ({
+        "type": "Element",
+        "name": text,  // 确保name是字符串
+        "id": Date.now().toString() + Math.random().toString(36).substr(2, 9),
+        "selected": false,
+        "tableElementKey": tableElementKey,
+        "children": [],
+        "text": text,  // 确保text是字符串
+        "style": "background-color: #409EFF"
+    });
+    
+    // 辅助函数:解析值并决定是直接值还是元素数组
+    const parseValue = (value) => {
+        // 检查是否是E[]包裹的元素
+        const elementMatch = value.match(/^E\[(.+)\]$/);
+        if (elementMatch) {
+            const tableElementKey = elementMatch[1];
+            // 映射tableElementKey到对应的text
+            const textMap = map
+            const text = textMap[tableElementKey].name || tableElementKey;
+            return {
+                directValue: "",
+                arrayValues: [createElement(tableElementKey, text)]
+            };
+        }
+        
+        // 普通值
+        return {
+            directValue: value,
+            arrayValues: []
+        };
+    };
+    
+    // 分割字符串为各个部分
+    const parts = str.split(',');
+    const elseIndex = parts.findIndex(part => part === 'else');
+    
+    if (elseIndex === -1) {
+        // 如果没有else部分,返回合理的默认结构
+        return {
+            "getDataList": [],
+            "elseTagLeft": "",
+            "elseTagsLeft": [],
+            "elseTagRight": "",
+            "elseTagsRight": []
+        };
+    }
+    
+    // 提取条件部分和else部分
+    const conditionParts = parts.slice(0, elseIndex);
+    const elseParts = parts.slice(elseIndex + 1);
+    
+    // 处理条件部分
+    const getDataList = [];
+    for (let i = 0; i < conditionParts.length; i += 2) {
+        const conditionStr = conditionParts[i];
+        const resultStr = conditionParts[i + 1];
+        
+        if (!resultStr) continue; // 跳过无效条目
+        
+        // 解析条件部分 (a[condition]x)
+        let leftValue, condition, rightValue;
+        
+        // 查找条件符号,按长度排序避免"=="被误解析为"="
+        const conditions = ['!=', '>=', '<=', '=', '>', '<'];
+        let foundCondition = null;
+        
+        for (const cond of conditions) {
+            if (conditionStr.includes(cond) && conditionStr.indexOf(cond) > 0) {
+                foundCondition = cond;
+                break;
+            }
+        }
+        
+        if (foundCondition) {
+            const conditionIndex = conditionStr.indexOf(foundCondition);
+            leftValue = conditionStr.substring(0, conditionIndex);
+            condition = foundCondition;
+            rightValue = conditionStr.substring(conditionIndex + foundCondition.length);
+        } else {
+            // 如果没有找到条件符号,默认使用=
+            leftValue = conditionStr;
+            condition = '=';
+            rightValue = '';
+        }
+        
+        // 解析结果部分 (b=y)
+        const [thenLeftStr, thenRightStr = ''] = resultStr.split('=');
+        
+        // 解析各个值
+        const leftParsed = parseValue(leftValue);
+        const rightParsed = parseValue(rightValue);
+        const thenLeftParsed = parseValue(thenLeftStr);
+        const thenRightParsed = parseValue(thenRightStr);
+        
+        // 添加到getDataList
+        getDataList.push({
+            "tagWhenLeft": leftParsed.directValue,
+            "tagsWhenLeft": leftParsed.arrayValues,
+            "condition": condition,
+            "tagWhenRight": rightParsed.directValue,
+            "tagsWhenRight": rightParsed.arrayValues,
+            "tagThenLeft": thenLeftParsed.directValue,
+            "tagsThenLeft": thenLeftParsed.arrayValues,
+            "tagThenRight": thenRightParsed.directValue,
+            "tagsThenRight": thenRightParsed.arrayValues
+        });
+    }
+    
+    // 处理else部分 - 修复主要问题点
+    const elseKeyValue = elseParts[0] || '';
+    const [elseLeftStr, elseRightStr = ''] = elseKeyValue.split('=');
+    
+    const elseLeftParsed = parseValue(elseLeftStr);
+    const elseRightParsed = parseValue(elseRightStr);
+    
+    // 构建并返回原始对象结构
+    return {
+        "getDataList": getDataList,
+        "elseTagLeft": elseLeftParsed.directValue,
+        "elseTagsLeft": elseLeftParsed.arrayValues,
+        "elseTagRight": elseRightParsed.directValue,
+        "elseTagsRight": elseRightParsed.arrayValues
+    };
+}
+    
+

+ 82 - 3
src/views/formula/edit.vue

@@ -213,7 +213,10 @@
                  @uncheck="unCheckEleComp" 
                  class="flex1" 
                  :moreConditions="moreConditions" 
-                :isMore="isMore">
+                :isMore="isMore"
+                :isGetData="isGetData"
+                :dataListGet="dataListGet"
+                >
               </component>
                 <div class="flex1" v-show="item.showSelectEle" style="margin-top:10px;margin-bottom:30px">
                   <el-scrollbar style="height: 400px">
@@ -601,6 +604,9 @@ export default {
       isMore:false,//是否是多条件判断
       moreConditions:[],//多条件判断数组
       formulaDetailMap:{},//公式详情map
+      dataListGet:'',
+      isGetData:false,//是否获取数据
+
 
     };
   },
@@ -1445,6 +1451,65 @@ export default {
             return;
         
         
+      }else if(this.$refs.dynamiccomponent&&this.$refs.dynamiccomponent.length>0&&this.$refs.dynamiccomponent[0]&& this.$refs.dynamiccomponent[0].symbol=='getData'){
+       const dataRes = this.$refs.dynamiccomponent[0].getDataConditionData();
+       console.log(dataRes,'dataRes');
+       const result =dataRes.result;
+       const mapEle = JSON.stringify(dataRes.mapEle);
+       console.log(mapEle,'mapEle');
+       
+        const resultMap =JSON.stringify(result);
+            if(this.formulaid){
+              updateFormula({
+                id:this.formulaid,
+               formula:"FC.switchCase"+'('+result+')',
+             
+                remark:'',
+                nodeId:this.nodeid,
+                elementId:this.eleid,
+                scale:this.isRetain?this.retainNum:'',
+                number:number,
+                map:mapEle,
+                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:"FC.switchCase" +'('+result+')',
+          
+                remark:'',
+                nodeId:this.nodeid,
+                elementId:this.eleid,
+                scale:this.isRetain?this.retainNum:'',
+                number:number,
+                map:mapEle,
+                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;
+       
       }
       
       
@@ -1555,10 +1620,21 @@ export default {
             this.formulaDetailMap = detail.map;
         this.moreConditions =  restoreArrayMore(detail.formulas,this.formulaDetailMap)
     
-      }else{
+      }else if(detail&&detail.formula.includes('FC.switchCase')){
+        //数据获取
+        this.formulaDetailMap = detail.map;
+         detail.formula = detail.formula.replace('FC.switchCase','FC.ifelse');
+         this.isGetData = true;
+         this.dataListGet=detail.formula
+         console.log( this.dataListGet,' this.dataListGet');
+         
+      }
+      else{
         this.isMore = false;
         this.moreConditions = []
         this.formulaDetailMap ={}
+        this.isGetData = false;
+        this.dataListGet=''
 
       }
 
@@ -1577,9 +1653,12 @@ export default {
         
         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);
+        console.log(formula,'formula');
+        
         this.processFormula = formula.processFormula;
         formula.resultFormula[0].id = this.resultFormula[0].id;
         formula.resultFormula[0].name = this.resultFormula[0].name;