mali-applet-ui 1.0.158 → 1.0.159
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import XEUtils from 'xe-utils'
|
|
2
|
+
|
|
3
|
+
// 判断是否是闰年,
|
|
4
|
+
const isLeapYear = (year) => {
|
|
5
|
+
if (year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0)) {
|
|
6
|
+
return true
|
|
7
|
+
}
|
|
8
|
+
return false
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// 获取当前月份的总天数
|
|
12
|
+
const totalDaysByDate = (date) => {
|
|
13
|
+
const today = new Date(date)
|
|
14
|
+
const year = today.getFullYear()
|
|
15
|
+
const month = today.getMonth() + 1
|
|
16
|
+
let monthDay = 31
|
|
17
|
+
switch (month) {
|
|
18
|
+
case 1: monthDay = 31; break
|
|
19
|
+
case 2:
|
|
20
|
+
if (isLeapYear(year)) {
|
|
21
|
+
monthDay = 29
|
|
22
|
+
} else {
|
|
23
|
+
monthDay = 28
|
|
24
|
+
}
|
|
25
|
+
break
|
|
26
|
+
case 3: monthDay = 31; break
|
|
27
|
+
case 4: monthDay = 30; break
|
|
28
|
+
case 5: monthDay = 31; break
|
|
29
|
+
case 6: monthDay = 30; break
|
|
30
|
+
case 7: monthDay = 31; break
|
|
31
|
+
case 8: monthDay = 31; break
|
|
32
|
+
case 9: monthDay = 30; break
|
|
33
|
+
case 10: monthDay = 31; break
|
|
34
|
+
case 11: monthDay = 30; break
|
|
35
|
+
case 12: monthDay = 31; break
|
|
36
|
+
}
|
|
37
|
+
return monthDay
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 获取当前月份数据
|
|
41
|
+
export const getDaysByDate = (date) => {
|
|
42
|
+
// 获取总天数
|
|
43
|
+
const totalDays = totalDaysByDate(date)
|
|
44
|
+
const days = []
|
|
45
|
+
const thisMonth = new Date(date)
|
|
46
|
+
const todayDate = new Date()
|
|
47
|
+
const today = XEUtils.toDateString(todayDate, 'yyyy-MM-dd')
|
|
48
|
+
for (let i = 1; i <= totalDays; i++) {
|
|
49
|
+
thisMonth.setDate(i)
|
|
50
|
+
const dateFormat = {
|
|
51
|
+
date: XEUtils.toDateString(thisMonth, 'yyyy-MM-dd'),
|
|
52
|
+
day: XEUtils.toDateString(thisMonth, 'd'),
|
|
53
|
+
statusList: []
|
|
54
|
+
}
|
|
55
|
+
if (dateFormat.date === today) {
|
|
56
|
+
dateFormat.isToday = true
|
|
57
|
+
} else {
|
|
58
|
+
if (todayDate.getTime() < thisMonth.getTime()) {
|
|
59
|
+
dateFormat.isNotYet = true
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
days.push(dateFormat)
|
|
63
|
+
}
|
|
64
|
+
const { previousMonth, nextMonth } = completion(date)
|
|
65
|
+
return [...previousMonth, ...days, ...nextMonth]
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 获取这个月的第一天和左后一天
|
|
69
|
+
const getMonthInfo = (date) => {
|
|
70
|
+
const designatedDate = new Date(date)
|
|
71
|
+
const nowMonth = designatedDate.getMonth() // 当前月
|
|
72
|
+
const nowYear = designatedDate.getFullYear() // 当前年
|
|
73
|
+
// 本月的开始时间
|
|
74
|
+
const monthStartDate = new Date(nowYear, nowMonth, 1)
|
|
75
|
+
// 本月的结束时间
|
|
76
|
+
const monthEndDate = new Date(nowYear, nowMonth + 1, 0)
|
|
77
|
+
return {
|
|
78
|
+
start: monthStartDate,
|
|
79
|
+
end: monthEndDate
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 补全开头和结尾
|
|
84
|
+
const completion = (date) => {
|
|
85
|
+
const { start: startDate, end: endDate } = getMonthInfo(date)
|
|
86
|
+
const startWeek = startDate.getDay()
|
|
87
|
+
const endWeek = endDate.getDay()
|
|
88
|
+
const startDifference = startWeek
|
|
89
|
+
const endDifference = 7 - endWeek
|
|
90
|
+
const previousMonth = []
|
|
91
|
+
const nextMonth = []
|
|
92
|
+
const todayDate = new Date()
|
|
93
|
+
const today = XEUtils.toDateString(todayDate, 'yyyy-MM-dd')
|
|
94
|
+
for (let i = startDifference; i > 0; i--) {
|
|
95
|
+
let needDate = new Date(startDate.getTime())
|
|
96
|
+
needDate = needDate.setDate(needDate.getDate() - i)
|
|
97
|
+
needDate = new Date(needDate)
|
|
98
|
+
const dateFormat = {
|
|
99
|
+
date: XEUtils.toDateString(needDate, 'yyyy-MM-dd'),
|
|
100
|
+
day: XEUtils.toDateString(needDate, 'd'),
|
|
101
|
+
statusList: [],
|
|
102
|
+
isLastMonth: true
|
|
103
|
+
}
|
|
104
|
+
if (dateFormat.date === today) {
|
|
105
|
+
dateFormat.isToday = true
|
|
106
|
+
} else {
|
|
107
|
+
if (todayDate.getTime() < needDate.getTime()) {
|
|
108
|
+
dateFormat.isNotYet = true
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
previousMonth.push(dateFormat)
|
|
112
|
+
}
|
|
113
|
+
for (let i = 1; i < endDifference; i++) {
|
|
114
|
+
let needDate = new Date(endDate.getTime())
|
|
115
|
+
needDate = needDate.setDate(needDate.getDate() + i)
|
|
116
|
+
needDate = new Date(needDate)
|
|
117
|
+
const dateFormat = {
|
|
118
|
+
date: XEUtils.toDateString(needDate, 'yyyy-MM-dd'),
|
|
119
|
+
day: XEUtils.toDateString(needDate, 'd'),
|
|
120
|
+
statusList: [],
|
|
121
|
+
isNextMonth: true
|
|
122
|
+
}
|
|
123
|
+
if (dateFormat.date === today) {
|
|
124
|
+
dateFormat.isToday = true
|
|
125
|
+
} else {
|
|
126
|
+
if (todayDate.getTime() < needDate.getTime()) {
|
|
127
|
+
dateFormat.isNotYet = true
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
nextMonth.push(dateFormat)
|
|
131
|
+
}
|
|
132
|
+
return {
|
|
133
|
+
previousMonth,
|
|
134
|
+
nextMonth
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// 每组多少
|
|
139
|
+
export const getGroupArray = (list) => {
|
|
140
|
+
const arr = []
|
|
141
|
+
for (let i = 0; i < list.length; i += 7) {
|
|
142
|
+
arr.push(list.slice(i, i + 7))
|
|
143
|
+
}
|
|
144
|
+
return arr
|
|
145
|
+
}
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
</template>
|
|
49
49
|
|
|
50
50
|
<script>
|
|
51
|
-
import { Calendar, GroupArray } from './calendar.js'
|
|
52
51
|
import XEUtils from 'xe-utils'
|
|
52
|
+
import { getDaysByDate, getGroupArray } from './handle.js'
|
|
53
53
|
|
|
54
54
|
export default {
|
|
55
55
|
name: 'MlCalendar',
|
|
@@ -130,8 +130,8 @@ export default {
|
|
|
130
130
|
if (!date) {
|
|
131
131
|
date = new Date()
|
|
132
132
|
}
|
|
133
|
-
const dates =
|
|
134
|
-
this.months =
|
|
133
|
+
const dates = getDaysByDate(this.selectMonth)
|
|
134
|
+
this.months = getGroupArray(dates, 7)
|
|
135
135
|
this.loadsChedule()
|
|
136
136
|
},
|
|
137
137
|
toggleFold () {
|
|
@@ -145,9 +145,9 @@ export default {
|
|
|
145
145
|
this.selectDay = value
|
|
146
146
|
this.selectMonth = XEUtils.toStringDate(value)
|
|
147
147
|
if (item.isLastMonth) {
|
|
148
|
-
this.
|
|
148
|
+
this.updateCalendar()
|
|
149
149
|
} else if (item.isNextMonth) {
|
|
150
|
-
this.
|
|
150
|
+
this.updateCalendar()
|
|
151
151
|
}
|
|
152
152
|
this.$emit('input', value)
|
|
153
153
|
this.$emit('click', { value })
|
|
@@ -183,9 +183,9 @@ export default {
|
|
|
183
183
|
background-color: #FFFFFF;
|
|
184
184
|
.ml-calendar-header {
|
|
185
185
|
display: flex;
|
|
186
|
-
justify-content: space-between;
|
|
187
186
|
align-items: center;
|
|
188
|
-
|
|
187
|
+
border-bottom: 1px solid #e8e8e8;
|
|
188
|
+
padding-bottom: 20rpx;
|
|
189
189
|
.ml-calendar-header-title {
|
|
190
190
|
flex-grow: 1;
|
|
191
191
|
text-align: center;
|
|
@@ -195,7 +195,8 @@ export default {
|
|
|
195
195
|
}
|
|
196
196
|
.ml-calendar-header-button {
|
|
197
197
|
flex-shrink: 0;
|
|
198
|
-
border:
|
|
198
|
+
border: 0;
|
|
199
|
+
background: #fff;
|
|
199
200
|
padding: 10rpx;
|
|
200
201
|
border-radius: 8rpx;
|
|
201
202
|
text-align: center;
|
|
@@ -206,15 +207,14 @@ export default {
|
|
|
206
207
|
.ml-calendar-date-head {
|
|
207
208
|
display: flex;
|
|
208
209
|
align-items: center;
|
|
209
|
-
margin: 0 -10rpx;
|
|
210
210
|
margin-bottom: 10rpx;
|
|
211
211
|
.ml-calendar-week-item {
|
|
212
212
|
flex-grow: 1;
|
|
213
213
|
.ml-calendar-week-box {
|
|
214
214
|
color: #999999;
|
|
215
215
|
text-align: center;
|
|
216
|
-
width:
|
|
217
|
-
height:
|
|
216
|
+
width: 80rpx;
|
|
217
|
+
height: 80rpx;
|
|
218
218
|
margin: auto;
|
|
219
219
|
display: flex;
|
|
220
220
|
justify-content: center;
|
|
@@ -230,7 +230,6 @@ export default {
|
|
|
230
230
|
.ml-calendar-date-week-list {
|
|
231
231
|
display: flex;
|
|
232
232
|
align-items: center;
|
|
233
|
-
margin: 0 -10rpx;
|
|
234
233
|
margin-bottom: 10rpx;
|
|
235
234
|
.ml-calendar-date-day-item {
|
|
236
235
|
flex-grow: 1;
|