ZaiZai 2 달 전
부모
커밋
ca40a022c3
1개의 변경된 파일172개의 추가작업 그리고 168개의 파일을 삭제
  1. 172 168
      src/views/project/list/edit-formula.vue

+ 172 - 168
src/views/project/list/edit-formula.vue

@@ -13,7 +13,7 @@
                         <span class="ml-5px text-14px">位</span>
                     </div>
                     <div class="range hc-flex h-full w-155px">
-                        <el-button :type="deviationRangeShow ? 'primary' : ''" @click="setDeviationRange">允许偏差值范围</el-button>
+                        <el-button :type="formulaCardType === 'range' ? 'primary' : ''" @click="setDeviationRange">允许偏差值范围</el-button>
                     </div>
                     <div class="menu h-full flex-1">
                         <hc-body padding="0">
@@ -35,7 +35,7 @@
                         <div class="name flex-1 text-14px">函数公式.</div>
                         <div class="extra relative ml-24px">
                             <el-button size="small" @click="clearResetFunClick">清除选择</el-button>
-                            <el-button :type="isResetFun ? 'primary' : 'info'" size="small" @click="resetFunClick">重置函数</el-button>
+                            <el-button :type="formulaCardType === 'reset-fun' ? 'primary' : 'info'" size="small" @click="resetFunClick">重置函数</el-button>
                         </div>
                     </div>
                     <div class="body relative">
@@ -51,7 +51,7 @@
                     </div>
                 </div>
                 <!-- 重置函数 -->
-                <div v-if="isResetFun" class="hc-formula-reset-fun mb-14px">
+                <div v-if="formulaCardType === 'reset-fun'" class="hc-formula-reset-fun mb-14px">
                     <hc-body split padding="0">
                         <template #left>
                             <hc-card class="reset-fun-left-card" scrollbar :loading="treeResetFunLoading">
@@ -59,9 +59,8 @@
                                     <hc-search-input v-model="resetFunTree" @search="resetFunTreeSearch" />
                                 </template>
                                 <el-tree
-                                    v-if="isResetFunTreeLazy" ref="treeResetFunLazyRef" :default-expanded-keys="treeResetFunLazyExpanded" node-key="id"
-                                    :props="defaultProps" :expand-on-click-node="false" lazy highlight-current :load="treeResetFunLazyLoad"
-                                    @node-click="treeResetFunLazyClick"
+                                    v-if="isResetFunTreeLazy" ref="treeResetFunLazyRef" :default-expanded-keys="treeResetFunLazyExpanded" node-key="id" :props="defaultProps"
+                                    :expand-on-click-node="false" lazy highlight-current :load="treeResetFunLazyLoad" @node-click="treeResetFunLazyClick"
                                 />
                                 <el-tree
                                     v-else ref="treeResetFunAllRef" :data="resetFunTreeAll" :props="defaultProps" node-key="id"
@@ -129,7 +128,7 @@
                     </hc-body>
                 </div>
                 <!-- 函数公式运算执行溯源 -->
-                <div v-if="!isResetFun && !deviationRangeShow && !isSelectEle" class="border-dashed-card hc-formula-card-project mb-14px">
+                <div v-if="formulaCardType === 'project'" class="border-dashed-card hc-formula-card-project mb-14px">
                     <div class="header mb-14px text-14px">函数公式运算执行溯源</div>
                     <div class="body relative">
                         <el-select v-model="projectId" filterable clearable class="mr-14px w-380px" placeholder="选择项目" @change="projectChange">
@@ -142,7 +141,7 @@
                     </div>
                 </div>
                 <!-- 允许偏差值范围 -->
-                <div v-if="deviationRangeShow && !isResetFun" class="border-dashed-card hc-formula-card-range mb-14px" :class="isRangeSelectEle ? 'is-h' : ''">
+                <div v-if="formulaCardType === 'range'" class="border-dashed-card hc-formula-card-range mb-14px" :class="isRangeSelectEle ? 'is-h' : ''">
                     <div class="hc-formula-card-range-form hc-flex mb-12px text-14px">
                         <div>允许偏差值范围:</div>
                         <div class="w-130px">
