mirror of
https://github.com/jumpserver/lina.git
synced 2025-09-20 02:31:43 +00:00
perf: 优化 nested field error
This commit is contained in:
@@ -43,12 +43,16 @@ export default {
|
|||||||
iFields() {
|
iFields() {
|
||||||
const fields = this.fields
|
const fields = this.fields
|
||||||
if (this.errors && typeof this.errors === 'object') {
|
if (this.errors && typeof this.errors === 'object') {
|
||||||
for (const [name, error] of Object.entries(this.errors)) {
|
// eslint-disable-next-line prefer-const
|
||||||
|
for (let [name, error] of Object.entries(this.errors)) {
|
||||||
const field = fields.find((v) => v.prop === name)
|
const field = fields.find((v) => v.prop === name)
|
||||||
if (!field) {
|
if (!field) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
this.$log.debug(`${name}: ${error}`)
|
this.$log.debug(`${name}: ${error}`)
|
||||||
|
if (typeof error === 'object' && !Array.isArray(error)) {
|
||||||
|
error = this.objectToString(error)
|
||||||
|
}
|
||||||
field.attrs.error = error.toString()
|
field.attrs.error = error.toString()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,15 +61,16 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
setFieldError(name, error) {
|
objectToString(obj) {
|
||||||
const field = this.totalFields.find((v) => v.prop === name)
|
let data = ''
|
||||||
if (!field) {
|
// eslint-disable-next-line prefer-const
|
||||||
return
|
for (let [key, value] of Object.entries(obj)) {
|
||||||
|
if (typeof value === 'object') {
|
||||||
|
value = this.objectToString(value)
|
||||||
|
}
|
||||||
|
data += ` ${key}: ${value} `
|
||||||
}
|
}
|
||||||
if (field.attrs.error === error) {
|
return data
|
||||||
error += '.'
|
|
||||||
}
|
|
||||||
field.attrs.error = error
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user