antd用的版本为1.78,vue2
1、视图部分
<a-date-picker
:disabled-date="disabledDate"
:disabled-time="disabledRangeTime"
v-model="form.send_time"
show-time
valueFormat="YYYY-MM-DD HH:mm:ss"
/>
2、data
data(){
return {
currentTime: '' , // 用来存储日期控件变化的时间
}
}
3、js
// 不知由于版本问题还是有些属性没设置好,导致"disabledRangeTime"获取不到current时间变化的参数,"disabledDate"那边是能获取的,所以只能在date那边设置了个变量存储当前变化的值
// 日期限制
disabledDate(current) {
this.currentTime = current // 此处为设置的过渡值
return current && current < this.dayjs().subtract(1, 'days').endOf('day')
},
// 时分秒限制
disabledRangeTime (){
const hours = this.dayjs().hour();
const minutes = this.dayjs().minute();
const seconds = this.dayjs().second();
if (this.dayjs().date() == this.currentTime.date()) {
return {
disabledHours: () => this.range(0, hours),
disabledMinutes: (selectedHour) =>
selectedHour <= hours ? this.range(0, minutes) : [],
disabledSeconds: (selectedHour, selectedMinute) =>
selectedHour <= hours && selectedMinute <= minutes
? this.range(0, seconds)
: []
};
}
return {
disabledHours: () => [],
disabledMinutes: () => [],
disabledSeconds: () => [],
}
},