compareDate(dateTime1, dateTime2) {
let formatDate1 = new Date(dateTime1);
let formatDate2 = new Date(dateTime2);
if (formatDate1 > formatDate2) {
return 1;
} else if (formatDate1 < formatDate2) {
return -1;
} else {
return 0;
}
},
compareYear(dateTime1, dateTime2) {
let year1 = new Date(dateTime1).getYear();
let year2 = new Date(dateTime2).getYear();
if (year1 > year2) {
return 1;
} else if (year1 < year2) {
return -1;
} else {
return 0;
}
}
//处理日历
procCalendar(item) {
//如果起始日期大于该日期
//可用范围
let startresult = DateTools.compareDate(this.enableRange[0], item.dateObj) == -1 || DateTools.compareDate(
this.enableRange[0], item.dateObj) == 0;
let endresult = DateTools.compareDate(item.dateObj, this.enableRange[1]) == -1 || DateTools.compareDate(
item.dateObj, this.enableRange[1]) == 0;
if (startresult && endresult) {
item.disable = false;
} else {
item.disable = true;
}
//定义初始样式
/* item.statusStyle = {
opacity: 1,
color: item.isOtherMonth ? ‘#ddd‘ : ‘#000‘,
background: ‘transparent‘
}; */
//定义初始样式
item.statusStyle = {
opacity: 1,
color: item.disable ? ‘#ddd‘ : item.isOtherMonth ? ‘#abcfff‘ : ‘#000‘,
background: ‘transparent‘
};
item.bgStyle = {
type: ‘‘,
background: ‘transparent‘
};
item.dotStyle = {
opacity: 1,
background: ‘transparent‘
};
item.tips = "";
//标记今天的日期
if (DateTools.isSameDay(new Date(), item.dateObj)) {
item.statusStyle.color = this.color;
if (item.isOtherMonth) item.statusStyle.opacity = 0.3;
}
//标记选中项
this.checkeds.forEach(date => {
if (DateTools.isSameDay(date, item.dateObj)) {
item.statusStyle.background = this.color;
item.statusStyle.color = ‘#fff‘;
item.statusStyle.opacity = 1;
if (this.isMultiSelect && this.showTips) item.tips = this.beginText;
}
});
//节假日或今日的日期标点
if (item.statusStyle.background != this.color) {
let holiday = this.showHoliday ? DateTools.getHoliday(item.dateObj) : false;
if (holiday || DateTools.isSameDay(new Date(), item.dateObj)) {
item.title = holiday || item.title;
item.dotStyle.background = this.color;
if (item.isOtherMonth) item.dotStyle.opacity = 0.2;
}
} else {
item.title = item.dateObj.getDate();
}
//有两个日期
if (this.checkeds.length == 2) {
if (DateTools.isSameDay(this.checkeds[0], item.dateObj)) { //开始日期
item.bgStyle.type = ‘bgbegin‘;
}
if (DateTools.isSameDay(this.checkeds[1], item.dateObj)) { //结束日期
if (this.isMultiSelect && this.showTips) item.tips = item.bgStyle.type ? this.beginText + ‘ / ‘ +
this.endText : this.endText;
if (!item.bgStyle.type) { //开始日期不等于结束日期
item.bgStyle.type = ‘bgend‘;
} else {
item.bgStyle.type = ‘‘;
}
}
if (!item.bgStyle.type && (+item.dateObj > +this.checkeds[0] && +item.dateObj < +this.checkeds[
1])) { //中间的日期
item.bgStyle.type = ‘bg‘;
item.statusStyle.color = this.color;
}
if (item.bgStyle.type) {
item.bgStyle.background = this.color;
item.dotStyle.opacity = 1;
item.statusStyle.opacity = 1;
}
}
},
原文:https://www.cnblogs.com/Plume-blogs/p/15267912.html