meixioacomponent 1.1.49 → 1.1.51

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 (25) hide show
  1. package/lib/meixioacomponent.common.js +337 -52
  2. package/lib/meixioacomponent.umd.js +337 -52
  3. package/lib/meixioacomponent.umd.min.js +7 -7
  4. package/package.json +1 -1
  5. package/packages/components/base/baseArea/api.js +7 -0
  6. package/packages/components/base/baseArea/areaConfig.js +4 -3
  7. package/packages/components/base/baseArea/baseAreaV2.vue +157 -0
  8. package/packages/components/base/baseArea/index.js +2 -1
  9. package/packages/components/base/elDatePicker/basic/date-table.vue +441 -441
  10. package/packages/components/base/elDatePicker/basic/month-table.vue +269 -269
  11. package/packages/components/base/elDatePicker/basic/time-spinner.vue +304 -304
  12. package/packages/components/base/elDatePicker/basic/year-table.vue +111 -111
  13. package/packages/components/base/elDatePicker/index.js +6 -6
  14. package/packages/components/base/elDatePicker/index.vue +27 -27
  15. package/packages/components/base/elDatePicker/panel/date-range.vue +680 -680
  16. package/packages/components/base/elDatePicker/panel/date.vue +609 -609
  17. package/packages/components/base/elDatePicker/panel/month-range.vue +289 -289
  18. package/packages/components/base/elDatePicker/panel/time-range.vue +248 -248
  19. package/packages/components/base/elDatePicker/panel/time-select.vue +178 -178
  20. package/packages/components/base/elDatePicker/panel/time.vue +186 -186
  21. package/packages/components/base/elDatePicker/picker/date-picker.js +55 -55
  22. package/packages/components/base/elDatePicker/picker/time-picker.js +39 -39
  23. package/packages/components/base/elDatePicker/picker/time-select.js +21 -21
  24. package/packages/components/base/elDatePicker/picker.vue +956 -956
  25. package/packages/components/proForm/proForm/pro_form.vue +6 -4
