Files
orico-officialWebsite-ts-admin/src/hooks/useDateSort.ts
2025-03-26 11:00:21 +08:00

15 lines
470 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export const useDateSort = (property: any, bol: any) => {
//property是你需要排序传入的key,bol为true时是升序false为降序
return function (a: any, b: any) {
let value1 = a[property];
let value2 = b[property];
if (bol) {
// 升序
return Date.parse(value1) - Date.parse(value2);
} else {
// 降序
return Date.parse(value2) - Date.parse(value1);
}
};
};