atom-calendar日历组件 app好用的日历组件推荐

204 阅读2分钟

这段时间自己开发一个app,里面需要用到一个日历功能,去网上找了好多组件,发现功能都不是很符合自己的需求,于是自己封装了一个超级好用的日历组件

有需要的小伙伴可以点击这里

日历组件

4f6d78845fdb9092e2b15ab208a5318.png

ca968f72ca49565700f90aa29839e1c.png

63a039ef6c8e76ee8c02c2c0d644237.png

简单介绍

  • 组件需要依赖 tailwindcss ,请自行在项目适配;
  • 本组件依赖 uni-app 内置组件swiper组件
  • nvue 页面中的swiper组件部分功能不支持,详情见uni-app 内置组件:swiper
  • 通过 uni_modules 引用组件,在页面 template 中即可直接使用,无需在页面中 import 和注册 components;
  • 可设置显示收缩按钮,收缩后只显示一个星期的日期,展开后显示一个月的日期;可以通过触摸屏幕左右滑动切换月份或切换年;
  • 本组件农历转换使用的 js 是 @1900-2100 区间内的公历、农历互转
  • 若有插件导入失败,重启编辑器;

API

属性说明

属性名类型默认值说明
defaultStartnumbermonday周几为每周的第一天,可选值:[0~7]
headerLineColorstring#008080头部线颜色
lastMonthIconurlString头部切换上月图标
nextMonthIconurlString头部切换下月图标
lastYearIconurlString头部切换上年图标
nextYearIconurlString头部切换下年图标
currentDayBgColorstring#008080当前日期背景色颜色
festivalColorstring#008080重要节日文字颜色
currentDayColorstring#008080当前日期文字颜色
clickItemColorstring#00808182点击日期背景颜色
viewTypestringmonth视图类型 可选值['month','week']
showHeaderbooleantrue是否显示头部导航

注意:

  1. 农历日期、节日、标记日期,只会显示其一,优先级 : 标记 > 节日 > 农历日期;

事件说明

事件名说明返回值
handleCurrent点击日期项触发该函数可通过回调参数 e 拿到该日期的详细信息
handleChange日历组件月份切换可通过回调参数 e 拿到切换后的当前年月
  1. 方法使用:在组件上添加 @handleCurrent="handleClick" 事件,事件名可自行定义
  2. 方法使用:在组件上添加 @handleChange="handleChange" 事件,事件名可自行定义

@handleCurrent 返回值 e 说明

类型说明
currentColorString选中颜色
yearnumber
monthNumber阳历月
dayNumber阳历日
typeNumber月份所属
isCurrenMonthboolean是否本月
lunarDateObject农历信息,包含农历日期、节日、生肖等 详情见 @1900-2100 区间内的公历、农历互转

基本用法

template中使用组件



<template>
  <AtomCalendar @handleCurrent="handleClick" />
</template>

script中使用

<script setup lang="ts">
import AtomCalendar from "@/components/atom-calendar.vue";
const handleClick = (e: any) => {
  console.log(e, "接收参数");
};
</script>