需求:选择当前时间之后的时间
1.隐藏“此刻”按钮
2.只允许选择当前时间5分钟之后的时间
import moment from 'moment';
let disabledDate = (current:any) => {
return current && current < moment().subtract(1, 'days').endOf('day');
};
let range = (start:any, end:any) => {
const result = [];
for (let i = start; i < end; i++) {
result.push(i);
}
return result;
},
let disabledDateTime = (current:any)=>{
if(current){
let today = moment().date();
if(today == current.date()){
let minute = Number(moment().minutes())
let hour = Number(moment().hour());
let finalHour:number,finalMinute:number;
if(current.hour() > hour ){
finalMinute = 0
}else{
if(current.minute() >= 58){
finalHour = hour + 1;
finalMinute = 0;
}else{
finalHour = hour;
finalMinute = minute + 5;
}
}
return {
disabledHours: () => range(0, finalHour),
disabledMinutes: () => range(0, finalMinute)
}
}else if(moment()>current){
return {
disabledHours: () => range(0, 24),
disabledMinutes: () => range(0, 60),
disabledSeconds: () => range(0, 60)
}
}
}else{
return {
disabledHours: () => range(0, 24),
disabledMinutes: () => range(0, 60),
disabledSeconds: () => range(0, 60),
}
}
};
let taskPlanDate = {
label:"扫描时间",
name:"taskPlanDate",
rules:[{ required: true, message: '扫描目标不能为空!' }]
};
<FormItem {...taskPlanDate}>
<DatePicker
disabledDate={disabledDate}
disabledTime={disabledDateTime}
showTime={{ defaultValue: moment('YYYY/MM/DD HH:mm:ss') }}
showNow={false}
onOk={(e: any) => {
console.log(e)
}}
/>
</FormItem>