您好,我正在使用 Angular 的完整日历,我想这样做,以便当用户单击日历中的空时间表(这是每周日历,每个日期间隔为 15 分钟)时,他们可以'按住单击并定义事件的持续时间。不幸的是,chatpgt 在这种情况下无法帮助我,因为它只显示截至 2020 年的信息,并且该库迄今为止仍在不断更新。
这是我的 html 代码:
<div class='demo-app'>
<div class='demo-app-main'>
<full-calendar *ngIf='calendarVisible' [options]='calendarOptions' >
<ng-template #eventContent let-arg>
<b>{{ arg.timeText }}</b>
<i>{{ arg.event.title }}</i>
</ng-template>
</full-calendar>
</div>
</div>
</div>
这是我的 .ts calendarOptions 定义:
calendarOptions: CalendarOptions = {
plugins: [
interactionPlugin,
dayGridPlugin,
timeGridPlugin,
listPlugin,
],
headerToolbar: {
left: 'prev,next today',
center: 'title',
right: 'timeGridWeek'
},
initialView: 'timeGridWeek',
slotMinTime: '08:00:00',
slotMaxTime: '21:00:00',
slotDuration: '00:15:00',
slotLabelInterval: '00:15:00',
slotLabelFormat: {
hour: '2-digit',
minute: '2-digit',
hour12: true,
},
contentHeight: 'auto',
aspectRatio: 1.5,
firstDay: 1,
weekends: true,
editable: false,
selectable: false,
selectMirror: true,
dayMaxEvents: true,
allDaySlot: false,
dayHeaderFormat: {
weekday: 'short',
day: '2-digit',
month: '2-digit'
},
locales: [esLocale],
businessHours: {
daysOfWeek: [0, 1, 2, 3, 4, 5, 6],
startTime: '09:00',
endTime: '21:00',
},
select: this.handleDateSelect.bind(this),
eventClick: this.handleEventClick.bind(this),
eventsSet: this.handleEvents.bind(this),
datesSet: this.handleDatesSet.bind(this)
}; Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
所以为了解决这个问题,就像@ADyson所说的那样,只需将selectAllow属性添加到您的calendarOptions对象中: selectAllow: this.handleDragEvent.bind(this)
//您的其他属性... selectAllow: this.handleDragEvent.bind(this) // ....然后,在您的类中添加该函数,我的函数验证新事件的持续时间是否超过15分钟,如果您的日历有不同的时间间隔,请将差异设置为该时间间隔
handleDragEvent(selectInfo: DateSelectArg): boolean { const diffInMilliseconds = Math.abs(selectInfo.end.getTime()- selectInfo.start.getTime()); const diffInMinutes = Math.floor(diffInMilliseconds / (1000 * 60)); return diffInMinutes <= 15; }