forked from github/dataease
fix(过滤器): 下拉过滤器切换枚举字段后没有清空默认值
This commit is contained in:
parent
fbfda46832
commit
4782a571d3
@ -157,6 +157,7 @@ export default {
|
|||||||
this.element.options.attrs.fieldId.length > 0 &&
|
this.element.options.attrs.fieldId.length > 0 &&
|
||||||
method(param).then(res => {
|
method(param).then(res => {
|
||||||
this.data = this.optionData(res.data)
|
this.data = this.optionData(res.data)
|
||||||
|
this.clearDefault(this.data)
|
||||||
bus.$emit('valid-values-change', true)
|
bus.$emit('valid-values-change', true)
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
bus.$emit('valid-values-change', false)
|
bus.$emit('valid-values-change', false)
|
||||||
@ -228,6 +229,27 @@ export default {
|
|||||||
bus.$off('reset-default-value', this.resetDefaultValue)
|
bus.$off('reset-default-value', this.resetDefaultValue)
|
||||||
},
|
},
|
||||||
methods: {
|
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() {
|
clearHandler() {
|
||||||
this.value = this.element.options.attrs.multiple ? [] : null
|
this.value = this.element.options.attrs.multiple ? [] : null
|
||||||
this.$refs.deSelect && this.$refs.deSelect.resetSelectAll && this.$refs.deSelect.resetSelectAll()
|
this.$refs.deSelect && this.$refs.deSelect.resetSelectAll && this.$refs.deSelect.resetSelectAll()
|
||||||
|
@ -179,6 +179,7 @@ export default {
|
|||||||
this.element.options.attrs.fieldId.length > 0 &&
|
this.element.options.attrs.fieldId.length > 0 &&
|
||||||
method(param).then(res => {
|
method(param).then(res => {
|
||||||
this.data = this.optionData(res.data)
|
this.data = this.optionData(res.data)
|
||||||
|
this.clearDefault(this.data)
|
||||||
this.changeInputStyle()
|
this.changeInputStyle()
|
||||||
if (this.element.options.attrs.multiple) {
|
if (this.element.options.attrs.multiple) {
|
||||||
this.checkAll = this.value.length === this.data.length
|
this.checkAll = this.value.length === this.data.length
|
||||||
@ -250,6 +251,27 @@ export default {
|
|||||||
bus.$off('reset-default-value', this.resetDefaultValue)
|
bus.$off('reset-default-value', this.resetDefaultValue)
|
||||||
},
|
},
|
||||||
methods: {
|
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() {
|
clearHandler() {
|
||||||
this.value = this.element.options.attrs.multiple ? [] : null
|
this.value = this.element.options.attrs.multiple ? [] : null
|
||||||
this.checkAll = false
|
this.checkAll = false
|
||||||
|
Loading…
Reference in New Issue
Block a user