|
|
|
|
@ -28,8 +28,8 @@ |
|
|
|
|
<el-date-picker |
|
|
|
|
v-model="queryParams.dateRange" |
|
|
|
|
@change="handleDateRangeChange" |
|
|
|
|
value-format="yyyy-MM-dd hh:mm:ss" |
|
|
|
|
type="daterange" |
|
|
|
|
value-format="yyyy-MM-dd HH:mm:ss" |
|
|
|
|
type="datetimerange" |
|
|
|
|
range-separator="至" |
|
|
|
|
start-placeholder="开始日期" |
|
|
|
|
end-placeholder="结束日期" |
|
|
|
|
@ -44,9 +44,9 @@ |
|
|
|
|
<el-form-item label="采集时间限制"> |
|
|
|
|
<el-date-picker |
|
|
|
|
v-model="queryParams.gatherTime" |
|
|
|
|
:disabledDate="disablePastDate" |
|
|
|
|
value-format="yyyy-MM-dd hh:mm:ss" |
|
|
|
|
value-format="yyyy-MM-dd HH:mm:ss" |
|
|
|
|
type="datetime" |
|
|
|
|
@change="handleDateTimeChange" |
|
|
|
|
:picker-options="{ disabledDate: disablePastDate }" |
|
|
|
|
placeholder="任意时间点"> |
|
|
|
|
</el-date-picker> |
|
|
|
|
@ -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(); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|