FullCalendar - 如何在创建新事件时禁用拖动功能来调整新事件的持续时间

问题描述 投票:0回答:1

您好,我正在使用 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)
  };
javascript html angular typescript fullcalendar
1个回答
0
投票

因此,要解决这个问题,就像 @ADyson 所说,只需将 selectAllow 属性添加到 calendarOptions 对象中即可: selectAllow: this.handleDragEvent.bind(this)

    //Your other attributes...
    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;
  }
© www.soinside.com 2019 - 2024. All rights reserved.