Skip to content

CalendarView 日历面板组件

提供单选、多选、范围、周/月、日期时间等日历选择能力,可作为业务日历选择器的底层面板组件。

性能提示

min-datemax-date 不建议设置差距过大。若业务需要较大时间跨度,建议配合 switch-modemonth / year-month)降低一次性渲染压力。

组件类型

单个日期选择

html
<wd-calendar-view type="date" v-model="value" @change="handleChange" />

多个日期选择

html
<wd-calendar-view type="dates" v-model="value" @change="handleChange" />

日期范围选择

html
<wd-calendar-view type="daterange" v-model="value" @change="handleChange" />

日期时间类型

html
<wd-calendar-view type="datetime" v-model="value" @change="handleChange" />
<wd-calendar-view type="datetimerange" v-model="valueRange" @change="handleChange" />

周与月类型

html
<wd-calendar-view type="week" v-model="value" :first-day-of-week="1" @change="handleChange" />
<wd-calendar-view type="month" v-model="value" @change="handleChange" />
<wd-calendar-view type="weekrange" v-model="valueRange" @change="handleChange" />
<wd-calendar-view type="monthrange" v-model="valueRange" @change="handleChange" />

组件状态

范围选择允许同一天

html
<wd-calendar-view type="daterange" v-model="valueRange" allow-same-day @change="handleChange" />

组件变体

切换模式

设置 switch-mode 控制面板切换行为:

  • none:平铺展示所有月份/年份,不展示切换按钮
  • month:支持按月切换,展示上个月/下个月按钮
  • year-month:支持按年与按月切换,展示上一年/下一年、上个月/下个月按钮
html
<wd-calendar-view type="date" v-model="value" switch-mode="month" @change="handleChange" />

组件样式

格式化日期

设置 formatter 可定制日期单元格文案与状态。

html
<wd-calendar-view type="daterange" v-model="valueRange" allow-same-day :formatter="formatter" @change="handleChange" />

设置周起始日

html
<wd-calendar-view :first-day-of-week="1" v-model="value" @change="handleChange" />

展示面板标题

html
<wd-calendar-view type="daterange" :show-panel-title="false" v-model="valueRange" @change="handleChange" />

特殊样式

最大范围限制

html
<wd-calendar-view type="daterange" :max-range="3" v-model="valueRange" @change="handleChange" />

时间选项过滤

设置 hide-secondtime-filter 过滤时分秒选项。

html
<wd-calendar-view type="datetime" v-model="value" hide-second :time-filter="timeFilter" @change="handleChange" />

Attributes

参数说明类型默认值
v-model选中值,13 位时间戳或时间戳数组number | number[] | null-
type日期类型,支持 date / dates / datetime / week / month / daterange / datetimerange / weekrange / monthrangestringdate
min-date最小日期时间戳number当前日期往前 6 个月
max-date最大日期时间戳number当前日期往后 6 个月
first-day-of-week周起始日(0 表示周日)number0
formatter日期格式化函数CalendarFormatter-
max-range范围类型的最大可选范围number-
range-prompt超出最大范围提示文案string-
allow-same-day范围类型是否允许同一天/同一周/同一月booleanfalse
show-panel-title是否展示面板标题booleantrue
default-time日期默认时分秒string | string[]00:00:00
panel-height可滚动面板高度number316
time-filter时间选项过滤函数(datetime / datetimerange)CalendarTimeFilter-
time-item-height时间选项高度number44
time-visible-item-count时间可见项数量number3
hide-second是否隐藏秒选择(datetime / datetimerange)booleanfalse
immediate-change是否手指松开即触发时间选择 change 事件booleanfalse
switch-mode切换模式:none 平铺展示所有月份/年份且不展示切换按钮;month 支持按月切换并展示上个月/下个月按钮;year-month 支持按年与按月切换并展示上一年/下一年、上个月/下个月按钮。大跨度日期场景建议使用 monthyear-month 以降低渲染压力stringnone
custom-class根节点自定义类名string''
custom-style根节点自定义样式string''

Events

