bi-eleme 2.2.1 → 2.4.1

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 (130) hide show
  1. package/lib/alert.js +4 -4
  2. package/lib/aside.js +4 -4
  3. package/lib/autocomplete.js +10 -10
  4. package/lib/avatar.js +4 -4
  5. package/lib/backtop.js +6 -6
  6. package/lib/badge.js +4 -4
  7. package/lib/breadcrumb-item.js +4 -4
  8. package/lib/breadcrumb.js +4 -4
  9. package/lib/button-group.js +4 -4
  10. package/lib/button.js +4 -4
  11. package/lib/calendar.js +15 -15
  12. package/lib/card.js +4 -4
  13. package/lib/carousel-item.js +4 -4
  14. package/lib/carousel.js +6 -6
  15. package/lib/cascader-panel.js +10 -10
  16. package/lib/cascader.js +12 -12
  17. package/lib/checkbox-button.js +4 -4
  18. package/lib/checkbox-group.js +4 -4
  19. package/lib/checkbox.js +4 -4
  20. package/lib/col.js +2 -2
  21. package/lib/collapse-item.js +6 -6
  22. package/lib/collapse.js +4 -4
  23. package/lib/color-picker.js +8 -8
  24. package/lib/container.js +4 -4
  25. package/lib/date-picker.js +65 -64
  26. package/lib/descriptions-item.js +2 -2
  27. package/lib/descriptions.js +2 -2
  28. package/lib/dialog.js +8 -8
  29. package/lib/divider.js +4 -4
  30. package/lib/drawer.js +6 -6
  31. package/lib/dropdown-item.js +4 -4
  32. package/lib/dropdown-menu.js +4 -4
  33. package/lib/dropdown.js +16 -16
  34. package/lib/element-ui.common.js +4773 -311
  35. package/lib/empty.js +4 -4
  36. package/lib/footer.js +4 -4
  37. package/lib/form-item.js +6 -6
  38. package/lib/form.js +11 -11
  39. package/lib/header.js +4 -4
  40. package/lib/icon.js +4 -4
  41. package/lib/image.js +8 -8
  42. package/lib/index.js +1 -1
  43. package/lib/infinite-scroll.js +2 -2
  44. package/lib/input-number.js +6 -6
  45. package/lib/input.js +6 -6
  46. package/lib/link.js +4 -4
  47. package/lib/loading.js +6 -6
  48. package/lib/main.js +4 -4
  49. package/lib/menu-item-group.js +4 -4
  50. package/lib/menu-item.js +6 -6
  51. package/lib/menu.js +6 -6
  52. package/lib/message-box.js +13 -13
  53. package/lib/message.js +8 -8
  54. package/lib/notification.js +8 -8
  55. package/lib/option-group.js +4 -4
  56. package/lib/option.js +4 -4
  57. package/lib/page-header.js +4 -4
  58. package/lib/pagination.js +4 -4
  59. package/lib/popconfirm.js +8 -8
  60. package/lib/popover.js +4 -4
  61. package/lib/progress.js +4 -4
  62. package/lib/radio-button.js +4 -4
  63. package/lib/radio-group.js +4 -4
  64. package/lib/radio.js +4 -4
  65. package/lib/rate.js +6 -6
  66. package/lib/result.js +4 -4
  67. package/lib/row.js +2 -2
  68. package/lib/scrollbar.js +2 -2
  69. package/lib/select.js +16 -16
  70. package/lib/skeleton-item.js +4 -4
  71. package/lib/skeleton.js +4 -4
  72. package/lib/slider.js +8 -8
  73. package/lib/spinner.js +4 -4
  74. package/lib/step.js +4 -4
  75. package/lib/steps.js +6 -6
  76. package/lib/submenu.js +6 -6
  77. package/lib/super-date.js +4833 -0
  78. package/lib/switch.js +6 -6
  79. package/lib/tab-pane.js +4 -4
  80. package/lib/table-column.js +2 -2
  81. package/lib/table.js +20 -18
  82. package/lib/tabs.js +4 -4
  83. package/lib/tag.js +4 -4
  84. package/lib/theme-chalk/index.css +1 -1
  85. package/lib/theme-chalk/super-date.css +1 -0
  86. package/lib/time-picker.js +59 -59
  87. package/lib/time-select.js +16 -16
  88. package/lib/timeline-item.js +4 -4
  89. package/lib/timeline.js +4 -4
  90. package/lib/tooltip.js +2 -2
  91. package/lib/transfer.js +8 -8
  92. package/lib/tree.js +6 -6
  93. package/lib/upload.js +15 -15
  94. package/lib/utils/date-util.js +5 -2
  95. package/lib/utils/date.js +67 -9
  96. package/package.json +1 -1
  97. package/packages/super-date/index.js +8 -0
  98. package/packages/super-date/src/basic/date-table.vue +448 -0
  99. package/packages/super-date/src/basic/month-table.vue +278 -0
  100. package/packages/super-date/src/basic/time-spinner.vue +340 -0
  101. package/packages/super-date/src/basic/year-table.vue +144 -0
  102. package/packages/super-date/src/panel/date-range.vue +1000 -0
  103. package/packages/super-date/src/panel/date.vue +649 -0
  104. package/packages/super-date/src/panel/month-range.vue +289 -0
  105. package/packages/super-date/src/panel/time-range.vue +250 -0
  106. package/packages/super-date/src/panel/time-select.vue +195 -0
  107. package/packages/super-date/src/panel/time.vue +211 -0
  108. package/packages/super-date/src/picker/date-picker.js +29 -0
  109. package/packages/super-date/src/picker/time-picker.js +39 -0
  110. package/packages/super-date/src/picker/time-select.js +21 -0
  111. package/packages/super-date/src/picker.vue +956 -0
  112. package/packages/theme-chalk/lib/index.css +1 -1
  113. package/packages/theme-chalk/lib/super-date.css +1 -0
  114. package/packages/theme-chalk/src/index.scss +1 -0
  115. package/packages/theme-chalk/src/super-date/date-picker.scss +106 -0
  116. package/packages/theme-chalk/src/super-date/date-range-picker.scss +138 -0
  117. package/packages/theme-chalk/src/super-date/date-table.scss +154 -0
  118. package/packages/theme-chalk/src/super-date/month-table.scss +96 -0
  119. package/packages/theme-chalk/src/super-date/picker-panel.scss +130 -0
  120. package/packages/theme-chalk/src/super-date/picker.scss +204 -0
  121. package/packages/theme-chalk/src/super-date/time-picker.scss +94 -0
  122. package/packages/theme-chalk/src/super-date/time-range-picker.scss +32 -0
  123. package/packages/theme-chalk/src/super-date/time-spinner.scss +111 -0
  124. package/packages/theme-chalk/src/super-date/year-table.scss +66 -0
  125. package/packages/theme-chalk/src/super-date.scss +12 -0
  126. package/src/index.js +4 -1
  127. package/src/utils/date-util.js +3 -0
  128. package/src/utils/date.js +291 -195
  129. package/types/element-ui.d.ts +9 -5
  130. package/types/super-date.d.ts +124 -0
