Commit fcf5fcde authored by “yiyousong”'s avatar “yiyousong”

feat: 站点表单添加ip和端口校验

parent 7b4e5ee7
...@@ -308,6 +308,7 @@ import YCheckbox from "@/components/ycheckbox/YCheckbox.vue"; ...@@ -308,6 +308,7 @@ import YCheckbox from "@/components/ycheckbox/YCheckbox.vue";
import YSwitch from "@/components/yswitch/YSwitch.vue"; import YSwitch from "@/components/yswitch/YSwitch.vue";
// import options from "@/utils/city"; // import options from "@/utils/city";
import { regionData } from "element-china-area-data"; import { regionData } from "element-china-area-data";
import { checkPort, checkIp } from "@/utils/validate";
export default { export default {
props: { props: {
formVisible: { formVisible: {
...@@ -459,15 +460,15 @@ export default { ...@@ -459,15 +460,15 @@ export default {
siteIp: [ siteIp: [
{ {
required: true, required: true,
message: "站点服务器ip不能为空", validator: checkIp,
trigger: ["blur", "change"], trigger: "blur",
}, },
], ],
sitePort: [ sitePort: [
{ {
required: true, required: true,
message: "站点服务器端口不能为空", validator: checkPort,
trigger: ["blur", "change"], trigger: "blur",
}, },
], ],
longitude: [ longitude: [
...@@ -739,10 +740,8 @@ export default { ...@@ -739,10 +740,8 @@ export default {
.then((res) => { .then((res) => {
if (res.status == 1) { if (res.status == 1) {
let { location } = res.geocodes[0]; let { location } = res.geocodes[0];
[ [this.formInfo.longitude, this.formInfo.latitude] =
this.formInfo.longitude, location.split(",");
this.formInfo.latitude,
] = location.split(",");
} else { } else {
this.$message.error("经纬度获取失败,请输入正确的地址"); this.$message.error("经纬度获取失败,请输入正确的地址");
} }
......
...@@ -111,3 +111,55 @@ export const changeCodeNumber = (rule, value, callback) => { ...@@ -111,3 +111,55 @@ export const changeCodeNumber = (rule, value, callback) => {
callback(); callback();
} }
}; };
// 验证mac地址
export const checkMac = (rule, value, callback) => {
if (!value) {
callback(new Error("请输入mac地址"));
} else if (
!/^(([a-f0-9][0,2,4,6,8,a,c,e]:([a-f0-9]{2}:){4})|([a-f0-9][0,2,4,6,8,a,c,e]-([a-f0-9]{2}-){4}))[a-f0-9]{2}$/i.test(
value
)
) {
callback(new Error("mac地址格式错误"));
} else {
callback();
}
};
// 验证端口
export const checkPort = (rule, value, callback) => {
if (!value) {
if (rule.required) {
callback(new Error("端口号不能为空"));
} else {
callback();
}
} else if (
!/^([0-9]|[1-9]\d|[1-9]\d{2}|[1-9]\d{3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-5])$/.test(
value
)
) {
callback(new Error("端口号格式错误"));
} else {
callback();
}
};
// 验证ip
export const checkIp = (rule, value, callback) => {
if (!value) {
if (rule.required) {
callback(new Error("ip不能为空"));
} else {
callback();
}
} else if (
!/^(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/.test(
value
)
) {
callback(new Error("ip格式错误"));
} else {
callback();
}
};
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment