【web】 设备信息采集 不允许选择当前之前的时间

dev
Wangxin 8 months ago
parent 2cc75b47ac
commit 41a4f12573
  1. 90
      ALOps_sys_fe/alops-ui/src/views/device/deviceInformation/index.vue

@ -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);
// 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();
//
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());
//
// change
return checkDate.getTime() < today.getTime();
}
}
}

Loading…
Cancel
Save