Vue3?FullCalendar使用并設(shè)置dayGrid視圖的最大事件數(shù)過(guò)程
FullCalendar 的 dayGrid 視圖默認(rèn)會(huì)顯示所有事件,但可以通過(guò)配置限制每天顯示的事件數(shù)量,超出部分以“+n more”的形式折疊。
安裝 FullCalendar 及相關(guān)插件
確保已安裝 FullCalendar 核心庫(kù)和 dayGrid 插件:
npm install @fullcalendar/core @fullcalendar/daygrid @fullcalendar/vue3
初始化顯示事件數(shù)
在 Vue3 組件中,以下示例,通過(guò)配置dayMaxEvents的值,實(shí)現(xiàn)每天顯示數(shù)量,超出部分“+n more”的形式折疊。
dayMaxEvents:true - 日歷自動(dòng)計(jì)算合適的數(shù)量,顯示“+n more”。
<template>
<div ref="fullcalendar" class="card"></div>
</template>
<script>
import FullCalendar from '@fullcalendar/vue3'
import dayGridPlugin from '@fullcalendar/daygrid'
const initCalendar = () => {
Tcalendar.value = null
Tcalendar.value = new Calendar(fullcalendar.value, {
plugins: [dayGridPlugin, timeGridPlugin, listPlugin, interactionPlugin],
initialView: type.value,
aspectRatio: 2.2, // 寬度比
locale: "zh-cn",
handleWindowResize: true,
// loading: loading //控制表格加載
editable: false, // 允許編輯表格
droppable: false, //允許從外部拖拽進(jìn)入日歷
eventDurationEditable: false, //控制時(shí)間段是否可以拖動(dòng)
eventResizableFromStart: false, //控制事件是否可以拖動(dòng)
selectable: true, // 允許用戶通過(guò)單擊和拖動(dòng)來(lái)突出顯示多個(gè)日期或時(shí)間段
firstDay: 1, // 設(shè)置一周中顯示的第一天是哪天,周日是0,周一是1,類推。
unselectAuto: true, // 當(dāng)點(diǎn)擊頁(yè)面日歷以外的位置時(shí),是否自動(dòng)取消當(dāng)前的選中狀態(tài)
//dayMaxEvents: true, //在dayGrid視圖中,給定日期內(nèi)的最大事件數(shù)
dayMaxEvents: 5,
headerToolbar: false, // 關(guān)閉默認(rèn)日歷頭部,采取自定義的方式切換日歷視圖
// allDaySlot: false, // 關(guān)閉全天選項(xiàng)
allDayText: "全天",
nowIndicator: true,
eventMaxStack: 2,
events: state.infoList, //主要數(shù)據(jù)
eventClassNames: function (arg) {
// 添加自定義class
return [arg.event.extendedProps.class];
},
eventContent: function (arg) {
// 日歷上event顯示的樣式
const italicEl = document.createElement("div");
// 列表才顯示
if (type.value === "listWeek") {
// 標(biāo)題
const nameEl = document.createElement("h4");
nameEl.setAttribute("class", `h4`);
nameEl.innerHTML = arg.event.extendedProps.name;
italicEl.append(nameEl);
// 崗位
const text1El = document.createElement("p");
text1El.innerHTML = arg.event.extendedProps.job;
italicEl.append(text1El);
// 面試官
const text2El = document.createElement("p");
text2El.innerHTML = "描述:" + arg.event.extendedProps.job;
italicEl.append(text2El);
} else {
// 標(biāo)題
const titleEl = document.createElement("div");
titleEl.setAttribute("class", `calendar-title`);
const nameEl = document.createElement("span");
nameEl.setAttribute("style","overflow:hidden;text-overflow: ellipsis;");
nameEl.innerHTML = arg.event.extendedProps.name;
titleEl.append(nameEl);
titleEl.setAttribute("id",arg.event.id);
// 時(shí)間
const timeEl = document.createElement("span");
if (arg.event.start && arg.event.end) {
timeEl.innerHTML =
dayjs(arg.event.start).format("HH:mm") +
"-" +
dayjs(arg.event.end).format("HH:mm");
if (timeEl.innerHTML !== "00:00-00:00") {
titleEl.append(timeEl);
}
}
titleEl.addEventListener('click',function(){
showEditDialog(this.id);
//handleClick(this.id);
})
italicEl.append(titleEl);
// 企業(yè)名稱
const enterpriseEl = document.createElement("div");
enterpriseEl.setAttribute("class", `calendar-enterprise`);
enterpriseEl.innerText = arg.event.extendedProps.enterpriseName;
italicEl.append(enterpriseEl);
}
italicEl.setAttribute("class", `calendar-card`);
return { domNodes: [italicEl] };
},
noEventsContent: function () {
const noEl = document.createElement("div");
noEl.innerHTML = "暫無(wú)日程安排,請(qǐng)安排相關(guān)日程";
return { domNodes: [noEl] };
},
// 點(diǎn)擊查看時(shí)觸發(fā)
eventClick: function (info) {
//handleClick(info);
},
// 視圖選擇日期觸發(fā)
select: function (info) {
//handleSelectDate(info);
},
// 拖拽event大小時(shí)觸發(fā)
eventResize: function (info) {
debugger
handleEventResize(info);
},
// 拖拽停止時(shí)觸發(fā)
eventDrop: function (info) {
debugger
handleDrap(info);
},
});
Tcalendar.value.render();
};
const getList=async()=>{
const res = await listWorkPlan(); // 這里加載數(shù)據(jù)
state.infoList = []
res.tableData.rows.forEach(item=>{
let tag = ""
if(item.workStatus==='1') {
tag = "tag_leave"
}
else{
tag = "tag_" + item.workType.replace(/^0+/, '')
}
let enterpriseName = '';
if(item.enterpriceId){
item.enterpriceId.forEach(itm => {
enterpriseName = enterpriseName?enterpriseName+","+itm.enterpriseName:itm.enterpriseName
})
}
let d ={
"id":item.id,
title: item.planTitle,
name: item.planTitle,
start: item.startTime,
end: item.endTime,
class: tag,
job: "",
description: item.planContent,
enterpriseName: enterpriseName,
}
state.infoList.push(d);
})
initCalendar();
}
onMounted(() => {
nextTick(() => {
getList();
});
});
</script>
自定義文本樣式
可以通過(guò) CSS 自定義折疊文本的樣式:
.tag_1,
.tag_2,
.tag_3,
.tag_4,
.tag_leave,
.tag_work_overtime,
.tag_99{
border-radius: 20px;
}
.tag_1 {
background-color: #d9ecff;
}
.tag_2 {
background-color: #a0cfff;
}
.tag_3 {
background-color: #79bbff;
}
.tag_4{
background-color: #409eff;
}
.tag_99{
background-color: #337ecc;
}
.tag_leave{
background-color: #f56c6c;
}
.tag_work_overtime{
background-color: #1ab394;
}注意事項(xiàng)
dayMaxEvents屬性對(duì)dayGridMonth和dayGridWeek視圖均有效。- 設(shè)置為
true時(shí),F(xiàn)ullCalendar 會(huì)自動(dòng)計(jì)算適合的數(shù)量。 - 設(shè)置為數(shù)字時(shí),明確限制顯示的事件數(shù)量。
- 事件超出限制時(shí),點(diǎn)擊“+n more”會(huì)展開(kāi) popover 顯示全部事件。
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
使用vite創(chuàng)建vue3項(xiàng)目的詳細(xì)圖文教程
創(chuàng)建Vue3項(xiàng)目有兩種常見(jiàn)的方式,一種是想vue2版本一樣使用腳手架工具創(chuàng)建,創(chuàng)建vue3項(xiàng)目的腳手架必須是4版本以上的,另一種方法就是使用vite創(chuàng)建,這篇文章主要給大家介紹了關(guān)于如何使用vite創(chuàng)建vue3項(xiàng)目的相關(guān)資料,需要的朋友可以參考下2022-11-11
在Vue項(xiàng)目中取消ESLint代碼檢測(cè)的步驟講解
今天小編就為大家分享一篇關(guān)于在Vue項(xiàng)目中取消ESLint代碼檢測(cè)的步驟講解,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2019-01-01
詳解VScode編輯器vue環(huán)境搭建所遇問(wèn)題解決方案
這篇文章主要介紹了VScode編輯器vue環(huán)境搭建所遇問(wèn)題解決方案,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-04-04
vue中使用elementui實(shí)現(xiàn)樹(shù)組件tree右鍵增刪改功能
這篇文章主要介紹了vue中使用elementui實(shí)現(xiàn)對(duì)樹(shù)組件tree右鍵增刪改功能,右擊節(jié)點(diǎn)可進(jìn)行增刪改,對(duì)節(jié)點(diǎn)數(shù)據(jù)進(jìn)行模糊查詢功能,本文給大家分享了完整代碼,需要的朋友可以參考下2022-08-08
如何實(shí)現(xiàn)echarts markline標(biāo)簽名顯示自己想要的
這篇文章主要介紹了實(shí)現(xiàn)echarts markline標(biāo)簽名顯示自己想要的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-07-07

