@vtj/materials 0.10.1-alpha.7 → 0.10.2

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.
@@ -1,421 +1,421 @@
1
- class Calendar {
2
- constructor({
3
- selected,
4
- startDate,
5
- endDate,
6
- range,
7
- } = {}) {
8
- // 当前日期
9
- this.date = this.getDateObj(new Date()) // 当前初入日期
10
- // 打点信息
11
- this.selected = selected || [];
12
- // 起始时间
13
- this.startDate = startDate
14
- // 终止时间
15
- this.endDate = endDate
16
- // 是否范围选择
17
- this.range = range
18
- // 多选状态
19
- this.cleanMultipleStatus()
20
- // 每周日期
21
- this.weeks = {}
22
- this.lastHover = false
23
- }
24
- /**
25
- * 设置日期
26
- * @param {Object} date
27
- */
28
- setDate(date) {
29
- const selectDate = this.getDateObj(date)
30
- this.getWeeks(selectDate.fullDate)
31
- }
32
-
33
- /**
34
- * 清理多选状态
35
- */
36
- cleanMultipleStatus() {
37
- this.multipleStatus = {
38
- before: '',
39
- after: '',
40
- data: []
41
- }
42
- }
43
-
44
- setStartDate(startDate) {
45
- this.startDate = startDate
46
- }
47
-
48
- setEndDate(endDate) {
49
- this.endDate = endDate
50
- }
51
-
52
- getPreMonthObj(date) {
53
- date = fixIosDateFormat(date)
54
- date = new Date(date)
55
-
56
- const oldMonth = date.getMonth()
57
- date.setMonth(oldMonth - 1)
58
- const newMonth = date.getMonth()
59
- if (oldMonth !== 0 && newMonth - oldMonth === 0) {
60
- date.setMonth(newMonth - 1)
61
- }
62
- return this.getDateObj(date)
63
- }
64
- getNextMonthObj(date) {
65
- date = fixIosDateFormat(date)
66
- date = new Date(date)
67
-
68
- const oldMonth = date.getMonth()
69
- date.setMonth(oldMonth + 1)
70
- const newMonth = date.getMonth()
71
- if (newMonth - oldMonth > 1) {
72
- date.setMonth(newMonth - 1)
73
- }
74
- return this.getDateObj(date)
75
- }
76
-
77
- /**
78
- * 获取指定格式Date对象
79
- */
80
- getDateObj(date) {
81
- date = fixIosDateFormat(date)
82
- date = new Date(date)
83
-
84
- return {
85
- fullDate: getDate(date),
86
- year: date.getFullYear(),
87
- month: addZero(date.getMonth() + 1),
88
- date: addZero(date.getDate()),
89
- day: date.getDay()
90
- }
91
- }
92
-
93
- /**
94
- * 获取上一个月日期集合
95
- */
96
- getPreMonthDays(amount, dateObj) {
97
- const result = []
98
- for (let i = amount - 1; i >= 0; i--) {
99
- const month = dateObj.month - 1
100
- result.push({
101
- date: new Date(dateObj.year, month, -i).getDate(),
102
- month,
103
- disable: true
104
- })
105
- }
106
- return result
107
- }
108
- /**
109
- * 获取本月日期集合
110
- */
111
- getCurrentMonthDays(amount, dateObj) {
112
- const result = []
113
- const fullDate = this.date.fullDate
114
- for (let i = 1; i <= amount; i++) {
115
- const currentDate = `${dateObj.year}-${dateObj.month}-${addZero(i)}`
116
- const isToday = fullDate === currentDate
117
- // 获取打点信息
118
- const info = this.selected && this.selected.find((item) => {
119
- if (this.dateEqual(currentDate, item.date)) {
120
- return item
121
- }
122
- })
123
-
124
- // 日期禁用
125
- let disableBefore = true
126
- let disableAfter = true
127
- if (this.startDate) {
128
- disableBefore = dateCompare(this.startDate, currentDate)
129
- }
130
-
131
- if (this.endDate) {
132
- disableAfter = dateCompare(currentDate, this.endDate)
133
- }
134
-
135
- let multiples = this.multipleStatus.data
136
- let multiplesStatus = -1
137
- if (this.range && multiples) {
138
- multiplesStatus = multiples.findIndex((item) => {
139
- return this.dateEqual(item, currentDate)
140
- })
141
- }
142
- const checked = multiplesStatus !== -1
143
-
144
- result.push({
145
- fullDate: currentDate,
146
- year: dateObj.year,
147
- date: i,
148
- multiple: this.range ? checked : false,
149
- beforeMultiple: this.isLogicBefore(currentDate, this.multipleStatus.before, this.multipleStatus.after),
150
- afterMultiple: this.isLogicAfter(currentDate, this.multipleStatus.before, this.multipleStatus.after),
151
- month: dateObj.month,
152
- disable: (this.startDate && !dateCompare(this.startDate, currentDate)) || (this.endDate && !dateCompare(
153
- currentDate, this.endDate)),
154
- isToday,
155
- userChecked: false,
156
- extraInfo: info
157
- })
158
- }
159
- return result
160
- }
161
- /**
162
- * 获取下一个月日期集合
163
- */
164
- _getNextMonthDays(amount, dateObj) {
165
- const result = []
166
- const month = dateObj.month + 1
167
- for (let i = 1; i <= amount; i++) {
168
- result.push({
169
- date: i,
170
- month,
171
- disable: true
172
- })
173
- }
174
- return result
175
- }
176
-
177
- /**
178
- * 获取当前日期详情
179
- * @param {Object} date
180
- */
181
- getInfo(date) {
182
- if (!date) {
183
- date = new Date()
184
- }
185
- const res = this.calendar.find(item => item.fullDate === this.getDateObj(date).fullDate)
186
- return res ? res : this.getDateObj(date)
187
- }
188
-
189
- /**
190
- * 比较时间是否相等
191
- */
192
- dateEqual(before, after) {
193
- before = new Date(fixIosDateFormat(before))
194
- after = new Date(fixIosDateFormat(after))
195
- return before.valueOf() === after.valueOf()
196
- }
197
-
198
- /**
199
- * 比较真实起始日期
200
- */
201
-
202
- isLogicBefore(currentDate, before, after) {
203
- let logicBefore = before
204
- if (before && after) {
205
- logicBefore = dateCompare(before, after) ? before : after
206
- }
207
- return this.dateEqual(logicBefore, currentDate)
208
- }
209
-
210
- isLogicAfter(currentDate, before, after) {
211
- let logicAfter = after
212
- if (before && after) {
213
- logicAfter = dateCompare(before, after) ? after : before
214
- }
215
- return this.dateEqual(logicAfter, currentDate)
216
- }
217
-
218
- /**
219
- * 获取日期范围内所有日期
220
- * @param {Object} begin
221
- * @param {Object} end
222
- */
223
- geDateAll(begin, end) {
224
- var arr = []
225
- var ab = begin.split('-')
226
- var ae = end.split('-')
227
- var db = new Date()
228
- db.setFullYear(ab[0], ab[1] - 1, ab[2])
229
- var de = new Date()
230
- de.setFullYear(ae[0], ae[1] - 1, ae[2])
231
- var unixDb = db.getTime() - 24 * 60 * 60 * 1000
232
- var unixDe = de.getTime() - 24 * 60 * 60 * 1000
233
- for (var k = unixDb; k <= unixDe;) {
234
- k = k + 24 * 60 * 60 * 1000
235
- arr.push(this.getDateObj(new Date(parseInt(k))).fullDate)
236
- }
237
- return arr
238
- }
239
-
240
- /**
241
- * 获取多选状态
242
- */
243
- setMultiple(fullDate) {
244
- if (!this.range) return
245
-
246
- let {
247
- before,
248
- after
249
- } = this.multipleStatus
250
- if (before && after) {
251
- if (!this.lastHover) {
252
- this.lastHover = true
253
- return
254
- }
255
- this.multipleStatus.before = fullDate
256
- this.multipleStatus.after = ''
257
- this.multipleStatus.data = []
258
- this.multipleStatus.fulldate = ''
259
- this.lastHover = false
260
- } else {
261
- if (!before) {
262
- this.multipleStatus.before = fullDate
263
- this.multipleStatus.after = undefined;
264
- this.lastHover = false
265
- } else {
266
- this.multipleStatus.after = fullDate
267
- if (dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
268
- this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus
269
- .after);
270
- } else {
271
- this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus
272
- .before);
273
- }
274
- this.lastHover = true
275
- }
276
- }
277
- this.getWeeks(fullDate)
278
- }
279
-
280
- /**
281
- * 鼠标 hover 更新多选状态
282
- */
283
- setHoverMultiple(fullDate) {
284
- //抖音小程序点击会触发hover事件,需要避免一下
285
- // #ifndef MP-TOUTIAO
286
- if (!this.range || this.lastHover) return
287
- const {
288
- before
289
- } = this.multipleStatus
290
-
291
- if (!before) {
292
- this.multipleStatus.before = fullDate
293
- } else {
294
- this.multipleStatus.after = fullDate
295
- if (dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
296
- this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus.after);
297
- } else {
298
- this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus.before);
299
- }
300
- }
301
- this.getWeeks(fullDate)
302
- // #endif
303
-
304
- }
305
-
306
- /**
307
- * 更新默认值多选状态
308
- */
309
- setDefaultMultiple(before, after) {
310
- this.multipleStatus.before = before
311
- this.multipleStatus.after = after
312
- if (before && after) {
313
- if (dateCompare(before, after)) {
314
- this.multipleStatus.data = this.geDateAll(before, after);
315
- this.getWeeks(after)
316
- } else {
317
- this.multipleStatus.data = this.geDateAll(after, before);
318
- this.getWeeks(before)
319
- }
320
- }
321
- }
322
-
323
- /**
324
- * 获取每周数据
325
- * @param {Object} dateData
326
- */
327
- getWeeks(dateData) {
328
- const {
329
- year,
330
- month,
331
- } = this.getDateObj(dateData)
332
-
333
- const preMonthDayAmount = new Date(year, month - 1, 1).getDay()
334
- const preMonthDays = this.getPreMonthDays(preMonthDayAmount, this.getDateObj(dateData))
335
-
336
- const currentMonthDayAmount = new Date(year, month, 0).getDate()
337
- const currentMonthDays = this.getCurrentMonthDays(currentMonthDayAmount, this.getDateObj(dateData))
338
-
339
- const nextMonthDayAmount = 42 - preMonthDayAmount - currentMonthDayAmount
340
- const nextMonthDays = this._getNextMonthDays(nextMonthDayAmount, this.getDateObj(dateData))
341
-
342
- const calendarDays = [...preMonthDays, ...currentMonthDays, ...nextMonthDays]
343
-
344
- const weeks = new Array(6)
345
- for (let i = 0; i < calendarDays.length; i++) {
346
- const index = Math.floor(i / 7)
347
- if (!weeks[index]) {
348
- weeks[index] = new Array(7)
349
- }
350
- weeks[index][i % 7] = calendarDays[i]
351
- }
352
-
353
- this.calendar = calendarDays
354
- this.weeks = weeks
355
- }
356
- }
357
-
358
- function getDateTime(date, hideSecond) {
359
- return `${getDate(date)} ${getTime(date, hideSecond)}`
360
- }
361
-
362
- function getDate(date) {
363
- date = fixIosDateFormat(date)
364
- date = new Date(date)
365
- const year = date.getFullYear()
366
- const month = date.getMonth() + 1
367
- const day = date.getDate()
368
- return `${year}-${addZero(month)}-${addZero(day)}`
369
- }
370
-
371
- function getTime(date, hideSecond) {
372
- date = fixIosDateFormat(date)
373
- date = new Date(date)
374
- const hour = date.getHours()
375
- const minute = date.getMinutes()
376
- const second = date.getSeconds()
377
- return hideSecond ? `${addZero(hour)}:${addZero(minute)}` : `${addZero(hour)}:${addZero(minute)}:${addZero(second)}`
378
- }
379
-
380
- function addZero(num) {
381
- if (num < 10) {
382
- num = `0${num}`
383
- }
384
- return num
385
- }
386
-
387
- function getDefaultSecond(hideSecond) {
388
- return hideSecond ? '00:00' : '00:00:00'
389
- }
390
-
391
- function dateCompare(startDate, endDate) {
392
- startDate = new Date(fixIosDateFormat(startDate))
393
- endDate = new Date(fixIosDateFormat(endDate))
394
- return startDate <= endDate
395
- }
396
-
397
- function checkDate(date) {
398
- const dateReg = /((19|20)\d{2})(-|\/)\d{1,2}(-|\/)\d{1,2}/g
399
- return date.match(dateReg)
400
- }
1
+ class Calendar {
2
+ constructor({
3
+ selected,
4
+ startDate,
5
+ endDate,
6
+ range,
7
+ } = {}) {
8
+ // 当前日期
9
+ this.date = this.getDateObj(new Date()) // 当前初入日期
10
+ // 打点信息
11
+ this.selected = selected || [];
12
+ // 起始时间
13
+ this.startDate = startDate
14
+ // 终止时间
15
+ this.endDate = endDate
16
+ // 是否范围选择
17
+ this.range = range
18
+ // 多选状态
19
+ this.cleanMultipleStatus()
20
+ // 每周日期
21
+ this.weeks = {}
22
+ this.lastHover = false
23
+ }
24
+ /**
25
+ * 设置日期
26
+ * @param {Object} date
27
+ */
28
+ setDate(date) {
29
+ const selectDate = this.getDateObj(date)
30
+ this.getWeeks(selectDate.fullDate)
31
+ }
32
+
33
+ /**
34
+ * 清理多选状态
35
+ */
36
+ cleanMultipleStatus() {
37
+ this.multipleStatus = {
38
+ before: '',
39
+ after: '',
40
+ data: []
41
+ }
42
+ }
43
+
44
+ setStartDate(startDate) {
45
+ this.startDate = startDate
46
+ }
47
+
48
+ setEndDate(endDate) {
49
+ this.endDate = endDate
50
+ }
51
+
52
+ getPreMonthObj(date) {
53
+ date = fixIosDateFormat(date)
54
+ date = new Date(date)
55
+
56
+ const oldMonth = date.getMonth()
57
+ date.setMonth(oldMonth - 1)
58
+ const newMonth = date.getMonth()
59
+ if (oldMonth !== 0 && newMonth - oldMonth === 0) {
60
+ date.setMonth(newMonth - 1)
61
+ }
62
+ return this.getDateObj(date)
63
+ }
64
+ getNextMonthObj(date) {
65
+ date = fixIosDateFormat(date)
66
+ date = new Date(date)
67
+
68
+ const oldMonth = date.getMonth()
69
+ date.setMonth(oldMonth + 1)
70
+ const newMonth = date.getMonth()
71
+ if (newMonth - oldMonth > 1) {
72
+ date.setMonth(newMonth - 1)
73
+ }
74
+ return this.getDateObj(date)
75
+ }
76
+
77
+ /**
78
+ * 获取指定格式Date对象
79
+ */
80
+ getDateObj(date) {
81
+ date = fixIosDateFormat(date)
82
+ date = new Date(date)
83
+
84
+ return {
85
+ fullDate: getDate(date),
86
+ year: date.getFullYear(),
87
+ month: addZero(date.getMonth() + 1),
88
+ date: addZero(date.getDate()),
89
+ day: date.getDay()
90
+ }
91
+ }
92
+
93
+ /**
94
+ * 获取上一个月日期集合
95
+ */
96
+ getPreMonthDays(amount, dateObj) {
97
+ const result = []
98
+ for (let i = amount - 1; i >= 0; i--) {
99
+ const month = dateObj.month - 1
100
+ result.push({
101
+ date: new Date(dateObj.year, month, -i).getDate(),
102
+ month,
103
+ disable: true
104
+ })
105
+ }
106
+ return result
107
+ }
108
+ /**
109
+ * 获取本月日期集合
110
+ */
111
+ getCurrentMonthDays(amount, dateObj) {
112
+ const result = []
113
+ const fullDate = this.date.fullDate
114
+ for (let i = 1; i <= amount; i++) {
115
+ const currentDate = `${dateObj.year}-${dateObj.month}-${addZero(i)}`
116
+ const isToday = fullDate === currentDate
117
+ // 获取打点信息
118
+ const info = this.selected && this.selected.find((item) => {
119
+ if (this.dateEqual(currentDate, item.date)) {
120
+ return item
121
+ }
122
+ })
123
+
124
+ // 日期禁用
125
+ let disableBefore = true
126
+ let disableAfter = true
127
+ if (this.startDate) {
128
+ disableBefore = dateCompare(this.startDate, currentDate)
129
+ }
130
+
131
+ if (this.endDate) {
132
+ disableAfter = dateCompare(currentDate, this.endDate)
133
+ }
134
+
135
+ let multiples = this.multipleStatus.data
136
+ let multiplesStatus = -1
137
+ if (this.range && multiples) {
138
+ multiplesStatus = multiples.findIndex((item) => {
139
+ return this.dateEqual(item, currentDate)
140
+ })
141
+ }
142
+ const checked = multiplesStatus !== -1
143
+
144
+ result.push({
145
+ fullDate: currentDate,
146
+ year: dateObj.year,
147
+ date: i,
148
+ multiple: this.range ? checked : false,
149
+ beforeMultiple: this.isLogicBefore(currentDate, this.multipleStatus.before, this.multipleStatus.after),
150
+ afterMultiple: this.isLogicAfter(currentDate, this.multipleStatus.before, this.multipleStatus.after),
151
+ month: dateObj.month,
152
+ disable: (this.startDate && !dateCompare(this.startDate, currentDate)) || (this.endDate && !dateCompare(
153
+ currentDate, this.endDate)),
154
+ isToday,
155
+ userChecked: false,
156
+ extraInfo: info
157
+ })
158
+ }
159
+ return result
160
+ }
161
+ /**
162
+ * 获取下一个月日期集合
163
+ */
164
+ _getNextMonthDays(amount, dateObj) {
165
+ const result = []
166
+ const month = dateObj.month + 1
167
+ for (let i = 1; i <= amount; i++) {
168
+ result.push({
169
+ date: i,
170
+ month,
171
+ disable: true
172
+ })
173
+ }
174
+ return result
175
+ }
176
+
177
+ /**
178
+ * 获取当前日期详情
179
+ * @param {Object} date
180
+ */
181
+ getInfo(date) {
182
+ if (!date) {
183
+ date = new Date()
184
+ }
185
+ const res = this.calendar.find(item => item.fullDate === this.getDateObj(date).fullDate)
186
+ return res ? res : this.getDateObj(date)
187
+ }
188
+
189
+ /**
190
+ * 比较时间是否相等
191
+ */
192
+ dateEqual(before, after) {
193
+ before = new Date(fixIosDateFormat(before))
194
+ after = new Date(fixIosDateFormat(after))
195
+ return before.valueOf() === after.valueOf()
196
+ }
197
+
198
+ /**
199
+ * 比较真实起始日期
200
+ */
201
+
202
+ isLogicBefore(currentDate, before, after) {
203
+ let logicBefore = before
204
+ if (before && after) {
205
+ logicBefore = dateCompare(before, after) ? before : after
206
+ }
207
+ return this.dateEqual(logicBefore, currentDate)
208
+ }
209
+
210
+ isLogicAfter(currentDate, before, after) {
211
+ let logicAfter = after
212
+ if (before && after) {
213
+ logicAfter = dateCompare(before, after) ? after : before
214
+ }
215
+ return this.dateEqual(logicAfter, currentDate)
216
+ }
217
+
218
+ /**
219
+ * 获取日期范围内所有日期
220
+ * @param {Object} begin
221
+ * @param {Object} end
222
+ */
223
+ geDateAll(begin, end) {
224
+ var arr = []
225
+ var ab = begin.split('-')
226
+ var ae = end.split('-')
227
+ var db = new Date()
228
+ db.setFullYear(ab[0], ab[1] - 1, ab[2])
229
+ var de = new Date()
230
+ de.setFullYear(ae[0], ae[1] - 1, ae[2])
231
+ var unixDb = db.getTime() - 24 * 60 * 60 * 1000
232
+ var unixDe = de.getTime() - 24 * 60 * 60 * 1000
233
+ for (var k = unixDb; k <= unixDe;) {
234
+ k = k + 24 * 60 * 60 * 1000
235
+ arr.push(this.getDateObj(new Date(parseInt(k))).fullDate)
236
+ }
237
+ return arr
238
+ }
239
+
240
+ /**
241
+ * 获取多选状态
242
+ */
243
+ setMultiple(fullDate) {
244
+ if (!this.range) return
245
+
246
+ let {
247
+ before,
248
+ after
249
+ } = this.multipleStatus
250
+ if (before && after) {
251
+ if (!this.lastHover) {
252
+ this.lastHover = true
253
+ return
254
+ }
255
+ this.multipleStatus.before = fullDate
256
+ this.multipleStatus.after = ''
257
+ this.multipleStatus.data = []
258
+ this.multipleStatus.fulldate = ''
259
+ this.lastHover = false
260
+ } else {
261
+ if (!before) {
262
+ this.multipleStatus.before = fullDate
263
+ this.multipleStatus.after = undefined;
264
+ this.lastHover = false
265
+ } else {
266
+ this.multipleStatus.after = fullDate
267
+ if (dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
268
+ this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus
269
+ .after);
270
+ } else {
271
+ this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus
272
+ .before);
273
+ }
274
+ this.lastHover = true
275
+ }
276
+ }
277
+ this.getWeeks(fullDate)
278
+ }
279
+
280
+ /**
281
+ * 鼠标 hover 更新多选状态
282
+ */
283
+ setHoverMultiple(fullDate) {
284
+ //抖音小程序点击会触发hover事件,需要避免一下
285
+ // #ifndef MP-TOUTIAO
286
+ if (!this.range || this.lastHover) return
287
+ const {
288
+ before
289
+ } = this.multipleStatus
290
+
291
+ if (!before) {
292
+ this.multipleStatus.before = fullDate
293
+ } else {
294
+ this.multipleStatus.after = fullDate
295
+ if (dateCompare(this.multipleStatus.before, this.multipleStatus.after)) {
296
+ this.multipleStatus.data = this.geDateAll(this.multipleStatus.before, this.multipleStatus.after);
297
+ } else {
298
+ this.multipleStatus.data = this.geDateAll(this.multipleStatus.after, this.multipleStatus.before);
299
+ }
300
+ }
301
+ this.getWeeks(fullDate)
302
+ // #endif
303
+
304
+ }
305
+
306
+ /**
307
+ * 更新默认值多选状态
308
+ */
309
+ setDefaultMultiple(before, after) {
310
+ this.multipleStatus.before = before
311
+ this.multipleStatus.after = after
312
+ if (before && after) {
313
+ if (dateCompare(before, after)) {
314
+ this.multipleStatus.data = this.geDateAll(before, after);
315
+ this.getWeeks(after)
316
+ } else {
317
+ this.multipleStatus.data = this.geDateAll(after, before);
318
+ this.getWeeks(before)
319
+ }
320
+ }
321
+ }
322
+
323
+ /**
324
+ * 获取每周数据
325
+ * @param {Object} dateData
326
+ */
327
+ getWeeks(dateData) {
328
+ const {
329
+ year,
330
+ month,
331
+ } = this.getDateObj(dateData)
332
+
333
+ const preMonthDayAmount = new Date(year, month - 1, 1).getDay()
334
+ const preMonthDays = this.getPreMonthDays(preMonthDayAmount, this.getDateObj(dateData))
335
+
336
+ const currentMonthDayAmount = new Date(year, month, 0).getDate()
337
+ const currentMonthDays = this.getCurrentMonthDays(currentMonthDayAmount, this.getDateObj(dateData))
338
+
339
+ const nextMonthDayAmount = 42 - preMonthDayAmount - currentMonthDayAmount
340
+ const nextMonthDays = this._getNextMonthDays(nextMonthDayAmount, this.getDateObj(dateData))
341
+
342
+ const calendarDays = [...preMonthDays, ...currentMonthDays, ...nextMonthDays]
343
+
344
+ const weeks = new Array(6)
345
+ for (let i = 0; i < calendarDays.length; i++) {
346
+ const index = Math.floor(i / 7)
347
+ if (!weeks[index]) {
348
+ weeks[index] = new Array(7)
349
+ }
350
+ weeks[index][i % 7] = calendarDays[i]
351
+ }
352
+
353
+ this.calendar = calendarDays
354
+ this.weeks = weeks
355
+ }
356
+ }
357
+
358
+ function getDateTime(date, hideSecond) {
359
+ return `${getDate(date)} ${getTime(date, hideSecond)}`
360
+ }
361
+
362
+ function getDate(date) {
363
+ date = fixIosDateFormat(date)
364
+ date = new Date(date)
365
+ const year = date.getFullYear()
366
+ const month = date.getMonth() + 1
367
+ const day = date.getDate()
368
+ return `${year}-${addZero(month)}-${addZero(day)}`
369
+ }
370
+
371
+ function getTime(date, hideSecond) {
372
+ date = fixIosDateFormat(date)
373
+ date = new Date(date)
374
+ const hour = date.getHours()
375
+ const minute = date.getMinutes()
376
+ const second = date.getSeconds()
377
+ return hideSecond ? `${addZero(hour)}:${addZero(minute)}` : `${addZero(hour)}:${addZero(minute)}:${addZero(second)}`
378
+ }
379
+
380
+ function addZero(num) {
381
+ if (num < 10) {
382
+ num = `0${num}`
383
+ }
384
+ return num
385
+ }
386
+
387
+ function getDefaultSecond(hideSecond) {
388
+ return hideSecond ? '00:00' : '00:00:00'
389
+ }
390
+
391
+ function dateCompare(startDate, endDate) {
392
+ startDate = new Date(fixIosDateFormat(startDate))
393
+ endDate = new Date(fixIosDateFormat(endDate))
394
+ return startDate <= endDate
395
+ }
396
+
397
+ function checkDate(date) {
398
+ const dateReg = /((19|20)\d{2})(-|\/)\d{1,2}(-|\/)\d{1,2}/g
399
+ return date.match(dateReg)
400
+ }
401
401
  //ios低版本15及以下,无法匹配 没有 ’秒‘ 时的情况,所以需要在末尾 秒 加上 问号