@@ -0,0 +1,1000 @@
1
+ <template>
2
+ <transition
3
+ name="el-zoom-in-top"
4
+ @after-leave="$emit('dodestroy')"
5
+ >
6
+ <div
7
+ v-show="visible"
8
+ class="el-super-date-panel el-picker-panel el-super-date-range-picker el-popper"
9
+ :class="[{
10
+ 'has-sidebar': $slots.sidebar || shortcuts,
11
+ 'has-time': showTime
12
+ }, popperClass]"
13
+ >
14
+ <div class="el-picker-panel__body-wrapper">
15
+ <slot
16
+ name="sidebar"
17
+ class="el-picker-panel__sidebar"
18
+ ></slot>
19
+ <div
20
+ class="el-picker-panel__sidebar"
21
+ v-if="shortcuts"
22
+ >
23
+ <button
24
+ type="button"
25
+ class="el-picker-panel__shortcut"
26
+ v-for="(shortcut, key) in shortcuts"
27
+ :key="key"
28
+ @click="handleShortcutClick(shortcut)"
29
+ >{{shortcut.text}}</button>
30
+ </div>
31
+ <div class="el-picker-panel__body">
32
+ <div class="rang-text">
33
+ <!-- {{ rangeText }} -->
34
+ <p>{{ formatRangeText(emitValue) }}</p>
35
+ </div>
36
+ <el-tabs
37
+ v-model="panelType"
38
+ @tab-click="handleDateTypeChange"
39
+ >
40
+ <!-- 静态时间 -->
41
+ <el-tab-pane
42
+ label="静态时间"
43
+ name="static"
44
+ >
45
+ <div>
46
+ <div class="el-picker-panel__content el-super-date-range-picker__content is-left">
47
+ <div class="el-super-date-range-picker__header">
48
+ <button
49
+ type="button"
50
+ @click="leftPrevYear"
51
+ class="el-picker-panel__icon-btn el-icon-left1"
52
+ ></button>
53
+ <button
54
+ type="button"
55
+ @click="leftPrevMonth"
56
+ class="el-picker-panel__icon-btn el-icon-left"
57
+ ></button>
58
+ <button
59
+ type="button"
60
+ @click="leftNextYear"
61
+ v-if="unlinkPanels"
62
+ :disabled="!enableYearArrow"
63
+ :class="{ 'is-disabled': !enableYearArrow }"
64
+ class="el-picker-panel__icon-btn el-icon-right1-2"
65
+ ></button>
66
+ <button
67
+ type="button"
68
+ @click="leftNextMonth"
69
+ v-if="unlinkPanels"
70
+ :disabled="!enableMonthArrow"
71
+ :class="{ 'is-disabled': !enableMonthArrow }"
72
+ class="el-picker-panel__icon-btn el-icon-right"
73
+ ></button>
74
+ <div>{{ leftLabel }}</div>
75
+ </div>
76
+ <date-table
77
+ selection-mode="range"
78
+ :date="leftDate"
79
+ :default-value="defaultValue"
80
+ :min-date="minDate"
81
+ :max-date="maxDate"
82
+ :range-state="rangeState"
83
+ :disabled-date="staticDisabledDate"
84
+ :cell-class-name="cellClassName"
85
+ @changerange="handleChangeRange"
86
+ :first-day-of-week="firstDayOfWeek"
87
+ @pick="handleRangePick"
88
+ >
89
+ </date-table>
90
+ </div>
91
+ <div class="el-picker-panel__content el-super-date-range-picker__content is-right">
92
+ <div class="el-super-date-range-picker__header">
93
+ <button
94
+ type="button"
95
+ @click="rightPrevYear"
96
+ v-if="unlinkPanels"
97
+ :disabled="!enableYearArrow"
98
+ :class="{ 'is-disabled': !enableYearArrow }"
99
+ class="el-picker-panel__icon-btn el-icon-left1"
100
+ ></button>
101
+ <button
102
+ type="button"
103
+ @click="rightPrevMonth"
104
+ v-if="unlinkPanels"
105
+ :disabled="!enableMonthArrow"
106
+ :class="{ 'is-disabled': !enableMonthArrow }"
107
+ class="el-picker-panel__icon-btn el-icon-left"
108
+ ></button>
109
+ <button
110
+ type="button"
111
+ @click="rightNextYear"
112
+ class="el-picker-panel__icon-btn el-icon-right1-2"
113
+ ></button>
114
+ <button
115
+ type="button"
116
+ @click="rightNextMonth"
117
+ class="el-picker-panel__icon-btn el-icon-right"
118
+ ></button>
119
+ <div>{{ rightLabel }}</div>
120
+ </div>
121
+ <date-table
122
+ selection-mode="range"
123
+ :date="rightDate"
124
+ :default-value="defaultValue"
125
+ :min-date="minDate"
126
+ :max-date="maxDate"
127
+ :range-state="rangeState"
128
+ :disabled-date="staticDisabledDate"
129
+ :cell-class-name="cellClassName"
130
+ @changerange="handleChangeRange"
131
+ :first-day-of-week="firstDayOfWeek"
132
+ @pick="handleRangePick"
133
+ >
134
+ </date-table>
135
+ </div>
136
+ </div>
137
+
138
+ </el-tab-pane>
139
+ <el-tab-pane
140
+ label="动态时间"
141
+ name="dynamic"
142
+ >
143
+ <div>
144
+ <div class="el-picker-panel__content el-super-date-range-picker__content is-left">
145
+ <div class="dynamic-content">
146
+ <div class="dynamic-header">
147
+ <el-button
148
+ :type="dynamicTypeLeft === 'specific'?'primary':''"
149
+ @click="handleDynamicType('specific')"
150
+ >具体时间</el-button>
151
+ <el-button
152
+ :type="dynamicTypeLeft === 'past'?'primary':''"
153
+ @click="handleDynamicType('past')"
154
+ >过去N天</el-button>
155
+
156
+ </div>
157
+ <div
158
+ v-if="dynamicTypeLeft === 'past'"
159
+ style="height:200px"
160
+ >
161
+ <el-input v-model.number="dynamicRange[0]"></el-input>
162
+ </div>
163
+ <div v-if="dynamicTypeLeft === 'specific'">
164
+ <div class="el-super-date-range-picker__header">
165
+ <button
166
+ type="button"
167
+ @click="dynamicPrevYear"
168
+ class="el-picker-panel__icon-btn el-icon-left1"
169
+ ></button>
170
+ <button
171
+ type="button"
172
+ @click="dynamicPrevMonth"
173
+ class="el-picker-panel__icon-btn el-icon-left"
174
+ ></button>
175
+ <button
176
+ type="button"
177
+ @click="dynamicNextYear"
178
+ class="el-picker-panel__icon-btn el-icon-right1-2"
179
+ ></button>
180
+ <button
181
+ type="button"
182
+ @click="dynamicNextMonth"
183
+ class="el-picker-panel__icon-btn el-icon-right"
184
+ ></button>
185
+ <div>{{ dynamicLabel }}</div>
186
+ </div>
187
+ <date-table
188
+ @pick="handleDatePick"
189
+ selection-mode="day"
190
+ :first-day-of-week="firstDayOfWeek"
191
+ :value="dynamicDate"
192
+ :default-value="dynamicDate ? new Date(dynamicDate) : null"
193
+ :date="dynamicValue"
194
+ :cell-class-name="cellClassName"
195
+ :disabled-date="dynamicDisabledDate"
196
+ :utc="8"
197
+ >
198
+ </date-table>
199
+ </div>
200
+ </div>
201
+ </div>
202
+ <div class="el-picker-panel__content el-super-date-range-picker__content is-right">
203
+ <div class="dynamic-content">
204
+ <div class="dynamic-header">
205
+ <el-button
206
+ :type="dynamicTypeRight==='today'?'primary':''"
207
+ @click="handleDynamicRange(0)"
208
+ >今日</el-button>
209
+ <el-button
210
+ :type="dynamicTypeRight==='yesterday'?'primary':''"
211
+ @click="handleDynamicRange(1)"
212
+ >昨日</el-button>
213
+ <el-button
214
+ :type="dynamicTypeRight==='past'?'primary':''"
215
+ @click="handleDynamicRange(2)"
216
+ >过去N天</el-button>
217
+ </div>
218
+ <div v-show="dynamicTypeRight==='past'">
219
+ <el-input v-model.number="dynamicRange[1]"></el-input>
220
+ </div>
221
+ </div>
222
+ </div>
223
+ </div>
224
+ </el-tab-pane>
225
+ </el-tabs>
226
+
227
+ <div
228
+ v-show="needTime"
229
+ class="el-super-date-range-picker__time-header"
230
+ >
231
+ <span class="el-super-date-range-picker__editors-wrap">
232
+
233
+ <span
234
+ class="el-super-date-range-picker__time-picker-wrap"
235
+ v-clickoutside="handleMinTimeClose"
236
+ >
237
+ <el-input
238
+ size="small"
239
+ class="el-super-date-range-picker__editor"
240
+ :disabled="rangeState.selecting"
241
+ :placeholder="t('el.datepicker.startTime')"
242
+ :value="minVisibleTime"
243
+ @focus="minTimePickerVisible = true"
244
+ @input="val => handleTimeInput(val, 'min')"
245
+ @change="val => handleTimeChange(val, 'min')"
246
+ />
247
+ <time-picker
248
+ ref="minTimePicker"
249
+ @pick="handleMinTimePick"
250
+ :time-arrow-control="arrowControl"
251
+ :visible="minTimePickerVisible"
252
+ @mounted="$refs.minTimePicker.format=timeFormat"
253
+ >
254
+ </time-picker>
255
+ </span>
256
+ </span>
257
+ <span class="el-super-date-range-picker__editors-wrap is-right">
258
+ <span
259
+ class="el-super-date-range-picker__time-picker-wrap"
260
+ v-clickoutside="handleMaxTimeClose"
261
+ >
262
+ <el-input
263
+ size="small"
264
+ class="el-super-date-range-picker__editor"
265
+ :disabled="rangeState.selecting"
266
+ :placeholder="t('el.datepicker.endTime')"
267
+ :value="maxVisibleTime"
268
+ :readonly="!minDate"
269
+ @focus="minDate && (maxTimePickerVisible = true)"
270
+ @input="val => handleTimeInput(val, 'max')"
271
+ @change="val => handleTimeChange(val, 'max')"
272
+ />
273
+ <time-picker
274
+ ref="maxTimePicker"
275
+ @pick="handleMaxTimePick"
276
+ :time-arrow-control="arrowControl"
277
+ :visible="maxTimePickerVisible"
278
+ @mounted="$refs.maxTimePicker.format=timeFormat"
279
+ >
280
+ </time-picker>
281
+ </span>
282
+ </span>
283
+ </div>
284
+ </div>
285
+ </div>
286
+ <div
287
+ class="el-picker-panel__footer"
288
+ v-if="showTime"
289
+ >
290
+ <el-button
291
+ size="mini"
292
+ type="text"
293
+ class="el-picker-panel__link-btn"
294
+ @click="handleClear"
295
+ >
296
+ {{ t('el.datepicker.clear') }}
297
+ </el-button>
298
+ <el-button
299
+ type="primary"
300
+ size="mini"
301
+ class="el-picker-panel__link-btn"
302
+ :disabled="btnDisabled"
303
+ @click="handleConfirm(false)"
304
+ >
305
+ {{ t('el.datepicker.confirm') }}
306
+ </el-button>
307
+ </div>
308
+ </div>
309
+ </transition>
310
+ </template>
311
+
312
+ <script type="text/babel">
313
+ import { formatDate, parseDate, isDate, modifyDate, modifyTime, modifyWithTimeString, prevYear, nextYear, prevMonth, nextMonth, nextDate, extractDateFormat, extractTimeFormat, getDaysDiff, setDaysDiff } from 'bi-eleme/src/utils/date-util'
314
+ import Clickoutside from 'bi-eleme/src/utils/clickoutside'
315
+ import Locale from 'bi-eleme/src/mixins/locale'
316
+ import TimePicker from './time'
317
+ import DateTable from '../basic/date-table'
318
+ import ElInput from 'bi-eleme/packages/input'
319
+ import ElButton from 'bi-eleme/packages/button'
320
+ import ElTabs from 'bi-eleme/packages/tabs'
321
+
322
+ const calcDefaultValue = (defaultValue) => {
323
+ if (Array.isArray(defaultValue)) {
324
+ return [new Date(defaultValue[0]), new Date(defaultValue[1])]
325
+ } else if (defaultValue) {
326
+ return [new Date(defaultValue), nextDate(new Date(defaultValue), 1)]
327
+ } else {
328
+ return [new Date(), nextDate(new Date(), 1)]
329
+ }
330
+ }
331
+
332
+ export default {
333
+ mixins: [Locale],
334
+
335
+ directives: { Clickoutside },
336
+
337
+ computed: {
338
+ rangeText() {
339
+ return `${this.minVisibleDate} ${this.rangeSeparator} ${this.maxVisibleDate}`
340
+ },
341
+
342
+ btnDisabled() {
343
+ if (this.panelType === 'dynamic') {
344
+ if (this.dynamicTypeLeft === 'specific') {
345
+ if (!this.dynamicDate) return true
346
+ // 将具体时间和动态时间范围进行比较
347
+ const specificDate = new Date(this.dynamicDate)
348
+ const endDate = setDaysDiff(new Date(), this.dynamicRange[1])
349
+ return specificDate > endDate
350
+ }
351
+ return typeof this.dynamicRange[0] !== 'number' || typeof this.dynamicRange[1] !== 'number' || this.dynamicRange[0] < 0 || this.dynamicRange[1] < 0 || this.dynamicRange[0] < this.dynamicRange[1]
352
+ }
353
+ return !(this.minDate && this.maxDate && !this.selecting && this.minDate <= this.maxDate && this.isValidValue([this.minDate, this.maxDate]))
354
+ },
355
+
356
+ leftLabel() {
357
+ return this.leftDate.getFullYear() + ' ' + this.t('el.datepicker.year') + ' ' + this.t(`el.datepicker.month${this.leftDate.getMonth() + 1}`)
358
+ },
359
+
360
+ rightLabel() {
361
+ return this.rightDate.getFullYear() + ' ' + this.t('el.datepicker.year') + ' ' + this.t(`el.datepicker.month${this.rightDate.getMonth() + 1}`)
362
+ },
363
+
364
+ dynamicLabel() {
365
+ return this.dynamicValue.getFullYear() + ' ' + this.t('el.datepicker.year') + ' ' + this.t(`el.datepicker.month${this.dynamicValue.getMonth() + 1}`)
366
+ },
367
+
368
+ leftYear() {
369
+ return this.leftDate.getFullYear()
370
+ },
371
+
372
+ leftMonth() {
373
+ return this.leftDate.getMonth()
374
+ },
375
+
376
+ leftMonthDate() {
377
+ return this.leftDate.getDate()
378
+ },
379
+
380
+ rightYear() {
381
+ return this.rightDate.getFullYear()
382
+ },
383
+
384
+ rightMonth() {
385
+ return this.rightDate.getMonth()
386
+ },
387
+
388
+ rightMonthDate() {
389
+ return this.rightDate.getDate()
390
+ },
391
+
392
+ minVisibleDate() {
393
+ if (this.dateUserInput.min !== null) return this.dateUserInput.min
394
+ if (this.minDate) return formatDate(this.minDate, this.dateFormat)
395
+ return ''
396
+ },
397
+
398
+ maxVisibleDate() {
399
+ if (this.dateUserInput.max !== null) return this.dateUserInput.max
400
+ if (this.maxDate || this.minDate) return formatDate(this.maxDate || this.minDate, this.dateFormat)
401
+ return ''
402
+ },
403
+
404
+ minVisibleTime() {
405
+ if (this.timeUserInput.min !== null) return this.timeUserInput.min
406
+ if (this.minDate) return formatDate(this.minDate, this.timeFormat)
407
+ return ''
408
+ },
409
+
410
+ maxVisibleTime() {
411
+ if (this.timeUserInput.max !== null) return this.timeUserInput.max
412
+ if (this.maxDate || this.minDate) return formatDate(this.maxDate || this.minDate, this.timeFormat)
413
+ return ''
414
+ },
415
+
416
+ timeFormat() {
417
+ if (this.format) {
418
+ return extractTimeFormat(this.format)
419
+ } else {
420
+ return 'HH:mm:ss'
421
+ }
422
+ },
423
+
424
+ dateFormat() {
425
+ if (this.format) {
426
+ return extractDateFormat(this.format)
427
+ } else {
428
+ return 'yyyy-MM-dd'
429
+ }
430
+ },
431
+
432
+ enableMonthArrow() {
433
+ const nextMonth = (this.leftMonth + 1) % 12
434
+ const yearOffset = this.leftMonth + 1 >= 12 ? 1 : 0
435
+ return this.unlinkPanels && new Date(this.leftYear + yearOffset, nextMonth) < new Date(this.rightYear, this.rightMonth)
436
+ },
437
+
438
+ enableYearArrow() {
439
+ return this.unlinkPanels && this.rightYear * 12 + this.rightMonth - (this.leftYear * 12 + this.leftMonth + 1) >= 12
440
+ },
441
+ emitValue() {
442
+ return {
443
+ date: [this.minDate, this.maxDate].map((date) => (date ? formatDate(date, this.dateFormat) : null)),
444
+ time: [this.minDate, this.maxDate].map((date) => (date ? formatDate(date, this.timeFormat) : null)),
445
+ type: this.panelType,
446
+ dynamicRange: this.dynamicRange
447
+ }
448
+ }
449
+ },
450
+
451
+ data() {
452
+ return {
453
+ dateUserInput: {
454
+ min: null,
455
+ max: null
456
+ },
457
+ timeUserInput: {
458
+ min: null,
459
+ max: null
460
+ },
461
+ popperClass: '',
462
+ value: {
463
+ date: [],
464
+ time: [],
465
+ type: 'static',
466
+ dynamicRange: []
467
+ },
468
+ dynamicDate: '',
469
+ dynamicValue: new Date(),
470
+ defaultValue: null,
471
+ defaultTime: ['00:00:00', '23:59:59'],
472
+ panelType: 'static',
473
+ rangeSeparator: '',
474
+ minDate: '',
475
+ maxDate: '',
476
+ leftDate: new Date(),
477
+ rightDate: nextMonth(new Date()),
478
+ rangeState: {
479
+ endDate: null,
480
+ selecting: false,
481
+ row: null,
482
+ column: null
483
+ },
484
+ showTime: !false,
485
+ shortcuts: '',
486
+ visible: '',
487
+ disabledDate: '',
488
+ cellClassName: '',
489
+ firstDayOfWeek: 7,
490
+ minTimePickerVisible: false,
491
+ maxTimePickerVisible: false,
492
+ format: '',
493
+ arrowControl: false,
494
+ unlinkPanels: false,
495
+ dateUserInput: {
496
+ min: null,
497
+ max: null
498
+ },
499
+ timeUserInput: {
500
+ min: null,
501
+ max: null
502
+ },
503
+ dynamicRange: [0, 0],
504
+ dynamicTypeLeft: 'past', // specific | past
505
+ dynamicTypeRight: 'past', // today | yesterday | past
506
+ selectableDays: [],
507
+ needTime: false
508
+ }
509
+ },
510
+
511
+ watch: {
512
+ // 'dynamicRange.0': {
513
+ // handler(val) {
514
+ // if (this.panelType === 'dynamic') {
515
+ // const newDate = new Date()
516
+ // this.dynamicValue = modifyWithTimeString(setDaysDiff(newDate, val), this.defaultTime[0])
517
+ // this.dynamicDate = formatDate(this.dynamicValue, 'yyyy-MM-dd')
518
+ // }
519
+ // },
520
+ // immediate: true
521
+ // },
522
+ minDate(val) {
523
+ this.dateUserInput.min = null
524
+ this.timeUserInput.min = null
525
+ this.$nextTick(() => {
526
+ if (this.$refs.maxTimePicker && this.maxDate && this.maxDate < this.minDate) {
527
+ const format = 'HH:mm:ss'
528
+ this.$refs.maxTimePicker.selectableRange = [[parseDate(formatDate(this.minDate, format), format), parseDate('23:59:59', format)]]
529
+ }
530
+ })
531
+ if (val && this.$refs.minTimePicker) {
532
+ this.$refs.minTimePicker.date = val
533
+ this.$refs.minTimePicker.value = val
534
+ }
535
+ },
536
+
537
+ maxDate(val) {
538
+ this.dateUserInput.max = null
539
+ this.timeUserInput.max = null
540
+ if (val && this.$refs.maxTimePicker) {
541
+ this.$refs.maxTimePicker.date = val
542
+ this.$refs.maxTimePicker.value = val
543
+ }
544
+ },
545
+
546
+ minTimePickerVisible(val) {
547
+ if (val) {
548
+ this.$nextTick(() => {
549
+ this.$refs.minTimePicker.date = this.minDate
550
+ this.$refs.minTimePicker.value = this.minDate
551
+ this.$refs.minTimePicker.adjustSpinners()
552
+ })
553
+ }
554
+ },
555
+
556
+ maxTimePickerVisible(val) {
557
+ if (val) {
558
+ this.$nextTick(() => {
559
+ this.$refs.maxTimePicker.date = this.maxDate
560
+ this.$refs.maxTimePicker.value = this.maxDate
561
+ this.$refs.maxTimePicker.adjustSpinners()
562
+ })
563
+ }
564
+ },
565
+
566
+ value(newVal) {
567
+ this.initDate(newVal)
568
+ },
569
+
570
+ defaultValue(val) {
571
+ if (!Array.isArray(this.value)) {
572
+ const [left, right] = calcDefaultValue(val)
573
+ this.leftDate = left
574
+ this.rightDate = val && val[1] && this.unlinkPanels ? right : nextMonth(this.leftDate)
575
+ }
576
+ },
577
+ visible(value) {
578
+ if (value) {
579
+ this.initDate()
580
+ }
581
+ }
582
+ },
583
+
584
+ methods: {
585
+ getDaysDiff(time) {
586
+ return getDaysDiff(time)
587
+ },
588
+ setDaysDiff(time, diff) {
589
+ return setDaysDiff(time, diff)
590
+ },
591
+ formatDate(date, format = 'yyyy-MM-dd') {
592
+ return setDmodifyWithTimeStringaysDiff(date, format)
593
+ },
594
+ setDaysDiffAndFormat(time, diff, format = 'yyyy-MM-dd') {
595
+ const newDate = setDaysDiff(time, diff)
596
+ return formatDate(newDate, format)
597
+ },
598
+ staticDisabledDate(time) {
599
+ // 检查 selectableDays 是否有效
600
+ if (!Array.isArray(this.selectableDays) || this.selectableDays.length !== 2 || !this.selectableDays.every((v) => typeof v === 'number')) {
601
+ return false
602
+ }
603
+ const daysDiff = getDaysDiff(time)
604
+ return daysDiff < this.selectableDays[0] || daysDiff > this.selectableDays[1]
605
+ },
606
+ dynamicDisabledDate(time) {
607
+ return getDaysDiff(time) < 3
608
+ },
609
+ initDate(newVal = this.value) {
610
+ console.log('🚀 ~ newVal:', newVal)
611
+ try {
612
+ if (!newVal) {
613
+ this.minDate = null
614
+ this.maxDate = null
615
+ this.panelType = 'static'
616
+ this.dynamicValue = null
617
+ } else {
618
+ const { date, time, type, dynamicRange } = Object.assign({}, newVal)
619
+ this.panelType = type || 'static'
620
+
621
+ if (Array.isArray(date)) {
622
+ this.minDate = isDate(date[0]) ? new Date(date[0]) : modifyWithTimeString(new Date(), time[0])
623
+ this.maxDate = isDate(date[1]) ? new Date(date[1]) : modifyWithTimeString(new Date(), time[1])
624
+
625
+ if (Array.isArray(time) && time.length === 2) {
626
+ if (this.minDate) this.minDate = modifyWithTimeString(this.minDate, time[0])
627
+ if (this.maxDate) this.maxDate = modifyWithTimeString(this.maxDate, time[1])
628
+ }
629
+
630
+ if (this.minDate) {
631
+ this.leftDate = this.minDate
632
+ if (this.unlinkPanels && this.maxDate) {
633
+ const minDateYear = this.minDate.getFullYear()
634
+ const minDateMonth = this.minDate.getMonth()
635
+ const maxDateYear = this.maxDate.getFullYear()
636
+ const maxDateMonth = this.maxDate.getMonth()
637
+ this.rightDate = minDateYear === maxDateYear && minDateMonth === maxDateMonth ? nextMonth(this.maxDate) : this.maxDate
638
+ } else {
639
+ this.rightDate = nextMonth(this.leftDate)
640
+ }
641
+ } else {
642
+ this.leftDate = calcDefaultValue(this.defaultValue)[0]
643
+ this.rightDate = nextMonth(this.leftDate)
644
+ }
645
+ }
646
+
647
+ if (this.panelType === 'static') {
648
+ this.dynamicRange = [getDaysDiff(this.minDate), getDaysDiff(this.maxDate)]
649
+
650
+ this.dynamicValue = modifyWithTimeString(setDaysDiff(new Date(), this.dynamicRange[0]), time[0])
651
+ this.dynamicDate = formatDate(this.dynamicValue, 'yyyy-MM-dd')
652
+ } else if (this.panelType === 'dynamic' && Array.isArray(dynamicRange) && dynamicRange.length === 2) {
653
+ this.dynamicRange = Array.from(dynamicRange)
654
+ if (typeof dynamicRange[0] === 'string') {
655
+ console.log('用了defaultTime')
656
+ this.dynamicTypeLeft = 'specific'
657
+ this.dynamicValue = modifyWithTimeString(new Date(dynamicRange[0]), this.defaultTime[0])
658
+
659
+ this.minDate = modifyWithTimeString(new Date(dynamicRange[0]), this.defaultTime[0])
660
+ } else {
661
+ console.log('用了defaultTime')
662
+ this.dynamicTypeLeft = 'past'
663
+ this.dynamicValue = modifyWithTimeString(setDaysDiff(new Date(), this.dynamicRange[0]), this.defaultTime[0])
664
+ this.minDate = modifyWithTimeString(setDaysDiff(new Date(), this.dynamicRange[0]), this.defaultTime[0])
665
+ }
666
+ console.log('用了defaultTime')
667
+ this.handleDynamicRange(this.dynamicRange[1])
668
+ this.dynamicDate = formatDate(this.dynamicValue, 'yyyy-MM-dd')
669
+ this.maxDate = modifyWithTimeString(setDaysDiff(new Date(), this.dynamicRange[1]), this.defaultTime[1])
670
+ }
671
+ }
672
+ // this.minDate = modifyWithTimeString(this.minDate, this.defaultTime[0])
673
+ // this.maxDate = modifyWithTimeString(this.maxDate, this.defaultTime[1])
674
+ } catch (error) {
675
+ console.log('🚀 ~ error:', error)
676
+ }
677
+ },
678
+ handleDateTypeChange(value) {},
679
+ handleDatePick(value) {
680
+ let newDate = modifyWithTimeString(value, this.defaultTime[0])
681
+ this.dynamicValue = newDate
682
+ this.dynamicRange[0] = formatDate(newDate, 'yyyy-MM-dd')
683
+ this.dynamicDate = formatDate(newDate, 'yyyy-MM-dd')
684
+ },
685
+
686
+ handleDynamicType(dynamicType) {
687
+ if (dynamicType === this.dynamicTypeLeft) return
688
+ this.dynamicTypeLeft = dynamicType
689
+ // 切换动态时间类型时的处理
690
+ // 如果切换到"过去N天"模式,需要根据dynamicRange[0]计算日期
691
+ // 如果切换到"具体时间"模式,需要显示日期选择器
692
+ // dynamicType past 过去N天
693
+ // dynamicType specific 具体时间
694
+ if (dynamicType === 'past') {
695
+ this.dynamicRange[0] = getDaysDiff(this.dynamicValue)
696
+ }
697
+ if (dynamicType === 'specific') {
698
+ this.dynamicRange[0] = formatDate(setDaysDiff(new Date(), this.dynamicRange[0]), 'yyyy-MM-dd')
699
+ }
700
+ },
701
+ handleDynamicRange(val) {
702
+ if (val === 0) this.dynamicTypeRight = 'today'
703
+ if (val === 1) this.dynamicTypeRight = 'yesterday'
704
+ if (val === 2) this.dynamicTypeRight = 'past'
705
+ this.$set(this.dynamicRange, 1, val)
706
+ },
707
+ handleClear() {
708
+ this.minDate = null
709
+ this.maxDate = null
710
+ this.leftDate = calcDefaultValue(this.defaultValue)[0]
711
+ this.rightDate = nextMonth(this.leftDate)
712
+ this.$emit('pick', { date: [], time: [...this.defaultTime], type: 'static', dynamicRange: [] })
713
+ },
714
+ handleChangeRange(val) {
715
+ this.minDate = val.minDate
716
+ this.maxDate = val.maxDate
717
+ this.rangeState = val.rangeState
718
+ },
719
+
720
+ handleDateInput(value, type) {
721
+ this.dateUserInput[type] = value
722
+ if (value.length !== this.dateFormat.length) return
723
+ const parsedValue = parseDate(value, this.dateFormat)
724
+
725
+ if (parsedValue) {
726
+ if (typeof this.disabledDate === 'function' && this.disabledDate(new Date(parsedValue))) {
727
+ return
728
+ }
729
+ if (type === 'min') {
730
+ this.minDate = modifyDate(this.minDate || new Date(), parsedValue.getFullYear(), parsedValue.getMonth(), parsedValue.getDate())
731
+ this.leftDate = new Date(parsedValue)
732
+ if (!this.unlinkPanels) {
733
+ this.rightDate = nextMonth(this.leftDate)
734
+ }
735
+ } else {
736
+ this.maxDate = modifyDate(this.maxDate || new Date(), parsedValue.getFullYear(), parsedValue.getMonth(), parsedValue.getDate())
737
+ this.rightDate = new Date(parsedValue)
738
+ if (!this.unlinkPanels) {
739
+ this.leftDate = prevMonth(parsedValue)
740
+ }
741
+ }
742
+ }
743
+ },
744
+
745
+ handleDateChange(value, type) {
746
+ const parsedValue = parseDate(value, this.dateFormat)
747
+ if (parsedValue) {
748
+ if (type === 'min') {
749
+ this.minDate = modifyDate(this.minDate, parsedValue.getFullYear(), parsedValue.getMonth(), parsedValue.getDate())
750
+ if (this.minDate > this.maxDate) {
751
+ this.maxDate = this.minDate
752
+ }
753
+ } else {
754
+ this.maxDate = modifyDate(this.maxDate, parsedValue.getFullYear(), parsedValue.getMonth(), parsedValue.getDate())
755
+ if (this.maxDate < this.minDate) {
756
+ this.minDate = this.maxDate
757
+ }
758
+ }
759
+ }
760
+ },
761
+
762
+ handleTimeInput(value, type) {
763
+ this.timeUserInput[type] = value
764
+ if (value.length !== this.timeFormat.length) return
765
+ const parsedValue = parseDate(value, this.timeFormat)
766
+
767
+ if (parsedValue) {
768
+ if (type === 'min') {
769
+ this.minDate = modifyTime(this.minDate, parsedValue.getHours(), parsedValue.getMinutes(), parsedValue.getSeconds())
770
+ this.$nextTick((_) => this.$refs.minTimePicker.adjustSpinners())
771
+ } else {
772
+ this.maxDate = modifyTime(this.maxDate, parsedValue.getHours(), parsedValue.getMinutes(), parsedValue.getSeconds())
773
+ this.$nextTick((_) => this.$refs.maxTimePicker.adjustSpinners())
774
+ }
775
+ }
776
+ },
777
+
778
+ handleTimeChange(value, type) {
779
+ console.log('🚀 ~ value:', value)
780
+ const parsedValue = parseDate(value, this.timeFormat)
781
+ if (parsedValue) {
782
+ if (type === 'min') {
783
+ this.minDate = modifyTime(this.minDate, parsedValue.getHours(), parsedValue.getMinutes(), parsedValue.getSeconds())
784
+ if (this.minDate > this.maxDate) {
785
+ this.maxDate = this.minDate
786
+ }
787
+ this.$refs.minTimePicker.value = this.minDate
788
+ this.minTimePickerVisible = false
789
+ this.value.time[0] = value
790
+ } else {
791
+ this.maxDate = modifyTime(this.maxDate, parsedValue.getHours(), parsedValue.getMinutes(), parsedValue.getSeconds())
792
+ if (this.maxDate < this.minDate) {
793
+ this.minDate = this.maxDate
794
+ }
795
+ this.$refs.maxTimePicker.value = this.minDate
796
+ this.maxTimePickerVisible = false
797
+ this.value.time[1] = value
798
+ }
799
+ }
800
+ },
801
+
802
+ handleRangePick(val, close = true) {
803
+ const defaultTime = this.value.time && this.value.time.length ? this.value.time : this.defaultTime || []
804
+ const minDate = modifyWithTimeString(val.minDate, defaultTime[0])
805
+ const maxDate = modifyWithTimeString(val.maxDate, defaultTime[1])
806
+
807
+ if (this.maxDate === maxDate && this.minDate === minDate) {
808
+ return
809
+ }
810
+ this.maxDate = maxDate
811
+ this.minDate = minDate
812
+
813
+ // workaround for https://github.com/ElemeFE/element/issues/7539, should remove this block when we don't have to care about Chromium 55 - 57
814
+ setTimeout(() => {
815
+ this.maxDate = maxDate
816
+ this.minDate = minDate
817
+ }, 10)
818
+ if (!close || this.showTime) return
819
+ this.handleConfirm()
820
+ },
821
+
822
+ handleShortcutClick(shortcut) {
823
+ if (shortcut.onClick) {
824
+ shortcut.onClick(this)
825
+ }
826
+ },
827
+
828
+ handleMinTimePick(value, visible, first) {
829
+ this.minDate = this.minDate || new Date()
830
+ if (value) {
831
+ this.minDate = modifyTime(this.minDate, value.getHours(), value.getMinutes(), value.getSeconds())
832
+ }
833
+
834
+ if (!first) {
835
+ this.minTimePickerVisible = visible
836
+ }
837
+
838
+ if (!this.maxDate || (this.maxDate && this.maxDate.getTime() < this.minDate.getTime())) {
839
+ this.maxDate = new Date(this.minDate)
840
+ }
841
+ },
842
+
843
+ handleMinTimeClose() {
844
+ this.minTimePickerVisible = false
845
+ },
846
+
847
+ handleMaxTimePick(value, visible, first) {
848
+ if (this.maxDate && value) {
849
+ this.maxDate = modifyTime(this.maxDate, value.getHours(), value.getMinutes(), value.getSeconds())
850
+ }
851
+
852
+ if (!first) {
853
+ this.maxTimePickerVisible = visible
854
+ }
855
+
856
+ if (this.maxDate && this.minDate && this.minDate.getTime() > this.maxDate.getTime()) {
857
+ this.minDate = new Date(this.maxDate)
858
+ }
859
+ },
860
+
861
+ handleMaxTimeClose() {
862
+ this.maxTimePickerVisible = false
863
+ },
864
+
865
+ // leftPrev*, rightNext* need to take care of `unlinkPanels`
866
+ dynamicPrevYear() {
867
+ this.dynamicValue = prevYear(this.dynamicValue)
868
+ },
869
+
870
+ dynamicPrevMonth() {
871
+ this.dynamicValue = prevMonth(this.dynamicValue)
872
+ },
873
+ leftPrevYear() {
874
+ this.leftDate = prevYear(this.leftDate)
875
+ if (!this.unlinkPanels) {
876
+ this.rightDate = nextMonth(this.leftDate)
877
+ }
878
+ },
879
+
880
+ leftPrevMonth() {
881
+ this.leftDate = prevMonth(this.leftDate)
882
+ if (!this.unlinkPanels) {
883
+ this.rightDate = nextMonth(this.leftDate)
884
+ }
885
+ },
886
+
887
+ rightNextYear() {
888
+ if (!this.unlinkPanels) {
889
+ this.leftDate = nextYear(this.leftDate)
890
+ this.rightDate = nextMonth(this.leftDate)
891
+ } else {
892
+ this.rightDate = nextYear(this.rightDate)
893
+ }
894
+ },
895
+
896
+ rightNextMonth() {
897
+ if (!this.unlinkPanels) {
898
+ this.leftDate = nextMonth(this.leftDate)
899
+ this.rightDate = nextMonth(this.leftDate)
900
+ } else {
901
+ this.rightDate = nextMonth(this.rightDate)
902
+ }
903
+ },
904
+
905
+ // leftNext*, rightPrev* are called when `unlinkPanels` is true
906
+ dynamicNextYear() {
907
+ this.dynamicValue = nextYear(this.dynamicValue)
908
+ },
909
+
910
+ dynamicNextMonth() {
911
+ this.dynamicValue = nextMonth(this.dynamicValue)
912
+ },
913
+ leftNextYear() {
914
+ this.leftDate = nextYear(this.leftDate)
915
+ },
916
+
917
+ leftNextMonth() {
918
+ this.leftDate = nextMonth(this.leftDate)
919
+ },
920
+
921
+ rightPrevYear() {
922
+ this.rightDate = prevYear(this.rightDate)
923
+ },
924
+
925
+ rightPrevMonth() {
926
+ this.rightDate = prevMonth(this.rightDate)
927
+ },
928
+ formatRangeText(value) {
929
+ const { date, type, dynamicRange } = value
930
+ if (type === 'dynamic') {
931
+ // const dynamicDate=
932
+ const dynamicRangeText = []
933
+ const dynamicDate = dynamicRange
934
+ .map((diff) => {
935
+ if (typeof diff === 'string') {
936
+ dynamicRangeText.push(diff)
937
+ return diff
938
+ } else {
939
+ if (diff === 0) {
940
+ dynamicRangeText.push('今天')
941
+ } else if (diff === 1) {
942
+ dynamicRangeText.push('昨天')
943
+ } else {
944
+ dynamicRangeText.push(`过去 ${diff} 天`)
945
+ }
946
+ return formatDate(setDaysDiff(new Date(), diff), 'yyyy-MM-dd')
947
+ }
948
+ })
949
+ .join(' - ')
950
+ return `${dynamicRangeText.join(' - ')} | ${dynamicDate}`
951
+ }
952
+ if (type === 'static') {
953
+ return `${date.join(' - ')}`
954
+ }
955
+ },
956
+ handleConfirm(visible = false) {
957
+ const emitValue = {
958
+ date: [this.minDate, this.maxDate].map((date) => (date ? formatDate(date, this.dateFormat) : null)),
959
+ time: [this.minDate, this.maxDate].map((date) => (date ? formatDate(date, this.timeFormat) : null)),
960
+ type: this.panelType,
961
+ dynamicRange: this.dynamicRange
962
+ }
963
+ // 如果是动态时间类型,则需要将dynamicDate赋值给dynamicRange[0]
964
+ if (this.panelType === 'dynamic') {
965
+ emitValue.date = this.dynamicRange.map((diff) => {
966
+ if (typeof diff === 'string') {
967
+ return diff
968
+ } else {
969
+ return formatDate(setDaysDiff(new Date(), diff), 'yyyy-MM-dd')
970
+ }
971
+ })
972
+ }
973
+ if (this.panelType === 'static') {
974
+ emitValue.dynamicRange = [getDaysDiff(this.minDate), getDaysDiff(this.maxDate)]
975
+ }
976
+ // 如果是动态时间类型,则需要将dynamicDate赋值给dynamicRange[0]
977
+
978
+ if (this.dynamicTypeLeft === 'specific') {
979
+ emitValue.dynamicRange[0] = this.dynamicDate
980
+ }
981
+ this.$emit('pick', emitValue, false)
982
+ },
983
+
984
+ isValidValue(value) {
985
+ return Array.isArray(value) && value && value[0] && value[1] && isDate(value[0]) && isDate(value[1]) && value[0].getTime() <= value[1].getTime() && (typeof this.disabledDate === 'function' ? !this.disabledDate(value[0]) && !this.disabledDate(value[1]) : true)
986
+ },
987
+
988
+ resetView() {
989
+ // NOTE: this is a hack to reset {min, max}Date on picker open.
990
+ // TODO: correct way of doing so is to refactor {min, max}Date to be dependent on value and internal selection state
991
+ // an alternative would be resetView whenever picker becomes visible, should also investigate date-panel's resetView
992
+ if (this.minDate && this.maxDate == null) this.rangeState.selecting = false
993
+ this.minDate = this.value && isDate(this.value[0]) ? new Date(this.value[0]) : null
994
+ this.maxDate = this.value && isDate(this.value[0]) ? new Date(this.value[1]) : null
995
+ }
996
+ },
997
+
998
+ components: { TimePicker, DateTable, ElInput, ElButton, ElTabs }
999
+ }
1000
+ </script>