fix(过滤器): 下拉过滤器切换枚举字段后没有清空默认值

This commit is contained in:
fit2cloud-chenyw 2023-01-13 18:32:18 +08:00
parent fbfda46832
commit 4782a571d3
2 changed files with 44 additions and 0 deletions

View File

@ -157,6 +157,7 @@ export default {
this.element.options.attrs.fieldId.length > 0 &&
method(param).then(res => {
this.data = this.optionData(res.data)
this.clearDefault(this.data)
bus.$emit('valid-values-change', true)
}).catch(e => {
bus.$emit('valid-values-change', false)
@ -228,6 +229,27 @@ export default {
bus.$off('reset-default-value', this.resetDefaultValue)
},
methods: {
clearDefault(optionList) {
const emptyOption = !optionList?.length
if (!this.inDraw && this.element.options.value) {
if (Array.isArray(this.element.options.value)) {
if (emptyOption) {
this.element.options.value = []
return
}
const tempValueArray = JSON.parse(JSON.stringify(this.element.options.value))
this.element.options.value = tempValueArray.filter(item => optionList.some(option => option === item))
} else {
if (emptyOption) {
this.element.options.value = ''
return
}
const tempValueArray = JSON.parse(JSON.stringify(this.element.options.value.split(',')))
this.element.options.value = tempValueArray.filter(item => optionList.some(option => option === item)).join(',')
}
}
},
clearHandler() {
this.value = this.element.options.attrs.multiple ? [] : null
this.$refs.deSelect && this.$refs.deSelect.resetSelectAll && this.$refs.deSelect.resetSelectAll()

View File

@ -179,6 +179,7 @@ export default {
this.element.options.attrs.fieldId.length > 0 &&
method(param).then(res => {
this.data = this.optionData(res.data)
this.clearDefault(this.data)
this.changeInputStyle()
if (this.element.options.attrs.multiple) {
this.checkAll = this.value.length === this.data.length
@ -250,6 +251,27 @@ export default {
bus.$off('reset-default-value', this.resetDefaultValue)
},
methods: {
clearDefault(optionList) {
const emptyOption = !optionList?.length
if (!this.inDraw && this.element.options.value) {
if (Array.isArray(this.element.options.value)) {
if (emptyOption) {
this.element.options.value = []
return
}
const tempValueArray = JSON.parse(JSON.stringify(this.element.options.value))
this.element.options.value = tempValueArray.filter(item => optionList.some(option => option === item))
} else {
if (emptyOption) {
this.element.options.value = ''
return
}
const tempValueArray = JSON.parse(JSON.stringify(this.element.options.value.split(',')))
this.element.options.value = tempValueArray.filter(item => optionList.some(option => option === item)).join(',')
}
}
},
clearHandler() {
this.value = this.element.options.attrs.multiple ? [] : null
this.checkAll = false