计划日历,手机点击日历日期显示当天计划,自定义日历,可切换周和月,左右滑动切换月份,点击上个月的日期自动跳转到上个月。
一、实现效果
uniapp的vue3版本,setup模式,style用的scss。
新建calendar.vue文件:
<template>
<!-- 左右滑动切换月份 -->
<view @touchstart="handleTouchStart" @touchend="handleTouchEnd">
<view class="titleBox">
<view class="title">{
{ currentYear }}.{
{ currentMonth }}</view>
</view>
<view class="week">
<view v-for="(item, index) in week" :key="index">{
{ item }}</view>
</view>
<!-- 日历 -->
<view class="calendarbBox">
<view class="singleDay" v-for="(item, index) in state.currentMonthAllDate" :key="index" @tap="selectedDate(item.date)">
<!-- 不是当前月日期 class="dayTextB",如果选中则跳转至所属月份-->
<text class="dayTextB" v-if="item.month != 'current'">{
{ item.number }}</text>
<!-- 没有选中当前日期class="dayText",选中当前日期class="dayTextA"-->
<text class="dayTextA" v-if="item.month == 'current' && String(state.currentToday) == String(item.date)">{
{ item.number }}</text>
<text class="dayText" v-if="item.month == 'current' && String(state.currentToday) != String(item.date)">{
{ item.number }}</text>
<!-- 当天有计划+当前日期没有选中的标志 -->
<view class="point" v-if="item.isPlan"></view>
<!-- 当前日期选中的标志 -->
<view class="selectedDayBGColor" v-if="String(state.currentToday) == String(item.date)"></view>
<!-- 当天有计划+当前日期选中的标志 -->
<view class="pointA" v-if="String(state.currentToday) == String(item.date)