Commit 60f0b1ec authored by XieZhiXiong's avatar XieZhiXiong

feat: 添加限制时分秒

parent 25226f9f
......@@ -5,6 +5,16 @@ import moment, { Moment } from 'moment';
import styles from './index.less';
import { getIntl } from 'umi';
const intl = getIntl();
function range(start, end) {
const result = [];
for (let i = start; i < end; i++) {
result.push(i);
}
return result;
}
interface Iprops {
containerStyle?: CSSProperties,
/**
......@@ -74,6 +84,24 @@ const RangeTime: React.FC<Iprops> = (props: Iprops) => {
}
}, [innerRangeTime]);
const disabledDateTime = (current: Moment, partial: 'start' | 'end') => {
const { startTime } = innerRangeTime;
if (partial === 'start') {
return {
disabledHours: () => range(0, 24).splice(0, moment().get('hour')),
disabledMinutes: () => range(0, 60).splice(0, moment().get('minute')),
disabledSeconds: () => range(0, 60).splice(0, moment().get('second')),
};
}
if (partial === 'end') {
return {
disabledHours: () => range(0, 24).splice(0, startTime.get('hour')),
disabledMinutes: () => range(0, 60).splice(0, current && current.isSame(startTime, 'hour') ? startTime.get('minute') : 0),
disabledSeconds: () => range(0, 60).splice(0, current && current.isSame(startTime, 'hour') && current.isSame(startTime, 'minute') ? startTime.get('second') + 1 : 0),
};
}
return {};
};
return (
<div className={cx(styles.container, containerStyle)}>
......@@ -83,6 +111,7 @@ const RangeTime: React.FC<Iprops> = (props: Iprops) => {
value={innerRangeTime.startTime}
onChange={(date: Moment | null, dateString: string) => handleChange(date, dateString, "startTime")}
disabledDate={(current) => getDisableDate(current, 'startTime')}
disabledTime={(current) => disabledDateTime(current, 'start')}
placeholder={placeholader![0]}
disabled={disabled}
showTime={showTime}
......@@ -95,6 +124,7 @@ const RangeTime: React.FC<Iprops> = (props: Iprops) => {
value={innerRangeTime.endTime}
onChange={(date: Moment | null, dateString: string) => handleChange(date, dateString, "endTime")}
disabledDate={(current) => getDisableDate(current, 'endTime')}
disabledTime={(current) => disabledDateTime(current, 'end')}
placeholder={placeholader![1]}
disabled={disabled}
showTime={showTime}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment