feat: 实现用户一次性只能预约七天
This commit is contained in:
parent
4c554401a9
commit
0b2c143225
@ -60,20 +60,27 @@ export default function DeviceDetailModal({ visiable, device, onclose }) {
|
|||||||
}, [visiable, device?.deviceId]);
|
}, [visiable, device?.deviceId]);
|
||||||
|
|
||||||
const { RangePicker } = DatePicker;
|
const { RangePicker } = DatePicker;
|
||||||
const disabledDate = (current) => {
|
const disabledDate = (current, { from } = {}) => {
|
||||||
if (!current) return false;
|
if (!current) return false;
|
||||||
|
|
||||||
const today = dayjs().startOf("day");
|
const today = dayjs().startOf("day");
|
||||||
const currentDay = current.startOf("day");
|
const currentDay = current.startOf("day");
|
||||||
|
|
||||||
|
// 禁用过去日期
|
||||||
const isPastDate = current.isBefore(today);
|
const isPastDate = current.isBefore(today);
|
||||||
|
|
||||||
|
// 禁用不可预约时间段
|
||||||
dayjs.extend(isBetween);
|
dayjs.extend(isBetween);
|
||||||
|
|
||||||
const isUnavailable = unavailableTimes.some(({ startTime, endTime }) => {
|
const isUnavailable = unavailableTimes.some(({ startTime, endTime }) => {
|
||||||
const start = dayjs(startTime).startOf("day");
|
const start = dayjs(startTime).startOf("day");
|
||||||
const end = dayjs(endTime).endOf("day");
|
const end = dayjs(endTime).endOf("day");
|
||||||
return currentDay.isBetween(start, end, null, "[]");
|
return currentDay.isBetween(start, end, null, "[]");
|
||||||
});
|
});
|
||||||
return isPastDate || isUnavailable;
|
|
||||||
|
// 限制选择范围为 7 天内(从 from 开始算起)
|
||||||
|
const isExceedingRange = from && Math.abs(current.diff(from, "day")) >= 7;
|
||||||
|
|
||||||
|
return isPastDate || isUnavailable || isExceedingRange;
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleOK = async () => {
|
const handleOK = async () => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user