-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalendarMonth.vue
115 lines (112 loc) · 2.99 KB
/
calendarMonth.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<template>
<div class="mu-calendar-monthday-content">
<div class="mu-calendar-monthday-row" :key="i" v-for="(week, i) in weeksArray">
<button
v-for="(date, j) in week"
:disabled="isDisableDate(date)"
:key="'dayButton' + i + '' + j"
:selected="equalsDate(date)"
:class="dayButtonClass(date)"
@click="handleClick(date)"
v-if="date">
<div class="mu-day-button-bg"></div>
<span class="mu-day-button-text" v-text="date.getDate()"></span>
</button>
<span v-else class="mu-day-empty"></span>
</div>
</div>
</template>
<script>
import * as dateUtils from '../../../es/dateUtils';
export default {
data() {
return {
weeksArray: dateUtils.getWeekArray(this.displayDate || new Date(), this.firstDayOfWeek),
};
},
props: {
displayDate: {
type: Date,
},
firstDayOfWeek: {
type: Number,
default: 1,
},
maxDate: {
type: Date,
},
minDate: {
type: Date,
},
startDate: {
type: Date,
},
endDate: {
type: Date,
},
shouldDisableDate: {
type: Function,
},
},
computed: {},
methods: {
equalsDate(date) {
return dateUtils.isEqualDate(date, this.startDate) || dateUtils.isEqualDate(date, this.endDate);
},
isStartDate(date) {
return dateUtils.isEqualDate(date, this.startDate);
},
isEndDate(date) {
return dateUtils.isEqualDate(date, this.endDate);
},
range(date) {
return dateUtils.isBetweenDates(date, this.startDate, this.endDate);
},
isDisableDate(day) {
if (day === null) return false;
let disabled = false;
if (this.maxDate && this.minDate) disabled = !dateUtils.isBetweenDates(day, this.minDate, this.maxDate);
if (!disabled && this.shouldDisableDate) disabled = this.shouldDisableDate(day, this.startDate, this.endDate);
return disabled;
},
handleClick(date) {
if (date) this.$emit('selected', date);
},
isNow(date) {
const now = new Date();
return date && date.getYear() === now.getYear() && date.getMonth() === now.getMonth() && date.getDate() === now.getDate();
},
dayButtonClass(date) {
return {
selected: this.equalsDate(date),
selectedRange: this.range(date),
'mu-day-button': true,
disabled: this.isDisableDate(date),
now: this.isNow(date),
startDate: this.isStartDate(date),
endDate: this.isEndDate(date),
};
},
},
watch: {
displayDate(val) {
return dateUtils.getWeekArray(val || new Date(), this.firstDayOfWeek);
},
},
};
</script>
<style lang="scss">
.mu-calendar-monthday-content {
.selectedRange {
background-color: #6ecaff;
&.startDate{
background-color: transparent;
background: linear-gradient(to right, white 50%, #6ecaff 50%);
}
&.endDate{
background-color: transparent;
background: linear-gradient(to right, #6ecaff 50%, white 50%);
}
}
}
</style>