<template><f-calendarv-model:value="value"><template#dateCellRender="{ current }"><ulclass="events"><liv-for="item in getListData(current)":key="item.content"><f-badge:status="item.type":text="item.content"/></li></ul></template><template#monthCellRender="{ current }"><divv-if="getMonthData(current)"class="notes-month"><section>{{ getMonthData(current) }}</section><span>Backlog number</span></div></template></f-calendar></template><scriptlang="ts">import{ defineComponent, ref }from'vue';import{ Dayjs }from'dayjs';exportdefaultdefineComponent({setup(){const value = ref<Dayjs>();constgetListData=(value: Dayjs)=>{let listData;switch(value.date()){case8:
listData =[{type:'warning',content:'This is warning event.'},{type:'success',content:'This is usual event.'},];break;case10:
listData =[{type:'warning',content:'This is warning event.'},{type:'success',content:'This is usual event.'},{type:'error',content:'This is error event.'},];break;case15:
listData =[{type:'warning',content:'This is warning event'},{type:'success',content:'This is very long usual event。。....'},{type:'error',content:'This is error event 1.'},{type:'error',content:'This is error event 2.'},{type:'error',content:'This is error event 3.'},{type:'error',content:'This is error event 4.'},];break;default:}return listData ||[];};constgetMonthData=(value: Dayjs)=>{if(value.month()===8){return1394;}};return{
value,
getListData,
getMonthData,};},});</script><stylescoped>.events{list-style: none;margin: 0;padding: 0;}.events .ant-badge-status{overflow: hidden;white-space: nowrap;width: 100%;text-overflow: ellipsis;font-size: 12px;}.notes-month{text-align: center;font-size: 28px;}.notes-month section{font-size: 28px;}</style>
自定义头部 自定义日历头部内容。
<template><divstyle="width: 300px;border: 1px solid #d9d9d9;border-radius: 4px"><f-calendarv-model:value="value":fullscreen="false"@panelChange="onPanelChange"><template#headerRender="{ value: current, type, onChange, onTypeChange }"><divstyle="padding: 10px"><divstyle="margin-bottom: 10px">Custom header</div><f-rowtype="flex"justify="space-between"><f-col><f-radio-groupsize="small":value="type"@change="e => onTypeChange(e.target.value)"><f-radio-buttonvalue="month">Month</f-radio-button><f-radio-buttonvalue="year">Year</f-radio-button></f-radio-group></f-col><f-col><f-selectsize="small":dropdown-match-select-width="false"class="my-year-select":value="String(current.year())"@change="
newYear => {
onChange(current.year(+newYear))
}
"><f-select-optionv-for="val in getYears(current)":key="String(val)"class="year-item">
{{ val }}
</f-select-option></f-select></f-col><f-col><f-selectsize="small":dropdown-match-select-width="false":value="String(current.month())"@change="
selectedMonth => {
onChange(current.month(parseInt(String(selectedMonth), 10)))
}
"><f-select-optionv-for="(val, index) in getMonths(current)":key="String(index)"class="month-item">
{{ val }}
</f-select-option></f-select></f-col></f-row></div></template></f-calendar></div></template><scriptlang="ts">import{ defineComponent, ref }from'vue'import{ Dayjs }from'dayjs'exportdefaultdefineComponent({setup(){const value = ref<Dayjs>()constonPanelChange=(value: Dayjs,mode: string)=>{
console.log(value, mode)}constgetMonths=(value: Dayjs)=>{const localeData = value.localeData()constmonths: any[]=[]for(let i =0; i <12; i++){
months.push(localeData.monthsShort(value.month(i)))}return months
}constgetYears=(value: Dayjs)=>{const year = value.year()constyears: number[]=[]for(let i = year -10; i < year +10; i +=1){
years.push(i)}return years
}return{
value,
onPanelChange,
getMonths,
getYears,}},})</script><style>.fs-picker-calendar td.fs-picker-cell-in-view{color: #333;}.fs-picker-calendar .fs-picker-cell{color: #bbbbbb;}</style>