@@ -163,13 +162,17 @@
                         </div>
                         <div v-if="deviationRangeResult === '1'" class="hc-flex mr-50px">
                             <VueTagsInput
-                                v-if="!(deviationRangeSymbol === '<' || deviationRangeSymbol === '≤')" v-model="deviationRangeTag1" :tags="deviationRangeTags1"
-                                placeholder="输入/参数" class="mr-12px" :class="curRangeFocusIndex === 1 ? 'cur' : ''" @focus="curRangeFocusIndex = 1"
+                                v-if="!(deviationRangeSymbol === '<' || deviationRangeSymbol === '≤')"
+                                v-model="deviationRangeTag1" :tags="deviationRangeTags1"
+                                placeholder="输入/参数" class="mr-12px" :class="curRangeFocusIndex === 1 ? 'cur' : ''"
+                                @focus="curRangeFocusIndex = 1"
                                 @blur="deviationRangeBlur1" @before-adding-tag="rangeAddingTag"
                             />
                             <VueTagsInput
-                                v-if="!(deviationRangeSymbol === '>' || deviationRangeSymbol === '≥')" v-model="deviationRangeTag2" :tags="deviationRangeTags2"
-                                placeholder="输入/参数" :class="curRangeFocusIndex === 2 ? 'cur' : ''" @focus="curRangeFocusIndex = 2" @blur="deviationRangeBlur2"
+                                v-if="!(deviationRangeSymbol === '>' || deviationRangeSymbol === '≥')"
+                                v-model="deviationRangeTag2" :tags="deviationRangeTags2"
+                                placeholder="输入/参数" :class="curRangeFocusIndex === 2 ? 'cur' : ''"
+                                @focus="curRangeFocusIndex = 2" @blur="deviationRangeBlur2"
                                 @before-adding-tag="rangeAddingTag"
                             />
                         </div>
@@ -287,8 +290,10 @@
                                         <hc-search-input v-model="resetFunTree" @search="resetFunTreeSearch" />
                                     </template>
                                     <el-tree
-                                        v-if="isResetFunTreeLazy" ref="treeRangeSelectLazyRef" :default-expanded-keys="treeResetFunLazyExpanded" node-key="id"
-                                        :props="defaultProps" :expand-on-click-node="false" lazy highlight-current :load="treeResetFunLazyLoad"
+                                        v-if="isResetFunTreeLazy" ref="treeRangeSelectLazyRef"
+                                        :default-expanded-keys="treeResetFunLazyExpanded" node-key="id"
+                                        :props="defaultProps" :expand-on-click-node="false" lazy highlight-current
+                                        :load="treeResetFunLazyLoad"
                                         @node-click="treeResetFunLazyClick"
                                     />
                                     <el-tree
@@ -312,7 +317,7 @@
                     </div>
                 </div>
                 <!-- 多标签处理 -->
-                <div v-if="isSelectEle" class="hc-formula-card-tag mb-14px">
+                <div v-if="formulaCardType === 'select-ele'" class="hc-formula-card-tag mb-14px">
                     <hc-body padding="0">
                         <el-tabs v-model="equationSelectIndex" type="border-card" closable :before-leave="leaveEquationSelect" @tab-remove="delEquationSelect">
                             <template v-for="(item, index) in equationSelectEle.children" :key="index">
@@ -367,7 +372,7 @@
 </template>
 
 <script setup>
