This commit is contained in:
qsh
2025-08-11 18:04:34 +08:00
parent 5c53cabf22
commit 21b8f1bb12
10 changed files with 274 additions and 116 deletions

View File

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