选择事件

  select: function (selectInfo) {
// 获取当前时间,并设置为当天的开始时间
var now = new Date();
now.setHours(0, 0, 0, 0);

// 如果选择的时间段开始时间早于当前时间,显示提示并取消选择
if (selectInfo.start < now) {
alert('不能选择当前时间之前的时间。');
calendar.unselect(); // 取消选择
return;
}

var title = prompt('Please enter event title:');
var roomId = roomSelect.options[0].value;
if (title) {
var newEvent = {
title: title,
start: selectInfo.start,
end: selectInfo.end,
allDay: false,
extendedProps: {
roomId: roomId
}
};

var isOverlap = calendar.getEvents().some(function(existingEvent) {
// 检查新事件的开始和结束时间是否在现有事件的时间段内
return (
newEvent.start >= existingEvent.start && newEvent.start < existingEvent.end ||
newEvent.end > existingEvent.start && newEvent.end <= existingEvent.end
);
});

if (isOverlap) {
alert('事件不能与现有事件重叠。');
} else {
calendar.addEvent(newEvent);
// 保存事件到后端的逻辑...
// saveEventToBackend(newEvent);
}
}

selectInfo.jsEvent.preventDefault();
},
posted @ 2024-08-05 08:09  佬zz  阅读(21)  评论(0)    收藏  举报