feat(ui): standardize collapsible filters and date selection UI
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Successful in 50s
Koori-ERP-Deploy-System / deploy-production (push) Has been skipped

This commit is contained in:
2026-01-20 14:03:59 +08:00
parent daae429cd4
commit 74728c47b9
6 changed files with 517 additions and 222 deletions

View File

@@ -135,3 +135,51 @@ export const formatDateTime = (datetime: string): string => {
hour12: false,
});
};
/**
* 獲取日期區間YYYY-MM-DD 格式)
* 支援: today, yesterday, this_week, this_month, last_month
*/
export const getDateRange = (type: string): { start: string, end: string } => {
const now = new Date();
// Reset time to avoid timezone issues when calculating dates
now.setHours(12, 0, 0, 0);
let start = new Date(now);
let end = new Date(now);
const format = (d: Date) => {
const year = d.getFullYear();
const month = String(d.getMonth() + 1).padStart(2, "0");
const day = String(d.getDate()).padStart(2, "0");
return `${year}-${month}-${day}`;
};
switch (type) {
case "today":
break;
case "yesterday":
start.setDate(now.getDate() - 1);
end.setDate(now.getDate() - 1);
break;
case "this_week":
// 週一為一週的第一天
const dayOfWeek = now.getDay() || 7;
start.setDate(now.getDate() - dayOfWeek + 1);
end.setDate(now.getDate() + (7 - dayOfWeek));
break;
case "this_month":
start = new Date(now.getFullYear(), now.getMonth(), 1);
end = new Date(now.getFullYear(), now.getMonth() + 1, 0);
break;
case "last_month":
start = new Date(now.getFullYear(), now.getMonth() - 1, 1);
end = new Date(now.getFullYear(), now.getMonth(), 0);
break;
}
return {
start: format(start),
end: format(end)
};
};