uniapp中的导入zzx-calendar日历的使用

news2024/9/24 21:25:14

需求:
一周的日历,并且可以查看当月的 ,下个月的,以及可以一周一周的切换日期
在这里插入图片描述
在这里插入图片描述
借助:hbuilder插件市场中的zzx-calendar插件库
在父组件中引入 并注册为子组件

<template>
 <zzx-calendar @selected-change="datechange" @myChangeSwp='myChangeSwp' :Activesdays='Activesdays'
                     ></zzx-calendar>
</template>
<script>
import zzxCalendar from "@/components/zzx-calendar/zzx-calendar.vue"
export default {
  components: {
    zzxCalendar
  },
  data(){
  faDays:'',//当前所选中的日期
  Activesdays:['2024-01-02',......],//高亮点日期
  },
  methods:{
  	//切换月
    myChangeSwp(val, val2) {
      
    },
    //
    datechange(e) {
      this.faDays = e.fullDate;
     
    },
   }
 }
</
script>

日历部分的代码改造

<template>
	<view class="zzx-calendar">
		<view class="calendar-heander">
				{{timeStr}}
			<!-- <view class="back-today" @click="goback" v-if="showBack">
				返回今日
			</view> -->
		</view>
		<view class="calendar-weeks">
			<view class="calendar-week" v-for="(week, index) in weeks" :key="index">
				
				{{week}}
			</view>
		</view>
		<view class="calendar-content">
		   <swiper class="calendar-swiper" :style="{
			   width: '100%',
			   height: sheight
		   }" :indicator-dots="false" :autoplay="false" :duration="duration" :current="current" @change="changeSwp" :circular="true">
				<swiper-item class="calendar-item" v-for="sitem in swiper" :key="sitem">
					<view class="calendar-days">
						<template v-if="sitem === current">
							<view class="calendar-day" v-for="(item,index) in days" :key="index"
							:class="{
								'day-hidden': !item.show
							}" @click="clickItem(item)">
							<view
								class="date"
								:class="[
									item.isToday ? todayClass : '',
									item.fullDate === selectedDate ? checkedClass : ''
									]"
							>
							{{item.time.getDate()}}
						
							<view class="pop" v-if="Activesdays.indexOf(item.time.getDate())!=-1"></view>
							</view>
							<view class="dot-show" v-if="item.info" :style="dotStyle">		
							</view>
							</view>
						</template>
						<template v-else>
							<template v-if="current - sitem === 1 || current-sitem ===-2">
								<view class="calendar-day" v-for="(item,index) in predays" :key="index"
									:class="{
										'day-hidden': !item.show
									}">
									<view
										class="date"
										:class="[
											item.isToday ? todayClass : ''
											]"
									>
									{{item.time.getDate()}}
									
									</view>
								</view>
							</template>
							<template v-else>
								<view class="calendar-day" v-for="(item,index) in nextdays" :key="index"
									:class="{
										'day-hidden': !item.show
									}">
									<view
										class="date"
										:class="[
											item.isToday ? todayClass : ''
											]"
									>
									{{item.time.getDate()}}
									</view>
								</view>
							</template>
							
						</template>
					</view>				
				</swiper-item>			
			</swiper>
			<view class="mode-change" @click="changeMode">
				<view :class="weekMode ? 'mode-arrow-bottom' : 'mode-arrow-top'">	
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import {gegerateDates, dateEqual,formatDate} from './generateDates.js';
	export default {
		props: {
			Activesdays:{
				type: Array, /// 打点日期列表
				default() {
					return [
					]
				}
			},
			duration: {
				type: Number,
				default: 500
			},
			dotList: {
				type: Array, /// 打点日期列表
				default() {
					return [
					]
				}
			},
			showBack: {
				type: Boolean, // 是否返回今日
				default: false
			},
			todayClass: {
				type: String, // 今日的自定义样式class
				default: 'is-today'
			},
			checkedClass: {
				type: String, // 选中日期的样式class
				default: 'is-checked'
			},
			dotStyle: {
				type: Object, // 打点日期的自定义样式
				default() {
					return {
						background: '#c6c6c6'
					}
				}
			}
		},
		watch:{
			dotList: function(newvalue){
				const days = this.days.slice(0);
				newvalue.forEach(item => {
					const index = days.findIndex(ditem => ditem.fullDate === item.date);
					if (index > 0) {
						days[index].info = item
					}
				});
				this.days = days;
			}
		},
		computed: {
			sheight() {
				// 根据年月判断有多少行
				// 判断该月有多少天
				let h = '70rpx';
				if (!this.weekMode) {
					const d = new Date(this.currentYear, this.currentMonth, 0);
					const days = d.getDate(); // 判断本月有多少天
					let day = new Date(d.setDate(1)).getDay();
					if (day === 0) {
						day = 7;
					}
					const pre = 8 - day;
					const rows = Math.ceil((days-pre) / 7) + 1;
					h = 70 * rows + 'rpx'
				}
				return h
			},
			timeStr() {
				let str = '';
			    const d = new Date(this.currentYear, this.currentMonth - 1, this.currentDate);
				const y = d.getFullYear();
				const m = (d.getMonth()+1) <=9 ? `0${d.getMonth()+1}` : d.getMonth()+1;
				str = `${y}${m}`;
				this.choseYear=y
				this.choseMonth=m
				return str;
			},
			predays() {
				let pres = [];
				if (this.weekMode) {
					const d = new Date(this.currentYear, this.currentMonth - 1,this.currentDate)
					d.setDate(d.getDate() - 7);
					pres = gegerateDates(d, 'week')
				} else {
					const d = new Date(this.currentYear, this.currentMonth - 2,1)
					pres = gegerateDates(d, 'month')
				}
				return pres;
			},
			nextdays() {
				let nexts = [];
				if (this.weekMode) {
					const d = new Date(this.currentYear, this.currentMonth - 1,this.currentDate)
					d.setDate(d.getDate() + 7);
					nexts = gegerateDates(d, 'week')
				} else {
					const d = new Date(this.currentYear, this.currentMonth,1)
					nexts = gegerateDates(d, 'month')
				}
				return nexts;
			}
		},
		data() {
			return {
				weeks: ['一', '二', '三', '四', '五', '六', '日'],
				current: 1,
				currentYear: '',
				currentMonth: '',
				currentDate: '',
				days: [],
				weekMode: true,
				swiper: [0,1,2],
				// dotList: [], // 打点的日期列表
				selectedDate: formatDate(new Date(), 'yyyy-MM-dd'),
				choseMonth:"",//滑动到的月
				choseYear:"",//滑动到的年
			};
		},
		methods: {
			changeSwp(e) {
				// console.log(e);
				const pre = this.current;
				const current = e.target.current;
				/* 根据前一个减去目前的值我们可以判断是下一个月/周还是上一个月/周 
				*current - pre === 1, -2时是下一个月/周
				*current -pre === -1, 2时是上一个月或者上一周
				*/
			   console.log(this.timeStr)
				this.choseYear
				this.$emit('myChangeSwp',this.choseYear,this.choseMonth)
				this.current = current;
				if (current - pre === 1 || current - pre === -2) {
					this.daysNext();
				} else {
					this.daysPre();
				}
			},
			// 初始化日历的方法
			initDate(cur) {
				let date = ''
				if (cur) {
				  date = new Date(cur)
				} else {
					date = new Date()
				}
				this.currentDate = date.getDate()          // 今日日期 几号
				this.currentYear = date.getFullYear()       // 当前年份
				this.currentMonth = date.getMonth() + 1    // 当前月份
				this.currentWeek = date.getDay() === 0 ? 7 : date.getDay() // 1...6,0   // 星期几
				const nowY = new Date().getFullYear()       // 当前年份
				const nowM = new Date().getMonth() + 1
				const nowD = new Date().getDate()          // 今日日期 几号
				const nowW = new Date().getDay();
				// this.selectedDate = formatDate(new Date(), 'yyyy-MM-dd')
				this.days = [];
				let days = [];
				if (this.weekMode) {
					days = gegerateDates(date, 'week');
					// this.selectedDate = days[0].fullDate;
				} else {
					days = gegerateDates(date, 'month');

				}
				days.forEach(day => {
					const dot = this.dotList.find(item => {
						return dateEqual(item.date, day.fullDate);
					})
					if (dot) {
						day.info = dot;
					}
				})
				this.days = days;
				//  派发事件,时间发生改变
				let obj = {
					start: '',
					end: ''
				};
				if (this.weekMode) {
					obj.start = this.days[0].time;
					obj.end = this.days[6].time
				} else {
					const start = new Date(this.currentYear, this.currentMonth - 1, 1);
					const end =  new Date(this.currentYear, this.currentMonth , 0);
					obj.start = start;
					obj.end = end;
				}
				this.$emit('days-change', obj)
			},
			//  上一个
			daysPre () {
			  if (this.weekMode) {
				const d = new Date(this.currentYear, this.currentMonth - 1,this.currentDate);
				d.setDate(d.getDate() - 7);
				this.initDate(d);  
			  } else {
				  const d = new Date(this.currentYear, this.currentMonth -2, 1);
				  this.initDate(d);
			  }
			},
			//  下一个
			daysNext () {
				 if (this.weekMode) {
					const d = new Date(this.currentYear, this.currentMonth - 1,this.currentDate);
					d.setDate(d.getDate() + 7);
					this.initDate(d);  
				 } else {
					const d = new Date(this.currentYear, this.currentMonth, 1);
					this.initDate(d);
				 }
			},
			changeMode() {
				const premode = this.weekMode;
				let isweek = false;
				if (premode) {
					isweek = !!this.days.find(item => item.fullDate === this.selectedDate)
				}
				this.weekMode = !this.weekMode;
				let d = new Date(this.currentYear, this.currentMonth - 1, this.currentDate)
				const sel = new Date(this.selectedDate.replace('-', '/').replace('-', '/'));
				const isMonth = sel.getFullYear() === this.currentYear && (sel.getMonth() + 1) === this.currentMonth;
				if ((this.selectedDate && isMonth) || isweek) {
					d = new Date(this.selectedDate.replace('-', '/').replace('-', '/'))
				}
				this.initDate(d)
			},
			// 点击日期
			clickItem(e) {
				this.selectedDate = e.fullDate;
				console.log(e)
				this.$emit('selected-change', e);
			},
			goback() {
				const d = new Date();
				let str = '';
				const y = d.getFullYear();
				const m = (d.getMonth()+1) <=9 ? `0${d.getMonth()+1}` : d.getMonth()+1;
				const day = d.getDate() <=9 ? `0${ d.getDate()}` :  d.getDate();
				str = `${y}-${m}-${day}`;
				this.selectedDate=str
				this.$emit('goDays',str);
			}
		},
		created() {
			this.initDate();
		},
		mounted() {
		}
	}
