@tongziyang/uni-calendar-plugin
Version:
A comprehensive calendar plugin for uniapp with support for Gregorian and Lunar calendars, date selection, hotel booking, check-in functionality, and more.
91 lines (82 loc) • 2.25 kB
text/typescript
import { ComponentPublicInstance } from 'vue';
// 日历模式类型
export type CalendarMode = 'year' | 'month' | 'week' | 'day';
// 日期信息接口
export interface DateInfo {
date: Date;
day: number;
month: number;
year: number;
isCurrentMonth: boolean;
isToday: boolean;
isSelected: boolean;
isInRange?: boolean;
isRangeStart?: boolean;
isRangeEnd?: boolean;
isHoliday?: boolean;
isWeekend?: boolean;
isCheckedIn?: boolean;
isRestDay?: boolean;
isHolidayPeriod?: boolean; // 是否在法定节假日期间(区别于普通节日)
isDisabled?: boolean; // 是否禁用
price?: number;
lunarDay?: string;
lunarMonth?: string;
lunarYear?: string;
lunarFestival?: string;
solarFestival?: string;
solarTerm?: string;
}
// 价格数据接口
export interface PriceData {
[date: string]: number;
}
// 打卡数据类型
export type CheckInData = Record<string, boolean>;
// 日历组件属性接口
export interface CalendarProps {
modelValue: Date | [Date, Date];
mode: CalendarMode;
showLunar: boolean;
showHoliday: boolean;
showPrice: boolean;
priceData: PriceData;
checkInData: CheckInData;
rangeMode: boolean;
hotelMode: boolean;
firstDayOfWeek: 0 | 1; // 0 表示周日为一周的第一天,1 表示周一为一周的第一天
disabledDate?: (date: Date) => boolean; // 禁用日期的函数
highlightWeekend: boolean;
autoHeight: boolean;
}
// 日历组件实例类型
export type CalendarInstance = ComponentPublicInstance<CalendarProps, {
// 组件方法
goToDate: (date: Date) => void;
goToToday: () => void;
goToNextMonth: () => void;
goToPrevMonth: () => void;
goToNextYear: () => void;
goToPrevYear: () => void;
checkIn: (date: Date) => void;
}>;
// 农历信息接口
export interface LunarInfo {
lunarDay: string;
lunarMonth: string;
lunarYear: string;
lunarFestival?: string;
solarFestival?: string;
solarTerm?: string;
}
// 节假日信息接口
export interface HolidayInfo {
name: string;
isRestDay: boolean;
isHolidayPeriod?: boolean; // 是否在法定节假日期间
isHoliday?: boolean; // 是否是节假日
}
// 节假日数据接口
export interface HolidayData {
[date: string]: HolidayInfo;
}