perf(过滤器): 文本下拉框自定义排序

This commit is contained in:
fit2cloud-chenyw 2022-11-16 14:19:08 +08:00
parent fc2469c45d
commit 33cbc06498
4 changed files with 33 additions and 9 deletions

View File

@ -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) {

View File

@ -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()
},

View File

@ -52,7 +52,7 @@
</span>
<span
v-if="widget.isCustomSortWidget && widget.isCustomSortWidget()"
v-if="widget.isSortWidget && widget.isSortWidget()"
style="padding-left: 10px;"
>

View File

@ -95,6 +95,7 @@
</el-dropdown-item>
<el-dropdown-item
v-if="isCustomSortWidget"
:command="beforeClickItem('custom')"
>
<span
@ -146,6 +147,7 @@
<script>
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) {