402
- const dateTimeReg = /^\d{4}-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])( [0-5]?[0-9]:[0-5]?[0-9](:[0-5]?[0-9])?)?$/;
403
-
404
- function fixIosDateFormat(value) {
405
- if (typeof value === 'string' && dateTimeReg.test(value)) {
406
- value = value.replace(/-/g, '/')
407
- }
408
- return value
409
- }
410
-
411
- export {
412
- Calendar,
413
- getDateTime,
414
- getDate,
415
- getTime,
416
- addZero,
417
- getDefaultSecond,
418
- dateCompare,
419
- checkDate,
420
- fixIosDateFormat
402
+ const dateTimeReg = /^\d{4}-(0?[1-9]|1[012])-(0?[1-9]|[12][0-9]|3[01])( [0-5]?[0-9]:[0-5]?[0-9](:[0-5]?[0-9])?)?$/;
403
+
404
+ function fixIosDateFormat(value) {
405
+ if (typeof value === 'string' && dateTimeReg.test(value)) {
406
+ value = value.replace(/-/g, '/')
407
+ }
408
+ return value
409
+ }
410
+
411
+ export {
412
+ Calendar,
413
+ getDateTime,
414
+ getDate,
415
+ getTime,
416
+ addZero,
417
+ getDefaultSecond,
418
+ dateCompare,
419
+ checkDate,
420
+ fixIosDateFormat
421
421
  }