diff --git a/frontend/src/utils/index.js b/frontend/src/utils/index.js index 3fbe39e6f6..01dd7eb895 100644 --- a/frontend/src/utils/index.js +++ b/frontend/src/utils/index.js @@ -314,6 +314,16 @@ export const isSameVueObj = (source, target) => { return false } +export const isSameArr = (source, target) => { + if (!source && !target) return true + if (source?.length && target?.length && source.length === target.length) { + const sortSource = source.sort() + const sortTarget = target.sort() + return JSON.stringify(sortSource) === JSON.stringify(sortTarget) + } + return false +} + export const changeFavicon = link => { let $favicon = document.querySelector('link[rel="icon"]') if ($favicon !== null) { diff --git a/frontend/src/views/panel/filter/FilterDialog.vue b/frontend/src/views/panel/filter/FilterDialog.vue index 23b444b139..800b383913 100644 --- a/frontend/src/views/panel/filter/FilterDialog.vue +++ b/frontend/src/views/panel/filter/FilterDialog.vue @@ -412,10 +412,6 @@ export default { this.myAttrs.fieldId = null this.myAttrs.activeName = null } - - if (this.myAttrs.sort?.sort === 'custom') { - this.myAttrs.sort.list = [] - } this.enableSureButton() }, diff --git a/frontend/src/views/panel/filter/filterMain/FilterControl.vue b/frontend/src/views/panel/filter/filterMain/FilterControl.vue index eee05b35ee..d054c00185 100644 --- a/frontend/src/views/panel/filter/filterMain/FilterControl.vue +++ b/frontend/src/views/panel/filter/filterMain/FilterControl.vue @@ -52,7 +52,7 @@ diff --git a/frontend/src/views/panel/filter/filterMain/FilterSort.vue b/frontend/src/views/panel/filter/filterMain/FilterSort.vue index a628f7375b..ede0f604cd 100644 --- a/frontend/src/views/panel/filter/filterMain/FilterSort.vue +++ b/frontend/src/views/panel/filter/filterMain/FilterSort.vue @@ -95,6 +95,7 @@ import { fieldListWithPermission } from '@/api/dataset/dataset' import FilterCustomSort from './FilterCustomSort' +import { isSameArr } from '@/utils' export default { name: 'FilterSort', components: { FilterCustomSort }, @@ -175,7 +177,7 @@ export default { }, computed: { fieldIds() { - return this.element.options.attrs.fieldId || [] + return this.element.options.attrs.fieldId }, isSortWidget() { return this.widget && this.widget.isSortWidget && this.widget.isSortWidget() @@ -195,8 +197,24 @@ export default { watch: { firstTableId(val, old) { if (val !== old) { + if (this.isSortWidget && (this.sortNode?.sort === 'asc' || this.sortNode?.sort === 'desc')) { + this.sortNode = { sort: 'none' } + this.$emit('sort-change', this.sortNode) + } this.loadFields() } + }, + fieldIds(val, old) { + if (val !== old) { + if (this.isCustomSortWidget && this.sortNode.sort === 'custom') { + const valArr = val?.length ? val.split(',') : null + const oldArr = old?.length ? old.split(',') : null + if (!isSameArr(valArr, oldArr)) { + this.sortNode = { sort: 'none' } + this.$emit('sort-change', this.sortNode) + } + } + } } }, @@ -210,12 +228,12 @@ export default { this.customSortList = JSON.parse(JSON.stringify(this.sortNode.list)) } } - if (!this.sortNode) { - this.sortNode = JSON.parse(JSON.stringify(this.defaultSortProp)) - } this.loadFields() } + if (!this.sortNode) { + this.sortNode = JSON.parse(JSON.stringify(this.defaultSortProp)) + } }, methods: { customSortChange(list) {