@kyfe/hroa-ui 1.0.4 → 1.0.5

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.
Files changed (76) hide show
  1. package/dist/hroa-ui.common.js +2464 -215
  2. package/dist/hroa-ui.css +1 -1
  3. package/dist/hroa-ui.umd.js +2464 -215
  4. package/dist/hroa-ui.umd.min.js +2 -2
  5. package/lib/getJsModule/index.css +1 -1
  6. package/lib/getJsModule/index.js +2 -2
  7. package/lib/hr-add-list/index.js +1 -1
  8. package/lib/hr-bottom-button/index.js +1 -1
  9. package/lib/hr-breadcrumb/index.js +1 -1
  10. package/lib/hr-button/index.js +1 -1
  11. package/lib/hr-clipboard/index.js +1 -1
  12. package/lib/hr-collapse-card/index.css +1 -0
  13. package/lib/hr-collapse-card/index.js +1 -0
  14. package/lib/hr-condition-filtrate/index.js +1 -1
  15. package/lib/hr-condition-filtrate-popup/index.js +1 -1
  16. package/lib/hr-dropdown-date/index.css +1 -0
  17. package/lib/hr-dropdown-date/index.js +1 -0
  18. package/lib/hr-elasticity-box/index.js +1 -1
  19. package/lib/hr-elasticity-box-item/index.js +1 -1
  20. package/lib/hr-emotional-picture/index.js +1 -1
  21. package/lib/hr-employee-choose/index.js +1 -1
  22. package/lib/hr-file-list/index.js +1 -1
  23. package/lib/hr-full-screen/index.css +1 -0
  24. package/lib/hr-full-screen/index.js +1 -0
  25. package/lib/hr-img-list/index.js +1 -1
  26. package/lib/hr-info-card/index.js +1 -1
  27. package/lib/hr-information/index.css +1 -1
  28. package/lib/hr-information/index.js +1 -1
  29. package/lib/hr-license-plate-number/index.js +1 -1
  30. package/lib/hr-module-card/index.js +1 -1
  31. package/lib/hr-multiterm-choose/index.js +1 -1
  32. package/lib/hr-no-data/index.js +1 -1
  33. package/lib/hr-notice-bar/index.js +1 -1
  34. package/lib/hr-open-ks/index.js +1 -1
  35. package/lib/hr-pager/index.css +1 -1
  36. package/lib/hr-pager/index.js +1 -1
  37. package/lib/hr-popup/index.js +1 -1
  38. package/lib/hr-preview-file/index.js +1 -1
  39. package/lib/hr-rate/index.js +1 -1
  40. package/lib/hr-reason-textarea/index.js +1 -1
  41. package/lib/hr-search-input/index.js +1 -1
  42. package/lib/hr-select/index.js +1 -1
  43. package/lib/hr-select-list/index.js +1 -1
  44. package/lib/hr-single-choose/index.js +1 -1
  45. package/lib/hr-slide-pager/index.js +1 -1
  46. package/lib/hr-sort/index.js +1 -1
  47. package/lib/hr-stack-image/index.js +1 -1
  48. package/lib/hr-tab-nav/index.css +1 -1
  49. package/lib/hr-tab-nav/index.js +1 -1
  50. package/lib/hr-view-item/index.js +1 -1
  51. package/lib/index/index.css +1 -1
  52. package/lib/index/index.js +2 -2
  53. package/lib/utils/index.js +1 -1
  54. package/package.json +2 -2
  55. package/packages/hr-collapse-card/index.js +3 -0
  56. package/packages/hr-collapse-card/src/images/icon_up.png +0 -0
  57. package/packages/hr-collapse-card/src/index.vue +151 -0
  58. package/packages/hr-collapse-card//346/212/230/345/217/240/345/215/241/347/211/207.md +0 -0
  59. package/packages/hr-dropdown-date/index.js +7 -0
  60. package/packages/hr-dropdown-date/src/calendar/calendar.js +128 -0
  61. package/packages/hr-dropdown-date/src/calendar/calendar.vue +485 -0
  62. package/packages/hr-dropdown-date/src/calendar/images/arrow@3x.png +0 -0
  63. package/packages/hr-dropdown-date/src/calendar/index.js +5 -0
  64. package/packages/hr-dropdown-date/src/date-picker/date-range-select.vue +92 -0
  65. package/packages/hr-dropdown-date/src/date-picker/month-range-select.vue +128 -0
  66. package/packages/hr-dropdown-date/src/date-picker/month-select.vue +98 -0
  67. package/packages/hr-dropdown-date/src/date-picker/style.less +120 -0
  68. package/packages/hr-dropdown-date/src/date-picker/utils.js +109 -0
  69. package/packages/hr-dropdown-date/src/index.vue +482 -0
  70. package/packages/hr-dropdown-date/src/week.js +194 -0
  71. package/packages/hr-full-screen/index.js +7 -0
  72. package/packages/hr-full-screen/src/index.vue +117 -0
  73. package/packages/hr-information/src/index.vue +1 -0
  74. package/packages/hr-pager/index.js +1 -1
  75. package/packages/hr-pager/src/index.vue +6 -5
  76. package/packages/hr-tab-nav/src/index.vue +79 -4
