diff --git a/src/components/other/dataQuery.vue b/src/components/other/dataQuery.vue index ed1d33c..1e05641 100644 --- a/src/components/other/dataQuery.vue +++ b/src/components/other/dataQuery.vue @@ -55,7 +55,7 @@ - + - + @@ -209,17 +211,42 @@ function goBack() { Taro.navigateBack(); } +function buildDateFromPickerValue(value: unknown, fallback: Date) { + if (value instanceof Date && !Number.isNaN(value.getTime())) { + return value; + } + + if (typeof value === 'number' || typeof value === 'string') { + const date = new Date(value); + if (!Number.isNaN(date.getTime())) { + return date; + } + } + + if (Array.isArray(value) && value.length >= 5) { + const [year, month, day, hour, minute] = value.map((item) => Number(item)); + const date = new Date(year, month - 1, day, hour, minute, 0); + if (!Number.isNaN(date.getTime())) { + return date; + } + } + + return fallback; +} + // 确认开始时间 -function confirmStartDate({ selectedValue }) { - startDateTime.value = selectedValue[0]; - startDate.value = formatDateMin(selectedValue[0]); +function confirmStartDate({ selectedValue }: { selectedValue: unknown }) { + const nextDate = buildDateFromPickerValue(selectedValue, startDateTime.value); + startDateTime.value = nextDate; + startDate.value = formatDateMin(nextDate); showStartPicker.value = false; } // 确认结束时间 -function confirmEndDate({ selectedValue }) { - endDateTime.value = selectedValue[0]; - endDate.value = formatDateMin(selectedValue[0]); +function confirmEndDate({ selectedValue }: { selectedValue: unknown }) { + const nextDate = buildDateFromPickerValue(selectedValue, endDateTime.value); + endDateTime.value = nextDate; + endDate.value = formatDateMin(nextDate); showEndPicker.value = false; } @@ -236,10 +263,10 @@ function queryData() { } // 验证时间范围 - const start = new Date(startDate.value); - const end = new Date(endDate.value); + const start = startDateTime.value; + const end = endDateTime.value; - if (start >= end) { + if (start.getTime() >= end.getTime()) { Taro.showToast({ title: '开始时间必须小于结束时间', icon: 'none' }); return; } @@ -728,4 +755,9 @@ function touchMove(e: any) { font-size: 14px; color: #999; } + +/* 日期选择器整体向下移动 - 避免与小程序关闭按钮重叠 */ +:deep(.nut-picker) { + margin-top: 30px; +}