@tplc/business
Version:
50 lines (43 loc) • 1.28 kB
text/typescript
import { HolidayInfo } from '../components/lcb-calendar-filter/types'
import dayjs from 'dayjs/esm'
export const calendarFormatter =
(holidayInfo: Record<string, HolidayInfo>, t: (key: string) => string) => (day: any) => {
const date = new Date(day.date)
const now = new Date()
const year = date.getFullYear()
const month = date.getMonth()
const da = date.getDate()
const nowYear = now.getFullYear()
const nowMonth = now.getMonth()
const nowDa = now.getDate()
const info = holidayInfo[dayjs(day.date).format('YYYY-MM-DD')]
if (info?.topText) {
day.topInfo = info.topText
}
if (info?.bottomText) {
day.bottomInfo = info.bottomText
}
if (info?.centerText) {
day.text = info.centerText
}
if (year === nowYear && month === nowMonth && da === nowDa) {
day.topInfo = t('今天')
}
if (info?.floorText) {
day.floorText = info.floorText
}
if (day.type === 'start') {
day.topInfo = t('开始')
}
if (day.type === 'end') {
day.topInfo = t('结束')
}
if (day.type === 'same') {
day.bottomInfo = t('开始/结束')
}
if (info?.status !== 1) {
day.disabled = true
}
day.restFlag = info?.restFlag
return day
}