diff --git a/ALOps_sys_fe/alops-ui/src/views/device/deviceInformation/index.vue b/ALOps_sys_fe/alops-ui/src/views/device/deviceInformation/index.vue index aa357cdd..26b4b390 100644 --- a/ALOps_sys_fe/alops-ui/src/views/device/deviceInformation/index.vue +++ b/ALOps_sys_fe/alops-ui/src/views/device/deviceInformation/index.vue @@ -28,8 +28,8 @@ @@ -150,19 +150,81 @@ export default { }) }, handleDateRangeChange(value) { - this.queryParams.startTime = value[0] - this.queryParams.endTime = value[1] + // 验证开始时间是否为今天且早于当前时间 + if (value && value[0]) { + const selectedDate = new Date(value[0]); + const now = new Date(); + const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); + const selectedDay = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate()); + + // 如果选择的是今天且时间早于当前时间,则重置为当前时间 + if (selectedDay.getTime() === today.getTime() && selectedDate.getTime() < now.getTime()) { + // 创建当前时间的下一分钟 + const nextMinute = new Date(now); + nextMinute.setMinutes(nextMinute.getMinutes() + 1); + + // 格式化时间为yyyy-MM-dd hh:mm:ss + const formattedDate = nextMinute.getFullYear() + '-' + + (nextMinute.getMonth() + 1).toString().padStart(2, '0') + '-' + + nextMinute.getDate().toString().padStart(2, '0') + ' ' + + nextMinute.getHours().toString().padStart(2, '0') + ':' + + nextMinute.getMinutes().toString().padStart(2, '0') + ':' + + nextMinute.getSeconds().toString().padStart(2, '0'); + + // 更新日期范围和对应的时间 + const newRange = [formattedDate, value[1] || formattedDate]; + this.queryParams.dateRange = newRange; + this.queryParams.startTime = newRange[0]; + this.queryParams.endTime = newRange[1]; + return; + } + } + + // 正常情况更新时间范围 + this.queryParams.startTime = value ? value[0] : null; + this.queryParams.endTime = value ? value[1] : null; + }, + + // 处理单个日期时间选择变化 + handleDateTimeChange(value) { + if (value) { + const selectedDate = new Date(value); + const now = new Date(); + const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); + const selectedDay = new Date(selectedDate.getFullYear(), selectedDate.getMonth(), selectedDate.getDate()); + + // 如果选择的是今天且时间早于当前时间,则重置为当前时间 + if (selectedDay.getTime() === today.getTime() && selectedDate.getTime() < now.getTime()) { + // 创建当前时间的下一分钟 + const nextMinute = new Date(now); + nextMinute.setMinutes(nextMinute.getMinutes() + 1); + + // 格式化时间为yyyy-MM-dd hh:mm:ss + const formattedDate = nextMinute.getFullYear() + '-' + + (nextMinute.getMonth() + 1).toString().padStart(2, '0') + '-' + + nextMinute.getDate().toString().padStart(2, '0') + ' ' + + nextMinute.getHours().toString().padStart(2, '0') + ':' + + nextMinute.getMinutes().toString().padStart(2, '0') + ':' + + nextMinute.getSeconds().toString().padStart(2, '0'); + + // 更新选中的时间 + this.queryParams.gatherTime = formattedDate; + } + } }, disablePastDate(time) { - // 获取当前日期(本地时间戳) - const today = new Date(); - // 重置时间为当天 00:00:00 - today.setHours(0, 0, 0, 0); + // 创建当前日期对象(不包含时分秒) + const now = new Date(); + const today = new Date(now.getFullYear(), now.getMonth(), now.getDate()); + + // 创建要检查的日期对象 + const checkTime = new Date(time); + const checkDate = new Date(checkTime.getFullYear(), checkTime.getMonth(), checkTime.getDate()); - // 禁用所有早于今天 00:00:00 的日期 - console.log("%c 🐇: disablePastDate -> time.getTime() < today.getTime() ", "font-size:16px;background-color:#c5c908;color:black;", time.getTime() , today.getTime(), time.getTime() < today.getTime()) - return time.getTime() < today.getTime(); + // 如果检查的日期早于今天,则禁用 + // 这样允许选择今天,但需要在change事件中进一步验证时间 + return checkDate.getTime() < today.getTime(); } } }