Skip to content

LimeDateStrip 日期横条

  • 用于展示周日历或一组日历信息
  • 插件依赖lime-style,lime-shared不喜勿下

安装

插件市场入口 导入即可,首次可能需要重新编译

代码演示

基础用法

通过v-model可以绑定选择的日历

html
<l-date-strip v-model="value" @change="onChange"></l-date-strip>
js
const value = new Date().getTime()

const onChange = (time: number) => {
	
}

切换方式

默认是以周为周期(swiper)的切换方式,通过switchMode设置为none可以换成scroll-view,这时是从minDatemaxDate的所有日期。

html
<l-date-strip switchMode="none" :minDate="minDate" :maxDate="maxDate"></l-date-strip>
js
const minDate: new Date(2022, 0, 10).getTime()
const maxDate: new Date(2027, 10, 27).getTime()

选中样式

通过 shape 可以设置为选中框的形状,可选值有:circle,square,none

html
<l-date-strip shape="circle"></l-date-strip>

自定义样式

通过 bgColor 可以设置背景色,activeBgColor可设置选中的背景色。

html
<l-date-strip bgColor="yellow" activeBgColor="#000" ></l-date-strip>

自定义日期文案

通过传入 format 函数来对日历上每一格的内容进行格式化。

html
<l-date-strip :format="customFormat"></l-date-strip>
js
// uniapp 不需要设置类型
import { Day } from '@/uni_modules/lime-date-strip';
const customFormat = (day : Day) : Day => {
	const { date } = day;
	const year = date.getFullYear();
	const month = date.getMonth() + 1;
	const curDate = date.getDate();

	day.suffix = '¥60';

	if (year == 2025) {
		if (month == 2) {
			const map = new Map<number, string>([
				[1, '初一'],
				[2, '初二'],
				[3, '初三'],
				[14, '情人节'],
				[15, '元宵节'],
			])
			if (map.has(curDate)) {
				day.prefix = map.get(curDate)!;
				day.suffix = '¥100';
			}
		}
	}

	return day;
};

查看示例

  • 导入后直接使用这个标签查看演示效果
html
 // 代码位于 uni_modules/lime-date-strip/compoents/lime-date-strip 
<lime-date-strip />

插件标签

  • 默认 l-date-strip 为 component
  • 默认 lime-date-strip 为 demo

关于vue2的使用方式

  • 插件使用了composition-api, 如果你希望在vue2中使用请按官方的教程vue-composition-api配置
  • 关键代码是: 在main.js中 在vue2部分加上这一段即可.
js
// vue2
import Vue from 'vue'
import VueCompositionAPI from '@vue/composition-api'
Vue.use(VueCompositionAPI)

API

Props

参数说明类型默认值
v-modle选中的日期number``
defaultValue选中的日期number``
value选中的日期number``
switchMode切换模式:
none 平铺展示所有日期,不展示切换按钮,
week 按周方式切换
stringweek
shape选中框形状:
square 方块,包含星期和日期,
circle 圆形,只包含日期,
none 文本高亮
stringsquare
minDate可选择的最小日期number
maxDate可选择的最大日期number当前日期的31天
height插件高度string
gridWidth每格日期宽度,仅switchMode为none生效string
activeBgColor选中框背景色string
activeColor选中框文本色string
bgColor横条背景色string
radius选中框圆角string
firstDayOfWeek第一天从星期几开始,默认 0 = 周日0-60

Events

事件名说明回调参数
change点击时触发event: number
select点击时触发event: number

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式)。uvue app无效。

名称默认值描述
--l-date-strip-bg-color:$bg-color-container-
--l-date-strip-height:86px-
--l-date-strip-padding:8px 0-
--l-date-strip-font-size:16px-
--l-date-strip-color:$text-color-1-
--l-date-strip-prefix-color:$text-color-3-
--l-date-strip-prefix-font-size:14px-
--l-date-strip-suffix-color:$text-color-2-
--l-date-strip-suffix-font-size:12px-
--l-date-strip-active-color:$primary-color-
--l-date-strip-square-radius:5px-
--l-date-strip-grid-width:50px-
--l-date-strip-grid-square-padding:6px 0-
--l-date-strip-grid-circle-radius:99px-

打赏

如果你觉得本插件,解决了你的问题,赠人玫瑰,手留余香。

源代码

组件源码