feat: 实现用户一次性只能预约七天

This commit is contained in:
BenjaminNH 2025-07-21 12:06:23 +08:00
parent 4c554401a9
commit 0b2c143225

View File

@ -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 () => {