From 4782a571d3f1573732e26590ffb751348596095e Mon Sep 17 00:00:00 2001 From: fit2cloud-chenyw Date: Fri, 13 Jan 2023 18:32:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E8=BF=87=E6=BB=A4=E5=99=A8):=20=E4=B8=8B?= =?UTF-8?q?=E6=8B=89=E8=BF=87=E6=BB=A4=E5=99=A8=E5=88=87=E6=8D=A2=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE=E5=AD=97=E6=AE=B5=E5=90=8E=E6=B2=A1=E6=9C=89=E6=B8=85?= =?UTF-8?q?=E7=A9=BA=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/widget/deWidget/DeSelect.vue | 22 +++++++++++++++++++ .../widget/deWidget/DeSelectGrid.vue | 22 +++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/frontend/src/components/widget/deWidget/DeSelect.vue b/frontend/src/components/widget/deWidget/DeSelect.vue index a0f2b5a393..7038e8938b 100644 --- a/frontend/src/components/widget/deWidget/DeSelect.vue +++ b/frontend/src/components/widget/deWidget/DeSelect.vue @@ -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() diff --git a/frontend/src/components/widget/deWidget/DeSelectGrid.vue b/frontend/src/components/widget/deWidget/DeSelectGrid.vue index b6cb323382..d4887feb9a 100644 --- a/frontend/src/components/widget/deWidget/DeSelectGrid.vue +++ b/frontend/src/components/widget/deWidget/DeSelectGrid.vue @@ -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