</script>

<style lang="scss" scoped>
.zzx-calendar {
	width: 100%;
	height: auto;
	.calendar-heander {
		text-align: center;
		height: 60rpx;
		line-height: 60rpx;
		position: relative;
		font-size: 30rpx;
		.back-today {
			position: absolute;
			right: 0;
			width: 100rpx;
			height: 30rpx;
			line-height: 30rpx;
			font-size: 20rpx;
			top: 15rpx;
			border-radius: 15rpx 0 0 15rpx;
			color: #ffffff;
			background-color: #FF6633;
		}
	}
	.calendar-weeks {
		width: 100%;
		display: flex;
		flex-flow:row nowrap;
		height: 60rpx;
		line-height: 60rpx;
		justify-content: center;
		align-items: center;
		font-size: 30rpx;
		
		
		.calendar-week {
			width: calc(100% / 7);
			height: 100%;
			text-align: center;
			position: relative;
		}
	}
	swiper {
		width: 100%;
		height: 60rpx;
	}
	.calendar-content {
		min-height: 60rpx;
	}
	.calendar-swiper {       
		min-height: 70rpx;
		transition: height ease-out 0.3s;
	}
	.calendar-item {
		margin: 0;
		padding: 0;
		height: 100%;
	}
	.calendar-days {
		display: flex;
		flex-flow: row wrap;
		width: 100%;
		height: 100%;
		overflow: hidden;
		font-size: 28rpx;
		.calendar-day {
			width: calc(100% / 7);
			height: 70rpx;
			text-align: center;
			display: flex;
			flex-flow: column nowrap;
			justify-content: flex-start;
			align-items: center;
			position: relative;
			.pop {
				position: absolute;
				left: calc(50% - 4rpx);
				top: 0;
				width: 8rpx;
				height: 8rpx;
				background-color: #8E91FB;
				border-radius: 2px;
				
			}
		}
	}
	.day-hidden {
		visibility: hidden;
	}
	.mode-change {
		display: flex;
		justify-content: center;
		margin-top:10rpx;
		.mode-arrow-top {
			width: 0;
			height:0;
			border-left: 12rpx solid transparent;
		    border-right: 12rpx solid transparent;
		    border-bottom: 10rpx solid #8E91FB;
		}
		.mode-arrow-bottom {
			width: 0;
			height:0;
			border-left: 12rpx solid transparent;
			border-right: 12rpx solid transparent;
			border-top: 10rpx solid #8E91FB;
		}
	}
	.is-today {
		background: #ffffff;
		// border: 1rpx solid #FF6633;
		border-radius: 50%;
		color: #8E91FB;
	}
	.is-checked {
		background: #8E91FB;
		color: #ffffff;
	}
	.date {
		width: 50rpx;
		height: 50rpx;
		line-height: 50rpx;
		margin: 0 auto;
		border-radius: 50rpx;
	}
	.dot-show {
		margin-top:4rpx;
		width: 10rpx;
		height: 10rpx;
		background: #c6c6c6;
		border-radius: 10rpx;
	}
}
</style>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1360120.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

