如何在FullCalendar中停用事件拖曳以調整持續時間
P粉787934476
P粉787934476 2023-09-15 12:40:23
0
1
590

您好,我正在使用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)
  };

P粉787934476
P粉787934476

全部回覆(1)
P粉668146636

所以為了解決這個問題,就像@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;
  }
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!