上午:
<el-time-picker style="width: 80%;" :disabled="!top_status" is-range v-model="top_time"range-separator="至" start-placeholder="开始时间" end-placeholder="结束时间" placeholder="选择时间范围" @change="startTime">
</el-time-picker>
const startTime = (value) => {
let formattedDates = [];
value.forEach((time) => {
let inputTime = new Date(time);
let hours = inputTime.getHours();
let minutes = inputTime.getMinutes();
let seconds = inputTime.getSeconds();
let formattedTime = `${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}:${seconds < 10 ? '0' + seconds : seconds}`;
formattedDates.push(formattedTime);
});
// 在这里处理选中时间的逻辑
let h = formattedDates[0].split(':')
let s = formattedDates[1].split(':')
console.log(s);
if (h[0] > 12 || s[0] > 12) {
ElMessage({
type: 'warning',
message: '只能选择上午',
});
top_time.value = ['Thu Jan 25 2024 08:00:00 GMT+0800 (中国标准时间)', 'Thu Jan 25 2024 08:01:11 GMT+0800 (中国标准时间)'];
}
};
下午:
<el-time-picker is-range v-model="bottom_time" :disabled="!bottom_status" range-separator="至"
start-placeholder="开始时间" end-placeholder="结束时间" placeholder="选择时间范围" @change="endTime">
</el-time-picker>
const endTime = (value) => {
let formattedDates = [];
value.forEach((time) => {
let inputTime = new Date(time);
let hours = inputTime.getHours();
let minutes = inputTime.getMinutes();
let seconds = inputTime.getSeconds();
let formattedTime = `${hours < 10 ? '0' + hours : hours}:${minutes < 10 ? '0' + minutes : minutes}:${seconds < 10 ? '0' + seconds : seconds}`;
formattedDates.push(formattedTime);
});
// 在这里处理选中时间的逻辑
let h = formattedDates[0].split(':')
let s = formattedDates[1].split(':')
if (h[0] < 12 || s[0] < 12) {
ElMessage({
type: 'warning',
message: '只能选择下午',
});
bottom_time.value = ['Thu Jan 25 2024 12:00:00 GMT+0800 (中国标准时间)', 'Thu Jan 25 2024 12:01:11 GMT+0800 (中国标准时间)'];
}
}