设计模式③ :生成实例

文章目录 一、前言二、Singleton 模式1. 介绍2. 应用3. 总结 三、Prototype 模式1. 介绍2. 应用3. 总结 四、Builder 模式1. 介绍2. 应用3. 总结 五、Abstract Factory 模式1. 介绍2. 应用3. 总结 参考内容 一、前言 有时候不想动脑子&#xff0c;就懒得看源码又不像浪费时间所…

LiveGBS流媒体平台GB/T28181常见问题-国标编号是什么设备编号和通道国标编号标记唯一的摄像头|视频|镜头通道

LiveGBS国标GB28181中国标编号是什么设备编号和通道国标编号标记唯一的摄像头|视频|镜头通道 1、什么是国标编号&#xff1f;2、国标设备ID和通道ID3、ID 统一编码规则4、搭建GB28181视频直播平台 1、什么是国标编号&#xff1f; 国标GB28181对接过程中&#xff0c;可能有的小…

flutter版本升级后,解决真机和模拟器运行错误问题

flutter从3.3.2升级到3.16.0&#xff0c;项目运行到真机和模拟器报同样的错&#xff0c;错误如下: 解决办法&#xff1a;在android目录下的build.gradle加入下面这行&#xff0c;如下图&#xff1a; 重新运行&#xff0c;正常把apk安装到真机上或者运行到模拟器上

