refactor(视图): 优化 AntV 表头排序

This commit is contained in:
wisonic-s 2024-06-13 14:59:05 +08:00
parent 14ab28dfce
commit 03ee95d39d

View File

@ -45,8 +45,7 @@ export default {
this.table.emit(S2Event.RANGE_SORT, [{
sortFieldId: this.meta.field,
sortMethod: type,
sortFunc: this.sortFunc,
meta: this.meta
sortFunc: this.sortFunc
}])
},
__t(key) {
@ -58,22 +57,26 @@ export default {
}
const data = cloneDeep(sortParams.data)
return data.sort((a, b) => {
if (a === b) {
return 0
}
//
if (a.SUMMARY) {
return 1
}
const field = sortParams.sortFieldId
const aValue = a[field]
const bValue = b[field]
if (aValue === bValue) {
return 0
}
if (sortParams.sortMethod === 'asc') {
if (typeof a === 'number') {
return a - b
if (typeof aValue === 'number') {
return aValue - bValue
}
return a < b ? 1 : -1
return aValue < bValue ? 1 : -1
}
if (typeof a === 'number') {
return b - a
if (typeof aValue === 'number') {
return bValue - aValue
}
return a > b ? 1 : -1
return aValue > bValue ? 1 : -1
})
}
}