mirror of
https://github.com/hicccc77/WeFlow.git
synced 2026-04-12 15:08:36 +00:00
feat(export): 导出日期范围添加时间选择功能
为导出窗口的日期范围选择器添加了时间(HH:mm)选择功能: - 在日期输入框下方添加了时间选择控件(type="time") - 默认时间范围:开始 00:00,结束 23:59 - 支持精确到分钟的时间范围设置 - 预设类型(今天、昨天、最近7天等)默认使用 00:00-23:59 - 自定义时间范围保留用户设置的具体时间 - 添加了结束时间不能早于开始时间的验证 修改文件: - src/utils/exportDateRange.ts - 支持 YYYY-MM-DD HH:mm 格式的解析和格式化 - src/components/Export/ExportDateRangeDialog.tsx - 添加时间选择 UI 和逻辑 - src/components/Export/ExportDateRangeDialog.scss - 时间输入框样式 - src/pages/ExportPage.tsx - 修复 preset 类型的默认时间不正确的 bug
This commit is contained in:
@@ -138,19 +138,24 @@ export const formatDateInputValue = (date: Date): string => {
|
||||
const y = date.getFullYear()
|
||||
const m = `${date.getMonth() + 1}`.padStart(2, '0')
|
||||
const d = `${date.getDate()}`.padStart(2, '0')
|
||||
return `${y}-${m}-${d}`
|
||||
const h = `${date.getHours()}`.padStart(2, '0')
|
||||
const min = `${date.getMinutes()}`.padStart(2, '0')
|
||||
return `${y}-${m}-${d} ${h}:${min}`
|
||||
}
|
||||
|
||||
export const parseDateInputValue = (raw: string): Date | null => {
|
||||
const text = String(raw || '').trim()
|
||||
const matched = /^(\d{4})-(\d{2})-(\d{2})$/.exec(text)
|
||||
const matched = /^(\d{4})-(\d{2})-(\d{2})(?:\s+(\d{2}):(\d{2}))?$/.exec(text)
|
||||
if (!matched) return null
|
||||
const year = Number(matched[1])
|
||||
const month = Number(matched[2])
|
||||
const day = Number(matched[3])
|
||||
const hour = matched[4] !== undefined ? Number(matched[4]) : 0
|
||||
const minute = matched[5] !== undefined ? Number(matched[5]) : 0
|
||||
if (!Number.isFinite(year) || !Number.isFinite(month) || !Number.isFinite(day)) return null
|
||||
if (month < 1 || month > 12 || day < 1 || day > 31) return null
|
||||
const parsed = new Date(year, month - 1, day)
|
||||
if (hour < 0 || hour > 23 || minute < 0 || minute > 59) return null
|
||||
const parsed = new Date(year, month - 1, day, hour, minute, 0, 0)
|
||||
if (
|
||||
parsed.getFullYear() !== year ||
|
||||
parsed.getMonth() !== month - 1 ||
|
||||
@@ -291,14 +296,14 @@ export const resolveExportDateRangeConfig = (
|
||||
const parsedStart = parseStoredDate(raw.start)
|
||||
const parsedEnd = parseStoredDate(raw.end)
|
||||
if (parsedStart && parsedEnd) {
|
||||
const start = startOfDay(parsedStart)
|
||||
const end = endOfDay(parsedEnd)
|
||||
const start = parsedStart
|
||||
const end = parsedEnd
|
||||
return {
|
||||
preset: 'custom',
|
||||
useAllTime: false,
|
||||
dateRange: {
|
||||
start,
|
||||
end: end < start ? endOfDay(start) : end
|
||||
end: end < start ? start : end
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user