fix: refactor time range to single source of truth with correct dates

- Default range changed from 30d to 7d
- Presets (today/7d/30d) now directly set customStart/customEnd dates,
  eliminating duplicate getTimeRange() calculation
- "All" preset fetches actual data boundaries from /api/date-range
  and backfills the custom date picker
- Clicking "custom" opens popover without triggering data refresh;
  only confirm applies changes
- SQL trend dates cast to ::text to avoid pg driver Date timezone offset
- Fix created_at filter from < to <= for end timestamp
This commit is contained in:
2026-04-07 16:22:18 +08:00
parent 35b8fec96c
commit 13805a47be
5 changed files with 108 additions and 62 deletions

View File

@@ -25,23 +25,6 @@ export function formatDate(iso: string): string {
// 预设时间范围
export type TimeRange = "today" | "7d" | "30d" | "all" | "custom";
export function getTimeRange(range: TimeRange): { start?: number; end?: number } {
const now = dayjs();
const end = now.endOf("day").unix();
switch (range) {
case "today":
return { start: now.startOf("day").unix(), end };
case "7d":
return { start: now.subtract(7, "day").startOf("day").unix(), end };
case "30d":
return { start: now.subtract(30, "day").startOf("day").unix(), end };
case "all":
return {};
default:
return {};
}
}
export function buildQuery(
base: string,
params: Record<string, string | number | undefined>