组件:
{form.getFieldValue('status') === '03' && getFieldDecorator('timingPublishTime', { initialValue: isEdit && infomentDetail.timingPublishTime ? moment(infomentDetail.timingPublishTime) : moment(), rules: [{ required: true, message: '请选择定时发布时间' }] })( <DatePicker format="YYYY-MM-DD HH:mm:ss" disabledDate={disabledDate} showTime disabledTime={disabledTime} /> )}
方法:
const range = (start: any, end: any) => { const result = []; for (let i = start; i < end; i += 1) { result.push(i); } return result; }; // 不可选择以前的时间 const disabledDate = (currentDate: any) => currentDate && currentDate < moment(); const disabledTime = (date: any) => { const hours = moment().hours(); const minutes = moment().minutes(); const seconds = moment().seconds(); // 当日只能选择当前时间之后的时间点 if (date && moment(date).date() === moment().date()) { return { disabledHours: () => range(0, 24).splice(0, hours), disabledMinutes: () => range(0, 60).splice(0, minutes + 1), disabledSeconds: () => range(0, 60).splice(0, seconds + 1) }; } return { disabledHours: () => [], disabledMinutes: () => [], disabledSeconds: () => [] }; };