PC+Wap仿土巴兔装修报价器源码 PHP源码

核心功能&#xff1a; 业主自助预算计算&#xff1a;通过简洁的界面&#xff0c;业主可以输入装修需求&#xff0c;系统自动进行预算计算信息自动收集&#xff1a;系统自动收集业主的基本信息&#xff0c;如姓名、联系方式、房屋面积等一键发送报价&#xff1a;业主完成预算计…

Apache Doris 2.0.2 安装步骤 Centos8

Linux 操作系统版本需求 Linux 系统版本当前系统版本CentOS7.1 及以上CentOS8Ubuntu16.04 及以上- 软件需求 软件版本当前版本Java1.81.8.0_391GCC4.8.2 及以上gcc (GCC) 8.5.0 20210514 (Red Hat 8.5.0-4) 1、查看操作系统版本 方法 1&#xff1a;使用命令行 打开终端或…

springboot第46集:Nginx,Sentinel,计算机硬件的介绍

image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png image.png 什么是单点容错率低&#xff1a; 单点容错率低指的是系统中存在某个关键节点&#xff0c;一旦这个节点发生故障或崩…

Apache SeaTunnel:探索下一代高性能分布式数据集成工具

大家下午好&#xff0c;我叫刘广东&#xff0c;然后是来自Apache SeaTunnel社区的一名Committer。今天给大家分享的议题是下一代高性能分布式海量数据集成工具&#xff0c;后面的整个的PPT&#xff0c;主要是基于开发者的视角去看待Apache SeaTunnel。后续所有的讲解主要是可能…

基于spark的Hive2Pg数据同步组件

一、背景 Hive中的数据需要同步到pg供在线使用&#xff0c;通常sqoop具有数据同步的功能&#xff0c;但是sqoop具有一定的问题&#xff0c;比如对数据的切分碰到数据字段存在异常的情况下&#xff0c;数据字段的空值率高、数据字段重复太多&#xff0c;影响sqoop的分区策略&…

飞塔FortiGate-1000C设备引进助力易天构建网络安全新防线

在当今数字化浪潮的推动下&#xff0c;企业对网络安全的需求日益迫切。为了应对不断升级的网络威胁&#xff0c;给客户提供最为优质的产品&#xff0c;易天引进了最新兼容性测试设备飞塔FortiGate-1000C&#xff0c;为光模块产品交付提供了更强劲的性能保障。 FortiGate-1000C是…

