sc
This commit is contained in:
@@ -392,9 +392,10 @@ async function getList() {
|
||||
} else {
|
||||
tableList.value = data.list.map((it, index) => ({
|
||||
...it,
|
||||
userSalaryGrantRespVOList: it.userSalaryGrantRespVOList.sort((pre, cur) =>
|
||||
pre.name.localeCompare(cur.name)
|
||||
),
|
||||
userSalaryGrantRespVOList: multiFieldSort(it.userSalaryGrantRespVOList, [
|
||||
{ key: 'dept' },
|
||||
{ key: 'name' }
|
||||
]),
|
||||
id: index + 1,
|
||||
edit: it.status == 1 ? '2' : '0'
|
||||
}))
|
||||
@@ -407,6 +408,32 @@ async function getList() {
|
||||
}
|
||||
}
|
||||
|
||||
function multiFieldSort(arr, fields) {
|
||||
return arr.sort((a, b) => {
|
||||
// 遍历每个排序字段
|
||||
for (const field of fields) {
|
||||
const { key, order = 'asc' } = field
|
||||
const valueA = a[key]
|
||||
const valueB = b[key]
|
||||
|
||||
// 处理不同类型的比较
|
||||
let compareResult
|
||||
if (typeof valueA === 'number' && typeof valueB === 'number') {
|
||||
compareResult = valueA - valueB // 数字比较
|
||||
} else {
|
||||
compareResult = String(valueA).localeCompare(String(valueB)) // 字符串比较(兼容其他类型)
|
||||
}
|
||||
|
||||
// 如果当前字段值不相等,直接返回比较结果(根据排序方向调整)
|
||||
if (compareResult !== 0) {
|
||||
return order === 'desc' ? -compareResult : compareResult
|
||||
}
|
||||
}
|
||||
// 所有字段都相等,保持原有顺序
|
||||
return 0
|
||||
})
|
||||
}
|
||||
|
||||
const createSalaryRef = ref()
|
||||
function craeteSalary() {
|
||||
createSalaryRef.value.open()
|
||||
|
||||
Reference in New Issue
Block a user