vue平铺日历组件
vue日历自定义平铺组件
<sy-icon @click="preMon" class="copy-icon" iconClass="iconjiantou1"></sy-icon> 表示的是上一个月,是我自定的字体图标
<sy-icon @click="nextMon" class="copy-icon right-arrow" iconClass="iconjiantou1"></sy-icon> 表示的是下一个月,是我的自定义图标
<template>
<div>
<div class="header-title">
<sy-icon @click="preMon" class="copy-icon" iconClass="iconjiantou1"></sy-icon>
<a class="data-now-a">{{currentYear}}/{{currentMonth+1}}</a>
<sy-icon @click="nextMon" class="copy-icon right-arrow" iconClass="iconjiantou1"></sy-icon>
</div>
<div class="flex-week">
<a class="a-week" v-for="(item,index1) in listXIngqi" :key="index1">{{ item }}</a>
</div>
<ul class="date">
<li v-for="(item, index) in list" :key="index"
@click="handerSelect(item)" class="riqili"
:class="( Number(item.y+''+item.m+''+item.d) >= Number(starttime) && Number(endtime) >= Number(item.y+''+item.m+''+item.d) ||
item.y+''+item.m+''+item.d == starttime|| item.y+''+item.m+''+item.d == endtime ) ? 'activeSelect' : ''"
>
<div class="day" :class="{'text-color': item.cur}">
{{item.d}}
<a :class="item.y+''+item.m+''+item.d"></a>
</div>
<i class="current-day-cricle" v-if="item.y === year && item.m === month && item.d === day"></i>
</li>
</ul>
</div>
</template>
<script>
export default {
data(){
return{
year: new Date().getFullYear(), // 今日年份
month: new Date().getMonth() + 1, // 今日月份
day: new Date().getDate(), // 今日日份
currentYear: '', // 当前显示年份
currentMonth: '', // 当前显示月份 0-11,显示时加一
currentDay: '', // 当前显示日份
monthDays: [], // 1-12月的天数
list: [],
listXIngqi:['一', '二', '三', '四', '五','六','日'],
selectCompare:[],
clickcount: 0, //点击次数
starttime:'',//点击的开始的日期
endtime:'', //点击的结束时间 数字
params_starttime:'',//抛出去的参数
params_endtime:'',//抛出去的参数
}
},
mounted () {
this.showCalender()
},
methods: {
// 点击的日期
handerSelect(mess){
console.log(mess);
if(mess.cur){
// 点击的是当前月
this.clickcount++;
if(this.clickcount % 2 == 1){
// 开始时间
this.starttime=mess.y+""+mess.m+""+mess.d;
this.endtime="";
this.params_starttime=mess.y+'-'+(mess.m>9 ? mess.m : '0'+mess.m)+'-'+(mess.d>9 ? mess.d : '0'+mess.d )
this.params_endtime="";
}else{
// 结束时间
this.endtime=mess.y+""+mess.m+""+mess.d;
this.params_endtime=mess.y+'-'+(mess.m>9 ? mess.m : '0'+mess.m)+'-'+(mess.d>9 ? mess.d : '0'+mess.d )
if(Number(this.starttime)>Number(this.endtime)){
this.endtime = Number(this.starttime);
this.params_endtime=this.params_starttime;
this.starttime = Number(mess.y+""+mess.m+""+mess.d);
this.params_starttime=mess.y+'-'+(mess.m>9 ? mess.m : '0'+mess.m)+'-'+(mess.d>9 ? mess.d : '0'+mess.d );
}
}
console.log('开始',this.starttime, this.params_starttime );
console.log('jieshu',this.endtime, this.params_endtime );
this.$emit('change',[this.params_starttime,this.params_endtime ] )
}else {
// if(mess.d>20){
// this.nextMon();
// }else{
// this.preMon();
// }
}
},
isLeap (year) { // 判断是不是闰年
return (year % 100 === 0 ? (year % 400 === 0 ? 1 : 0) : (year % 4 === 0 ? 1 : 0))
},
showCalender (type) {
this.list = []
this.newDate = new Date()
if (!type) this.currentYear = this.newDate.getFullYear()
if (!type) this.currentMonth = this.newDate.getMonth()
this.monthDays = [31, 28 + this.isLeap(this.currentYear), 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
this.currentDay = this.newDate.getDate()
this.firstDay = new Date(`${this.currentYear}-${this.currentMonth + 1}-1`)
this.firstnow = this.firstDay.getDay() // 当月第一日是星期几 1-7
if (this.firstnow === 0) this.firstnow = 7
if (this.firstnow > 1) {
// 前一个月份
let monIndex = this.currentMonth
let year
if (monIndex === 0) {
year--
monIndex = 11
} else {
monIndex--
}
for (let i = 0; i < this.firstnow - 1; i++) {
this.list.unshift({
y: year,
m: monIndex + 1,
d: this.monthDays[monIndex] - i
})
}
}
for (let i = 0; i < this.monthDays[this.currentMonth]; i++) {
// 当前月份
this.list.push({
y: this.currentYear,
m: this.currentMonth + 1,
d: i + 1,
cur: true
})
}
const num = (this.monthDays[this.currentMonth] + this.firstnow - 1) % 7
if (num > 0) {
// 下个月份
let monIndex2 = this.currentMonth
let year2
if (monIndex2 === 11) {
year2++
monIndex2 = 0
} else {
monIndex2++
}
for (let i = 0; i < 7 - num; i++) {
this.list.push({
y: year2,
m: monIndex2 + 1,
d: i + 1
})
}
}
},
clearData(){
this.clickcount=0;
this.starttime='';
this.endtime='';
this.params_starttime='';
this.params_endtime='';
},
preMon () {
this.clearData();
if (this.currentMonth === 0) {
this.currentYear--
this.currentMonth = 11
} else {
this.currentMonth--
}
this.showCalender('pre')
},
nextMon () {
this.clearData();
if (this.currentMonth === 11) {
this.currentYear++
this.currentMonth = 0
} else {
this.currentMonth++
}
console.log( 'this.currentMonth',this.currentMonth );
this.showCalender('next')
}
}
}
</script>
<style lang="scss" scoped>
.header-title{
margin-right: 16px;
height: 40px;
opacity: 1;
background: #f8f8f7;
border-radius: 6px;
display: flex;
justify-content: center;
align-items: center;
justify-content: space-between;
padding-left: 16px;
padding-right: 16px;
margin-top: 16px;
margin-bottom: 17px;
.copy-icon{
font-size: 20px;
color: #71809c;
}
.data-now-a{
font-size: 15px;
font-family: Helvetica, Helvetica-Regular;
font-weight: 400;
color: rgba(0,0,0,0.85);
}
.right-arrow{
transform: rotate(-180deg);
}
}
.flex-week{
display: flex;
justify-content: space-between;
padding-right: 37px;
padding-left: 21px;
.a-week{
font-size: 14px;
font-family: Helvetica, Helvetica-Regular;
font-weight: 400;
text-align: center;
color: #253f50;
display: inline-block;
width: 40px;
height: 30px;
}
}
.date{
display: flex;
justify-content: flex-start;
flex-wrap: wrap;
align-items: center;
padding-left: 20px;
padding-right: 36px;
.riqili{
height: 40px;
width: 40px;
display: flex;
// 末尾或者上月天数颜色
justify-content: center;
align-items: center;
color: #b8bfce;
font-size: 12px;
margin-bottom: 10px;
position: relative;
margin-right: 3px;
//当前月的正常颜色
.text-color{
font-size: 14px;
font-family: Helvetica, Helvetica-Regular;
font-weight: 400;
text-align: center;
color: #72809e;
}
// 当月当天的标识
.current-day-cricle{
display: block;
width: 5px;
height: 5px;
background: #28ae61;
border-radius: 50%;
position: absolute;
bottom: 6px;
left: 17px;
}
}
.riqili:nth-child(4n){
margin-right: 5px;
}
.riqili:nth-child(7n){
margin-right: 0px;
}
}
.activeSelect{
width: 40px;
height: 40px;
opacity: 1;
background: #3b8bfa;
border-radius: 50%;
.day{
color: #fff !important;
}
}
</style>
在页面中直接使用就可以了
<calendar-data @change="changeSelect"></calendar-data>
//arr是你选择的开始日期和结束日期
changeSelect(arr){
this.timeArrStartAndEnd=arr;
},
参考的地址:https://www.cnblogs.com/xue-wejie/p/10553291.html
vue平铺日历组件的更多相关文章
- Vue文件封装日历组件
封装就是要具有灵活性,样式自适应,调用的时候传入props就可以变成自己想要的样式. 效果展示网址:https://1963331542.github.io/ 源代码: <template> ...
- 基于Vue的简单日历组件
日历组件 由于移动端项目中需要用到日历组件,网上找了下,没看到几个合适的,就尝试着自己写一个.然后发现也不是很复杂,目前只做了最基本的功能,大家也可以拿去做做二次开发. 如何写一个日历组件 基础效果如 ...
- Flutter——ListView组件(平铺列表组件)
ListView的常见参数: 名称 类型 说明 scrollDirection Axis Axis.horizontal 水平列表 Axis.vertical 垂直列表 padding EdgeIns ...
- 如何用vue封装一个防用户删除的平铺页面的水印组件
需求 为了防止截图等安全问题,在web项目页面中生成一个平铺全屏的水印 要求水印内容为用户名,水印节点用户不能通过开发者工具等删除 效果 如上图 在body节点下插入水印DOM节点,水印节点覆盖在页面 ...
- vue初学实践之路——vue简单日历组件(1)
---恢复内容开始--- 最近做的项目有一个需求,需要有一个日历组件供预定功能使用,之前的代码过于繁琐复杂,所以我采用vue重写了这个组件. npm.vue等等安装. 只是一个简单的日历组件,所以并不 ...
- vue-calendar 基于 vue 2.0 开发的轻量,高性能日历组件
vue-calendar-component 基于 vue 2.0 开发的轻量,高性能日历组件 占用内存小,性能好,样式好看,可扩展性强 原生 js 开发,没引入第三方库 Why Github 上很多 ...
- Vue自定义日历组件
今天给大家介绍Vue的日历组件,可自定义样式.日历类型及支持扩展,可自定义事件回调.Props数据传输. 线上demo效果 示例 Template: <Calendar :sundayStart ...
- 一个vue的日历组件
说明: 1.基于element-ui开发的vue日历组件. 地址 更新: 1.增加value-format指定返回值的格式2.增加头部插槽自定义头部 <ele-calendar > < ...
- 使用ant design vue的日历组件,实现一个简单交易日与非交易日的切换
使用ant design vue的日历组件,实现一个简单交易日与非交易日的切换 需求: 日历区分交易日.非交易日 可以切换面板查看整年交易日信息 可以在手动调整交易日.非交易日 演示实例 序--使用软 ...
- vue之手把手教你写日历组件
---恢复内容开始--- 1.日历组件 1.分析功能:日历基本功能,点击事件改变日期,样式的改变 1.结构分析:html 1.分为上下两个部分 2.上面分为左按钮,中间内容展示,右按钮 下面分为周几展 ...
随机推荐
- gal game 杂谈——前言
gal game 杂谈--前言 大年三十凌晨(早上)打算开始写了吧,作为第一篇先写一些前言好了. 第一次接触gal game还是在B站上看到有人玩<我和她的世界末日>当时觉得挺有意思的,加 ...
- AI那么厉害,那测试开发和自动化测试这些职位是不是就多余了?
在当今科技飞速发展的时代,AI大模型如ChatGPT等如同璀璨星辰般闪耀登场,它们的强大功能引发了各个领域的诸多思考.在软件测试领域,不少人心里直犯嘀咕:这AI大模型都这么厉害了,那测试开发和自动化测 ...
- MongoDB之用户管理
注意点: 验证库: 建立用户时use到的库及用户的验证库,在使用用户时,要加上验证库才能登陆. 对于管理员用户,必须在admin下创建. 1. 建用户时,use到的库,就是此用户的验证库 2. 登录时 ...
- 逆向WeChat(八)
上一篇逆向WeChat(七)是逆向微信客户端本地数据库相关事宜. 本篇逆向微信客户端本地日志xlog相关的事宜. 本篇在博客园地址https://www.cnblogs.com/bbqzsl/p/18 ...
- Threejs入门-灯光
在 Three.js 中,灯光是非常重要的元素之一,它能够模拟现实世界中的光照效果,帮助我们打造更加真实的三维场景.灯光的种类和配置方式可以影响整个场景的视觉效果,在不同的应用中,灯光的使用非常关键. ...
- Vue3 组合式API
1.入口 创建实例时,配置setup方法,然后其内部书写组合式API代码,通过组合式API生产的数据和返回,需要暴漏出去才能给HTML使用 <script> //组合式(解构赋值) con ...
- 手撕vector
Myclass.h #pragma once #include<iostream> #include<Windows.h> #define SUCCESS 1 // 成功 #d ...
- Kettle设置定时跑任务
1.Kettle设置作业 保存,test.kjb 2. 创建批处理 zxjb.bat C: cd C:\kettle\pdi-ce-9.4.0.0-343\data-integration kitch ...
- Flutter之GetX之路由管理
GetX之路由管理 GetX有一套完整的路由管理,并且不需要context上下文,API非常简洁 直接导航 导航到新的页面 Get.to(NextScreen()); 返回,此方法可以用于关闭Snac ...
- 入门 .NET Aspire: 使用 .NET 简化云原生应用开发
入门 .NET Aspire: 使用 .NET 简化云原生应用开发 https://devblogs.microsoft.com/dotnet/introducing-dotnet-aspire-si ...