-import { computed, nextTick, ref, watch } from 'vue'
+import { nextTick, ref, watch } from 'vue'
 import { useClick } from 'hc-vue3-ui'
 import {
     arrIndex, deepClone, getArrValue, getObjVal,
@@ -434,6 +439,7 @@ const getDataApi = async () => {
 //保留位数
 const isRetain = ref(false)
 const retainNum = ref(2)
+const formulaCardType = ref('project')
 
 //把公式文本还原数组
 const rightDict = ref([])
@@ -495,40 +501,36 @@ const getItemTableName = (item) => {
 }
 
 //允许偏差值范围
-const deviationRangeShow = ref(false)
 const setDeviationRange = () => {
-    if (isResetFun.value) {
-        window?.$message.warning('请先关闭重置函数')
+    const cardType = formulaCardType.value
+    if (cardType === 'range') {
+        curRangeFocusIndex.value = 0
+        formulaCardType.value = 'project'
         return
     }
-    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
-        }
+    formulaCardType.value = 'range'
+    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 {
-        curRangeFocusIndex.value = 0
+        deviationRangeTags1.value = arguments1
+    }
+    //参数2
+    if (isString(arguments2)) {
+        deviationRangeTag2.value = arguments2
+    } else {
+        deviationRangeTags2.value = arguments2
     }
 }
 
@@ -542,8 +544,8 @@ const getTypeMapApi = async () => {
     formulaMenuList.value = deepClone(res)
     //生成map,方便查找
     for (let key in res) {
-        if (typeof(res[key]) === 'object') {
-            res[key].forEach((formula)=>{
+        if (typeof (res[key]) === 'object') {
+            res[key].forEach((formula) => {
                 formula.template = JSON.parse(formula.template)
                 if (operatorReg.test(formula.template.ft)) {
                     formulaMenuMap.value[formula.template.ft] = formula
@@ -557,9 +559,11 @@ const getTypeMapApi = async () => {
 }
 
 //菜单被选择
+const equationSelectEle = ref({})
 const equationSelectEleCopy = ref({})
 const handleFormulaMenu = async (index, path) => {
-    if (isResetFun.value) {
+    const cardType = formulaCardType.value
+    if (cardType === 'reset-fun') {
         //重置函数
         if (path[0] !== '基础运算') {
             window?.$message.warning('当前只能使用基础运算')
@@ -574,9 +578,17 @@ const handleFormulaMenu = async (index, path) => {
             console.error(e)
         }
     } else {
+        const data = await getEquationSelectEle()
+        equationSelectEle.value = getObjValue(data)
         await equationSelect(path)
         //深拷贝数据
         equationSelectEleCopy.value = deepClone(equationSelectEle.value)
+        //是否有滚动条
+        const newEle = await isSelectEle()
+        isScrollBar.value = !newEle
+        if (newEle) {
+            formulaCardType.value = 'select-ele'
+        }
     }
 }
 
@@ -625,6 +637,27 @@ const equationSelect = async (path) => {
     equationSelectIndex.value = equationSelectEle.value.children.length - 1
 }
 
+//获取当前选中的元素
+const getEquationSelectEle = async () => {
+    const type = processType.value
+    if (isNullES(type)) return null
+    const index = processIndex.value
+    let arr = []
+    if (type === 'resultFormula') {
+        arr = resultFormula.value
+    } else if (type === 'processFormula') {
+        arr = processFormula.value
+    }
+    if (arr.length <= 0) return null
+    return arr[index]
+}
+
+const isSelectEle = async () => {
+    if (isNullES(equationSelectEle.value)) return false
+    if (isNullES(equationSelectEle.value.children)) return false
+    return equationSelectEle.value.children.length > 0
+}
+
 //移除挂载的函数
 const delEquationSelect = (name) => {
     console.log(name)
@@ -688,48 +721,18 @@ const clearResetFunClick = () => {
     processType.value = ''
 }
 
-//获取当前选中的元素
-const equationSelectEle = computed(() => {
-    const type = processType.value
-    if (isNullES(type)) return null
-    const index = processIndex.value
-    let arr = []
-    if (type === 'resultFormula') {
-        arr = resultFormula.value
-    } else if (type === 'processFormula') {
-        arr = processFormula.value
-    }
-    if (arr.length <= 0) return null
-    return arr[index]
-})
-
-const isSelectEle = computed(() => {
-    if (isNullES(equationSelectEle.value)) return false
-    if (isNullES(equationSelectEle.value.children)) return false
-    return equationSelectEle.value.children.length > 0
-})
-
-//是否有滚动条
-watch(isSelectEle, (newVal) => {
-    isScrollBar.value = !newVal
-})
-
-
 //是否重置函数
-const isResetFun = ref(false)
 const resetFunClick = () => {
-    if (deviationRangeShow.value) {
-        window?.$message.warning('请先关闭允许偏差值范围')
-        return
-    }
-    const val = !isResetFun.value
-    if (val) {
-        curRangeFocusIndex.value = 99
-    } else {
+    const cardType = formulaCardType.value
+    if (cardType === 'reset-fun') {
         curRangeFocusIndex.value = 0
+        formulaCardType.value = 'project'
+        isScrollBar.value = true
+    } else {
+        formulaCardType.value = 'reset-fun'
+        curRangeFocusIndex.value = 99
+        isScrollBar.value = false
     }
-    isResetFun.value = val
-    isScrollBar.value = !val
 }
 
 //tree树配置
@@ -774,7 +777,8 @@ const treeResetFunLazyLoad = async (node, resolve) => {
         try {
             const expandId = tableType ? Number(treeNode.tableType) - 1 : Number(treeNode.parentId) - 1
             if (!isNullES(expandId) && expandId >= 0) node.childNodes[expandId].expand()
-        } catch { /* empty */ }
+        } catch { /* empty */
+        }
         //处理选中
         try {
             const paramsId = treeNode.initTableId
@@ -782,7 +786,8 @@ const treeResetFunLazyLoad = async (node, resolve) => {
                 treeResetFunLazyRef.value?.setCurrentKey(paramsId)
                 treeRangeSelectLazyRef.value?.setCurrentKey(paramsId)
             }
-        } catch { /* empty */ }
+        } catch { /* empty */
+        }
         //获取节点详情
         await getNodeDetailApi(treeNode)
     } else if (eleType) {
@@ -814,8 +819,8 @@ const resetFunTreeSearch = async () => {
     const parentId = obj.hasChildren ? obj.id : ''
     const { data, code } = await privateApi.tabTypeLazyTreeAll({
         parentId: parentId,
-        current:1,
-        size:1000,
+        current: 1,
+        size: 1000,
         titleName: resetFunTree.value,
     })
     if (code !== 200) {
@@ -1194,7 +1199,7 @@ const setProcessFormula = () => {
         return
     }
     processFormula.value = deepClone(arr)
-    isResetFun.value = false
+    formulaCardType.value = 'project'
     isScrollBar.value = true
 }
 
@@ -1337,7 +1342,8 @@ const getTemplateFt = (item) => {
     item.template.args.forEach(obj => {
         template = template.replace(obj.key, obj.m)
     })
-    //item.arguments[0].tableElementKey = item.arguments[0].tableElementKey.replace('_key', ':key')
+    const key = item.arguments[0].tableElementKey.replace('_key', ':key')
+    item.arguments[0].tableElementKey = key
     return template
 }
 
@@ -1365,96 +1371,94 @@ const setCurElement = (item, index, indexs) => {
 //保存
 const submitLoading = ref(false)
 const submitClick = async () => {
-    if (isResetFun.value) {
-        //重置函数
+    const cardType = formulaCardType.value
+    //重置函数
+    if (cardType === 'reset-fun') {
         setProcessFormula()
+        return
+    }
+    //允许偏差值范围
+    submitLoading.value = true
+    const result = deviationRangeResult.value
+    deviationRangeObj.value = {
+        symbol: deviationRangeSymbol.value,
+        model: result,
+        arguments1: result === '2' ? selectEleFormula3.value : deviationRangeTag1.value,
+        arguments2: result === '2' ? selectEleFormula4.value : deviationRangeTag2.value,
+    }
+    //处理数据
+    const process = processFormula.value, results = resultFormula.value
+    let obj = formulaArrayToString(process, results)
+    let deviationRangeText = rangeToString(deviationRangeObj.value, obj.eleMap)
+    obj.eleMap.deviationRangeJson = JSON.stringify(deviationRangeObj.value)
+    //特殊公式会有number
+    let number = findNumber(process) || findNumber(results)
+    //发起请求
+    const { eleId, globalType, nodeId, pid } = getObjValue(dataInfo.value)
+    const formData = {
+        formula: obj.text,
+        remark: '',
+        nodeId: nodeId,
+        elementId: eleId,
+        scale: isRetain.value ? retainNum.value : '',
+        number: number,
+        map: JSON.stringify(obj.eleMap),
+        scope: globalType,
+        projectId: projectId.value || pid,
+        dev: deviationRangeText,
+    }
+    let res = {}
+    if (isNullES(formulaId.value)) {
+        //新增
+        res = await formulaApi.save({ ...formData, ver: 1 })
     } else {
-        //允许偏差值范围
-        submitLoading.value = true
-        const result = deviationRangeResult.value
-        deviationRangeObj.value = {
-            symbol: deviationRangeSymbol.value,
-            model: result,
-            arguments1: result === '2' ? selectEleFormula3.value : deviationRangeTag1.value,
-            arguments2: result === '2' ? selectEleFormula4.value : deviationRangeTag2.value,
-        }
-        //处理数据
-        const process = processFormula.value, results = resultFormula.value
-        let obj = formulaArrayToString(process, results)
-        let deviationRangeText = rangeToString(deviationRangeObj.value, obj.eleMap)
-        obj.eleMap.deviationRangeJson = JSON.stringify(deviationRangeObj.value)
-        //特殊公式会有number
-        let number = findNumber(process) || findNumber(results)
-        //发起请求
-        const { eleId, globalType, nodeId, pid } = getObjValue(dataInfo.value)
-        const formData = {
-            formula: obj.text,
-            remark: '',
-            nodeId: nodeId,
-            elementId: eleId,
-            scale: isRetain.value ? retainNum.value : '',
-            number: number,
-            map: JSON.stringify(obj.eleMap),
-            scope: globalType,
-            projectId: projectId.value || pid,
-            dev: deviationRangeText,
-        }
-        let res = {}
-        if (isNullES(formulaId.value)) {
-            //新增
-            res = await formulaApi.save({ ...formData, ver:1 })
-        } else {
-            //更新
-            res = await formulaApi.update({ id: formulaId.value, ...formData })
-        }
-        const { code, msg, data } = getObjValue(res)
-        if (code !== 200) {
-            submitLoading.value = false
-            return
-        }
-        let msgStr = '保存成功'
-        if (msg === '公式已删除') {
-            formulaId.value = ''
-            msgStr = msg
-        } else if (!isNullES(data)) {
-            formulaId.value = data
-        }
-        window?.$message.success(msgStr)
-        getFormulaStringToArrayApi()
+        //更新
+        res = await formulaApi.update({ id: formulaId.value, ...formData })
+    }
+    const { code, msg, data } = getObjValue(res)
+    if (code !== 200) {
         submitLoading.value = false
+        return
     }
+    let msgStr = '保存成功'
+    if (msg === '公式已删除') {
+        formulaId.value = ''
+        msgStr = msg
+    } else if (!isNullES(data)) {
+        formulaId.value = data
+    }
+    window?.$message.success(msgStr)
+    await getFormulaStringToArrayApi()
+    submitLoading.value = false
 }
 
 //关闭抽屉
 const drawerClose = () => {
-    if (isResetFun.value) {
-        //重置函数
-        isResetFun.value = false
+    const cardType = formulaCardType.value
+    if (cardType === 'reset-fun') { //重置函数
+        formulaCardType.value = 'project'
         isScrollBar.value = true
         curRangeFocusIndex.value = 0
-    } else if (deviationRangeShow.value) {
-        //允许偏差值范围
-        deviationRangeShow.value = false
+        selectEleFormula.value = []
+    } else if (cardType === 'range') {//允许偏差值范围
+        formulaCardType.value = 'project'
         isRangeSelectEle.value = false
         curRangeFocusIndex.value = 0
-    } else {
-        isShow.value = false
-        //重置元素
-        isResetFun.value = false
-        isScrollBar.value = true
-        //允许偏差值范围
-        deviationRangeShow.value = false
-        curRangeFocusIndex.value = 0
-        //选择的元素
-        selectEleFormula.value = []
         selectEleFormula3.value = []
         selectEleFormula4.value = []
-        //手写模式
-        isHandWritEle.value = false
-        handWritText.value = ''
-        handWritEleMap.value = {}
-        emit('close')
+        isScrollBar.value = true
+    } else if (cardType === 'select-ele') { //多标签处理
+        formulaCardType.value = 'project'
+        equationSelectIndex.value = -1
+        equationSelectEle.value = {}
+        isScrollBar.value = true
     }
+    //手写模式
+    isHandWritEle.value = false
+    handWritText.value = ''
+    handWritEleMap.value = {}
+    isShow.value = false
+    emit('close')
 }
 </script>