perf: Optimize cloud account update error reporting to prompt on the corresponding field

This commit is contained in:
jiangweidong 2025-04-17 11:40:49 +08:00 committed by 老广
parent b4ba209a8b
commit 56f05e09ca
2 changed files with 35 additions and 6 deletions

View File

@ -244,6 +244,7 @@ export default {
this.$refs.form.setFieldError(key, err)
}
}
this.$emit('performError', data)
}
},
hasSaveContinue: {

View File

@ -3,6 +3,7 @@
ref="form"
class="form"
v-bind="settings"
@performError="handlePerformError"
@performFinished="handlePerformFinished"
@submitSuccess="handleSubmitSuccess"
/>
@ -54,6 +55,7 @@ export default {
}
return {
priSubmitForm: null,
submitType: 'auto',
settings: {
url: `/api/v1/xpack/cloud/accounts/`,
@ -106,6 +108,9 @@ export default {
},
project: {
label: this.$t('Project')
},
hostname_prefix: {
required: false
}
}
},
@ -172,16 +177,11 @@ export default {
},
methods: {
submitForm(form, btn, submitType) {
this.priSubmitForm = form
form.validate((valid) => {
if (valid) {
btn.loading = true
this.$refs.form.$refs.form.dataForm.submitForm('form', false)
if (this.origin === 'update') {
setTimeout(() => {
this.$emit('submitSuccess')
this.$emit('update:visible', false)
}, 500)
}
this.submitType = submitType
}
})
@ -190,12 +190,40 @@ export default {
if (this.submitType === 'manual') {
this.$emit('update:object', res)
this.$emit('update:active', 2)
} else if (this.submitType === 'update') {
setTimeout(() => {
this.$emit('submitSuccess')
this.$emit('update:visible', false)
}, 500)
}
},
handlePerformFinished() {
for (const btn of this.settings.moreButtons) {
btn.loading = false
}
},
handlePerformError(errorData) {
if (errorData.hasOwnProperty('attrs')) {
for (const f in errorData['attrs']) {
this.setAttrsFieldError(f, errorData['attrs'][f])
}
}
},
setAttrsFieldError(name, errors) {
for (const item of this.priSubmitForm.content) {
if (item.id === 'attrs') {
errors = Array.isArray(errors) ? errors.join(',') : errors
const totalFields = item.el.fields
const field = totalFields.find((v) => v.prop === name)
if (!field) {
return
}
if (typeof errors === 'string') {
field.el.errors = errors
field.attrs.error = errors
}
}
}
}
}
}