antd 过去时间不可选

//不可选日期
export function disabledDate(current) {
  return current && current < moment().subtract(1, "days");
}
//不可选时分秒
const range = (start, end) => {
  const result = [];
  for (let i = start; i <= end; i++) {
    result.push(i);
  }
  return result;
};
const formatHours = (date,type) => {
  let hour = moment().hour();
  let disabledHours = [];
  const chosedDate = type == "date" ? moment(date).date() : moment(date[0]).date();
  if (moment().date() == chosedDate) {
    disabledHours = range(0, 24).splice(0, hour);
  };
  return disabledHours;
};
const formatMinutes = (date,type) => {
  let minute = moment().minute();
  let disabledMinutes = [];
  const chosedDate = type == "date" ? moment(date).date() : moment(date[0]).date();
  if (moment().date() == chosedDate) {
    disabledMinutes = range(0, 60).splice(0, minute+1);
  };
  return disabledMinutes;
};
//DatePicker
export function disabledDateTime(date) {
  return {
    disabledHours: () => formatHours(date,'date'),
    disabledMinutes: () => formatMinutes(date,'date'),
    disabledSeconds: () => []
  };
}
//RangePicker
export function disabledRangeTime(date, type) {
  if (type === "start") {
    return {
      disabledHours: () => formatHours(date,'range'),
      disabledMinutes: () => formatMinutes(date,'range'),
      disabledSeconds: () => []
    };
  }
}

Example:

<FormItem
  label="执行时间段"
   labelCol={{ span: 3, offset: 1 }}
   wrapperCol={{ span: 6 }}
>
	 {getFieldDecorator("rangerTimer", {
	   rules: [{ required: true, message: "请选择时间" }]
	 })(
	   <RangePicker
	    disabledDate={disabledDate}
	    disabledTime={disabledRangeTime}
	    showTime={{ hideDisabledOptions: true }}
	   />
	 )}
</FormItem>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值