Skip to content

t-calendar

Calendar 日历

组件介绍

t-calendar 是一个功能强大的日历选择组件,支持单日期选择、多日期选择、日期范围选择等多种模式,同时提供农历显示、节日显示、自定义选中日期标记和徽章等功能。组件采用 Canvas 绘制技术,性能优异,支持横向和纵向滑动切换月份,适用于各种日期选择场景。

平台兼容

HarmonyH5AndroidiOS小程序UTS

基础用法

基础用法参考 demo/calendar/calendar.uvue,通过 mode 属性设置选择模式,使用 v-model 绑定选中日期。

vue
<template>
  <!-- 单日期选择 -->
  <t-calendar mode="single" v-model="singleDate" class="mb-30"></t-calendar>
  <t-text>单日期选择: {{ singleDate }}</t-text>

  <!-- 多日期选择 -->
  <t-calendar mode="multiple" v-model="multipleDates" class="mb-30"></t-calendar>
  <t-text>多日期选择: {{ multipleDates }}</t-text>

  <!-- 日期范围选择 -->
  <t-calendar mode="range" v-model="rangeDates" class="mb-30"></t-calendar>
  <t-text>日期范围选择: {{ rangeDates }}</t-text>

  <!-- 显示农历和节日 -->
  <t-calendar mode="single" v-model="lunarDate" :lunar="true" :festival="true" class="mb-30"></t-calendar>
  <t-text>显示农历和节日: {{ lunarDate }}</t-text>

  <!-- 纵向滑动 -->
  <t-calendar mode="single" v-model="verticalDate" :vertical="true" class="mb-30"></t-calendar>
  <t-text>纵向滑动: {{ verticalDate }}</t-text>
</template>

<script setup>
const singleDate = ref([]);
const multipleDates = ref([]);
const rangeDates = ref([]);
const lunarDate = ref([]);
const verticalDate = ref([]);
</script>

Props

属性名说明类型默认值
path点击组件后跳转的页面路径;为空时仅响应事件string''
hover是否启用点击效果booleanfalse
type组件主题类型,可选 infoprimaryerrorwarningsuccessstring'primary'
disabled是否禁用booleanfalse
effect组件显示主题,可选 normaldarklightplainstring'normal'
size组件尺寸,可选 largemediumsmallministring'medium'
closeValidate是否关闭验证booleanfalse
modelValue绑定的日期值string[][]
title标题string'请选择日期'
mode选择模式,可选 singlemultiplerangestring'range'
disableTouch是否禁用触摸booleanfalse
vertical是否启用竖向滑动booleanfalse
selected自定义选中日期的配置UTSJSONObject[][]
lunar是否显示农历booleantrue
showMonthBg是否显示月份背景booleantrue
monthShowCurrentMonth是否只显示当前月份booleanfalse
festival是否显示节日booleantrue
startDate开始日期string''
endDate结束日期string''

Events

事件名说明回调参数
update:modelValue绑定值变化时触发string[]
select选择日期时触发CalendarDateType
change日期变化时触发string[]

Methods

方法名说明参数
prevMonth切换到上一月-
nextMonth切换到下一月-
prevYear切换到上一年-
nextYear切换到下一年-
resetSelection重置选中的值-
jumpToDate跳转到指定日期date: string (日期字符串,格式:YYYY-MM-DD)
getCurrentTime获取当前显示的时间-
setCurrentTime设置当前显示的时间time: string (日期字符串,格式:YYYY-MM-DD)