关于Fullcalendar实现多个会议室预约问题

关于Fullcalendar实现多个会议室预约问题

是这样,我尝试仿图1,在同一天搞几个会议室

img

但是搞来搞去,查来查去,都没效果,改代码,搞插件尝试过了,其他都能找到,就是这个多列没找到

请问各路dl如何解决

img

以下是图2代码


<template>
    <!-- 代办任务  日程表 -->
    <div class="top" style="background: #fff; padding: 8px 6px">


        <div class="tabs" style="width: 100%">
            <FullCalendar ref="fullCalendar" :options="calendarOptions" class="demo-app-calendar">
            </FullCalendar>
        </div>



    </div>
</template>
  
  
  
<script>
import FullCalendar from '@fullcalendar/vue'
import dayGridPlugin from '@fullcalendar/daygrid'
import timeGridPlugin from '@fullcalendar/timegrid'
import interactionPlugin from '@fullcalendar/interaction'
import zhCnLocale from '@fullcalendar/core/locales/zh-cn'



export default {
    //import引入的组件需要注入到对象中才能使用
    components: { FullCalendar },
    data() {
        return {

            calendarOptions: {
                plugins: [
                    // 加载插件,V5采用插件模块方式加入
                    dayGridPlugin,
                    timeGridPlugin,
                    interactionPlugin, // needed for dateClick

                ],

                height: 1000, //日历高度
                width: 600,
                headerToolbar: {
                    // 头部toolba
                    left: 'prev,next today',
                    center: 'title',
                    right: 'timeGridDay,dayGridMonth',
                    // right: 'timeGridDay,timeGridWeek,dayGridMonth',
                    // right: 'dayGridMonth'
                },
                handleWindowResize: true, //随浏览器窗口变化
                initialView: 'timeGridDay', // 初始化插件显示


                // initialDate:""//初始化日期
                initialDate: new Date(), // 日历第一次加载时显示的初始日期。可以解析为Date的任何职包括ISO8601日期字符串,例如"2014-02-01"// initialEvents: INITIAL_EVENTS, // alternatively, use the `events` setting to fetch from a feed
                editable: true, //是否可编辑
                // droppable: true,//可拖拽的
                // timeZone: 'local',//采用时区
                weekNumberCalculation: 'ISO', // 指定"ISO"结果为ISO8601周数。指定"ISO"将firstDay的默认值更改为1(Monday)
                selectable: true,
                allDaySlot: false,//隐藏全天

                // selectMirror: true,
                dayMaxEvents: true,
                // weekends: true, // 是否显示一周七天
                //   validRange: {//设置可显示的总日期范围,全局日期范围;超出范围按钮会禁用 还没用明白
                //   start:  new Date().getDay()
                // },
                // eventClick: this.handleEventClick, // 日程点击事件
                // eventMouseEnter: this.handleEventMouseEnter, // 用户将鼠标悬停在事件上时触发
                // eventsSet: this.handleEvents,
                select: this.handleDateSelect,//选中日历某个单元格,或者某一批单元格时触发。
                dateClick: this.handleDateClick,//日期方格点击事件
                eventClick: this.handleEventClick, //日程点击事件
                eventDrop: this.calendarEventDropOrResize, //拖动事件触发
                eventResizeStop: this.test,
                locale: zhCnLocale,
                nowIndicator: true, // 当前的时间线显示,为true时当前小时那一格有个红线,并且有红三角
                nextDayThreshold: '01:00:00',

                events: [
                    //日程事件的json
                    // { title: 'event 1', date: '2021-04-23 12:00:00' },
                    // { title: 'event 2', date: '2021-04-24 05:59:23' },
                    // { title: 'event 3', date: '2021-04-25 08:23:00' },
                    { title: 'event 4', date: '2023-08-17 09:30:00' },
                    { title: 'event 5', date: '2023-08-17 12:00:00' },
                    { title: 'event 2', date: '2023-08-17 15:00:00' }
                ],



                buttonText: {
                    dayGridMonth: '月视图',
                    timeGridDay: '日视图'
                },
                // datesSet: this.handleDateSet,
                /* you can update a remote database when these fire:
                eventAdd:
                eventChange:
                eventRemove:
                */


            },

        }
    },
    mounted() {
        // 年度总结报告
        // that.calendarOptions.events.push({
        //   color: '#ff9900',
        //   title: element.name,
        //   date: element.time,
        //   status: this.statusName,
        //   type: element.type,
        //   times: element.time,
        //   category: element.category
        // })
        // 这里有两点要注意,想要调用插件的方法,要在组件上设置ref
        // 并且在组件未加载的时候this.$refs中是没有fullCalendar的,所以未加载的时候调用方法会报错
        this.calendarApi = this.$refs.fullCalendar.getApi()


    },
    methods: {
        calendarEventDropOrResize(info) {
            console.log("拖动事件");
            console.log(info);
        },
        handleEventClick(info) {
            console.log("日程点击事件");
            console.log(info);
        },
        handleDateClick(info) {
            console.log("方格点击事件");
            console.log(info);
        },
        test(info) {
            console.log("日程范围改变后事件");
            console.log(info);
        },
        handleDateSelect(info) {
            console.log("选中日历某个单元格,或者某一批单元格时触发。");
            console.log(info);
        }
    }

}
</script>
  

