浏览代码

符号添加判断

duy 2 年之前
父节点
当前提交
067beb27dc
共有 1 个文件被更改,包括 31 次插入26 次删除
  1. 31 26
      src/views/formula/edit1.vue

+ 31 - 26
src/views/formula/edit1.vue

@@ -174,7 +174,7 @@
         <div class="text-align-c">
           <el-button size="small" @click="canceloperationVisible ">取消</el-button>
           <el-button size="small" @click="operationHandle" type="primary">保存</el-button>
-          
+
         </div>
       </div>
     </div>
@@ -950,26 +950,27 @@ export default {
     eleChang(value,item){
       if(value){
         //简单语法判断
-         this.itemList.push(item);
-          if(this.itemList.length != 0 && this.deleEleIndex < 0){
-                  let lastEle = this.itemList[this.itemList.length-1];
-                  if(lastEle.type == 'Text'){
-                    this.$message({
-                      type: "warning",
-                      message: "元素无法连续出现在输入值后面"
-                    });
-                item.checked = false;
-                return;
-               }
-              if(lastEle.type == 'Brackets' && lastEle.name == ')'){
-                this.$message({
-                  type: "warning",
-                  message: "元素无法连续出现在右括号后面"
-                });
-                item.checked = false;
-                return;
-              }
-          }  
+        if(this.itemList.length != 0 && this.deleEleIndex < 0){
+                let lastEle = this.itemList[this.itemList.length-1];
+                if(lastEle.type == 'Text'){
+                  this.$message({
+                    type: "warning",
+                    message: "元素无法连续出现在输入值后面"
+                  });
+              item.checked = false;
+              return;
+             }
+            if(lastEle.type == 'Brackets' && lastEle.name == ')'){
+              this.$message({
+                type: "warning",
+                message: "元素无法连续出现在右括号后面"
+              });
+              item.checked = false;
+              return;
+            }
+        }
+
+        this.itemList.push(item);
       }else{
            let index = -1;
             for (let i = 0; i < this.itemList.length; i++) {
@@ -985,13 +986,17 @@ export default {
     },
     //快捷添加运算符号
     addOperator(operator){
-      
+
+      let lastEle = this.selectEleFormula[this.selectEleFormula.length-1];
       this.itemList.forEach(e => {
-          this.eleAddFormulaHandle(e);
-        this.eleAddFormulaHandle(this.formulaMap[operator]);
+        if(this.selectEleFormula.length != 0 && lastEle.type != 'Operator' && lastEle.type != 'Brackets' && lastEle.name != '('){
+          this.eleAddFormulaHandle(this.formulaMap[operator]);
+        }
+
+        this.eleAddFormulaHandle(e);
       })
-      
-       
+
+
       this.itemList=[]
     },
     //插入运算符