@@ -1,609 +1,609 @@
1
- <template>
2
- <transition name="el-zoom-in-top" @after-enter="handleEnter" @after-leave="handleLeave">
3
- <div
4
- v-show="visible"
5
- class="el-picker-panel el-date-picker el-popper"
6
- :class="[{
7
- 'has-sidebar': $slots.sidebar || shortcuts,
8
- 'has-time': showTime
9
- }, popperClass]">
10
- <div class="el-picker-panel__body-wrapper">
11
- <slot name="sidebar" class="el-picker-panel__sidebar"></slot>
12
- <div class="el-picker-panel__sidebar" v-if="shortcuts">
13
- <button
14
- type="button"
15
- class="el-picker-panel__shortcut"
16
- v-for="(shortcut, key) in shortcuts"
17
- :key="key"
18
- @click="handleShortcutClick(shortcut)">{{ shortcut.text }}</button>
19
- </div>
20
- <div class="el-picker-panel__body">
21
- <div class="el-date-picker__time-header" v-if="showTime">
22
- <span class="el-date-picker__editor-wrap">
23
- <el-input
24
- :placeholder="t('el.datepicker.selectDate')"
25
- :value="visibleDate"
26
- size="small"
27
- @input="val => userInputDate = val"
28
- @change="handleVisibleDateChange" />
29
- </span>
30
- <span class="el-date-picker__editor-wrap" v-clickoutside="handleTimePickClose">
31
- <el-input
32
- ref="input"
33
- @focus="timePickerVisible = true"
34
- :placeholder="t('el.datepicker.selectTime')"
35
- :value="visibleTime"
36
- size="small"
37
- @input="val => userInputTime = val"
38
- @change="handleVisibleTimeChange" />
39
- <time-picker
40
- ref="timepicker"
41
- :time-arrow-control="arrowControl"
42
- @pick="handleTimePick"
43
- :visible="timePickerVisible"
44
- @mounted="proxyTimePickerDataProperties">
45
- </time-picker>
46
- </span>
47
- </div>
48
- <div
49
- class="el-date-picker__header"
50
- :class="{ 'el-date-picker__header--bordered': currentView === 'year' || currentView === 'month' }"
51
- v-show="currentView !== 'time'">
52
- <button
53
- type="button"
54
- @click="prevYear"
55
- :aria-label="t(`el.datepicker.prevYear`)"
56
- class="el-picker-panel__icon-btn el-date-picker__prev-btn el-icon-d-arrow-left">
57
- </button>
58
- <button
59
- type="button"
60
- @click="prevMonth"
61
- v-show="currentView === 'date'"
62
- :aria-label="t(`el.datepicker.prevMonth`)"
63
- class="el-picker-panel__icon-btn el-date-picker__prev-btn el-icon-arrow-left">
64
- </button>
65
- <span
66
- @click="showYearPicker"
67
- role="button"
68
- class="el-date-picker__header-label">{{ yearLabel }}</span>
69
- <span
70
- @click="showMonthPicker"
71
- v-show="currentView === 'date'"
72
- role="button"
73
- class="el-date-picker__header-label"
74
- :class="{ active: currentView === 'month' }">{{t(`el.datepicker.month${ month + 1 }`)}}</span>
75
- <button
76
- type="button"
77
- @click="nextYear"
78
- :aria-label="t(`el.datepicker.nextYear`)"
79
- class="el-picker-panel__icon-btn el-date-picker__next-btn el-icon-d-arrow-right">
80
- </button>
81
- <button
82
- type="button"
83
- @click="nextMonth"
84
- v-show="currentView === 'date'"
85
- :aria-label="t(`el.datepicker.nextMonth`)"
86
- class="el-picker-panel__icon-btn el-date-picker__next-btn el-icon-arrow-right">
87
- </button>
88
- </div>
89
-
90
- <div class="el-picker-panel__content">
91
- <date-table
92
- v-show="currentView === 'date'"
93
- @pick="handleDatePick"
94
- :selection-mode="selectionMode"
95
- :first-day-of-week="firstDayOfWeek"
96
- :value="value"
97
- :default-value="defaultValue ? new Date(defaultValue) : null"
98
- :date="date"
99
- :cell-class-name="cellClassName"
100
- :disabled-date="disabledDate">
101
- </date-table>
102
- <year-table
103
- v-show="currentView === 'year'"
104
- @pick="handleYearPick"
105
- :selection-mode="selectionMode"
106
- :value="value"
107
- :default-value="defaultValue ? new Date(defaultValue) : null"
108
- :date="date"
109
- :disabled-date="disabledDate">
110
- </year-table>
111
- <month-table
112
- v-show="currentView === 'month'"
113
- @pick="handleMonthPick"
114
- :selection-mode="selectionMode"
115
- :value="value"
116
- :default-value="defaultValue ? new Date(defaultValue) : null"
117
- :date="date"
118
- :disabled-date="disabledDate">
119
- </month-table>
120
- </div>
121
- </div>
122
- </div>
123
-
124
- <div
125
- class="el-picker-panel__footer"
126
- v-show="footerVisible && (currentView === 'date' || currentView === 'month' || currentView === 'year')">
127
- <el-button
128
- size="mini"
129
- type="text"
130
- class="el-picker-panel__link-btn"
131
- @click="changeToNow"
132
- v-show="selectionMode !== 'dates' && selectionMode !== 'months' && selectionMode !== 'years'">
133
- {{ t('el.datepicker.now') }}
134
- </el-button>
135
- <el-button
136
- plain
137
- size="mini"
138
- class="el-picker-panel__link-btn"
139
- @click="confirm">
140
- {{ t('el.datepicker.confirm') }}
141
- </el-button>
142
- </div>
143
- </div>
144
- </transition>
145
- </template>
146
-
147
- <script type="text/babel">
148
- import {
149
- formatDate,
150
- parseDate,
151
- getWeekNumber,
152
- isDate,
153
- modifyDate,
154
- modifyTime,
155
- modifyWithTimeString,
156
- clearMilliseconds,
157
- clearTime,
158
- prevYear,
159
- nextYear,
160
- prevMonth,
161
- nextMonth,
162
- changeYearMonthAndClampDate,
163
- extractDateFormat,
164
- extractTimeFormat,
165
- timeWithinRange
166
- } from 'element-ui/src/utils/date-util';
167
- import Clickoutside from 'element-ui/src/utils/clickoutside';
168
- import Locale from 'element-ui/src/mixins/locale';
169
- import ElInput from 'element-ui/packages/input';
170
- import ElButton from 'element-ui/packages/button';
171
- import TimePicker from './time';
172
- import YearTable from '../basic/year-table';
173
- import MonthTable from '../basic/month-table';
174
- import DateTable from '../basic/date-table';
175
-
176
- export default {
177
- mixins: [Locale],
178
-
179
- directives: { Clickoutside },
180
-
181
- watch: {
182
- showTime(val) {
183
- /* istanbul ignore if */
184
- if (!val) return;
185
- this.$nextTick(_ => {
186
- const inputElm = this.$refs.input.$el;
187
- if (inputElm) {
188
- this.pickerWidth = inputElm.getBoundingClientRect().width + 10;
189
- }
190
- });
191
- },
192
-
193
- value(val) {
194
- if (this.selectionMode === 'dates' && this.value) return;
195
- if (this.selectionMode === 'months' && this.value) return;
196
- if (this.selectionMode === 'years' && this.value) return;
197
- if (isDate(val)) {
198
- this.date = new Date(val);
199
- } else {
200
- this.date = this.getDefaultValue();
201
- }
202
- },
203
-
204
- defaultValue(val) {
205
- if (!isDate(this.value)) {
206
- this.date = val ? new Date(val) : new Date();
207
- }
208
- },
209
-
210
- timePickerVisible(val) {
211
- if (val) this.$nextTick(() => this.$refs.timepicker.adjustSpinners());
212
- },
213
-
214
- selectionMode(newVal) {
215
- if (newVal === 'month') {
216
- /* istanbul ignore next */
217
- if (this.currentView !== 'year' || this.currentView !== 'month') {
218
- this.currentView = 'month';
219
- }
220
- } else if (newVal === 'dates') {
221
- this.currentView = 'date';
222
- } else if (newVal === 'years') {
223
- this.currentView = 'year';
224
- } else if (newVal === 'months') {
225
- this.currentView = 'month';
226
- }
227
- }
228
- },
229
-
230
- methods: {
231
- proxyTimePickerDataProperties() {
232
- const format = timeFormat => {this.$refs.timepicker.format = timeFormat;};
233
- const value = value => {this.$refs.timepicker.value = value;};
234
- const date = date => {this.$refs.timepicker.date = date;};
235
- const selectableRange = selectableRange => {this.$refs.timepicker.selectableRange = selectableRange;};
236
-
237
- this.$watch('value', value);
238
- this.$watch('date', date);
239
- this.$watch('selectableRange', selectableRange);
240
-
241
- format(this.timeFormat);
242
- value(this.value);
243
- date(this.date);
244
- selectableRange(this.selectableRange);
245
- },
246
-
247
- handleClear() {
248
- this.date = this.getDefaultValue();
249
- this.$emit('pick', null);
250
- },
251
-
252
- emit(value, ...args) {
253
- if (!value) {
254
- this.$emit('pick', value, ...args);
255
- } else if (Array.isArray(value)) {
256
- const dates = value.map(date => this.showTime ? clearMilliseconds(date) : clearTime(date));
257
- this.$emit('pick', dates, ...args);
258
- } else {
259
- this.$emit('pick', this.showTime ? clearMilliseconds(value) : clearTime(value), ...args);
260
- }
261
- this.userInputDate = null;
262
- this.userInputTime = null;
263
- },
264
-
265
- // resetDate() {
266
- // this.date = new Date(this.date);
267
- // },
268
-
269
- showMonthPicker() {
270
- this.currentView = 'month';
271
- },
272
-
273
- showYearPicker() {
274
- this.currentView = 'year';
275
- },
276
-
277
- // XXX: 没用到
278
- // handleLabelClick() {
279
- // if (this.currentView === 'date') {
280
- // this.showMonthPicker();
281
- // } else if (this.currentView === 'month') {
282
- // this.showYearPicker();
283
- // }
284
- // },
285
-
286
- prevMonth() {
287
- this.date = prevMonth(this.date);
288
- },
289
-
290
- nextMonth() {
291
- this.date = nextMonth(this.date);
292
- },
293
-
294
- prevYear() {
295
- if (this.currentView === 'year') {
296
- this.date = prevYear(this.date, 10);
297
- } else {
298
- this.date = prevYear(this.date);
299
- }
300
- },
301
-
302
- nextYear() {
303
- if (this.currentView === 'year') {
304
- this.date = nextYear(this.date, 10);
305
- } else {
306
- this.date = nextYear(this.date);
307
- }
308
- },
309
-
310
- handleShortcutClick(shortcut) {
311
- if (shortcut.onClick) {
312
- shortcut.onClick(this);
313
- }
314
- },
315
-
316
- handleTimePick(value, visible, first) {
317
- if (isDate(value)) {
318
- const newDate = this.value
319
- ? modifyTime(this.value, value.getHours(), value.getMinutes(), value.getSeconds())
320
- : modifyWithTimeString(this.getDefaultValue(), this.defaultTime);
321
- this.date = newDate;
322
- this.emit(this.date, true);
323
- } else {
324
- this.emit(value, true);
325
- }
326
- if (!first) {
327
- this.timePickerVisible = visible;
328
- }
329
- },
330
-
331
- handleTimePickClose() {
332
- this.timePickerVisible = false;
333
- },
334
-
335
- handleMonthPick(month) {
336
- if (this.selectionMode === 'month') {
337
- this.date = modifyDate(this.date, this.year, month, 1);
338
- this.emit(this.date);
339
- } else if (this.selectionMode === 'months') {
340
- this.emit(month, true);
341
- } else {
342
- this.date = changeYearMonthAndClampDate(this.date, this.year, month);
343
- // TODO: should emit intermediate value ??
344
- // this.emit(this.date);
345
- this.currentView = 'date';
346
- }
347
- },
348
-
349
- handleDatePick(value) {
350
- if (this.selectionMode === 'day') {
351
- let newDate = this.value
352
- ? modifyDate(this.value, value.getFullYear(), value.getMonth(), value.getDate())
353
- : modifyWithTimeString(value, this.defaultTime);
354
- // change default time while out of selectableRange
355
- if (!this.checkDateWithinRange(newDate)) {
356
- newDate = modifyDate(this.selectableRange[0][0], value.getFullYear(), value.getMonth(), value.getDate());
357
- }
358
- this.date = newDate;
359
- this.emit(this.date, this.showTime);
360
- } else if (this.selectionMode === 'week') {
361
- this.emit(value.date);
362
- } else if (this.selectionMode === 'dates') {
363
- this.emit(value, true); // set false to keep panel open
364
- }
365
- },
366
-
367
- handleYearPick(year) {
368
- if (this.selectionMode === 'year') {
369
- this.date = modifyDate(this.date, year, 0, 1);
370
- this.emit(this.date);
371
- } else if (this.selectionMode === 'years') {
372
- this.emit(year, true);
373
- } else {
374
- this.date = changeYearMonthAndClampDate(this.date, year, this.month);
375
- // TODO: should emit intermediate value ??
376
- // this.emit(this.date, true);
377
- this.currentView = 'month';
378
- }
379
- },
380
-
381
- changeToNow() {
382
- // NOTE: not a permanent solution
383
- // consider disable "now" button in the future
384
- if ((!this.disabledDate || !this.disabledDate(new Date())) && this.checkDateWithinRange(new Date())) {
385
- this.date = new Date();
386
- this.emit(this.date);
387
- }
388
- },
389
-
390
- confirm() {
391
- if (this.selectionMode === 'dates' || this.selectionMode === 'months' || this.selectionMode === 'years') {
392
- this.emit(this.value);
393
- } else {
394
- // value were emitted in handle{Date,Time}Pick, nothing to update here
395
- // deal with the scenario where: user opens the picker, then confirm without doing anything
396
- const value = this.value
397
- ? this.value
398
- : modifyWithTimeString(this.getDefaultValue(), this.defaultTime);
399
- this.date = new Date(value); // refresh date
400
- this.emit(value);
401
- }
402
- },
403
-
404
- resetView() {
405
- if (this.selectionMode === 'month' || this.selectionMode === 'months') {
406
- this.currentView = 'month';
407
- } else if (this.selectionMode === 'year' || this.selectionMode === 'years') {
408
- this.currentView = 'year';
409
- } else {
410
- this.currentView = 'date';
411
- }
412
- },
413
-
414
- handleEnter() {
415
- document.body.addEventListener('keydown', this.handleKeydown);
416
- },
417
-
418
- handleLeave() {
419
- this.$emit('dodestroy');
420
- document.body.removeEventListener('keydown', this.handleKeydown);
421
- },
422
-
423
- handleKeydown(event) {
424
- const keyCode = event.keyCode;
425
- const list = [38, 40, 37, 39];
426
- if (this.visible && !this.timePickerVisible) {
427
- if (list.indexOf(keyCode) !== -1) {
428
- this.handleKeyControl(keyCode);
429
- event.stopPropagation();
430
- event.preventDefault();
431
- }
432
- if (keyCode === 13 && this.userInputDate === null && this.userInputTime === null) { // Enter
433
- this.emit(this.date, false);
434
- }
435
- }
436
- },
437
-
438
- handleKeyControl(keyCode) {
439
- const mapping = {
440
- 'year': {
441
- 38: -4, 40: 4, 37: -1, 39: 1, offset: (date, step) => date.setFullYear(date.getFullYear() + step)
442
- },
443
- 'month': {
444
- 38: -4, 40: 4, 37: -1, 39: 1, offset: (date, step) => date.setMonth(date.getMonth() + step)
445
- },
446
- 'week': {
447
- 38: -1, 40: 1, 37: -1, 39: 1, offset: (date, step) => date.setDate(date.getDate() + step * 7)
448
- },
449
- 'day': {
450
- 38: -7, 40: 7, 37: -1, 39: 1, offset: (date, step) => date.setDate(date.getDate() + step)
451
- }
452
- };
453
- const mode = this.selectionMode;
454
- const year = 3.1536e10;
455
- const now = this.date.getTime();
456
- const newDate = new Date(this.date.getTime());
457
- while (Math.abs(now - newDate.getTime()) <= year) {
458
- const map = mapping[mode];
459
- map.offset(newDate, map[keyCode]);
460
- if (typeof this.disabledDate === 'function' && this.disabledDate(newDate)) {
461
- continue;
462
- }
463
- this.date = newDate;
464
- this.$emit('pick', newDate, true);
465
- break;
466
- }
467
- },
468
-
469
- handleVisibleTimeChange(value) {
470
- const time = parseDate(value, this.timeFormat);
471
- if (time && this.checkDateWithinRange(time)) {
472
- this.date = modifyDate(time, this.year, this.month, this.monthDate);
473
- this.userInputTime = null;
474
- this.$refs.timepicker.value = this.date;
475
- this.timePickerVisible = false;
476
- this.emit(this.date, true);
477
- }
478
- },
479
-
480
- handleVisibleDateChange(value) {
481
- const date = parseDate(value, this.dateFormat);
482
- if (date) {
483
- if (typeof this.disabledDate === 'function' && this.disabledDate(date)) {
484
- return;
485
- }
486
- this.date = modifyTime(date, this.date.getHours(), this.date.getMinutes(), this.date.getSeconds());
487
- this.userInputDate = null;
488
- this.resetView();
489
- this.emit(this.date, true);
490
- }
491
- },
492
-
493
- isValidValue(value) {
494
- return value && !isNaN(value) && (
495
- typeof this.disabledDate === 'function'
496
- ? !this.disabledDate(value)
497
- : true
498
- ) && this.checkDateWithinRange(value);
499
- },
500
-
501
- getDefaultValue() {
502
- // if default-value is set, return it
503
- // otherwise, return now (the moment this method gets called)
504
- return this.defaultValue ? new Date(this.defaultValue) : new Date();
505
- },
506
-
507
- checkDateWithinRange(date) {
508
- return this.selectableRange.length > 0
509
- ? timeWithinRange(date, this.selectableRange, this.format || 'HH:mm:ss')
510
- : true;
511
- }
512
- },
513
-
514
- components: {
515
- TimePicker, YearTable, MonthTable, DateTable, ElInput, ElButton
516
- },
517
-
518
- data() {
519
- return {
520
- popperClass: '',
521
- date: new Date(),
522
- value: '',
523
- defaultValue: null, // use getDefaultValue() for time computation
524
- defaultTime: null,
525
- showTime: false,
526
- selectionMode: 'day',
527
- shortcuts: '',
528
- visible: false,
529
- currentView: 'date',
530
- disabledDate: '',
531
- cellClassName: '',
532
- selectableRange: [],
533
- firstDayOfWeek: 7,
534
- showWeekNumber: false,
535
- timePickerVisible: false,
536
- format: '',
537
- arrowControl: false,
538
- userInputDate: null,
539
- userInputTime: null
540
- };
541
- },
542
-
543
- computed: {
544
- year() {
545
- return this.date.getFullYear();
546
- },
547
-
548
- month() {
549
- return this.date.getMonth();
550
- },
551
-
552
- week() {
553
- return getWeekNumber(this.date);
554
- },
555
-
556
- monthDate() {
557
- return this.date.getDate();
558
- },
559
-
560
- footerVisible() {
561
- return this.showTime || this.selectionMode === 'dates' || this.selectionMode === 'months' || this.selectionMode === 'years';
562
- },
563
-
564
- visibleTime() {
565
- if (this.userInputTime !== null) {
566
- return this.userInputTime;
567
- } else {
568
- return formatDate(this.value || this.defaultValue, this.timeFormat);
569
- }
570
- },
571
-
572
- visibleDate() {
573
- if (this.userInputDate !== null) {
574
- return this.userInputDate;
575
- } else {
576
- return formatDate(this.value || this.defaultValue, this.dateFormat);
577
- }
578
- },
579
-
580
- yearLabel() {
581
- const yearTranslation = this.t('el.datepicker.year');
582
- if (this.currentView === 'year') {
583
- const startYear = Math.floor(this.year / 10) * 10;
584
- if (yearTranslation) {
585
- return startYear + ' ' + yearTranslation + ' - ' + (startYear + 9) + ' ' + yearTranslation;
586
- }
587
- return startYear + ' - ' + (startYear + 9);
588
- }
589
- return this.year + ' ' + yearTranslation;
590
- },
591
-
592
- timeFormat() {
593
- if (this.format) {
594
- return extractTimeFormat(this.format);
595
- } else {
596
- return 'HH:mm:ss';
597
- }
598
- },
599
-
600
- dateFormat() {
601
- if (this.format) {
602
- return extractDateFormat(this.format);
603
- } else {
604
- return 'yyyy-MM-dd';
605
- }
606
- }
607
- }
608
- };
609
- </script>
1
+ <template>
2
+ <transition name="el-zoom-in-top" @after-enter="handleEnter" @after-leave="handleLeave">
3
+ <div
4
+ v-show="visible"
5
+ class="el-picker-panel el-date-picker el-popper"
6
+ :class="[{
7
+ 'has-sidebar': $slots.sidebar || shortcuts,
8
+ 'has-time': showTime
9
+ }, popperClass]">
10
+ <div class="el-picker-panel__body-wrapper">
11
+ <slot name="sidebar" class="el-picker-panel__sidebar"></slot>
12
+ <div class="el-picker-panel__sidebar" v-if="shortcuts">
13
+ <button
14
+ type="button"
15
+ class="el-picker-panel__shortcut"
16
+ v-for="(shortcut, key) in shortcuts"
17
+ :key="key"
18
+ @click="handleShortcutClick(shortcut)">{{ shortcut.text }}</button>
19
+ </div>
20
+ <div class="el-picker-panel__body">
21
+ <div class="el-date-picker__time-header" v-if="showTime">
22
+ <span class="el-date-picker__editor-wrap">
23
+ <el-input
24
+ :placeholder="t('el.datepicker.selectDate')"
25
+ :value="visibleDate"
26
+ size="small"
27
+ @input="val => userInputDate = val"
28
+ @change="handleVisibleDateChange" />
29
+ </span>
30
+ <span class="el-date-picker__editor-wrap" v-clickoutside="handleTimePickClose">
31
+ <el-input
32
+ ref="input"
33
+ @focus="timePickerVisible = true"
34
+ :placeholder="t('el.datepicker.selectTime')"
35
+ :value="visibleTime"
36
+ size="small"
37
+ @input="val => userInputTime = val"
38
+ @change="handleVisibleTimeChange" />
39
+ <time-picker
40
+ ref="timepicker"
41
+ :time-arrow-control="arrowControl"
42
+ @pick="handleTimePick"
43
+ :visible="timePickerVisible"
44
+ @mounted="proxyTimePickerDataProperties">
45
+ </time-picker>
46
+ </span>
47
+ </div>
48
+ <div
49
+ class="el-date-picker__header"
50
+ :class="{ 'el-date-picker__header--bordered': currentView === 'year' || currentView === 'month' }"
51
+ v-show="currentView !== 'time'">
52
+ <button
53
+ type="button"
54
+ @click="prevYear"
55
+ :aria-label="t(`el.datepicker.prevYear`)"
56
+ class="el-picker-panel__icon-btn el-date-picker__prev-btn el-icon-d-arrow-left">
57
+ </button>
58
+ <button
59
+ type="button"
60
+ @click="prevMonth"
61
+ v-show="currentView === 'date'"
62
+ :aria-label="t(`el.datepicker.prevMonth`)"
63
+ class="el-picker-panel__icon-btn el-date-picker__prev-btn el-icon-arrow-left">
64
+ </button>
65
+ <span
66
+ @click="showYearPicker"
67
+ role="button"
68
+ class="el-date-picker__header-label">{{ yearLabel }}</span>
69
+ <span
70
+ @click="showMonthPicker"
71
+ v-show="currentView === 'date'"
72
+ role="button"
73
+ class="el-date-picker__header-label"
74
+ :class="{ active: currentView === 'month' }">{{t(`el.datepicker.month${ month + 1 }`)}}</span>
75
+ <button
76
+ type="button"
77
+ @click="nextYear"
78
+ :aria-label="t(`el.datepicker.nextYear`)"
79
+ class="el-picker-panel__icon-btn el-date-picker__next-btn el-icon-d-arrow-right">
80
+ </button>
81
+ <button
82
+ type="button"
83
+ @click="nextMonth"
84
+ v-show="currentView === 'date'"
85
+ :aria-label="t(`el.datepicker.nextMonth`)"
86
+ class="el-picker-panel__icon-btn el-date-picker__next-btn el-icon-arrow-right">
87
+ </button>
88
+ </div>
89
+
90
+ <div class="el-picker-panel__content">
91
+ <date-table
92
+ v-show="currentView === 'date'"
93
+ @pick="handleDatePick"
94
+ :selection-mode="selectionMode"
95
+ :first-day-of-week="firstDayOfWeek"
96
+ :value="value"
97
+ :default-value="defaultValue ? new Date(defaultValue) : null"
98
+ :date="date"
99
+ :cell-class-name="cellClassName"
100
+ :disabled-date="disabledDate">
101
+ </date-table>
102
+ <year-table
103
+ v-show="currentView === 'year'"
104
+ @pick="handleYearPick"
105
+ :selection-mode="selectionMode"
106
+ :value="value"
107
+ :default-value="defaultValue ? new Date(defaultValue) : null"
108
+ :date="date"
109
+ :disabled-date="disabledDate">
110
+ </year-table>
111
+ <month-table
112
+ v-show="currentView === 'month'"
113
+ @pick="handleMonthPick"
114
+ :selection-mode="selectionMode"
115
+ :value="value"
116
+ :default-value="defaultValue ? new Date(defaultValue) : null"
117
+ :date="date"
118
+ :disabled-date="disabledDate">
119
+ </month-table>
120
+ </div>
121
+ </div>
122
+ </div>
123
+
124
+ <div
125
+ class="el-picker-panel__footer"
126
+ v-show="footerVisible && (currentView === 'date' || currentView === 'month' || currentView === 'year')">
127
+ <el-button
128
+ size="mini"
129
+ type="text"
130
+ class="el-picker-panel__link-btn"
131
+ @click="changeToNow"
132
+ v-show="selectionMode !== 'dates' && selectionMode !== 'months' && selectionMode !== 'years'">
133
+ {{ t('el.datepicker.now') }}
134
+ </el-button>
135
+ <el-button
136
+ plain
137
+ size="mini"
138
+ class="el-picker-panel__link-btn"
139
+ @click="confirm">
140
+ {{ t('el.datepicker.confirm') }}
141
+ </el-button>
142
+ </div>
143
+ </div>
144
+ </transition>
145
+ </template>
146
+
147
+ <script type="text/babel">
148
+ import {
149
+ formatDate,
150
+ parseDate,
151
+ getWeekNumber,
152
+ isDate,
153
+ modifyDate,
154
+ modifyTime,
155
+ modifyWithTimeString,
156
+ clearMilliseconds,
157
+ clearTime,
158
+ prevYear,
159
+ nextYear,
160
+ prevMonth,
161
+ nextMonth,
162
+ changeYearMonthAndClampDate,
163
+ extractDateFormat,
164
+ extractTimeFormat,
165
+ timeWithinRange
166
+ } from 'element-ui/src/utils/date-util';
167
+ import Clickoutside from 'element-ui/src/utils/clickoutside';
168
+ import Locale from 'element-ui/src/mixins/locale';
169
+ import ElInput from 'element-ui/packages/input';
170
+ import ElButton from 'element-ui/packages/button';
171
+ import TimePicker from './time';
172
+ import YearTable from '../basic/year-table';
173
+ import MonthTable from '../basic/month-table';
174
+ import DateTable from '../basic/date-table';
175
+
176
+ export default {
177
+ mixins: [Locale],
178
+
179
+ directives: { Clickoutside },
180
+
181
+ watch: {
182
+ showTime(val) {
183
+ /* istanbul ignore if */
184
+ if (!val) return;
185
+ this.$nextTick(_ => {
186
+ const inputElm = this.$refs.input.$el;
187
+ if (inputElm) {
188
+ this.pickerWidth = inputElm.getBoundingClientRect().width + 10;
189
+ }
190
+ });
191
+ },
192
+
193
+ value(val) {
194
+ if (this.selectionMode === 'dates' && this.value) return;
195
+ if (this.selectionMode === 'months' && this.value) return;
196
+ if (this.selectionMode === 'years' && this.value) return;
197
+ if (isDate(val)) {
198
+ this.date = new Date(val);
199
+ } else {
200
+ this.date = this.getDefaultValue();
201
+ }
202
+ },
203
+
204
+ defaultValue(val) {
205
+ if (!isDate(this.value)) {
206
+ this.date = val ? new Date(val) : new Date();
207
+ }
208
+ },
209
+
210
+ timePickerVisible(val) {
211
+ if (val) this.$nextTick(() => this.$refs.timepicker.adjustSpinners());
212
+ },
213
+
214
+ selectionMode(newVal) {
215
+ if (newVal === 'month') {
216
+ /* istanbul ignore next */
217
+ if (this.currentView !== 'year' || this.currentView !== 'month') {
218
+ this.currentView = 'month';
219
+ }
220
+ } else if (newVal === 'dates') {
221
+ this.currentView = 'date';
222
+ } else if (newVal === 'years') {
223
+ this.currentView = 'year';
224
+ } else if (newVal === 'months') {
225
+ this.currentView = 'month';
226
+ }
227
+ }
228
+ },
229
+
230
+ methods: {
231
+ proxyTimePickerDataProperties() {
232
+ const format = timeFormat => {this.$refs.timepicker.format = timeFormat;};
233
+ const value = value => {this.$refs.timepicker.value = value;};
234
+ const date = date => {this.$refs.timepicker.date = date;};
235
+ const selectableRange = selectableRange => {this.$refs.timepicker.selectableRange = selectableRange;};
236
+
237
+ this.$watch('value', value);
238
+ this.$watch('date', date);
239
+ this.$watch('selectableRange', selectableRange);
240
+
241
+ format(this.timeFormat);
242
+ value(this.value);
243
+ date(this.date);
244
+ selectableRange(this.selectableRange);
245
+ },
246
+
247
+ handleClear() {
248
+ this.date = this.getDefaultValue();
249
+ this.$emit('pick', null);
250
+ },
251
+
252
+ emit(value, ...args) {
253
+ if (!value) {
254
+ this.$emit('pick', value, ...args);
255
+ } else if (Array.isArray(value)) {
256
+ const dates = value.map(date => this.showTime ? clearMilliseconds(date) : clearTime(date));
257
+ this.$emit('pick', dates, ...args);
258
+ } else {
259
+ this.$emit('pick', this.showTime ? clearMilliseconds(value) : clearTime(value), ...args);
260
+ }
261
+ this.userInputDate = null;
262
+ this.userInputTime = null;
263
+ },
264
+
265
+ // resetDate() {
266
+ // this.date = new Date(this.date);
267
+ // },
268
+
269
+ showMonthPicker() {
270
+ this.currentView = 'month';
271
+ },
272
+
273
+ showYearPicker() {
274
+ this.currentView = 'year';
275
+ },
276
+
277
+ // XXX: 没用到
278
+ // handleLabelClick() {
279
+ // if (this.currentView === 'date') {
280
+ // this.showMonthPicker();
281
+ // } else if (this.currentView === 'month') {
282
+ // this.showYearPicker();
283
+ // }
284
+ // },
285
+
286
+ prevMonth() {
287
+ this.date = prevMonth(this.date);
288
+ },
289
+
290
+ nextMonth() {
291
+ this.date = nextMonth(this.date);
292
+ },
293
+
294
+ prevYear() {
295
+ if (this.currentView === 'year') {
296
+ this.date = prevYear(this.date, 10);
297
+ } else {
298
+ this.date = prevYear(this.date);
299
+ }
300
+ },
301
+
302
+ nextYear() {
303
+ if (this.currentView === 'year') {
304
+ this.date = nextYear(this.date, 10);
305
+ } else {
306
+ this.date = nextYear(this.date);
307
+ }
308
+ },
309
+
310
+ handleShortcutClick(shortcut) {
311
+ if (shortcut.onClick) {
312
+ shortcut.onClick(this);
313
+ }
314
+ },
315
+
316
+ handleTimePick(value, visible, first) {
317
+ if (isDate(value)) {
318
+ const newDate = this.value
319
+ ? modifyTime(this.value, value.getHours(), value.getMinutes(), value.getSeconds())
320
+ : modifyWithTimeString(this.getDefaultValue(), this.defaultTime);
321
+ this.date = newDate;
322
+ this.emit(this.date, true);
323
+ } else {
324
+ this.emit(value, true);
325
+ }
326
+ if (!first) {
327
+ this.timePickerVisible = visible;
328
+ }
329
+ },
330
+
331
+ handleTimePickClose() {
332
+ this.timePickerVisible = false;
333
+ },
334
+
335
+ handleMonthPick(month) {
336
+ if (this.selectionMode === 'month') {
337
+ this.date = modifyDate(this.date, this.year, month, 1);
338
+ this.emit(this.date);
339
+ } else if (this.selectionMode === 'months') {
340
+ this.emit(month, true);
341
+ } else {
342
+ this.date = changeYearMonthAndClampDate(this.date, this.year, month);
343
+ // TODO: should emit intermediate value ??
344
+ // this.emit(this.date);
345
+ this.currentView = 'date';
346
+ }
347
+ },
348
+
349
+ handleDatePick(value) {
350
+ if (this.selectionMode === 'day') {
351
+ let newDate = this.value
352
+ ? modifyDate(this.value, value.getFullYear(), value.getMonth(), value.getDate())
353
+ : modifyWithTimeString(value, this.defaultTime);
354
+ // change default time while out of selectableRange
355
+ if (!this.checkDateWithinRange(newDate)) {
356
+ newDate = modifyDate(this.selectableRange[0][0], value.getFullYear(), value.getMonth(), value.getDate());
357
+ }
358
+ this.date = newDate;
359
+ this.emit(this.date, this.showTime);
360
+ } else if (this.selectionMode === 'week') {
361
+ this.emit(value.date);
362
+ } else if (this.selectionMode === 'dates') {
363
+ this.emit(value, true); // set false to keep panel open
364
+ }
365
+ },
366
+
367
+ handleYearPick(year) {
368
+ if (this.selectionMode === 'year') {
369
+ this.date = modifyDate(this.date, year, 0, 1);
370
+ this.emit(this.date);
371
+ } else if (this.selectionMode === 'years') {
372
+ this.emit(year, true);
373
+ } else {
374
+ this.date = changeYearMonthAndClampDate(this.date, year, this.month);
375
+ // TODO: should emit intermediate value ??
376
+ // this.emit(this.date, true);
377
+ this.currentView = 'month';
378
+ }
379
+ },
380
+
381
+ changeToNow() {
382
+ // NOTE: not a permanent solution
383
+ // consider disable "now" button in the future
384
+ if ((!this.disabledDate || !this.disabledDate(new Date())) && this.checkDateWithinRange(new Date())) {
385
+ this.date = new Date();
386
+ this.emit(this.date);
387
+ }
388
+ },
389
+
390
+ confirm() {
391
+ if (this.selectionMode === 'dates' || this.selectionMode === 'months' || this.selectionMode === 'years') {
392
+ this.emit(this.value);
393
+ } else {
394
+ // value were emitted in handle{Date,Time}Pick, nothing to update here
395
+ // deal with the scenario where: user opens the picker, then confirm without doing anything
396
+ const value = this.value
397
+ ? this.value
398
+ : modifyWithTimeString(this.getDefaultValue(), this.defaultTime);
399
+ this.date = new Date(value); // refresh date
400
+ this.emit(value);
401
+ }
402
+ },
403
+
404
+ resetView() {
405
+ if (this.selectionMode === 'month' || this.selectionMode === 'months') {
406
+ this.currentView = 'month';
407
+ } else if (this.selectionMode === 'year' || this.selectionMode === 'years') {
408
+ this.currentView = 'year';
409
+ } else {
410
+ this.currentView = 'date';
411
+ }
412
+ },
413
+
414
+ handleEnter() {
415
+ document.body.addEventListener('keydown', this.handleKeydown);
416
+ },
417
+
418
+ handleLeave() {
419
+ this.$emit('dodestroy');
420
+ document.body.removeEventListener('keydown', this.handleKeydown);
421
+ },
422
+
423
+ handleKeydown(event) {
424
+ const keyCode = event.keyCode;
425
+ const list = [38, 40, 37, 39];
426
+ if (this.visible && !this.timePickerVisible) {
427
+ if (list.indexOf(keyCode) !== -1) {
428
+ this.handleKeyControl(keyCode);
429
+ event.stopPropagation();
430
+ event.preventDefault();
431
+ }
432
+ if (keyCode === 13 && this.userInputDate === null && this.userInputTime === null) { // Enter
433
+ this.emit(this.date, false);
434
+ }
435
+ }
436
+ },
437
+
438
+ handleKeyControl(keyCode) {
439
+ const mapping = {
440
+ 'year': {
441
+ 38: -4, 40: 4, 37: -1, 39: 1, offset: (date, step) => date.setFullYear(date.getFullYear() + step)
442
+ },
443
+ 'month': {
444
+ 38: -4, 40: 4, 37: -1, 39: 1, offset: (date, step) => date.setMonth(date.getMonth() + step)
445
+ },
446
+ 'week': {
447
+ 38: -1, 40: 1, 37: -1, 39: 1, offset: (date, step) => date.setDate(date.getDate() + step * 7)
448
+ },
449
+ 'day': {
450
+ 38: -7, 40: 7, 37: -1, 39: 1, offset: (date, step) => date.setDate(date.getDate() + step)
451
+ }
452
+ };
453
+ const mode = this.selectionMode;
454
+ const year = 3.1536e10;
455
+ const now = this.date.getTime();
456
+ const newDate = new Date(this.date.getTime());
457
+ while (Math.abs(now - newDate.getTime()) <= year) {
458
+ const map = mapping[mode];
459
+ map.offset(newDate, map[keyCode]);
460
+ if (typeof this.disabledDate === 'function' && this.disabledDate(newDate)) {
461
+ continue;
462
+ }
463
+ this.date = newDate;
464
+ this.$emit('pick', newDate, true);
465
+ break;
466
+ }
467
+ },
468
+
469
+ handleVisibleTimeChange(value) {
470
+ const time = parseDate(value, this.timeFormat);
471
+ if (time && this.checkDateWithinRange(time)) {
472
+ this.date = modifyDate(time, this.year, this.month, this.monthDate);
473
+ this.userInputTime = null;
474
+ this.$refs.timepicker.value = this.date;
475
+ this.timePickerVisible = false;
476
+ this.emit(this.date, true);
477
+ }
478
+ },
479
+
480
+ handleVisibleDateChange(value) {
481
+ const date = parseDate(value, this.dateFormat);
482
+ if (date) {
483
+ if (typeof this.disabledDate === 'function' && this.disabledDate(date)) {
484
+ return;
485
+ }
486
+ this.date = modifyTime(date, this.date.getHours(), this.date.getMinutes(), this.date.getSeconds());
487
+ this.userInputDate = null;
488
+ this.resetView();
489
+ this.emit(this.date, true);
490
+ }
491
+ },
492
+
493
+ isValidValue(value) {
494
+ return value && !isNaN(value) && (
495
+ typeof this.disabledDate === 'function'
496
+ ? !this.disabledDate(value)
497
+ : true
498
+ ) && this.checkDateWithinRange(value);
499
+ },
500
+
501
+ getDefaultValue() {
502
+ // if default-value is set, return it
503
+ // otherwise, return now (the moment this method gets called)
504
+ return this.defaultValue ? new Date(this.defaultValue) : new Date();
505
+ },
506
+
507
+ checkDateWithinRange(date) {
508
+ return this.selectableRange.length > 0
509
+ ? timeWithinRange(date, this.selectableRange, this.format || 'HH:mm:ss')
510
+ : true;
511
+ }
512
+ },
513
+
514
+ components: {
515
+ TimePicker, YearTable, MonthTable, DateTable, ElInput, ElButton
516
+ },
517
+
518
+ data() {
519
+ return {
520
+ popperClass: '',
521
+ date: new Date(),
522
+ value: '',
523
+ defaultValue: null, // use getDefaultValue() for time computation
524
+ defaultTime: null,
525
+ showTime: false,
526
+ selectionMode: 'day',
527
+ shortcuts: '',
528
+ visible: false,
529
+ currentView: 'date',
530
+ disabledDate: '',
531
+ cellClassName: '',
532
+ selectableRange: [],
533
+ firstDayOfWeek: 7,
534
+ showWeekNumber: false,
535
+ timePickerVisible: false,
536
+ format: '',
537
+ arrowControl: false,
538
+ userInputDate: null,
539
+ userInputTime: null
540
+ };
541
+ },
542
+
543
+ computed: {
544
+ year() {
545
+ return this.date.getFullYear();
546
+ },
547
+
548
+ month() {
549
+ return this.date.getMonth();
550
+ },
551
+
552
+ week() {
553
+ return getWeekNumber(this.date);
554
+ },
555
+
556
+ monthDate() {
557
+ return this.date.getDate();
558
+ },
559
+
560
+ footerVisible() {
561
+ return this.showTime || this.selectionMode === 'dates' || this.selectionMode === 'months' || this.selectionMode === 'years';
562
+ },
563
+
564
+ visibleTime() {
565
+ if (this.userInputTime !== null) {
566
+ return this.userInputTime;
567
+ } else {
568
+ return formatDate(this.value || this.defaultValue, this.timeFormat);
569
+ }
570
+ },
571
+
572
+ visibleDate() {
573
+ if (this.userInputDate !== null) {
574
+ return this.userInputDate;
575
+ } else {
576
+ return formatDate(this.value || this.defaultValue, this.dateFormat);
577
+ }
578
+ },
579
+
580
+ yearLabel() {
581
+ const yearTranslation = this.t('el.datepicker.year');
582
+ if (this.currentView === 'year') {
583
+ const startYear = Math.floor(this.year / 10) * 10;
584
+ if (yearTranslation) {
585
+ return startYear + ' ' + yearTranslation + ' - ' + (startYear + 9) + ' ' + yearTranslation;
586
+ }
587
+ return startYear + ' - ' + (startYear + 9);
588
+ }
589
+ return this.year + ' ' + yearTranslation;
590
+ },
591
+
592
+ timeFormat() {
593
+ if (this.format) {
594
+ return extractTimeFormat(this.format);
595
+ } else {
596
+ return 'HH:mm:ss';
597
+ }
598
+ },
599
+
600
+ dateFormat() {
601
+ if (this.format) {
602
+ return extractDateFormat(this.format);
603
+ } else {
604
+ return 'yyyy-MM-dd';
605
+ }
606
+ }
607
+ }
608
+ };
609
+ </script>