Преглед на файлове

王子文 日报非数字数值前端校验

wangggziwen преди 2 години
родител
ревизия
d1eccd0bae
променени са 1 файла, в които са добавени 28 реда и са изтрити 0 реда
  1. 28 0
      ui/src/views/production/daily/index.vue

+ 28 - 0
ui/src/views/production/daily/index.vue

@@ -4064,6 +4064,31 @@ export default {
   // },
   mixins: [echartMixins],
   methods: {
+    /** 校验用户输入是否为数字 */
+    isNumberInput() {
+      let flag = true;
+      let inputNodes = document.getElementsByClassName("el-input__inner");
+      for (let i = 0; i < inputNodes.length; i++) {
+        let value = inputNodes[i].value;
+        if (value.indexOf("%") == -1 &&
+          value != this.reportData.reportDate &&
+          value != this.reportData.plantModeIs &&
+          value != this.analysisQueryParams.startDate &&
+          value != this.analysisQueryParams.endDate &&
+          value != this.chemicalChosen
+        ) {
+          if (isNaN(Number(value)) == true) {
+            flag = false;
+          }
+        }
+      }
+      if (flag == true) {
+        return true;
+      } else {
+        this.$message.info("输入值不合法,必须为数值类型。");
+        return false;
+      }
+    },
     /** 处理趋势图对话框对比指标change事件 */
     handleAddChemicals() {
       if (this.chemicalChosen != null && this.chemicalChosen != "") { // 选中对比指标
@@ -4283,6 +4308,9 @@ export default {
     },
     /** 确定修改按钮操作 */
     handleConfirmUpdate(row) {
+      if (this.isNumberInput() == false) {
+        return false;
+      }
       this.updating = false;
       updateReport(this.reportData).then(response => {
         if (response.code == 200) {