ZaiZai 2 weeks ago
parent
commit
66c9ccba29

+ 76 - 2
src/views/project/list/edit-formula.vue

@@ -1197,9 +1197,83 @@ const submitClick = async () => {
     if (isResetFun.value) {
         //重置函数
         setProcessFormula()
-    } else if (deviationRangeShow.value) {
+    } else {
         //允许偏差值范围
-        console.log('1111')
+        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 = ''
+        for (let i = 0; i < process.length; i++) {
+            if (process[i].children) {
+                for (let j = 0; j < process[i].children.length; j++) {
+                    if (process[i].children[j].number) {
+                        number = process[i].children[j].number
+                        break
+                    }
+                }
+            }
+            if (number) {
+                break
+            }
+        }
+        if (number === '') {
+            for (let i = 0; i < results.length; i++) {
+                if (results[i].children) {
+                    for (let j = 0; j < results[i].children.length; j++) {
+                        if (results[i].children[j].number) {
+                            number = results[i].children[j].number
+                            break
+                        }
+                    }
+                }
+                if (number) {
+                    break
+                }
+            }
+        }
+        //发起请求
+        const { eleId, globalType, nodeId, pid } = getObjValue(dataInfo.value)
+        if (isNullES(formulaId.value)) {
+            //新增
+            const { code } = await formulaApi.save({
+                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,
+                ver:1,
+            })
+        } else {
+            //更新
+            const { code } = await formulaApi.update({
+                id: formulaId.value,
+                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,
+            })
+        }
     }
 }
 

+ 22 - 77
src/views/project/list/formula/rangeToString.js

@@ -1,89 +1,34 @@
 import { isNullES } from 'js-fast-way'
 import { formulaArrayToString } from './formulaArrayToString'
 
-// 范围操作符配置对象
-const RANGE_CONFIGS = {
-    // 闭区间配置
-    '【min,max】': {
-        left: '[', // 左边界符号
-        right: ']', // 右边界符号
-        defaultMin: null, // 默认最小值
-        defaultMax: null, // 默认最大值
-    },
-    // 大于区间配置
-    '>': {
-        left: '(',
-        right: ')',
-        defaultMin: null,
-        defaultMax: '100000', // 设置最大值上限
-    },
-    // 小于区间配置
-    '<': {
-        left: '(',
-        right: ')',
-        defaultMin: '0', // 设置最小值下限
-        defaultMax: null,
-    },
-    // 大于等于区间配置
-    '≥': {
-        left: '[',
-        right: ']',
-        defaultMin: null,
-        defaultMax: '100000',
-    },
-    // 小于等于区间配置
-    '≤': {
-        left: '[',
-        right: ']',
-        defaultMin: '0',
-        defaultMax: null,
-    },
-}
-
-/**
- * 将范围表达式转换为字符串
- * @param {Object} processFormula - 包含范围表达式的对象
- * @param {Object} eleMap - 元素映射对象
- * @returns {string} 格式化后的范围字符串
- */
 export const rangeToString = (processFormula, eleMap) => {
-    // 如果两个参数都为空,返回空字符串
+    let text = ''
     if (isNullES(processFormula.arguments1) && isNullES(processFormula.arguments2)) {
-        return ''
+        text = ''
+    } else if (processFormula.symbol === '【min,max】') {
+        text = '[' + getArg(processFormula.arguments1, eleMap) + ',' + getArg(processFormula.arguments2, eleMap) + ']'
+    } else if (processFormula.symbol === '>') {
+        text = '(' + getArg(processFormula.arguments1, eleMap) + ',' + '100000' + ')'
+    } else if (processFormula.symbol === '<') {
+        text = '(' + '0' + ',' + getArg(processFormula.arguments2, eleMap) + ')'
+    } else if (processFormula.symbol === '≥') {
+        text = '[' + getArg(processFormula.arguments1, eleMap) + ',' + '100000' + ']'
+    } else if (processFormula.symbol === '≤') {
+        text = '[' + '0' + ',' + getArg(processFormula.arguments2, eleMap) + ']'
     }
-    // 获取对应符号的配置
-    const config = RANGE_CONFIGS[processFormula.symbol]
-    // 如果符号不支持,抛出错误
-    if (!config) {
-        throw new Error(`不支持的符号: ${processFormula.symbol}`)
-    }
-
-    // 处理最小值和最大值,使用配置中的默认值或处理参数值
-    const min = config.defaultMin ?? getArg(processFormula.arguments1, eleMap)
-    const max = config.defaultMax ?? getArg(processFormula.arguments2, eleMap)
-
-    // 拼接并返回最终的范围字符串
-    return `${config.left}${min},${max}${config.right}`
+    return text
 }
 
-/**
- * 处理参数值
- * @param {Array|string} arg - 参数值,可以是数组或字符串
- * @param {Object} eleMap - 元素映射对象
- * @returns {string} 处理后的参数字符串
- */
 function getArg(arg, eleMap) {
-    // 如果参数为空,返回空字符串
-    if (!arg) return ''
-
-    // 如果参数是数组,使用 formulaArrayToString 处理
+    let text = ''
     if (Array.isArray(arg)) {
-        const { text: argtext, eleMap: argeleMap } = formulaArrayToString(arg, [{ children: [] }])
-        // 合并元素映射对象
-        Object.assign(eleMap, argeleMap)
-        return argtext
+        let { text:argtext, eleMap:argeleMap } = formulaArrayToString(arg, [{ children:[] }])
+        text = argtext
+        for (let key in argeleMap) {
+            eleMap[key] = argeleMap[key]
+        }
+    } else if (typeof arg == 'string') {
+        text = arg
     }
-
-    // 如果参数是其他类型,转换为字符串返回
-    return String(arg)
+    return text
 }