Browse Source

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

duy 1 week ago
parent
commit
2ce9c0a07e

+ 96 - 5
src/views/project/list/edit-formula.vue

@@ -1159,7 +1159,7 @@ const handWritClick = () => {
     try {
     try {
         let { text, eleMap } = formulaArrayToString(processFormula.value, resultFormula.value)
         let { text, eleMap } = formulaArrayToString(processFormula.value, resultFormula.value)
         handWritText.value = text
         handWritText.value = text
-        handWritEleMap.value = eleMap
+        handWritEleMap.value = JSON.stringify(eleMap)
         isHandWritEle.value = true
         isHandWritEle.value = true
     } catch (error) {
     } catch (error) {
         console.log(error)
         console.log(error)
@@ -1169,13 +1169,26 @@ const handWritClick = () => {
 
 
 //手写模式转换
 //手写模式转换
 const handWritTransform = () => {
 const handWritTransform = () => {
-
-    handWritEleClose()
+    try {
+        let formula = formulaStringToArray(handWritText.value, handWritEleMap.value, formulaMenuMap.value)
+        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
+        handWritEleClose()
+    } catch (error) {
+        console.log(error)
+        window?.$message.error('转成配置用的数组失败')
+    }
 }
 }
 
 
 //手写模式关闭
 //手写模式关闭
 const handWritEleClose = () => {
 const handWritEleClose = () => {
     isHandWritEle.value = false
     isHandWritEle.value = false
+    handWritText.value = ''
+    handWritEleMap.value = {}
 }
 }
 
 
 //保存
 //保存
@@ -1184,9 +1197,83 @@ const submitClick = async () => {
     if (isResetFun.value) {
     if (isResetFun.value) {
         //重置函数
         //重置函数
         setProcessFormula()
         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,
+            })
+        }
     }
     }
 }
 }
 
 
@@ -1214,6 +1301,10 @@ const drawerClose = () => {
         selectEleFormula.value = []
         selectEleFormula.value = []
         selectEleFormula3.value = []
         selectEleFormula3.value = []
         selectEleFormula4.value = []
         selectEleFormula4.value = []
+        //手写模式
+        isHandWritEle.value = false
+        handWritText.value = ''
+        handWritEleMap.value = {}
         emit('close')
         emit('close')
     }
     }
 }
 }

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

@@ -1,89 +1,34 @@
 import { isNullES } from 'js-fast-way'
 import { isNullES } from 'js-fast-way'
 import { formulaArrayToString } from './formulaArrayToString'
 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) => {
 export const rangeToString = (processFormula, eleMap) => {
-    // 如果两个参数都为空,返回空字符串
+    let text = ''
     if (isNullES(processFormula.arguments1) && isNullES(processFormula.arguments2)) {
     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) {
 function getArg(arg, eleMap) {
-    // 如果参数为空,返回空字符串
-    if (!arg) return ''
-
-    // 如果参数是数组,使用 formulaArrayToString 处理
+    let text = ''
     if (Array.isArray(arg)) {
     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
 }
 }