'sort-change': ({ column, prop, order }) => {
const orderType = {
ascending: 1,
descending: -1
}
const { label } = column
if (label === '星期') {
console.log('星期')
this.tableData.sort((a, b) => {
const aXingQi = this.$tools.formatDate(a.shangBanSJ, '{a}')
const bXingQi = this.$tools.formatDate(b.shangBanSJ, '{a}')
return aXingQi.localeCompare(bXingQi) * orderType[order]
})
} else if (label === '班次') {
this.tableData.sort((a, b) => {
const aHour = this.$tools.formatDate(a.shangBanSJ, '{h}') < 12 ? '上午' : '下午'
const bHour = this.$tools.formatDate(b.shangBanSJ, '{h}') < 12 ? '上午' : '下午'
return aHour.localeCompare(bHour) * orderType[order]
})
} else {
this.tableData.sort((a, b) => {
return a[prop]?.toString().localeCompare(b[prop].toString()) * orderType[order]
})
}
// if (order === 'descending') {
// // 降序
// this.tableData.sort((a, b) => {
// console.log('a[prop]', a[prop])
// return a[prop].localeCompare(b[prop]) * orderType[order]
// })
// } else if (order === 'ascending') {
// // 升序
// this.tableData.sort((a, b) => {
// console.log('a[prop]', a[prop])
// return a[prop].localeCompare(b[prop]) * orderType[order]
// })
// }
},
前端数据排序
最新推荐文章于 2024-02-05 15:01:03 发布