chore: perf
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
gitea/salix-front/pipeline/pr-dev This commit looks good
Details
This commit is contained in:
parent
3f15c3cce0
commit
8269037faa
|
@ -1,4 +1,5 @@
|
||||||
function orderData(data, order) {
|
function orderData(data, order) {
|
||||||
|
if (typeof order === 'function') return data.sort(data);
|
||||||
if (typeof order === 'string') order = [order];
|
if (typeof order === 'string') order = [order];
|
||||||
if (Array.isArray(order)) {
|
if (Array.isArray(order)) {
|
||||||
let orderComp = [];
|
let orderComp = [];
|
||||||
|
@ -12,13 +13,13 @@ function orderData(data, order) {
|
||||||
}
|
}
|
||||||
|
|
||||||
return data.sort((a, b) => sortFunc(a, b, orderComp));
|
return data.sort((a, b) => sortFunc(a, b, orderComp));
|
||||||
} else if (typeof order === 'function') return data.sort(data);
|
}
|
||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
function sortFunc(a, b, order) {
|
function sortFunc(a, b, order) {
|
||||||
for (let i of order) {
|
for (let { field, way } of order) {
|
||||||
let compRes = compareFunc(a[i.field], b[i.field]) * i.way;
|
let compRes = compareFunc(a[field], b[field]) * way;
|
||||||
if (compRes !== 0) return compRes;
|
if (compRes !== 0) return compRes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue