王震
2023-11-22 59d52aad1c52714688dda99d3c8febf892faddbd
Merge branch 'master' of http://114.132.189.42:9002/r/mes-ocea-before
已修改2个文件
334 ■■■■ 文件已修改
src/views/quality/rawMaterial/rawMaterial-form.vue 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/quality/teststandard/standard-form.vue 327 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/quality/rawMaterial/rawMaterial-form.vue
@@ -171,10 +171,6 @@
                      </div>
                    </template>
                  </el-table-column>
                  <el-table-column prop="deviceName" label="试验设备" min-width="260">
                    <template slot-scope="scope">
                      <div v-if="!scope.row.children">
@@ -215,8 +211,6 @@
            </el-col>
        </el-row>
      </div>
      <div class="rawMaterial-result">
        <el-row>
          <el-col :span="24">检验结论</el-col>
@@ -385,7 +379,6 @@
        }
        this.showPart = true
      },
      updateDevice(row, index) {
            let rowId=JSON.stringify(row.rpId)
            updateDeviceById({ deviceId: row.deviceId, rpId: row.rpId }).then(res => {
src/views/quality/teststandard/standard-form.vue
@@ -194,14 +194,26 @@
      this.visible = true
      this.$nextTick(() => {
        this.$refs.dataForm.resetFields()
        this.dataForm = {
          id: 0,
          standardName: '',
          standardNo: '',
          remark: '',
          judgeFormula: '',
          inspectionType: null,
          operationId: null,
          operationNo: null,
          operationName: null,
        }
        if (this.dataForm.id) {
          getTestStandard(this.dataForm.id).then((response) => {
            console.log(response.data.data)
            this.dataForm = response.data.data
            this.$refs.templateJudgmentCondition.setVal(
              this.dataForm.judgeFormula == null
                ? ''
                : this.dataForm.judgeFormula
            )
            // this.$refs.templateJudgmentCondition.setVal(
            //   this.dataForm.judgeFormula == null
            //     ? ''
            //     : this.dataForm.judgeFormula
            // )
          })
          this.params = []
          getTestStandardParams(
@@ -237,162 +249,163 @@
    // 表单提交
    dataFormSubmit() {
      this.isSubmit = true
      // 校验判定公式
      let judgeFormula = this.$refs.templateJudgmentCondition.getVal()
      // 替换公式中的pi常量为3.14
      if (judgeFormula.length > 0) {
        const piExistIndex = judgeFormula.indexOf('pi')
        if (piExistIndex >= 0) {
          judgeFormula = judgeFormula.replace(/pi/g, '3.14')
        }
      }
      // 替换公式中的passAll()函数为true
      if (judgeFormula.length > 0) {
        const piExistIndex = judgeFormula.indexOf('passAll()')
        if (piExistIndex >= 0) {
          judgeFormula = judgeFormula.replace(/passAll[(][)]/g, 'true')
        }
      }
      // 先判定公式中函数格式是否正确,再用默认值计算出函数值,替换进公式,最后将公式中剩余的参数进行默认值替换,利用js eval函数进行公式校验
      let flag = true
      let funcEl
      for (let j = 0; j < this.funcs.length; j++) {
        funcEl = this.funcs[j]
        // 计算函数关键在公式中出现的次数
        const num = this.getNumCharInStr(judgeFormula, funcEl.name, 0)
        // for循环次数校验替换
        for (let k = 0; k < num; k++) {
          const existIndex = judgeFormula.indexOf(funcEl.name)
          if (existIndex >= 0) {
            // 函数关键字在公式中存在
            const prefixStr = judgeFormula.substring(0, existIndex)
            const startToEndStr = judgeFormula.substring(
              existIndex + funcEl.name.length
            )
            if (startToEndStr.length > 0) {
              const paramStartIndex = startToEndStr.indexOf('(')
              const paramEndIndex = startToEndStr.indexOf(')')
              if (paramStartIndex === 0 && paramEndIndex > 0) {
                const suffixStr = startToEndStr.substring(paramEndIndex + 1)
                const paramStr = startToEndStr.substring(
                  paramStartIndex + 1,
                  paramEndIndex
                )
                if (paramStr.trim() !== '') {
                  const paramArr = paramStr.split(',')
                  if (paramArr.length > 0) {
                    if (
                      (funcEl.singleParam && paramArr.length === 1) ||
                      !funcEl.singleParam
                    ) {
                      let paramFlag = true
                      for (let i = 0; i < paramArr.length; i++) {
                        const param = this.params.find(
                          (item) =>
                            paramArr[i].trim() === 'V[' + item.code + ']'
                        )
                        if (param !== undefined) {
                        } else {
                          flag = false
                          paramFlag = false
                          this.$message.error('函数参数不存在')
                        }
                      }
                      if (paramFlag) {
                        if (funcEl.returnType === 'number') {
                          judgeFormula = prefixStr + '1' + suffixStr
                        } else {
                          judgeFormula = prefixStr + 'true' + suffixStr
                        }
                      } else {
                        break
                      }
                    } else {
                      flag = false
                      this.$message.error('函数参数个数不正确')
                      break
                    }
                  } else {
                    break
                  }
                } else {
                  flag = false
                  this.$message.error('函数必须要有参数')
                  break
                }
              } else {
                flag = false
                this.$message.error(
                  '函数需包含左右小括号,且左侧小括号需紧邻函数'
                )
                break
              }
            } else {
              flag = false
              this.$message.error('函数需包含左右小括号')
              break
            }
          }
        }
      }
      if (flag) {
        // 将公式中剩余的参数进行默认值替换
        let param
        for (let x = 0; x < this.params.length; x++) {
          param = this.params[x]
          // 计算参数在公式中出现的次数
          const num = this.getNumCharInStr(
            judgeFormula,
            'V[' + param.code + ']',
            0
          )
          // for循环次数校验替换
          for (let y = 0; y < num; y++) {
            const existIndex = judgeFormula.indexOf('V[' + param.code + ']')
            if (existIndex >= 0) {
              const prefixStr = judgeFormula.substring(0, existIndex)
              const suffixStr = judgeFormula.substring(
                existIndex + ('V[' + param.code + ']').length
              )
              judgeFormula = prefixStr + this.getRandom() + suffixStr
            }
          }
        }
        try {
          eval(judgeFormula)
        } catch (exception) {
          flag = false
        }
        if (flag) {
          this.dataForm.judgeFormula = this.$refs.templateJudgmentCondition.getVal()
          this.$refs.dataForm.validate((valid) => {
            if (valid) {
              if (this.dataForm.id) {
                putTestStandard(this.dataForm).then((data) => {
                  this.$message.success('修改成功')
                  this.visible = false
                  this.isSubmit = false
                  this.$emit('refreshDataList')
                })
              } else {
                addTestStandard(this.dataForm).then((data) => {
                  this.$message.success('添加成功')
                  this.visible = false
                  this.isSubmit = false
                  this.$emit('refreshDataList')
                })
              }
            } else {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          if (this.dataForm.id) {
            putTestStandard(this.dataForm).then((data) => {
              this.$message.success('修改成功')
              this.visible = false
              this.isSubmit = false
            }
          })
              this.$emit('refreshDataList')
            })
          } else {
            addTestStandard(this.dataForm).then((data) => {
              this.$message.success('添加成功')
              this.visible = false
              this.isSubmit = false
              this.$emit('refreshDataList')
            })
          }
        } else {
          this.isSubmit = false
          this.$message.error('公式格式错误,请仔细检查')
        }
      } else {
        this.isSubmit = false
      }
      })
      // 校验判定公式
      // let judgeFormula = this.$refs.templateJudgmentCondition.getVal()
      // // 替换公式中的pi常量为3.14
      // if (judgeFormula.length > 0) {
      //   const piExistIndex = judgeFormula.indexOf('pi')
      //   if (piExistIndex >= 0) {
      //     judgeFormula = judgeFormula.replace(/pi/g, '3.14')
      //   }
      // }
      // // 替换公式中的passAll()函数为true
      // if (judgeFormula.length > 0) {
      //   const piExistIndex = judgeFormula.indexOf('passAll()')
      //   if (piExistIndex >= 0) {
      //     judgeFormula = judgeFormula.replace(/passAll[(][)]/g, 'true')
      //   }
      // }
      // // 先判定公式中函数格式是否正确,再用默认值计算出函数值,替换进公式,最后将公式中剩余的参数进行默认值替换,利用js eval函数进行公式校验
      // let flag = true
      // let funcEl
      // for (let j = 0; j < this.funcs.length; j++) {
      //   funcEl = this.funcs[j]
      //   // 计算函数关键在公式中出现的次数
      //   const num = this.getNumCharInStr(judgeFormula, funcEl.name, 0)
      //   // for循环次数校验替换
      //   for (let k = 0; k < num; k++) {
      //     const existIndex = judgeFormula.indexOf(funcEl.name)
      //     if (existIndex >= 0) {
      //       // 函数关键字在公式中存在
      //       const prefixStr = judgeFormula.substring(0, existIndex)
      //       const startToEndStr = judgeFormula.substring(
      //         existIndex + funcEl.name.length
      //       )
      //       if (startToEndStr.length > 0) {
      //         const paramStartIndex = startToEndStr.indexOf('(')
      //         const paramEndIndex = startToEndStr.indexOf(')')
      //         if (paramStartIndex === 0 && paramEndIndex > 0) {
      //           const suffixStr = startToEndStr.substring(paramEndIndex + 1)
      //           const paramStr = startToEndStr.substring(
      //             paramStartIndex + 1,
      //             paramEndIndex
      //           )
      //           if (paramStr.trim() !== '') {
      //             const paramArr = paramStr.split(',')
      //             if (paramArr.length > 0) {
      //               if (
      //                 (funcEl.singleParam && paramArr.length === 1) ||
      //                 !funcEl.singleParam
      //               ) {
      //                 let paramFlag = true
      //                 for (let i = 0; i < paramArr.length; i++) {
      //                   const param = this.params.find(
      //                     (item) =>
      //                       paramArr[i].trim() === 'V[' + item.code + ']'
      //                   )
      //                   if (param !== undefined) {
      //                   } else {
      //                     flag = false
      //                     paramFlag = false
      //                     this.$message.error('函数参数不存在')
      //                   }
      //                 }
      //                 if (paramFlag) {
      //                   if (funcEl.returnType === 'number') {
      //                     judgeFormula = prefixStr + '1' + suffixStr
      //                   } else {
      //                     judgeFormula = prefixStr + 'true' + suffixStr
      //                   }
      //                 } else {
      //                   break
      //                 }
      //               } else {
      //                 flag = false
      //                 this.$message.error('函数参数个数不正确')
      //                 break
      //               }
      //             } else {
      //               break
      //             }
      //           } else {
      //             flag = false
      //             this.$message.error('函数必须要有参数')
      //             break
      //           }
      //         } else {
      //           flag = false
      //           this.$message.error(
      //             '函数需包含左右小括号,且左侧小括号需紧邻函数'
      //           )
      //           break
      //         }
      //       } else {
      //         flag = false
      //         this.$message.error('函数需包含左右小括号')
      //         break
      //       }
      //     }
      //   }
      // }
      // if (flag) {
      //   // 将公式中剩余的参数进行默认值替换
      //   let param
      //   for (let x = 0; x < this.params.length; x++) {
      //     param = this.params[x]
      //     // 计算参数在公式中出现的次数
      //     const num = this.getNumCharInStr(
      //       judgeFormula,
      //       'V[' + param.code + ']',
      //       0
      //     )
      //     // for循环次数校验替换
      //     for (let y = 0; y < num; y++) {
      //       const existIndex = judgeFormula.indexOf('V[' + param.code + ']')
      //       if (existIndex >= 0) {
      //         const prefixStr = judgeFormula.substring(0, existIndex)
      //         const suffixStr = judgeFormula.substring(
      //           existIndex + ('V[' + param.code + ']').length
      //         )
      //         judgeFormula = prefixStr + this.getRandom() + suffixStr
      //       }
      //     }
      //   }
      //   try {
      //     eval(judgeFormula)
      //   } catch (exception) {
      //     flag = false
      //   }
      //   if (flag) {
      //     this.dataForm.judgeFormula = this.$refs.templateJudgmentCondition.getVal()
      //   } else {
      //     this.isSubmit = false
      //     this.$message.error('公式格式错误,请仔细检查')
      //   }
      // } else {
      //   this.isSubmit = false
      // }
    },
    openOperationDialog() {
      this.showOperate = true