filecoin通过filutils 区块浏览器获取历史收益数据

filecoin 历史收益数据 每天每T平均收益 导出历史每日收益为文档 filutils 区块浏览器 导出历史每日收益为文档 #!/bin/bashfor i in {1..10} doecho $iresult$(curl --location --request POST https://api.filutils.com/api/v2/powerreward \--header User-Agent: Apifox/1.…

fmincon函数求解非线性超越方程的学习记录

最近的算法中用到了fmincon函数&#xff0c;寻找多变量非线性方程最小值的函数&#xff1b;因此学习一下&#xff1b; fmincon函数的基础语法如下所示&#xff1a; fmincon函数是为了求解下列方程的最小值&#xff1b; b 和 beq 是向量&#xff0c;A 和 Aeq 是矩阵&#xff0c…

企业级大数据安全架构(二)安全方案

作者&#xff1a;楼高 1 Knox访问控制 Apache Knox是一个为Apache Hadoop部署提供交互的应用网关&#xff0c;通过其REST API和用户友好的UI&#xff0c;为所有与Hadoop集群的REST和HTTP交互提供了统一的访问点。Knox不仅仅是一个访问网关&#xff0c;它还具备强大的访问控制…

(2024,少样本微调自适应,泛化误差界限,减小泛化误差的措施)多模态基础模型的少样本自适应:综述

Few-shot Adaptation of Multi-modal Foundation Models: A Survey 公和众和号&#xff1a;EDPJ&#xff08;添加 VX&#xff1a;CV_EDPJ 或直接进 Q 交流群&#xff1a;922230617 获取资料&#xff09; 目录 0. 摘要 1. 简介 2. 多模态基础模型的预训练 3. 多模态基础模…

关于kthread_stop的疑问(linux3.16)

线程一旦启动起来后&#xff0c;会一直运行&#xff0c;除非该线程主动调用do_exit函数&#xff0c;或者其他的进程调用kthread_stop函数&#xff0c;结束线程的运行。 之前找销毁内核线程的接口时&#xff0c;发现了kthread_stop这个接口。网上说这个函数能够销毁一个内核线程…

JavaScript:构造函数面向对象

JavaScript&#xff1a;构造函数&面向对象 构造函数实例化静态成员实例成员 内置构造函数引用类型基本含义常用属性方法ObjectArray 包装类型基本含义常用属性方法StringNumber 面向对象原型对象constructor对象原型原型链原型继承 构造函数 在讲解构造函数之前&#xff0…

[NISACTF 2022]bingdundun~

[NISACTF 2022]bingdundun~ wp 信息搜集 进入题目&#xff1a; 点一下 upload? &#xff1a; 注意看上面的 URL &#xff0c;此时是 ?bingdundunupload 。 随便找个文件上传一下&#xff1a; 注意看上面的 URL &#xff0c;此时变成&#xff1a;upload.php 。 那么我有理…

【力扣算法日记】无重复字符的最长子串

最近刷了很多算法题&#xff0c;这些解题过程也拓展了自己的思路&#xff0c;是个适合记录的素材。所以决定在继技术知识点详解的【一文系列】之后&#xff0c;开启新坑——【力扣算法系列】&#xff0c;来记录力扣刷题过程。 分享题目不确定&#xff0c;目前打算只分享我认为…

聊一聊 .NET高级调试 内核模式堆泄露

一&#xff1a;背景 1. 讲故事 前几天有位朋友找到我&#xff0c;说他的机器内存在不断的上涨&#xff0c;但在任务管理器中查不出是哪个进程吃的内存&#xff0c;特别奇怪&#xff0c;截图如下&#xff1a; 在我的分析旅程中都是用户态模式的内存泄漏&#xff0c;像上图中的…

【JVM】类加载器ClassLoader

一、简介 在Java中&#xff0c;类加载器&#xff08;ClassLoader&#xff09;是一个关键的组件&#xff0c;它负责将字节码文件加载到内存并转换成Java类。Java的类加载器主要可以分成两类&#xff1a;系统提供的和由Java应用开发人员编写的。Java开发者可以根据需要创建自己的…

ES集群分片数据的高可用

文章目录 ES集群分片数据的高可用1. 集群设置索引节点2. 集群新增文档数据3.查看集群中文档数据分片节点4. 让节点9201宕机&#xff0c;查看其分片变化5. 让节点9201&#xff0c;查看分片变化 ES集群分片数据的高可用 集群中的索引主分片和副分片在不同的计算机上&#xff0c;如…