<a-date-picker
show-time
v-model="model.sendTime"
allowClear
format="YYYY-MM-DD HH:mm:ss"
style="width: 100%"
valueFormat="YYYY-MM-DD HH:mm:ss"
:disabled-date="disabledDate"
:disabled-time="dateDisabled ? disabledDateTimeB : disabledDateTime"
@change="handleDateChange"
/>
range(start, end) {
const result = []
for (let i = start; i < end; i++) {
result.push(i)
}
return result
},
disabledDate(current) {
return current && current < moment().subtract(1, 'days') //当天之前的不可选,不包括当天
},
// 选择时间不大于当前时间禁用已过期时间
disabledDateTime() {
let nowHour = new Date().getHours()
let nowMinutes = new Date().getMinutes()
return {
disabledHours: () => this.range(0, nowHour),
disabledMinutes: () => this.range(0, nowMinutes),
disabledSeconds: () => [0, 60],
}
},
// 选择时间大于当前时间,不禁用分钟
disabledDateTimeB() {
let nowHour = new Date().getHours()
return {
disabledHours: () => this.range(0, nowHour),
disabledMinutes: () => [-1, 60],
disabledSeconds: () => [-1, 60],
}
},
// 切换禁用时分秒函数
handleDateChange(date) {
const currentDate = moment(new Date()).valueOf()
const clickDate = moment(date).valueOf()
if (clickDate > currentDate) {
this.dateDisabled = true
} else {
this.dateDisabled = false
}
},