feat(export): add yearly time range presets

This commit is contained in:
tisonhuang
2026-03-05 11:40:32 +08:00
parent 01f774db54
commit b5cb4051ab

View File

@@ -49,7 +49,16 @@ type ContentCardType = ContentType | 'sns'
type SessionLayout = 'shared' | 'per-session' type SessionLayout = 'shared' | 'per-session'
type DisplayNamePreference = 'group-nickname' | 'remark' | 'nickname' type DisplayNamePreference = 'group-nickname' | 'remark' | 'nickname'
type DateRangePreset = 'all' | 'today' | 'yesterday' | 'last3days' | 'last7days' | 'last30days' | 'custom' type DateRangePreset =
| 'all'
| 'today'
| 'yesterday'
| 'last3days'
| 'last7days'
| 'last30days'
| 'last1year'
| 'last2years'
| 'custom'
type CalendarCell = { date: Date; inCurrentMonth: boolean } type CalendarCell = { date: Date; inCurrentMonth: boolean }
type TextExportFormat = 'chatlab' | 'chatlab-jsonl' | 'json' | 'arkme-json' | 'html' | 'txt' | 'excel' | 'weclone' | 'sql' type TextExportFormat = 'chatlab' | 'chatlab-jsonl' | 'json' | 'arkme-json' | 'html' | 'txt' | 'excel' | 'weclone' | 'sql'
@@ -465,6 +474,18 @@ const createDateRangeByPreset = (
} }
} }
if (preset === 'last1year' || preset === 'last2years') {
const yearsBack = preset === 'last1year' ? 1 : 2
const start = new Date(baseStart)
const expectedMonth = start.getMonth()
start.setFullYear(start.getFullYear() - yearsBack)
// Handle leap-year fallback (e.g. Feb 29 -> Feb 28).
if (start.getMonth() !== expectedMonth) {
start.setDate(0)
}
return { start, end }
}
const daysBack = preset === 'last3days' ? 2 : preset === 'last7days' ? 6 : 29 const daysBack = preset === 'last3days' ? 2 : preset === 'last7days' ? 6 : 29
const start = new Date(baseStart) const start = new Date(baseStart)
start.setDate(start.getDate() - daysBack) start.setDate(start.getDate() - daysBack)
@@ -2425,6 +2446,8 @@ function ExportPage() {
if (timeRangePreset === 'last3days') return '最近3天' if (timeRangePreset === 'last3days') return '最近3天'
if (timeRangePreset === 'last7days') return '最近一周' if (timeRangePreset === 'last7days') return '最近一周'
if (timeRangePreset === 'last30days') return '最近一个月' if (timeRangePreset === 'last30days') return '最近一个月'
if (timeRangePreset === 'last1year') return '最近一年'
if (timeRangePreset === 'last2years') return '最近两年'
if (options.dateRange) { if (options.dateRange) {
return `${formatDateInputValue(options.dateRange.start)}${formatDateInputValue(options.dateRange.end)}` return `${formatDateInputValue(options.dateRange.start)}${formatDateInputValue(options.dateRange.end)}`
} }
@@ -4673,7 +4696,9 @@ function ExportPage() {
{ value: 'yesterday', label: '昨天' }, { value: 'yesterday', label: '昨天' },
{ value: 'last3days', label: '最近3天' }, { value: 'last3days', label: '最近3天' },
{ value: 'last7days', label: '最近一周' }, { value: 'last7days', label: '最近一周' },
{ value: 'last30days', label: '最近一个月' } { value: 'last30days', label: '最近一个月' },
{ value: 'last1year', label: '最近一年' },
{ value: 'last2years', label: '最近两年' }
] as Array<{ value: Exclude<DateRangePreset, 'custom'>; label: string }>).map((preset) => { ] as Array<{ value: Exclude<DateRangePreset, 'custom'>; label: string }>).map((preset) => {
const isActive = isTimeRangePresetActive(preset.value) const isActive = isTimeRangePresetActive(preset.value)
return ( return (