vue 日历组件只显示本月和下个月 -- 多选日期
效果就是上图
代码贴出
1.在components > calander > index.vue
<template>
<div class="page" v-if="show">
<div class="box">
<div class="box_head" v-if="!propshow">
<div class="font28" @click="calanderShowData">取消</div>
<div class="font28" @click="calanderSubmit">确定</div>
</div> <div class="box-flex">
<div class="flex-item item-content-current-day item-content-tit">
<div class="item-content titleHead">{{currentDate}}</div>
</div>
</div>
</div>
<div class="box-flex">
<div class="flex-item">
<div class="item-content">一</div>
</div>
<div class="flex-item">
<div class="item-content">二</div>
</div>
<div class="flex-item">
<div class="item-content">三</div>
</div>
<div class="flex-item">
<div class="item-content">四</div>
</div>
<div class="flex-item">
<div class="item-content">五</div>
</div>
<div class="flex-item">
<div class="item-content">六</div>
</div>
<div class="flex-item">
<div class="item-content">日</div>
</div>
</div>
<div class="box-flex">
<div class="flex-item flexData" v-for='(item, index) in currentDayList' :key='item' @click='itemFun(item.num,mouth[index],index, "first", item.state)' :class="{'hover-date': Section[index] && item.num, 'noBack': !item.state && item.num && !propshow }">
<div class="item-content red-background" v-if='currentDay === item.num && mouth[index].mouth === currentMouth.mouth && currentMouth.year === mouth[index].year' :class="{'hoverColorData' : Section[index] && item.num, 'hover-date':active[index]}">
<p>今天</p>
<p v-if="item.number && propshow">{{item.number}}展位</p>
</div>
<div class="item-content backgroundData" v-else :class="{'hover-date':active[index]}" >
<p>{{item.num}}</p>
<p v-if="item.number && propshow">{{item.number}}展位</p>
</div>
</div>
</div>
<div class="box">
<div class="box-flex">
<div class="flex-item item-content-current-day item-content-tit">
<div class="item-content titleHead">{{currentDateTwo}}</div>
</div> </div>
</div>
<div class="box-flex">
<div class="flex-item">
<div class="item-content">一</div>
</div>
<div class="flex-item">
<div class="item-content">二</div>
</div>
<div class="flex-item">
<div class="item-content">三</div>
</div>
<div class="flex-item">
<div class="item-content">四</div>
</div>
<div class="flex-item">
<div class="item-content">五</div>
</div>
<div class="flex-item">
<div class="item-content">六</div>
</div>
<div class="flex-item">
<div class="item-content">日</div>
</div>
</div>
<div class="box-flex">
<div class="flex-item flexData" v-for='(item, index) in currentDayListData' :key='item' @click='itemFun(item.num,mouths[index],index, "last", item.state)' :class="{'hover-date': Sections[index] && item.num, 'noBack': !item.state && item.num && !propshow}">
<div class="item-content backgroundData" :class="{'hover-date':actives[index]}">
<p>{{item.num}}{{item.number}}</p>
<p v-if="item.number && propshow">{{item.number}}展位</p>
</div>
</div>
</div> <div v-if="propshow" class="propshowData"></div>
</div>
</template> <script>
import vue from 'vue'
export default {
name: 'calander',
data () {
return {
calanderList: [],
show: false,
currentDate: '2017年05月03日',
currentDateTwo: '2017年06月03日',
dayList: '',
currentDayList: [],
currentObj: '',
currentDay: '',
mouth: [],
currentMouth: null,
hoverDate: {'date': null, 'mouth': null, 'year': null},
activeClick: 0,
active: [],
actives: [],
Section: [],
firstIndex: 0,
lastIndex: 0,
currentDayListData: [],
currentJudge: false,
currentObjNew: '',
Sections: [],
lastType: '',
fristType: '',
numArray: [],
numArrayTwo: []
}
},
props: {
propshow: false,
boothArray: [], // 从父级传来的数组参数,主要是传来天中携带的number展位参数
calanderList: [],
yearAndmouthFirst: {},
yearAndmouthTwo: {},
calanderShow: false
},
mounted () {
this.definedMon()
},
methods: {
definedMon(){
let timeData = this.getNextMonth(new Date(),1)
var currentObj = this.getCurrentDayString()
this.currentDate = currentObj.getFullYear() + '年' + (currentObj.getMonth() + 1) + '月' + currentObj.getDate() + '日'
this.currentDateTwo = timeData.getFullYear() + '年' + (timeData.getMonth() + 1) + '月' + timeData.getDate() + '日' this.currentDay = currentObj.getDate() this.currentObj = currentObj
this.currentMouth = {
mouth: currentObj.getMonth() + 1,
year: currentObj.getFullYear()
} setTimeout(() => {
console.log(69999999999)
this.setSchedule(currentObj, 'newMonth')
this.setSchedule(this.getNextMonth(new Date(),1), 'nextMonth')
},100);
},
monthDay: function (year, month) {
month = parseInt(month, 10);
var d = new Date(year, month, 0); //这个是都可以兼容的
var date = new Date(year + "/" + month + "/0") //IE浏览器可以获取天数,谷歌浏览器会返回NaN
return d.getDate();
},
getNextMonth: function (date,length) {
let yy = date.getFullYear()
let mm = date.getMonth()
let dd = date.getDate() let nm= 0//目标月份
nm = mm+length
let nd = 0//目标天数
if(this.monthDay(yy,nm+1)<dd){
nd = this.monthDay(yy,nm+1)
}else{
nd = dd-1
} date.setDate(1)
date.setMonth(nm)
date.setDate(nd)
return date
},
calanderSubmit(){
this.$emit('assignment', this.numArray)
},
calanderShowData(){
this.$emit('calanderShowClick', this.calanderShow)
},
formatTwo (n) {
if (n >= 10) return n
else return '0' + n
},
// 判断日历的当前日期是否不可点击
isDisabled (calander, index, item) {
// if (new Date(calander).getTime() < new Date().getTime()) {
// this.mouth[index].state = 'disabled'
// return false
// }
},
getWeekDayNextMonth(){
var myDate = new Date()
myDate.setMonth(myDate.getMonth() + 1);
myDate.setDate(1);
var weekDay=new Array(7, 1, 2, 3, 4, 5, 6)
return weekDay[myDate.getDay()];
},
itemFun (item, yearAndmouth, index, type, stateClick) {
if (stateClick) {
let dataD = new Date();
let curMonthDays = new Date(dataD.getFullYear(), (dataD.getMonth()+1), 0).getDate()
this.hoverDate = {'date': item, 'mouth': yearAndmouth.mouth, 'year': yearAndmouth.year} if (type == 'first') {
var activeArrayData = this.active
var SectionArrayData = this.Section
} else {
var activeArrayData = this.actives
var SectionArrayData = this.Sections
}
var delceIndex = -1
this.numArray.forEach((e, i) => {
if (yearAndmouth.year == e.year && yearAndmouth.mouth == e.mouth && item == e.date) {
delceIndex = i
}
}) if (delceIndex != -1) {
activeArrayData[index] = false
vue.set(activeArrayData, index, activeArrayData[index]) this.numArray.splice(delceIndex,1)
delceIndex = -1
return
}
this.yearAndmouthFirst = yearAndmouth
this.yearAndmouthFirst.date = item
this.activeClick = 1
this.fristType = type
this.firstIndex = item
this.yearFirst = yearAndmouth.year
this.mouthFirst = yearAndmouth.mouth activeArrayData[index] = true
vue.set(activeArrayData, index, activeArrayData[index])
this.numArray.push(this.yearAndmouthFirst)
}
},
doDay: function (e) {
var that = this
var currentObj = that.currentObj
var Y = currentObj.getFullYear()
var m = currentObj.getMonth() + 1
let newData = new Date
let newMonth=newData.getMonth()+1;
let d = currentObj.getDate()
var str = ''
if (e.currentTarget.dataset.key === 'left') {
m -= 1
if (m <= 0) {
str = (Y - 1) + '/' + 12 + '/' + d
} else {
str = Y + '/' + m + '/' + d
}
this.currentJudge = true
} else if(e.currentTarget.dataset.key === 'right') {
if (newMonth !== m) {
m += 1
if (m <= 12) {
str = Y + '/' + m + '/' + d
} else {
str = (Y + 1) + '/' + 1 + '/' + d
}
this.currentJudge = true
} else {
this.currentJudge = false
}
} else if (e.currentTarget.dataset.key === 'leftTwo'){
if (newMonth !== m) {
m -= 1
if (m <= 0) {
str = (Y - 1) + '/' + 12 + '/' + d
} else {
str = Y + '/' + m + '/' + d
}
this.currentJudge = true
} else {
this.currentJudge = false
}
} else if (e.currentTarget.dataset.key === 'rightTwo'){
m += 1
if (m <= 12) {
str = Y + '/' + m + '/' + d
} else {
str = (Y + 1) + '/' + 1 + '/' + d
}
this.currentJudge = true
}
if (this.currentJudge) {
currentObj = new Date(str)
this.currentDate = currentObj.getFullYear() + '年' + (currentObj.getMonth() + 1) + '月' + currentObj.getDate() + '日'
this.currentDateTwo = currentObj.getFullYear() + '年' + (currentObj.getMonth() + 2) + '月' + currentObj.getDate() + '日'
this.currentObjNew = currentObj.getFullYear() + '/' + (currentObj.getMonth() + 2) + '/' + currentObj.getDate() + '/' this.currentObj = currentObj
if (e.currentTarget.dataset.key == 'left' || e.currentTarget.dataset.key == 'right') {
this.setSchedule(currentObj, 'newMonth')
} else {
this.setSchedule(new Date(this.currentObjNew), 'nextMonth')
}
}
},
getCurrentDayString: function () {
var objDate = this.currentObj
if (objDate !== '') {
return objDate
} else {
var cobj = new Date()
var a = cobj.getFullYear() + '/' + (cobj.getMonth() + 1) + '/' + cobj.getDate()
return new Date(a)
}
},
setSchedule: function (currentObj, type) {
var that = this
var m = currentObj.getMonth() + 1
var Y = currentObj.getFullYear()
var d = currentObj.getDate()
var newDate = new Date()
var newYear = newDate.getFullYear()
var newMonth = newDate.getMonth() + 1 // var dayString = Y + '/' + m + '/' + currentObj.getDate()
var currentDayNum = new Date(Y, m, 0).getDate()
var currentDayWeek = currentObj.getUTCDay() + 1 var result = currentDayWeek - (d % 7 - 1) var firstKey = result <= 0 ? 7 + result : result var currentDayListNew = [] var mouth = []
var f = 0
for (var i = 0; i < 42; i++) {
mouth[i] = {
'mouth': m,
'year': Y
}
currentDayListNew[i] = {
'num': '',
'number': '',
'state': false
}
if (i < firstKey - 1) {
currentDayListNew[i].num = ''
} else {
if (f < currentDayNum) {
currentDayListNew[i].num = f + 1
f = currentDayListNew[i].num
if (newYear == Y && newMonth == m) {
if (f >= d) {
currentDayListNew[i].state = true
}
} else {
if (f <= d) {
currentDayListNew[i].state = true
}
}
} else if (f >= currentDayNum) {
currentDayListNew[i].num = ''
}
if (this.boothArray.length > 0) {
this.boothArray.forEach((element, indexArray) => {
if (element.year == Y && element.mouth == m) {
if (element.date == currentDayListNew[i].num) {
if (String(element.number) == 0) {
currentDayListNew[i].state = false
}
currentDayListNew[i].number = String(element.number)
}
}
})
}
if (this.calanderList.length > 0) {
this.calanderList.forEach((element, indexList) => {
if (element.year == Y && element.mouth == m) {
if (element.date == currentDayListNew[i].num) {
if (type == 'newMonth') {
this.Section[i] = true
this.active[i] = true
this.numArray.push(element)
} else {
this.Sections[i] = true
this.actives[i] = true
this.numArray.push(element)
}
}
}
});
}
}
}
if (type == 'newMonth') {
that.currentDayList = currentDayListNew
that.mouth = mouth
} else {
that.currentDayListData = currentDayListNew
that.mouths = mouth
}
this.show = true
}
}
}
</script> <style scoped>
.box_head{
height: 1.173333rem /* 88/75 */;
background: #fff;
display: flex;
justify-content: space-between;
align-items: center;
padding: 0 .4rem /* 30/75 */;
border-bottom: .013333rem /* 1/75 */ solid #E5E5E5;
}
.noBack{
background: #bbb!important;
/* border-radius: 5px!important; */
}
.hoverColorData{
color: #fff!important;
}
.propshowData{
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
background: rgba(0, 0, 0, 0.1);
z-index: 9999;
}
.page{
background: #fff;
position: relative;
}
.titleHead{
margin: .266667rem /* 20/75 */ 0!important;
}
.sectionBack{
background: #8A2BE2;
}
page {
background-color: #2a8cef;
background:-webkit-gradient(linear, 0 0, 0 bottom, from(#2a8cef), to(#8A2BE2));
display: flex;
flex-direction: column;
width: 100%;
flex-wrap: nowrap;
justify-content: flex-start;
align-items: stretch;
font-size: 16px;
color: #222;
}
.disabled{
color: #ccc !important;
}
.hover-date{
background: #367EED;
color: #fff !important;
border-radius: 5px;
}
.box {
display: block;
/* margin: 10px; */
border-top: .013333rem /* 1/75 */ solid #efefef;
}
.glyphicon-triangle-left img{
transform:rotate(180deg)
}
.glyphicon img{
width:12px;
height: 19px;
margin-top:15px;
}
.box-flex {
display: -webkit-box;
display: -webkit-flex;
display: flex;
flex-wrap: wrap;
padding: 0 .133333rem /* 10/75 */;
} .flex-item {
flex-flow: nowrap;
flex-grow: 1;
flex-shrink: 1;
width: 14%;
margin: 1px 1px 1px 0px;
} .item-content {
margin: 1px;
padding: 5px 1px;
text-align: center;
/* height: 45px; */
/* line-height: 45px; */
font-size:14px;
position: relative;
flex-wrap: wrap;
justify-content: center;
}
.item-content i{
width:100%;
text-align: center;
left:0;
position: absolute;
top:8px;
}
.item-content span{
width:100%;
text-align: center;
left:0;
position: absolute;
top:3px;
font-size:12px;
color: #367EED;
line-height: 1;
}
.item-content-tit{
width:30%;
/* margin: .133333rem 10/75 0; */
}
.item-content-tit .item-content{
font-size:17px;
}
.red-background{
color:#367EED;
border-radius: 5px;
} .item-content-current-day {
flex-grow: 2;
}
</style>
2.在页面中引用组件
<calander @assignment="assignment" :propshow="propshow" :boothArray="boothArray" :calanderList="calanderList"></calander> <script>
import calander from '@/components/calander'
export default {
components: {
calander
},
data() {
return {
calanderList: [],
boothArray: [],
propshow: false,
};
},
methods: {
assignment(){
// 组件调取父级方法
},
}
}
</script>
vue 日历组件只显示本月和下个月 -- 多选日期的更多相关文章
- bootstrap中日历组件只显示年月
大多数情况下日历组件我们使用的都是yyyy-mm-dd的日历格式,但是有时候需求不需要我们精确到日,而是最小单位到月份(yyyy-mm),网上找了很多方法,但是都没有我想要的效果,一些属性的设置都没有 ...
- Vue日历组件的功能
本来呢,开开心心的写完了这个功能,然后发现elemeng更新了,增加了日历组件这个功能 我的内心机器奔溃,但是,element的日历组件太简单了,我感觉还是手撸一个吧,毕竟也不是很难 实现了显示农历, ...
- vue 日历组件
Github 上很多点击弹出日历选择某个时间的组件,却没有找到单纯展示日历并且能点击获取时间的组件 npm i vue-calendar-component --save cnpm i vue-cal ...
- 一个vue的日历组件
说明: 1.基于element-ui开发的vue日历组件. 地址 更新: 1.增加value-format指定返回值的格式2.增加头部插槽自定义头部 <ele-calendar > < ...
- bootstrap datetimepicker 中只显示年或者只显示月份
1.只显示datetimepicker 日历中只显示年份 $("#day-access-calendar").datepicker({ startView: 2, maxView ...
- vue 中 echart 在子组件中只显示一次的问题
问题描述 一次项目开发过程中,需要做一些图表,用的是百度开源的 echarts. vue推荐组件化开发,所以就把每个图表封装成子组件,然后在需要用到该图表的父组件中直接使用. 实际开发中,数据肯定都是 ...
- Vue中使用Vue.component定义两个全局组件,用单标签应用组件时,只显示一个组件的问题和 $emit的使用。
解决方法: 定义了两个 Vue.component 在 el 中使用的时候要用 双标签, 用单表标签的时候,只会显示第个 组件间 这样写只显示 welcome-button 组件 <welcom ...
- 在vue中使用elementUI饿了么框架使用el-calendar日历组件,实现自定义显示备忘录标注
饿了么官网给的自定义例子是点击哪个日期在日期后面加个勾 而我们想要的是显示备忘录,像这样↓,日历上直接显示 这时候我们要把template里的代码改一下 <el-calendar> < ...
- vue初学实践之路——vue简单日历组件(1)
---恢复内容开始--- 最近做的项目有一个需求,需要有一个日历组件供预定功能使用,之前的代码过于繁琐复杂,所以我采用vue重写了这个组件. npm.vue等等安装. 只是一个简单的日历组件,所以并不 ...
随机推荐
- Memcache&Redis
Memcached 是一个高性能的分布式内存对象缓存系统,用于动态Web应用以减轻数据库负载.减少数据库读取次数来提高网站速度 先在一台机器安装memcache 然后使用Python 安装pip3 i ...
- python中接入支付宝当面付
准备 由于正式环境需要商户信息,所以这里使用支付宝提供的沙箱环境.切换到正式环境后只需稍改配置. 1.点击进入蚂蚁金服平台官网. 2.如下图选择:开发者中心->开发服务下的研发服务->沙箱 ...
- [js]es6语法: 字符串和数组的方法
s的方法 根据index取value: 取首尾项,arr[0], arr[arr.length-1] 根据value取index(判断是否包含子字符串): s.indexOf 栗子: 'maotai' ...
- Micro和Macro性能学习【转载】
转自:https://datascience.stackexchange.com/questions/15989/micro-average-vs-macro-average-performance- ...
- XML DOM 节点类型(Node Types)
节点类型 下面的表格列出了不同的 W3C 节点类型,以及它们可拥有的子元素: 节点类型 描述 子元素 Document 表示整个文档(DOM 树的根节点) Element (max. one) Pro ...
- 逆向 AWS API 设计
由于AWS并没有像Google一样公开出一份API Design Guide,所以只能根据 API 的模样去逆向工程最初的设计考量.既然上一篇介绍了很多 REST 的缺陷,那么这里也会介绍一下 AWS ...
- Beta阶段敏捷冲刺日志的集合贴
Beta阶段冲刺前计划与安排:http://www.cnblogs.com/software-teamwork/p/9060118.html Day1(5.22):https://www.cnblog ...
- 200. Number of Islands(DFS)
Given a 2d grid map of '1's (land) and '0's (water), count the number of islands. An island is surro ...
- TheFatRat一般使用
利用它生成后门 第一种通常情况下速度很快,较稳定,但免杀效果极差 推荐使用第二种 免杀效果好,如下图 第一种是最新的模块,较免杀效果极好.还可伪造图标 第二种是旧的
- Linux NFS挂载
Linux NFS挂载 一.NFS挂载 192.25.10.101/home/sharedata/azkaban/ODS_HS08 挂载到 192.25.10.102/home/data_azkaba ...