事件名称说明参数
change面板值变化时触发{ value }
pickstart时间选择滚动开始时触发-
pickend时间选择滚动结束时触发-

Methods

方法名称说明参数
scrollIntoView使当前日期或选中日期滚动到可视区域(面板隐藏到显示时建议调用)-

CalendarDayItem 数据结构

属性说明类型
type日期状态类型CalendarDayType
date13 位时间戳number
text日期文本内容string
topInfo上方提示信息string
bottomInfo下方提示信息string
disabled是否禁用boolean

CalendarDayType

类型说明
selected单日期选中
start范围开始日期
end范围结束日期
middle范围开始与结束之间的日期
same范围开始与结束日期同一天
current当前日期
multiple-middle多日期范围选择,开始与结束之间的日期
multiple-selected多日期范围选择,选中的日期

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-calendar-view-panel-title-font-size$typography-body-size-main-
--wot-calendar-view-panel-title-line-height$typography-body-line--height-size-main面板标题字号
--wot-calendar-view-panel-title-color$text-main面板标题行高
--wot-calendar-view-panel-title-padding$padding-extra-tight $padding-loose面板标题文字颜色
--wot-calendar-view-panel-title-font-weight$font-weight-medium面板标题内边距
--wot-calendar-view-panel-title-margin$spacing-super-tight $spacing-zero面板标题字重
--wot-calendar-view-weeks-padding$padding-tight $spacing-loose面板标题外边距
--wot-calendar-view-week-color$text-secondary星期栏内边距
--wot-calendar-view-week-font-size$typography-body-size-main星期文字颜色
--wot-calendar-view-week-line-height$typography-body-line--height-size-main星期文字字号
--wot-calendar-view-day-font-size$typography-body-size-extra-large星期文字行高
--wot-calendar-view-day-color$text-main日期单元字号
--wot-calendar-view-day-font-weight$font-weight-medium日期单元文字颜色
--wot-calendar-view-day-height$n-60日期单元字重
--wot-calendar-view-month-width$n-60日期单元高度
--wot-calendar-view-month-height$n-60月份单元宽度
--wot-calendar-view-month-font-weight$font-weight-medium月份单元高度
--wot-calendar-view-color-active$primary-6月份单元字重
--wot-calendar-view-color-selected$text-white激活态颜色
--wot-calendar-view-color-disabled$text-disabled选中态文字颜色
--wot-calendar-view-range-bg$primary-2禁用态文字颜色
--wot-calendar-view-range-color$text-main区间态背景色
--wot-calendar-view-border-radius-active$radius-main区间态文字颜色
--wot-calendar-view-info-font-size$typography-label-size-extra-small激活态圆角
--wot-calendar-view-info-line-height$typography-label-line--height-size-extra-small顶部/底部辅助信息字号
--wot-calendar-view-info-position$spacing-extra-tight顶部/底部辅助信息行高
--wot-calendar-view-item-margin-bottom$spacing-super-tight顶部/底部辅助信息偏移位置
--wot-calendar-view-item-padding$padding-zero $spacing-loose日期/月份单元底部间距
--wot-calendar-view-time-picker-font-size$typography-body-size-extra-large日期/月份容器内边距
--wot-calendar-view-time-picker-color$text-main时间选择器字号
--wot-calendar-view-time-picker-bg$filled-content时间选择器文字颜色
--wot-calendar-view-time-label-height$n-44时间选择器背景色
--wot-calendar-view-time-label-border$stroke-main solid $border-main时间标签高度
--wot-calendar-view-controls-padding$padding-loose时间标签分隔边框
--wot-calendar-view-control-icon-color$icon-secondary面板控制栏内边距
--wot-calendar-view-control-icon-size$n-20控制栏图标颜色
--wot-calendar-view-control-icon-spacing$spacing-extra-loose控制栏图标尺寸
--wot-calendar-view-control-color-disabled$icon-disabled控制栏图标间距
--wot-calendar-view-time-box-shadow$n-0 (-$n-4) $n-8 $n-0 $opac-1_02控制栏禁用图标颜色

源代码

文档
组件

Released under the MIT License.

Released under the MIT License.