chenrui  3 жил өмнө
parent
commit
734d6611bd

+ 39 - 4
src/views/systemManagement/EditSystem/index.vue

@@ -363,6 +363,16 @@ export default {
       //     !search || data.UserName.toLowerCase().includes(search.toLowerCase())
       // );
     },
+    //正整数
+    positiveInteger(ip) {
+      let reg = /^[+]{0,1}(\d+)$/;
+      return reg.test(ip);
+    },
+    isValidIPs(ip) {
+      let reg =
+        /^(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))-(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))$/;
+      return reg.test(ip);
+    },
     isValidseg(ip) {
       let reg =
         /^((?:(?:[01]?\d?\d|2(?:[0-4]\d|5[0-5]))\.){2}(?:[01]?\d?\d|2(?:[0-4]\d|5[0-5])))(?:(?:\.(?:[01]?\d?\d|2(?:[0-4]\d|5[0-5])))(\/(?:(?:[01]?\d?\d|2(?:[0-4]\d|5[0-5]))))?|(\/(?:(?:[01]?\d?\d|2(?:[0-4]\d|5[0-5])))\.(?:(?:[01]?\d?\d|2(?:[0-4]\d|5[0-5])))))$/;
@@ -382,9 +392,23 @@ export default {
       let isSave = true;
       if (ipArr.length >= 2) {
         ipArr.forEach((item) => {
-          if (this.isValidIP(item) == true || this.isValidseg(item) == true) {
+          if (
+            this.isValidIP(item) == true ||
+            this.isValidseg(item) == true ||
+            this.isValidIPs(item) == true
+          ) {
             // this.$message.error("请输入正确IP段,并以;号隔开");
-            isSave = true;
+            if (this.isValidseg(item) == true) {
+              let arr = [];
+              arr = item.split("/");
+              let alt = arr[arr.length - 1];
+              if (alt > 32 && this.positiveInteger(alt) == true) {
+                isSave = false;
+                this.$message.error("请输入正确IP段,并以;号隔开");
+              }
+            } else {
+              isSave = true;
+            }
           } else {
             this.$message.error("请输入正确IP段,并以;号隔开");
             isSave = false;
@@ -393,9 +417,20 @@ export default {
       } else {
         if (
           this.isValidIP(ipArr[0]) == true ||
-          this.isValidseg(ipArr[0]) == true
+          this.isValidseg(ipArr[0]) == true ||
+          this.isValidIPs(ipArr[0]) == true
         ) {
-          isSave = true;
+          if (this.isValidseg(ipArr[0]) == true) {
+            let arr = [];
+            arr = ipArr[0].split("/");
+            let alt = arr[arr.length - 1];
+            if (alt > 32 && this.positiveInteger(alt) == true) {
+              isSave = false;
+              this.$message.error("请输入正确IP段,并以;号隔开");
+            }
+          } else {
+            isSave = true;
+          }
         } else {
           if (ipArr.length != 0) {
             this.$message.error("请输入正确IP段,并以;号隔开");

+ 42 - 5
src/views/systemManagement/addSystem/index.vue

@@ -318,11 +318,24 @@ export default {
       console.log(this.FormData.IpList);
       console.log(arr, "1111111");
     },
+    //正整数
+    positiveInteger(ip) {
+      let reg = /^[+]{0,1}(\d+)$/;
+      return reg.test(ip);
+    },
+    //ip区间
+    isValidIPs(ip) {
+      let reg =
+        /^(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))-(?=(\b|\D))(((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))\.){3}((\d{1,2})|(1\d{1,2})|(2[0-4]\d)|(25[0-5]))(?=(\b|\D))$/;
+      return reg.test(ip);
+    },
+    //ip
     isValidIP: function (ip) {
       let reg =
         /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/;
       return reg.test(ip);
     },
+    //ip段
     isValidseg(ip) {
       let reg =
         /^((?:(?:[01]?\d?\d|2(?:[0-4]\d|5[0-5]))\.){2}(?:[01]?\d?\d|2(?:[0-4]\d|5[0-5])))(?:(?:\.(?:[01]?\d?\d|2(?:[0-4]\d|5[0-5])))(\/(?:(?:[01]?\d?\d|2(?:[0-4]\d|5[0-5]))))?|(\/(?:(?:[01]?\d?\d|2(?:[0-4]\d|5[0-5])))\.(?:(?:[01]?\d?\d|2(?:[0-4]\d|5[0-5])))))$/;
@@ -337,9 +350,22 @@ export default {
       let isSave = true;
       if (ipArr.length >= 2) {
         ipArr.forEach((item) => {
-          if (this.isValidIP(item) == true || this.isValidseg(item) == true) {
-            // this.$message.error("请输入正确IP段,并以;号隔开");
-            isSave = true;
+          if (
+            this.isValidIP(item) == true ||
+            this.isValidseg(item) == true ||
+            this.isValidIPs(item) == true
+          ) {
+            if (this.isValidseg(item) == true) {
+              let arr = [];
+              arr = item.split("/");
+              let alt = arr[arr.length - 1];
+              if (alt > 32 && this.positiveInteger(alt) == true) {
+                isSave = false;
+                this.$message.error("请输入正确IP段,并以;号隔开");
+              }
+            } else {
+              isSave = true;
+            }
           } else {
             this.$message.error("请输入正确IP段,并以;号隔开");
             isSave = false;
@@ -348,9 +374,20 @@ export default {
       } else {
         if (
           this.isValidIP(ipArr[0]) == true ||
-          this.isValidseg(ipArr[0]) == true
+          this.isValidseg(ipArr[0]) == true ||
+          this.isValidIPs(ipArr[0]) == true
         ) {
-          isSave = true;
+          if (this.isValidseg(ipArr[0]) == true) {
+            let arr = [];
+            arr = ipArr[0].split("/");
+            let alt = arr[arr.length - 1];
+            if (alt > 32 && this.positiveInteger(alt) == true) {
+              isSave = false;
+              this.$message.error("请输入正确IP段,并以;号隔开");
+            }
+          } else {
+            isSave = true;
+          }
         } else {
           if (ipArr.length != 0) {
             this.$message.error("请输入正确IP段,并以;号隔开");