Преглед изворни кода

Merge branch 'main' of http://39.108.216.210:3000/web/admin into main

xd111 пре 2 недеља
родитељ
комит
bdb4e24a64

+ 8 - 0
src/styles/view/project/edit-formula.scss

@@ -289,3 +289,11 @@
         }
     }
 }
+
+//手写模式
+.el-textarea.hc-formula-hand-writ-text {
+    height: 100%;
+    .el-textarea__inner {
+        height: 100%;
+    }
+}

+ 88 - 8
src/views/project/list/edit-formula.vue

@@ -26,7 +26,7 @@
                         </hc-body>
                     </div>
                     <div class="hand hc-flex h-full w-100px">
-                        <el-button>手写模式</el-button>
+                        <el-button @click="handWritClick">手写模式</el-button>
                     </div>
                 </div>
                 <!-- 函数公式 -->
@@ -314,6 +314,20 @@
                 <el-button type="primary" :loading="submitLoading" @click="submitClick">保存</el-button>
             </template>
         </hc-card>
+        <!-- 手写模式 -->
+        <hc-dialog v-model="isHandWritEle" is-table widths="900px" title="手写模式" @close="handWritEleClose">
+            <template #search>
+                <div class="relative">
+                    <div class="mb-6px text-orange-6">tips:手写模式不保证能转换成配置模式!!即使能转换也不保证正确!!!</div>
+                    <div class="text-orange-6">无法在手写模式手写加入新的元素!新的节点参数!</div>
+                </div>
+            </template>
+            <el-input v-model="handWritText" type="textarea" class="hc-formula-hand-writ-text" placeholder="请输入内容" />
+            <template #footer>
+                <el-button hc-btn @click="handWritEleClose">取消</el-button>
+                <el-button hc-btn type="primary" @click="handWritTransform">转换</el-button>
+            </template>
+        </hc-dialog>
     </hc-drawer>
 </template>
 
@@ -321,8 +335,8 @@
 import { nextTick, ref, watch } from 'vue'
 import { useClick } from 'hc-vue3-ui'
 import {
-    arrIndex, deepClone, getArrValue,
-    getObjValue, getRandom, isNullES,
+    arrIndex, deepClone, getArrValue, getObjValue,
+    getRandom, isArray, isNullES, isString,
 } from 'js-fast-way'
 import { ElMessageBox } from 'element-plus'
 import { VueTagsInput } from '@vojtechlanka/vue-tags-input'
@@ -376,10 +390,10 @@ const isScrollBar = ref(true)
 //获取数据
 const getDataApi = async () => {
     console.log(dataInfo.value)
-    getTypeMapApi().then()
-    getWbsFormElementData().then()
+    await getTypeMapApi()
+    await getWbsFormElementData()
+    await getFormulaStringToArrayApi()
     getProjectDataApi().then()
-    getFormulaStringToArrayApi().then()
 }
 
 //保留位数
@@ -389,10 +403,11 @@ const retainNum = ref(2)
 //把公式文本还原数组
 const rightDict = ref([])
 const formulaId = ref('')
+const deviationRangeObj = ref({})
 const getFormulaStringToArrayApi = async () => {
     const { eleId, globalType, nodeId, pid } = getObjValue(dataInfo.value)
     const { code, data } = await formulaApi.detail({
-        projectId: projectId.value || pid,
+        projectId: pid,
         elementId: eleId,
         nodeId: nodeId,
         scope: globalType,
@@ -411,8 +426,24 @@ const getFormulaStringToArrayApi = async () => {
         formulaId.value = res.id
         //把公式字符串还原成数组
         let formula = formulaStringToArray(res.formula, res.map, formulaMenuMap.value)
-        console.log('formula', formula)
         processFormula.value = getArrValue(formula?.processFormula)
+        const results = resultFormula.value
+        formula.resultFormula[0].id = results[0].id
+        formula.resultFormula[0].name = results[0].name
+        formula.resultFormula[0].tableElementKey = results[0].tableElementKey
+        resultFormula.value[0].children = formula.resultFormula[0].children
+        //允许偏差值范围
+        let mapObj = JSON.parse(res.map)
+        if (mapObj.deviationRangeJson) {
+            deviationRangeObj.value = JSON.parse(mapObj.deviationRangeJson)
+        }
+    }
+    if (res.scale >= 0) {
+        isRetain.value = true
+        retainNum.value = res.scale
+    } else {
+        isRetain.value = false
+        retainNum.value = 2
     }
 }
 
@@ -426,7 +457,29 @@ const setDeviationRange = () => {
     const val = !deviationRangeShow.value
     deviationRangeShow.value = val
     if (val) {
+        const { symbol, model, arguments1, arguments2 } = deviationRangeObj.value
+        deviationRangeSymbol.value = symbol
+        deviationRangeResult.value = model
         curRangeFocusIndex.value = 1
+        //公式
+        if (isArray(arguments1) && arguments1.length > 1 || isArray(arguments2) && arguments2.length > 1) {
+            //selectEleFormula.value = arguments1
+            selectEleFormula3.value = arguments1
+            selectEleFormula4.value = arguments2
+            return
+        }
+        //参数1
+        if (isString(arguments1)) {
+            deviationRangeTag1.value = arguments1
+        } else {
+            deviationRangeTags1.value = arguments1
+        }
+        //参数2
+        if (isString(arguments2)) {
+            deviationRangeTag2.value = arguments2
+        } else {
+            deviationRangeTags2.value = arguments2
+        }
     } else {
         curRangeFocusIndex.value = 0
     }
@@ -1098,6 +1151,33 @@ const deviationRangeSelectEle = () => {
     isScrollBar.value = !val
 }
 
+//手写模式
+const handWritText = ref('')
+const handWritEleMap = ref({})
+const isHandWritEle = ref(false)
+const handWritClick = () => {
+    try {
+        let { text, eleMap } = formulaArrayToString(processFormula.value, resultFormula.value)
+        handWritText.value = text
+        handWritEleMap.value = eleMap
+        isHandWritEle.value = true
+    } catch (error) {
+        console.log(error)
+        window?.$message.error('生成公式文本失败')
+    }
+}
+
+//手写模式转换
+const handWritTransform = () => {
+
+    handWritEleClose()
+}
+
+//手写模式关闭
+const handWritEleClose = () => {
+    isHandWritEle.value = false
+}
+
 //保存
 const submitLoading = ref(false)
 const submitClick = async () => {

+ 157 - 284
src/views/project/list/formula/formulaArrayToString.js

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