@@ -0,0 +1,485 @@
1
+ <template>
2
+ <section class="wh_container">
3
+ <div class="wh_content_all">
4
+ <!-- 月份切换栏 -->
5
+ <div class="wh_top_changge">
6
+ <li>
7
+ <slot name="left"></slot>
8
+ </li>
9
+ <li @click="PreMonth(myDate,false)"
10
+ class="pre-warp">
11
+ <div class="wh_jiantou1">
12
+ </div>
13
+ </li>
14
+ <li class="wh_content_li">{{dateTop}}</li>
15
+ <li @click="NextMonth(myDate,false)"
16
+ class="next-warp">
17
+ <div class="wh_jiantou2"></div>
18
+ </li>
19
+ <li>
20
+ <slot name="right"></slot>
21
+ </li>
22
+ </div>
23
+ <!-- 星期指示栏 -->
24
+ <div class="wh_content">
25
+ <div class="wh_content_item wh_content_item-header"
26
+ v-for="tag in textTop"
27
+ :key="tag">
28
+ <div class="wh_top_tag">{{tag}}</div>
29
+ </div>
30
+ </div>
31
+ <!-- 日期容器 -->
32
+ <div class="wh_content">
33
+ <div class="wh_content_item wh_content_item-content"
34
+ v-for="(item,index) in list"
35
+ :key="item"
36
+ :class="{'is-week':isWeekClass(item),'is-before-half-week':isHalfWeekClass('1',item),'is-after-half-week':isHalfWeekClass('2',item)}"
37
+ @click="clickDay(item,index)">
38
+ <div class="wh_item_date"
39
+ v-bind:class="[{ wh_isMark: item.isMark},{wh_other_dayhide:item.otherMonth!=='nowMonth' || disableCheck(item.date)},{wh_want_dayhide:item.dayHide},{wh_isToday:item.isToday},{wh_chose_day:item.chooseDay}]">
40
+ <p class="wh_item_date_h1">{{item.id}}</p>
41
+ </div>
42
+ </div>
43
+ </div>
44
+ </div>
45
+ </section>
46
+ </template>
47
+ <script>
48
+ import timeUtil from "./calendar.js";
49
+ import { getWeekRange, getDayForMill } from '../week.js'
50
+
51
+ export default {
52
+ data () {
53
+ return {
54
+ myDate: new Date(),
55
+ list: [],
56
+ dateTop: '',
57
+ minStartTimestamp: null,
58
+ maxStartTimestamp: null,
59
+ minEndTimestamp: null,
60
+ maxEndTimestamp: null,
61
+ dayTimestamp: getDayForMill(1),
62
+ };
63
+ },
64
+ props: {
65
+ // 周选择器组件的时间范围
66
+ weekRange: {
67
+ type: Object
68
+ },
69
+ textTop: {
70
+ type: Array,
71
+ default: () => ["一", "二", "三", "四", "五", "六", "日"]
72
+ },
73
+ formatter: {
74
+ type: Function
75
+ },
76
+ agoDayHide: {
77
+ type: String,
78
+ default: `0`
79
+ },
80
+ futureDayHide: {
81
+ type: String,
82
+ default: `2554387200`
83
+ },
84
+ // 是否为周选择器
85
+ isWeek: {
86
+ type: Boolean,
87
+ default: true
88
+ },
89
+ },
90
+ created () {
91
+ if (this.weekRange && this.weekRange.monday) {
92
+ this.myDate = new Date(this.weekRange.monday)
93
+ } else {
94
+ this.myDate = new Date(getWeekRange(new Date()).monday)
95
+ }
96
+ },
97
+ mounted () {
98
+ console.log('周选择器----------weekRange', this.weekRange)
99
+ this.getList(this.myDate, this.weekRange)
100
+ },
101
+ watch: {
102
+ // 监听时间变化做状态回显
103
+ weekRange () {
104
+ console.log('weekRange change!!')
105
+ this.setWeekRange(this.weekRange)
106
+ }
107
+ },
108
+ methods: {
109
+ /**
110
+ * 本周之后的时间禁用
111
+ */
112
+ disableCheck (time) {
113
+ let week = getWeekRange(new Date())
114
+ let maxEndTimestamp = week.sunday
115
+ return (+new Date(time) > maxEndTimestamp)
116
+ },
117
+ /**
118
+ * @description 判断是否为选中日期的头尾
119
+ * @param { type } type 1头 2尾
120
+ * @param { Object } date 日历时间数据对象
121
+ * @returns { Boolean }
122
+ */
123
+ isHalfWeekClass (type, date) {
124
+ if (!this.isWeek) return false
125
+ switch (type) {
126
+ case '1':
127
+ if (date.timestamp >= this.minStartTimestamp && date.timestamp <= this.maxStartTimestamp) return true
128
+ break
129
+ case '2':
130
+ if (date.timestamp >= this.minEndTimestamp && date.timestamp <= this.maxEndTimestamp) return true
131
+ break
132
+ default:
133
+ break
134
+ }
135
+ return false
136
+ },
137
+ /**
138
+ * @description 判断是否为选中的日期
139
+ * @param { Object } 日历时间数据对象
140
+ * @returns { Boolean }
141
+ */
142
+ isWeekClass (date) {
143
+ if (!this.isWeek) return false
144
+ if (date.timestamp >= this.maxStartTimestamp && date.timestamp < this.minEndTimestamp) {
145
+ return true
146
+ }
147
+ return false
148
+ },
149
+ setClass (data) {
150
+ let obj = {};
151
+ obj[data.markClassName] = data.markClassName;
152
+ return obj;
153
+ },
154
+ clickDay (item) {
155
+ // 周选择器
156
+ if (this.isWeek) {
157
+ // 禁止选中当前之后的时间
158
+ let week = getWeekRange(new Date(item.date))
159
+ let _minStartTimestamp = week.monday
160
+ if (+new Date() < _minStartTimestamp) {
161
+ return false
162
+ }
163
+ // 根据选中的日期设置选中的周范围
164
+ this.setWeekRange(new Date(item.date))
165
+ this.$emit('confirm', {
166
+ monday: this.minStartTimestamp,
167
+ sunday: this.maxEndTimestamp
168
+ })
169
+ return
170
+ }
171
+ },
172
+ /**
173
+ * @description 获取上个月日历内容
174
+ */
175
+ PreMonth () {
176
+ // 获取当前日期的上个月日期
177
+ this.myDate = timeUtil.getOtherMonth(this.myDate, 'preMonth')
178
+ this.getList(this.myDate)
179
+ },
180
+ /**
181
+ * @description 获取下个月日历内容
182
+ */
183
+ NextMonth () {
184
+ // 获取当前日期的下个月日期
185
+ this.myDate = timeUtil.getOtherMonth(this.myDate, 'nextMonth')
186
+ this.getList(this.myDate)
187
+ },
188
+ /**
189
+ * @description 获取所选日期月份的所有日期
190
+ * @param { Date } date 所选日期的date对象
191
+ * @param { Object } dateRange 需要设置的选中范围
192
+ */
193
+ async getList (date, dateRange = null) {
194
+ this.dateTop = `${date.getFullYear()}年${date.getMonth() + 1}月`
195
+ // 获取所选月份的所有日期
196
+ let arr = timeUtil.getMonthList(this.myDate)
197
+ for (let i = 0; i < arr.length; i++) {
198
+ let markClassName = ''
199
+ let k = arr[i]
200
+ if (typeof (this.formatter) === 'function') {
201
+ this.formatter(k)
202
+ }
203
+ k.chooseDay = false
204
+ const nowTime = k.date
205
+ const t = new Date(nowTime).getTime() / 1000
206
+
207
+ //标记选中某些天 设置class
208
+ k.markClassName = markClassName
209
+ k.isMark = false
210
+ //无法选中某天
211
+ k.dayHide = t < this.agoDayHide || t > this.futureDayHide
212
+ if (k.isToday) {
213
+ k.isToday = false
214
+ this.$emit("isToday", nowTime)
215
+ }
216
+ }
217
+ if (this.isWeek) {
218
+ // 如果有传入dateRange,则进行日期范围回显
219
+ if (dateRange) {
220
+ this.setWeekRange(dateRange)
221
+ }
222
+ this.list = arr
223
+ }
224
+ },
225
+ /**
226
+ * @description 根据选中的日期设置选中的周范围
227
+ * @param { Date, Object } date 查询的日期/需要选中回显的日期范围
228
+ */
229
+ setWeekRange (date) {
230
+ if (typeof date === 'number') {
231
+ date = new Date(date)
232
+ }
233
+ if (date.monday && date.sunday) {
234
+ // 传入的date为指定的对象类型 则直接设置时间范围
235
+ this.minStartTimestamp = date.monday
236
+ this.maxStartTimestamp = date.monday + this.dayTimestamp - 1
237
+ this.minEndTimestamp = date.sunday - this.dayTimestamp + 1
238
+ this.maxEndTimestamp = date.sunday
239
+ } else {
240
+ let week = getWeekRange(date)
241
+ this.minStartTimestamp = week.monday
242
+ this.maxStartTimestamp = week.monday + this.dayTimestamp - 1
243
+ this.minEndTimestamp = week.sunday - this.dayTimestamp + 1
244
+ this.maxEndTimestamp = week.sunday
245
+ }
246
+ },
247
+ },
248
+ }
249
+ </script>
250
+
251
+ <style scoped lang="less">
252
+ @selectColor: #7972fe;
253
+ @dateHeaderHeight: 88px;
254
+ @itemDateHeight: 80px;
255
+ @isWeekColor: #ecebff;
256
+
257
+ .wh_container {
258
+ position: relative;
259
+ width: 750px;
260
+ height: 780px;
261
+ margin: auto;
262
+ }
263
+ .loading {
264
+ position: absolute;
265
+ width: 100%;
266
+ height: 100%;
267
+ top: 0;
268
+ /deep/ .van-loading {
269
+ margin: 40% 0 0 47%;
270
+ }
271
+ }
272
+
273
+ li {
274
+ list-style-type: none;
275
+ }
276
+ .wh_top_changge {
277
+ height: 90px;
278
+ display: flex;
279
+ }
280
+
281
+ .wh_top_changge li {
282
+ cursor: pointer;
283
+ display: flex;
284
+ color: #666666;
285
+ font-size: 30px;
286
+ flex: 1;
287
+ justify-content: center;
288
+ align-items: center;
289
+ height: 90px;
290
+ }
291
+
292
+ .wh_top_changge .wh_content_li {
293
+ cursor: auto;
294
+ flex: 1;
295
+ }
296
+ .wh_content_all {
297
+ background-color: #ffffff;
298
+ width: 100%;
299
+ overflow: hidden;
300
+ padding-bottom: 8px;
301
+ }
302
+
303
+ .wh_content {
304
+ display: flex;
305
+ flex-wrap: wrap;
306
+ padding: 0 3% 0 3%;
307
+ width: 100%;
308
+ }
309
+
310
+ .wh_content:first-child .wh_content_item_tag,
311
+ .wh_content:first-child .wh_content_item {
312
+ color: #666666;
313
+ font-size: 16px;
314
+ }
315
+
316
+ .wh_content_item,
317
+ .wh_content_item_tag {
318
+ font-size: 15px;
319
+ width: 13.4%;
320
+ text-align: center;
321
+ color: #666666;
322
+ position: relative;
323
+ }
324
+ .wh_content_item-header {
325
+ height: @dateHeaderHeight;
326
+ }
327
+
328
+ .wh_content_item-content {
329
+ height: @itemDateHeight;
330
+ }
331
+
332
+ .wh_top_tag {
333
+ font-size: 30px;
334
+ width: @dateHeaderHeight;
335
+ height: @dateHeaderHeight;
336
+ line-height: @dateHeaderHeight;
337
+ margin: auto;
338
+ display: flex;
339
+ justify-content: center;
340
+ align-items: center;
341
+ }
342
+
343
+ .wh_item_date {
344
+ width: @itemDateHeight;
345
+ height: @itemDateHeight;
346
+ line-height: @itemDateHeight;
347
+ margin: auto;
348
+ display: flex;
349
+ justify-content: center;
350
+ align-items: center;
351
+ flex-direction: column;
352
+
353
+ .wh_item_date_h1 {
354
+ margin-top: 4px;
355
+ width: 100%;
356
+ height: 30px;
357
+ line-height: 30px;
358
+ font-size: 28px;
359
+ }
360
+ .wh_item_date_h2 {
361
+ line-height: normal;
362
+ // max-width: 100%;
363
+ display: inline-block;
364
+ height: 30px;
365
+ font-size: 24px;
366
+ padding: 4px 10px;
367
+ white-space: nowrap;
368
+ overflow: hidden;
369
+ text-overflow: ellipsis;
370
+ transform: scale(0.9);
371
+ }
372
+ &__0 {
373
+ color: #cecece;
374
+ }
375
+ &__1 {
376
+ color: #ff5804;
377
+ background-color: #ffeee7;
378
+ }
379
+ &__2 {
380
+ color: #00ac00;
381
+ background-color: #e3fff4;
382
+ }
383
+ &__3 {
384
+ color: #7972fe;
385
+ background-color: #f0edff;
386
+ }
387
+ }
388
+ .wh_chose_day {
389
+ .wh_item_date_h2 {
390
+ color: #fff !important;
391
+ background-color: rgba(0, 0, 0, 0) !important;
392
+ }
393
+ }
394
+
395
+ .wh_isToday {
396
+ .wh_item_date_h2 {
397
+ color: #fff !important;
398
+ background-color: rgba(0, 0, 0, 0) !important;
399
+ }
400
+ }
401
+ .wh_top_changge .pre-warp {
402
+ flex: none;
403
+ flex-basis: 20px;
404
+ }
405
+
406
+ .wh_top_changge .next-warp {
407
+ flex: none;
408
+ flex-basis: 20px;
409
+ }
410
+
411
+ .wh_jiantou1 {
412
+ width: 48px;
413
+ height: 48px;
414
+ background-size: 30px 30px;
415
+ background-repeat: no-repeat;
416
+ background-position: center center;
417
+ background-image: url("./images/arrow@3x.png");
418
+ }
419
+
420
+ .wh_jiantou1:active,
421
+ .wh_jiantou2:active {
422
+ border-color: #ddd;
423
+ }
424
+
425
+ .wh_jiantou2 {
426
+ width: 48px;
427
+ height: 48px;
428
+ transform: rotate(-180deg);
429
+ background-size: 30px 30px;
430
+ background-repeat: no-repeat;
431
+ background-position: center center;
432
+ background-image: url("./images/arrow@3x.png");
433
+ }
434
+ .wh_content_item > .wh_isMark {
435
+ margin: auto;
436
+ border-radius: 100px;
437
+ background: #7972fe;
438
+ z-index: 2;
439
+ }
440
+ .wh_content_item .wh_other_dayhide {
441
+ color: #bfbfbf;
442
+ }
443
+ .wh_content_item .wh_want_dayhide {
444
+ color: #bfbfbf;
445
+ }
446
+ .wh_content_item .wh_isToday {
447
+ color: #fff;
448
+ background: #7972fe;
449
+ border-radius: 100px;
450
+ }
451
+ .wh_content_item .wh_chose_day {
452
+ background: #7972fe;
453
+ color: #fff;
454
+ border-radius: 100px;
455
+ }
456
+ .is-week {
457
+ background: @isWeekColor;
458
+ }
459
+ .is-before-half-week {
460
+ .wh_item_date {
461
+ color: #fff;
462
+ border-radius: 100px;
463
+ background: @selectColor;
464
+ }
465
+ background: linear-gradient(
466
+ to left,
467
+ white 51%,
468
+ white 100% #fff 0%,
469
+ #ecebff 50%
470
+ );
471
+ }
472
+ .is-after-half-week {
473
+ .wh_item_date {
474
+ color: #fff;
475
+ border-radius: 100px;
476
+ background: @selectColor;
477
+ }
478
+ background: linear-gradient(
479
+ to left,
480
+ #ecebff 51%,
481
+ white 0% #fff 100%,
482
+ white 50%
483
+ );
484
+ }
485
+ </style>
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Created by ZWH on 2017/6/22.
3
+ */
4
+ import Calendar from './calendar.vue';
5
+ export default Calendar;
@@ -0,0 +1,92 @@
1
+ <template>
2
+ <van-calendar class="ks-daterange-select ks-calendar"
3
+ :default-date="currentDate"
4
+ ref="ksDaterangedSelect"
5
+ :poppable="false"
6
+ :show-confirm="false"
7
+ :show-title="false"
8
+ :show-subtitle="false"
9
+ :min-date="currentMin"
10
+ :max-date="currentMax"
11
+ :lazy-render="false"
12
+ :safe-area-inset-bottom="false"
13
+ :allow-same-day="true"
14
+ type="range"
15
+ @select="handleSelect" />
16
+ </template>
17
+
18
+ <script>
19
+ import { formatToDate, formatToString } from './utils'
20
+
21
+ export default {
22
+ name: 'date-range-select',
23
+ props: {
24
+ defaultValue: {
25
+ type: Array,
26
+ default: () => ([])
27
+ },
28
+ min: [String, Number, Date],
29
+ max: [String, Number, Date]
30
+ },
31
+ data () {
32
+ return {
33
+ currentDate: [],
34
+ currentMin: new Date(),
35
+ currentMax: new Date()
36
+ }
37
+ },
38
+ created () {
39
+ this.init()
40
+ },
41
+ methods: {
42
+ init () {
43
+ if (this.defaultValue.length) {
44
+ this.currentDate = [formatToDate(this.defaultValue[0]), formatToDate(this.defaultValue[1])]
45
+ }
46
+ if (!this.min) {
47
+ let _date = new Date()
48
+ let y = _date.getFullYear()
49
+ let m = _date.getMonth() + 1
50
+ this.currentMin = (m - 6) < 1 ? new Date(y - 1, 12 + m - 5, 1) : new Date(y, m - 5, 1)
51
+ } else {
52
+ this.currentMin = formatToDate(this.min)
53
+ }
54
+ if (!this.max) {
55
+ let _date = new Date()
56
+ let y = _date.getFullYear()
57
+ let m = _date.getMonth() + 1
58
+ this.currentMax = (m + 6) > 12 ? new Date(y + 1, m + 6 - 12, 0) : new Date(y, m + 6, 0)
59
+ } else {
60
+ this.currentMax = formatToDate(this.max)
61
+ }
62
+ setTimeout(() => {
63
+ this.autoScroll()
64
+ })
65
+ },
66
+ /**
67
+ * @description 初始化时自动往上滚动 用于解决ios部分机型初始化日历时白屏问题
68
+ */
69
+ autoScroll () {
70
+ this.$refs.ksDaterangedSelect.$refs.body.scrollTop -= 46
71
+ },
72
+ handleSelect (e) {
73
+ this.$emit('select', { date: e, str: [formatToString(e[0]), formatToString(e[1])] })
74
+ }
75
+ }
76
+ }
77
+ </script>
78
+
79
+ <style lang="less">
80
+ .ks-daterange-select {
81
+ .van-calendar__day {
82
+ margin: 3px 0;
83
+ }
84
+ .van-calendar__day--middle {
85
+ color: #7972fe !important;
86
+ &::after {
87
+ top: 0 !important;
88
+ bottom: 0 !important;
89
+ }
90
+ }
91
+ }
92
+ </style>
@@ -0,0 +1,128 @@
1
+ <template>
2
+ <div class="van-calendar__body ks-date-picker"
3
+ ref="body">
4
+ <div class="van-calendar__month"
5
+ v-for="y of years"
6
+ :key="y">
7
+ <div class="van-calendar__month-title">{{y}}年</div>
8
+ <div class="van-calendar__days">
9
+ <div class="van-calendar__day ks-month__day"
10
+ v-for="m of months"
11
+ :key="m"
12
+ :class="{
13
+ 'van-calendar__day--disabled': (currentMin && +new Date(`${y}/${m}/1`) < currentMin) || (currentMax && +new Date(`${y}/${m}/1`) > currentMax)
14
+ }"
15
+ @click="handleSelect(y, m, (currentMin && +new Date(`${y}/${m}/1`) < currentMin) || (currentMax && +new Date(`${y}/${m}/1`) > currentMax))">
16
+ <div :class="{
17
+ 'van-calendar__day--start': +currentStart === +new Date(`${y}/${m}/1`) && +currentEnd !== +new Date(`${y}/${m}/1`),
18
+ 'van-calendar__day--end': +currentEnd === +new Date(`${y}/${m}/1`) && +currentStart !== +new Date(`${y}/${m}/1`),
19
+ 'van-calendar__day--middle': +currentStart < +new Date(`${y}/${m}/1`) && +currentEnd > +new Date(`${y}/${m}/1`),
20
+ 'van-calendar__day--start-end': +currentStart === +new Date(`${y}/${m}/1`) && +currentEnd === +new Date(`${y}/${m}/1`)
21
+ }">
22
+ {{m}}月
23
+ <div v-if="+currentStart === +new Date(`${y}/${m}/1`) || +currentEnd === +new Date(`${y}/${m}/1`)"
24
+ class="van-calendar__bottom-info">
25
+ {{
26
+ +currentStart === +new Date(`${y}/${m}/1`) && +currentEnd === +new Date(`${y}/${m}/1`)
27
+ ? '开始/结束'
28
+ : +currentStart === +new Date(`${y}/${m}/1`) && +currentEnd !== +new Date(`${y}/${m}/1`)
29
+ ? '开始'
30
+ : '结束'
31
+ }}
32
+ </div>
33
+ </div>
34
+ </div>
35
+ </div>
36
+ </div>
37
+ </div>
38
+ </template>
39
+
40
+ <script>
41
+ import { getRangeYears, foramtToMonth, formatToString } from './utils'
42
+
43
+ export default {
44
+ name: 'month-range-select',
45
+ props: {
46
+ defaultValue: {
47
+ type: Array,
48
+ default: () => ([])
49
+ },
50
+ yearRange: {
51
+ type: Array,
52
+ default: () => [new Date().getFullYear() - 5, new Date().getFullYear()],
53
+ },
54
+ horizontal: {
55
+ type: Boolean,
56
+ default: false
57
+ },
58
+ min: [String, Number, Date],
59
+ max: [String, Number, Date]
60
+ },
61
+ data () {
62
+ return {
63
+ years: getRangeYears(this.yearRange),
64
+ months: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12],
65
+ currentStart: null,
66
+ currentEnd: null,
67
+ currentMin: null,
68
+ currentMax: null
69
+ }
70
+ },
71
+ created () {
72
+ this.init()
73
+ },
74
+ methods: {
75
+ init () {
76
+ this.currentMin = this.min ? +foramtToMonth(this.min) : null
77
+ this.currentMax = this.max ? +foramtToMonth(this.max) : null
78
+ if (this.defaultValue.length === 2) {
79
+ this.currentStart = foramtToMonth(this.defaultValue[0])
80
+ this.currentEnd = foramtToMonth(this.defaultValue[1])
81
+ }
82
+ this.scrollInto()
83
+ },
84
+ scrollInto () {
85
+ setTimeout(() => {
86
+ if (this.defaultValue.length === 2) {
87
+ let top = this.$el.querySelector('.van-calendar__day--start') || this.$el.querySelector('.van-calendar__day--start-end')
88
+ this.$refs.body.scrollTop = top ? top.getBoundingClientRect().top + 80 : 0
89
+ } else {
90
+ if (this.$refs.body) {
91
+ this.$refs.body.scrollTop = 999
92
+ }
93
+ }
94
+ }, 200)
95
+ },
96
+ handleSelect (y, m, disabled) {
97
+ if (!disabled) {
98
+ let _month = foramtToMonth(`${y}/${m}`)
99
+ if (this.currentStart && !this.currentEnd && +this.currentStart <= +_month) {
100
+ this.currentEnd = _month
101
+ this.$emit('select', {
102
+ date: [this.currentStart, this.currentEnd],
103
+ str: [formatToString(this.currentStart, 'month'), formatToString(this.currentEnd, 'month')]
104
+ })
105
+ } else {
106
+ this.currentEnd = null
107
+ this.currentStart = _month
108
+ this.$emit('select', {
109
+ date: [this.currentStart, null],
110
+ str: [formatToString(this.currentStart, 'month'), '']
111
+ })
112
+ }
113
+ }
114
+ }
115
+ }
116
+ }
117
+ </script>
118
+
119
+ <style lang="less">
120
+ @import url("./style.less");
121
+ .van-calendar__body {
122
+ height: 100%;
123
+ }
124
+ .ks-month__day {
125
+ width: 16.666%;
126
+ height: 50px;
127
+ }
128
+ </style>