refactor: 重写设备空闲判断部分使代码更明确

This commit is contained in:
BenjaminNH 2025-07-14 13:01:24 +08:00
parent fce4a8da6c
commit 87cc58be92

View File

@ -64,16 +64,16 @@ export default function DeviceDetailModal({ visiable, device, onclose }) {
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");
if (currentDay.isBefore(today)) { const isPastDate = current.isBefore(today);
return true;
}
dayjs.extend(isBetween); dayjs.extend(isBetween);
return 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;
}; };
const handleOK = async () => { const handleOK = async () => {