소스 검색

fix:表达式优化:第一次添加表达式(或清空后)不带加号

liu.shiyi 1 년 전
부모
커밋
110d53712c
1개의 변경된 파일4개의 추가작업 그리고 1개의 파일을 삭제
  1. 4 1
      data-room-ui/packages/BigScreenDesign/RightSetting/ExpressionDialog.vue

+ 4 - 1
data-room-ui/packages/BigScreenDesign/RightSetting/ExpressionDialog.vue

@@ -185,7 +185,10 @@ export default {
       const str = node.value
       const str = node.value
       const code = node.code
       const code = node.code
       if (node.disabled) return
       if (node.disabled) return
-      this.$refs.codemirrorRef.codemirror.setValue(this.currentConfig.expression + ' +  ' + str)
+      // 判断编辑器里面是return + 0或者多个空格 还是包含其他表达式,每次添加第一个表达式时不要加‘+’,防止计算错误
+      const isInit = /^[\w\s]+$/.test(this.currentConfig.expression)
+      const newStr = isInit ? this.currentConfig.expression + str : this.currentConfig.expression + ' +  ' + str
+      this.$refs.codemirrorRef.codemirror.setValue(newStr)
       // 同时将点击的数据存在expressionCodes中
       // 同时将点击的数据存在expressionCodes中
       if (this.currentConfig.expressionCodes && Array.isArray(this.currentConfig.expressionCodes)) {
       if (this.currentConfig.expressionCodes && Array.isArray(this.currentConfig.expressionCodes)) {
         this.currentConfig.expressionCodes.push(code)
         this.currentConfig.expressionCodes.push(code)