【以下回答由 GPT 生成】

问题分析:

根据问题描述,目前使用的Fullcalendar插件无法实现多个会议室预订功能,需要对代码进行修改。由于提供的代码没有明确显示会议室信息,因此假设需要在同一天显示多个会议室的预订情况。

解决方案:

  1. 首先,需要调整数据结构,使其能够包含每个会议室的预订情况。可以创建一个包含多个会议室的数组,每个会议室包含一个唯一标识符和一个预订列表。

  2. 在代码中,使用v-for指令循环渲染会议室列。可以参考以下示例代码:

<FullCalendar ref="fullCalendar" :options="calendarOptions" class="demo-app-calendar">
    <div v-for="room in rooms" :key="room.id">
        <h3>{{ room.name }}</h3>
        <div class="calendar-container">
            <FullCalendar :options="getRoomCalendarOptions(room)"></FullCalendar>
        </div>
    </div>
</FullCalendar>
  1. data中定义一个包含多个会议室的数组,并初始化每个会议室的预订情况。下面是一个示例:
data() {
    return {
        rooms: [
            {
                id: 1,
                name: '会议室1',
                bookings: [
                    {
                        title: '预订1',
                        start: '2022-10-01T09:00:00',
                        end: '2022-10-01T10:00:00'
                    },
                    {
                        title: '预订2',
                        start: '2022-10-01T13:00:00',
                        end: '2022-10-01T14:00:00'
                    }
                ]
            },
            {
                id: 2,
                name: '会议室2',
                bookings: [
                    {
                        title: '预订3',
                        start: '2022-10-01T10:00:00',
                        end: '2022-10-01T11:00:00'
                    },
                    {
                        title: '预订4',
                        start: '2022-10-01T14:00:00',
                        end: '2022-10-01T15:00:00'
                    }
                ]
            }
        ]
    }
},
  1. methods中定义一个函数,用于生成每个会议室的Fullcalendar配置。在此函数中,可以使用会议室的预订列表来设置Fullcalendar的events属性。示例如下:
methods: {
    getRoomCalendarOptions(room) {
        return {
            plugins: [dayGridPlugin, timeGridPlugin, interactionPlugin],
            initialView: 'timeGridDay',
            height: 'auto',
            events: room.bookings,
        }
    }
},
  1. 通过以上修改,每个会议室将以列的形式显示在Fullcalendar中,并且每个会议室列的预订情况将被正确显示。

以上是一种解决方案,可以根据实际需求进行调整和修改。希望这可以帮助到你。如果有任何问题,请随时提问。



【相关推荐】



如果你已经解决了该问题, 非常希望你能够分享一下解决方案, 写成博客, 将相关链接放在评论区, 以帮助更多的人 ^-^