Skip to content

Commit

Permalink
优化 ipv4 的校验规则
Browse files Browse the repository at this point in the history
  • Loading branch information
shaohq committed Apr 30, 2022
1 parent fe615ec commit 29837b6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
12 changes: 12 additions & 0 deletions web/src/utils/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ const comp = {
return callback(window.VueAppComponent.$t('validator.dnsName'))
}
}
app.config.globalProperties.$validators.ipv4 = function (rule, value, callback) {
if (!value) {
return callback()
}
let reg = /(\b25[0-5]|\b2[0-4][0-9]|\b[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}/
console.log(reg.test(value))
if (reg.test(value)) {
return callback()
} else {
return callback('非法的 ipv4 地址')
}
}
}
}

Expand Down
4 changes: 3 additions & 1 deletion web/src/views/clusters/create/CreateCluster.vue
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ export default {
resource_package: this.form.kuboardspray_resource_package,
}
await this.kuboardSprayApi.post('/clusters', req).then(resp => {
console.log(resp.data.data)
if (resp.status === 500) {
console.log(resp.data.data)
}
this.$message.success(this.$t('msg.save_succeeded'))
this.$router.push(`/clusters/${this.form.cluster_name}?mode=edit`)
}).catch(e => {
Expand Down
2 changes: 2 additions & 0 deletions web/src/views/clusters/plan/common/SshParamsNode.vue
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export default {
return {
hostRules: [
{ required: true, message: this.$t('field.ansible_host') + this.$t('field.is_required_field'), trigger: 'blur' },
{ validator: this.$validators.ipv4, trigger: 'change' },
{
validator: (rule, value, callback) => {
if (value === location.hostname) {
Expand All @@ -127,6 +128,7 @@ export default {
],
ipRules: [
{ required: true, message: this.$t('ip') + this.$t('field.is_required_field'), trigger: 'change' },
{ validator: this.$validators.ipv4, trigger: 'change' },
{
validator: (rule, value, callback) => {
for (let key in this.cluster.inventory.all.hosts) {
Expand Down

0 comments on commit 29837b6

Please sign in to comment.