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,441 +1,441 @@
1
- <template>
2
- <table
3
- cellspacing="0"
4
- cellpadding="0"
5
- class="el-date-table"
6
- @click="handleClick"
7
- @mousemove="handleMouseMove"
8
- :class="{ 'is-week-mode': selectionMode === 'week' }">
9
- <tbody>
10
- <tr>
11
- <th v-if="showWeekNumber">{{ t('el.datepicker.week') }}</th>
12
- <th v-for="(week, key) in WEEKS" :key="key">{{ t('el.datepicker.weeks.' + week) }}</th>
13
- </tr>
14
- <tr
15
- class="el-date-table__row"
16
- v-for="(row, key) in rows"
17
- :class="{ current: isWeekActive(row[1]) }"
18
- :key="key">
19
- <td
20
- v-for="(cell, key) in row"
21
- :class="getCellClasses(cell)"
22
- :key="key">
23
- <div>
24
- <span>
25
- {{ cell.text }}
26
- </span>
27
- </div>
28
- </td>
29
- </tr>
30
- </tbody>
31
- </table>
32
- </template>
33
-
34
- <script>
35
- import { getFirstDayOfMonth, getDayCountOfMonth, getWeekNumber, getStartDateOfMonth, prevDate, nextDate, isDate, clearTime as _clearTime} from 'element-ui/src/utils/date-util';
36
- import Locale from 'element-ui/src/mixins/locale';
37
- import { arrayFindIndex, arrayFind, coerceTruthyValueToArray } from 'element-ui/src/utils/util';
38
-
39
- const WEEKS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
40
- const getDateTimestamp = function(time) {
41
- if (typeof time === 'number' || typeof time === 'string') {
42
- return _clearTime(new Date(time)).getTime();
43
- } else if (time instanceof Date) {
44
- return _clearTime(time).getTime();
45
- } else {
46
- return NaN;
47
- }
48
- };
49
-
50
- // remove the first element that satisfies `pred` from arr
51
- // return a new array if modification occurs
52
- // return the original array otherwise
53
- const removeFromArray = function(arr, pred) {
54
- const idx = typeof pred === 'function' ? arrayFindIndex(arr, pred) : arr.indexOf(pred);
55
- return idx >= 0 ? [...arr.slice(0, idx), ...arr.slice(idx + 1)] : arr;
56
- };
57
-
58
- export default {
59
- mixins: [Locale],
60
-
61
- props: {
62
- firstDayOfWeek: {
63
- default: 7,
64
- type: Number,
65
- validator: val => val >= 1 && val <= 7
66
- },
67
-
68
- value: {},
69
-
70
- defaultValue: {
71
- validator(val) {
72
- // either: null, valid Date object, Array of valid Date objects
73
- return val === null || isDate(val) || (Array.isArray(val) && val.every(isDate));
74
- }
75
- },
76
-
77
- date: {},
78
-
79
- selectionMode: {
80
- default: 'day'
81
- },
82
-
83
- showWeekNumber: {
84
- type: Boolean,
85
- default: false
86
- },
87
-
88
- disabledDate: {},
89
-
90
- cellClassName: {},
91
-
92
- minDate: {},
93
-
94
- maxDate: {},
95
-
96
- rangeState: {
97
- default() {
98
- return {
99
- endDate: null,
100
- selecting: false
101
- };
102
- }
103
- }
104
- },
105
-
106
- computed: {
107
- offsetDay() {
108
- const week = this.firstDayOfWeek;
109
- // 周日为界限,左右偏移的天数,3217654 例如周一就是 -1,目的是调整前两行日期的位置
110
- return week > 3 ? 7 - week : -week;
111
- },
112
-
113
- WEEKS() {
114
- const week = this.firstDayOfWeek;
115
- return WEEKS.concat(WEEKS).slice(week, week + 7);
116
- },
117
-
118
- year() {
119
- return this.date.getFullYear();
120
- },
121
-
122
- month() {
123
- return this.date.getMonth();
124
- },
125
-
126
- startDate() {
127
- return getStartDateOfMonth(this.year, this.month);
128
- },
129
-
130
- rows() {
131
- // TODO: refactory rows / getCellClasses
132
- const date = new Date(this.year, this.month, 1);
133
- let day = getFirstDayOfMonth(date); // day of first day
134
- const dateCountOfMonth = getDayCountOfMonth(date.getFullYear(), date.getMonth());
135
- const dateCountOfLastMonth = getDayCountOfMonth(date.getFullYear(), (date.getMonth() === 0 ? 11 : date.getMonth() - 1));
136
-
137
- day = (day === 0 ? 7 : day);
138
-
139
- const offset = this.offsetDay;
140
- const rows = this.tableRows;
141
- let count = 1;
142
-
143
- const startDate = this.startDate;
144
- const disabledDate = this.disabledDate;
145
- const cellClassName = this.cellClassName;
146
- const selectedDate = this.selectionMode === 'dates' ? coerceTruthyValueToArray(this.value) : [];
147
- const now = getDateTimestamp(new Date());
148
-
149
- for (let i = 0; i < 6; i++) {
150
- const row = rows[i];
151
-
152
- if (this.showWeekNumber) {
153
- if (!row[0]) {
154
- row[0] = { type: 'week', text: getWeekNumber(nextDate(startDate, i * 7 + 1)) };
155
- }
156
- }
157
-
158
- for (let j = 0; j < 7; j++) {
159
- let cell = row[this.showWeekNumber ? j + 1 : j];
160
- if (!cell) {
161
- cell = { row: i, column: j, type: 'normal', inRange: false, start: false, end: false };
162
- }
163
-
164
- cell.type = 'normal';
165
-
166
- const index = i * 7 + j;
167
- const time = nextDate(startDate, index - offset).getTime();
168
- cell.inRange = time >= getDateTimestamp(this.minDate) && time <= getDateTimestamp(this.maxDate);
169
- cell.start = this.minDate && time === getDateTimestamp(this.minDate);
170
- cell.end = this.maxDate && time === getDateTimestamp(this.maxDate);
171
- const isToday = time === now;
172
-
173
- if (isToday) {
174
- cell.type = 'today';
175
- }
176
-
177
- if (i >= 0 && i <= 1) {
178
- const numberOfDaysFromPreviousMonth = day + offset < 0 ? 7 + day + offset : day + offset;
179
-
180
- if (j + i * 7 >= numberOfDaysFromPreviousMonth) {
181
- cell.text = count++;
182
- } else {
183
- cell.text = dateCountOfLastMonth - (numberOfDaysFromPreviousMonth - j % 7) + 1 + i * 7;
184
- cell.type = 'prev-month';
185
- }
186
- } else {
187
- if (count <= dateCountOfMonth) {
188
- cell.text = count++;
189
- } else {
190
- cell.text = count++ - dateCountOfMonth;
191
- cell.type = 'next-month';
192
- }
193
- }
194
-
195
- let cellDate = new Date(time);
196
- cell.disabled = typeof disabledDate === 'function' && disabledDate(cellDate);
197
- cell.selected = arrayFind(selectedDate, date => date.getTime() === cellDate.getTime());
198
- cell.customClass = typeof cellClassName === 'function' && cellClassName(cellDate);
199
- this.$set(row, this.showWeekNumber ? j + 1 : j, cell);
200
- }
201
-
202
- if (this.selectionMode === 'week') {
203
- const start = this.showWeekNumber ? 1 : 0;
204
- const end = this.showWeekNumber ? 7 : 6;
205
- const isWeekActive = this.isWeekActive(row[start + 1]);
206
-
207
- row[start].inRange = isWeekActive;
208
- row[start].start = isWeekActive;
209
- row[end].inRange = isWeekActive;
210
- row[end].end = isWeekActive;
211
- }
212
- }
213
-
214
- return rows;
215
- }
216
- },
217
-
218
- watch: {
219
- 'rangeState.endDate'(newVal) {
220
- this.markRange(this.minDate, newVal);
221
- },
222
-
223
- minDate(newVal, oldVal) {
224
- if (getDateTimestamp(newVal) !== getDateTimestamp(oldVal)) {
225
- this.markRange(this.minDate, this.maxDate);
226
- }
227
- },
228
-
229
- maxDate(newVal, oldVal) {
230
- if (getDateTimestamp(newVal) !== getDateTimestamp(oldVal)) {
231
- this.markRange(this.minDate, this.maxDate);
232
- }
233
- }
234
- },
235
-
236
- data() {
237
- return {
238
- tableRows: [ [], [], [], [], [], [] ],
239
- lastRow: null,
240
- lastColumn: null
241
- };
242
- },
243
-
244
- methods: {
245
- cellMatchesDate(cell, date) {
246
- const value = new Date(date);
247
- return this.year === value.getFullYear() &&
248
- this.month === value.getMonth() &&
249
- Number(cell.text) === value.getDate();
250
- },
251
-
252
- getCellClasses(cell) {
253
- const selectionMode = this.selectionMode;
254
- const defaultValue = this.defaultValue ? Array.isArray(this.defaultValue) ? this.defaultValue : [this.defaultValue] : [];
255
-
256
- let classes = [];
257
- if ((cell.type === 'normal' || cell.type === 'today') && !cell.disabled) {
258
- classes.push('available');
259
- if (cell.type === 'today') {
260
- classes.push('today');
261
- }
262
- } else {
263
- classes.push(cell.type);
264
- }
265
-
266
- if (cell.type === 'normal' && defaultValue.some(date => this.cellMatchesDate(cell, date))) {
267
- classes.push('default');
268
- }
269
-
270
- if (selectionMode === 'day' && (cell.type === 'normal' || cell.type === 'today') && this.cellMatchesDate(cell, this.value)) {
271
- classes.push('current');
272
- }
273
-
274
- if (cell.inRange && ((cell.type === 'normal' || cell.type === 'today') || this.selectionMode === 'week')) {
275
- classes.push('in-range');
276
-
277
- if (cell.start) {
278
- classes.push('start-date');
279
- }
280
-
281
- if (cell.end) {
282
- classes.push('end-date');
283
- }
284
- }
285
-
286
- if (cell.disabled) {
287
- classes.push('disabled');
288
- }
289
-
290
- if (cell.selected) {
291
- classes.push('selected');
292
- }
293
-
294
- if (cell.customClass) {
295
- classes.push(cell.customClass);
296
- }
297
-
298
- return classes.join(' ');
299
- },
300
-
301
- getDateOfCell(row, column) {
302
- const offsetFromStart = row * 7 + (column - (this.showWeekNumber ? 1 : 0)) - this.offsetDay;
303
- return nextDate(this.startDate, offsetFromStart);
304
- },
305
-
306
- isWeekActive(cell) {
307
- if (this.selectionMode !== 'week') return false;
308
- const newDate = new Date(this.year, this.month, 1);
309
- const year = newDate.getFullYear();
310
- const month = newDate.getMonth();
311
-
312
- if (cell.type === 'prev-month') {
313
- newDate.setMonth(month === 0 ? 11 : month - 1);
314
- newDate.setFullYear(month === 0 ? year - 1 : year);
315
- }
316
-
317
- if (cell.type === 'next-month') {
318
- newDate.setMonth(month === 11 ? 0 : month + 1);
319
- newDate.setFullYear(month === 11 ? year + 1 : year);
320
- }
321
-
322
- newDate.setDate(parseInt(cell.text, 10));
323
-
324
- if (isDate(this.value)) {
325
- const dayOffset = (this.value.getDay() - this.firstDayOfWeek + 7) % 7 - 1;
326
- const weekDate = prevDate(this.value, dayOffset);
327
- return weekDate.getTime() === newDate.getTime();
328
- }
329
- return false;
330
- },
331
-
332
- markRange(minDate, maxDate) {
333
- minDate = getDateTimestamp(minDate);
334
- maxDate = getDateTimestamp(maxDate) || minDate;
335
- [minDate, maxDate] = [Math.min(minDate, maxDate), Math.max(minDate, maxDate)];
336
-
337
- const startDate = this.startDate;
338
- const rows = this.rows;
339
- for (let i = 0, k = rows.length; i < k; i++) {
340
- const row = rows[i];
341
- for (let j = 0, l = row.length; j < l; j++) {
342
- if (this.showWeekNumber && j === 0) continue;
343
-
344
- const cell = row[j];
345
- const index = i * 7 + j + (this.showWeekNumber ? -1 : 0);
346
- const time = nextDate(startDate, index - this.offsetDay).getTime();
347
-
348
- cell.inRange = minDate && time >= minDate && time <= maxDate;
349
- cell.start = minDate && time === minDate;
350
- cell.end = maxDate && time === maxDate;
351
- }
352
- }
353
- },
354
-
355
- handleMouseMove(event) {
356
- if (!this.rangeState.selecting) return;
357
-
358
- let target = event.target;
359
- if (target.tagName === 'SPAN') {
360
- target = target.parentNode.parentNode;
361
- }
362
- if (target.tagName === 'DIV') {
363
- target = target.parentNode;
364
- }
365
- if (target.tagName !== 'TD') return;
366
-
367
- const row = target.parentNode.rowIndex - 1;
368
- const column = target.cellIndex;
369
-
370
- // can not select disabled date
371
- if (this.rows[row][column].disabled) return;
372
-
373
- // only update rangeState when mouse moves to a new cell
374
- // this avoids frequent Date object creation and improves performance
375
- if (row !== this.lastRow || column !== this.lastColumn) {
376
- this.lastRow = row;
377
- this.lastColumn = column;
378
- this.$emit('changerange', {
379
- minDate: this.minDate,
380
- maxDate: this.maxDate,
381
- rangeState: {
382
- selecting: true,
383
- endDate: this.getDateOfCell(row, column)
384
- }
385
- });
386
- }
387
- },
388
-
389
- handleClick(event) {
390
- let target = event.target;
391
- if (target.tagName === 'SPAN') {
392
- target = target.parentNode.parentNode;
393
- }
394
- if (target.tagName === 'DIV') {
395
- target = target.parentNode;
396
- }
397
-
398
- if (target.tagName !== 'TD') return;
399
-
400
- const row = target.parentNode.rowIndex - 1;
401
- const column = this.selectionMode === 'week' ? 1 : target.cellIndex;
402
- const cell = this.rows[row][column];
403
-
404
- if (cell.disabled || cell.type === 'week') return;
405
-
406
- const newDate = this.getDateOfCell(row, column);
407
-
408
- if (this.selectionMode === 'range') {
409
- if (!this.rangeState.selecting) {
410
- this.$emit('pick', {minDate: newDate, maxDate: null});
411
- this.rangeState.selecting = true;
412
- } else {
413
- if (newDate >= this.minDate) {
414
- this.$emit('pick', {minDate: this.minDate, maxDate: newDate});
415
- } else {
416
- this.$emit('pick', {minDate: newDate, maxDate: this.minDate});
417
- }
418
- this.rangeState.selecting = false;
419
- }
420
- } else if (this.selectionMode === 'day') {
421
- this.$emit('pick', newDate);
422
- } else if (this.selectionMode === 'week') {
423
- const weekNumber = getWeekNumber(newDate);
424
- const value = newDate.getFullYear() + 'w' + weekNumber;
425
- this.$emit('pick', {
426
- year: newDate.getFullYear(),
427
- week: weekNumber,
428
- value: value,
429
- date: newDate
430
- });
431
- } else if (this.selectionMode === 'dates') {
432
- const value = this.value || [];
433
- const newValue = cell.selected
434
- ? removeFromArray(value, date => date.getTime() === newDate.getTime())
435
- : [...value, newDate];
436
- this.$emit('pick', newValue);
437
- }
438
- }
439
- }
440
- };
441
- </script>
1
+ <template>
2
+ <table
3
+ cellspacing="0"
4
+ cellpadding="0"
5
+ class="el-date-table"
6
+ @click="handleClick"
7
+ @mousemove="handleMouseMove"
8
+ :class="{ 'is-week-mode': selectionMode === 'week' }">
9
+ <tbody>
10
+ <tr>
11
+ <th v-if="showWeekNumber">{{ t('el.datepicker.week') }}</th>
12
+ <th v-for="(week, key) in WEEKS" :key="key">{{ t('el.datepicker.weeks.' + week) }}</th>
13
+ </tr>
14
+ <tr
15
+ class="el-date-table__row"
16
+ v-for="(row, key) in rows"
17
+ :class="{ current: isWeekActive(row[1]) }"
18
+ :key="key">
19
+ <td
20
+ v-for="(cell, key) in row"
21
+ :class="getCellClasses(cell)"
22
+ :key="key">
23
+ <div>
24
+ <span>
25
+ {{ cell.text }}
26
+ </span>
27
+ </div>
28
+ </td>
29
+ </tr>
30
+ </tbody>
31
+ </table>
32
+ </template>
33
+
34
+ <script>
35
+ import { getFirstDayOfMonth, getDayCountOfMonth, getWeekNumber, getStartDateOfMonth, prevDate, nextDate, isDate, clearTime as _clearTime} from 'element-ui/src/utils/date-util';
36
+ import Locale from 'element-ui/src/mixins/locale';
37
+ import { arrayFindIndex, arrayFind, coerceTruthyValueToArray } from 'element-ui/src/utils/util';
38
+
39
+ const WEEKS = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
40
+ const getDateTimestamp = function(time) {
41
+ if (typeof time === 'number' || typeof time === 'string') {
42
+ return _clearTime(new Date(time)).getTime();
43
+ } else if (time instanceof Date) {
44
+ return _clearTime(time).getTime();
45
+ } else {
46
+ return NaN;
47
+ }
48
+ };
49
+
50
+ // remove the first element that satisfies `pred` from arr
51
+ // return a new array if modification occurs
52
+ // return the original array otherwise
53
+ const removeFromArray = function(arr, pred) {
54
+ const idx = typeof pred === 'function' ? arrayFindIndex(arr, pred) : arr.indexOf(pred);
55
+ return idx >= 0 ? [...arr.slice(0, idx), ...arr.slice(idx + 1)] : arr;
56
+ };
57
+
58
+ export default {
59
+ mixins: [Locale],
60
+
61
+ props: {
62
+ firstDayOfWeek: {
63
+ default: 7,
64
+ type: Number,
65
+ validator: val => val >= 1 && val <= 7
66
+ },
67
+
68
+ value: {},
69
+
70
+ defaultValue: {
71
+ validator(val) {
72
+ // either: null, valid Date object, Array of valid Date objects
73
+ return val === null || isDate(val) || (Array.isArray(val) && val.every(isDate));
74
+ }
75
+ },
76
+
77
+ date: {},
78
+
79
+ selectionMode: {
80
+ default: 'day'
81
+ },
82
+
83
+ showWeekNumber: {
84
+ type: Boolean,
85
+ default: false
86
+ },
87
+
88
+ disabledDate: {},
89
+
90
+ cellClassName: {},
91
+
92
+ minDate: {},
93
+
94
+ maxDate: {},
95
+
96
+ rangeState: {
97
+ default() {
98
+ return {
99
+ endDate: null,
100
+ selecting: false
101
+ };
102
+ }
103
+ }
104
+ },
105
+
106
+ computed: {
107
+ offsetDay() {
108
+ const week = this.firstDayOfWeek;
109
+ // 周日为界限,左右偏移的天数,3217654 例如周一就是 -1,目的是调整前两行日期的位置
110
+ return week > 3 ? 7 - week : -week;
111
+ },
112
+
113
+ WEEKS() {
114
+ const week = this.firstDayOfWeek;
115
+ return WEEKS.concat(WEEKS).slice(week, week + 7);
116
+ },
117
+
118
+ year() {
119
+ return this.date.getFullYear();
120
+ },
121
+
122
+ month() {
123
+ return this.date.getMonth();
124
+ },
125
+
126
+ startDate() {
127
+ return getStartDateOfMonth(this.year, this.month);
128
+ },
129
+
130
+ rows() {
131
+ // TODO: refactory rows / getCellClasses
132
+ const date = new Date(this.year, this.month, 1);
133
+ let day = getFirstDayOfMonth(date); // day of first day
134
+ const dateCountOfMonth = getDayCountOfMonth(date.getFullYear(), date.getMonth());
135
+ const dateCountOfLastMonth = getDayCountOfMonth(date.getFullYear(), (date.getMonth() === 0 ? 11 : date.getMonth() - 1));
136
+
137
+ day = (day === 0 ? 7 : day);
138
+
139
+ const offset = this.offsetDay;
140
+ const rows = this.tableRows;
141
+ let count = 1;
142
+
143
+ const startDate = this.startDate;
144
+ const disabledDate = this.disabledDate;
145
+ const cellClassName = this.cellClassName;
146
+ const selectedDate = this.selectionMode === 'dates' ? coerceTruthyValueToArray(this.value) : [];
147
+ const now = getDateTimestamp(new Date());
148
+
149
+ for (let i = 0; i < 6; i++) {
150
+ const row = rows[i];
151
+
152
+ if (this.showWeekNumber) {
153
+ if (!row[0]) {
154
+ row[0] = { type: 'week', text: getWeekNumber(nextDate(startDate, i * 7 + 1)) };
155
+ }
156
+ }
157
+
158
+ for (let j = 0; j < 7; j++) {
159
+ let cell = row[this.showWeekNumber ? j + 1 : j];
160
+ if (!cell) {
161
+ cell = { row: i, column: j, type: 'normal', inRange: false, start: false, end: false };
162
+ }
163
+
164
+ cell.type = 'normal';
165
+
166
+ const index = i * 7 + j;
167
+ const time = nextDate(startDate, index - offset).getTime();
168
+ cell.inRange = time >= getDateTimestamp(this.minDate) && time <= getDateTimestamp(this.maxDate);
169
+ cell.start = this.minDate && time === getDateTimestamp(this.minDate);
170
+ cell.end = this.maxDate && time === getDateTimestamp(this.maxDate);
171
+ const isToday = time === now;
172
+
173
+ if (isToday) {
174
+ cell.type = 'today';
175
+ }
176
+
177
+ if (i >= 0 && i <= 1) {
178
+ const numberOfDaysFromPreviousMonth = day + offset < 0 ? 7 + day + offset : day + offset;
179
+
180
+ if (j + i * 7 >= numberOfDaysFromPreviousMonth) {
181
+ cell.text = count++;
182
+ } else {
183
+ cell.text = dateCountOfLastMonth - (numberOfDaysFromPreviousMonth - j % 7) + 1 + i * 7;
184
+ cell.type = 'prev-month';
185
+ }
186
+ } else {
187
+ if (count <= dateCountOfMonth) {
188
+ cell.text = count++;
189
+ } else {
190
+ cell.text = count++ - dateCountOfMonth;
191
+ cell.type = 'next-month';
192
+ }
193
+ }
194
+
195
+ let cellDate = new Date(time);
196
+ cell.disabled = typeof disabledDate === 'function' && disabledDate(cellDate);
197
+ cell.selected = arrayFind(selectedDate, date => date.getTime() === cellDate.getTime());
198
+ cell.customClass = typeof cellClassName === 'function' && cellClassName(cellDate);
199
+ this.$set(row, this.showWeekNumber ? j + 1 : j, cell);
200
+ }
201
+
202
+ if (this.selectionMode === 'week') {
203
+ const start = this.showWeekNumber ? 1 : 0;
204
+ const end = this.showWeekNumber ? 7 : 6;
205
+ const isWeekActive = this.isWeekActive(row[start + 1]);
206
+
207
+ row[start].inRange = isWeekActive;
208
+ row[start].start = isWeekActive;
209
+ row[end].inRange = isWeekActive;
210
+ row[end].end = isWeekActive;
211
+ }
212
+ }
213
+
214
+ return rows;
215
+ }
216
+ },
217
+
218
+ watch: {
219
+ 'rangeState.endDate'(newVal) {
220
+ this.markRange(this.minDate, newVal);
221
+ },
222
+
223
+ minDate(newVal, oldVal) {
224
+ if (getDateTimestamp(newVal) !== getDateTimestamp(oldVal)) {
225
+ this.markRange(this.minDate, this.maxDate);
226
+ }
227
+ },
228
+
229
+ maxDate(newVal, oldVal) {
230
+ if (getDateTimestamp(newVal) !== getDateTimestamp(oldVal)) {
231
+ this.markRange(this.minDate, this.maxDate);
232
+ }
233
+ }
234
+ },
235
+
236
+ data() {
237
+ return {
238
+ tableRows: [ [], [], [], [], [], [] ],
239
+ lastRow: null,
240
+ lastColumn: null
241
+ };
242
+ },
243
+
244
+ methods: {
245
+ cellMatchesDate(cell, date) {
246
+ const value = new Date(date);
247
+ return this.year === value.getFullYear() &&
248
+ this.month === value.getMonth() &&
249
+ Number(cell.text) === value.getDate();
250
+ },
251
+
252
+ getCellClasses(cell) {
253
+ const selectionMode = this.selectionMode;
254
+ const defaultValue = this.defaultValue ? Array.isArray(this.defaultValue) ? this.defaultValue : [this.defaultValue] : [];
255
+
256
+ let classes = [];
257
+ if ((cell.type === 'normal' || cell.type === 'today') && !cell.disabled) {
258
+ classes.push('available');
259
+ if (cell.type === 'today') {
260
+ classes.push('today');
261
+ }
262
+ } else {
263
+ classes.push(cell.type);
264
+ }
265
+
266
+ if (cell.type === 'normal' && defaultValue.some(date => this.cellMatchesDate(cell, date))) {
267
+ classes.push('default');
268
+ }
269
+
270
+ if (selectionMode === 'day' && (cell.type === 'normal' || cell.type === 'today') && this.cellMatchesDate(cell, this.value)) {
271
+ classes.push('current');
272
+ }
273
+
274
+ if (cell.inRange && ((cell.type === 'normal' || cell.type === 'today') || this.selectionMode === 'week')) {
275
+ classes.push('in-range');
276
+
277
+ if (cell.start) {
278
+ classes.push('start-date');
279
+ }
280
+
281
+ if (cell.end) {
282
+ classes.push('end-date');
283
+ }
284
+ }
285
+
286
+ if (cell.disabled) {
287
+ classes.push('disabled');
288
+ }
289
+
290
+ if (cell.selected) {
291
+ classes.push('selected');
292
+ }
293
+
294
+ if (cell.customClass) {
295
+ classes.push(cell.customClass);
296
+ }
297
+
298
+ return classes.join(' ');
299
+ },
300
+
301
+ getDateOfCell(row, column) {
302
+ const offsetFromStart = row * 7 + (column - (this.showWeekNumber ? 1 : 0)) - this.offsetDay;
303
+ return nextDate(this.startDate, offsetFromStart);
304
+ },
305
+
306
+ isWeekActive(cell) {
307
+ if (this.selectionMode !== 'week') return false;
308
+ const newDate = new Date(this.year, this.month, 1);
309
+ const year = newDate.getFullYear();
310
+ const month = newDate.getMonth();
311
+
312
+ if (cell.type === 'prev-month') {
313
+ newDate.setMonth(month === 0 ? 11 : month - 1);
314
+ newDate.setFullYear(month === 0 ? year - 1 : year);
315
+ }
316
+
317
+ if (cell.type === 'next-month') {
318
+ newDate.setMonth(month === 11 ? 0 : month + 1);
319
+ newDate.setFullYear(month === 11 ? year + 1 : year);
320
+ }
321
+
322
+ newDate.setDate(parseInt(cell.text, 10));
323
+
324
+ if (isDate(this.value)) {
325
+ const dayOffset = (this.value.getDay() - this.firstDayOfWeek + 7) % 7 - 1;
326
+ const weekDate = prevDate(this.value, dayOffset);
327
+ return weekDate.getTime() === newDate.getTime();
328
+ }
329
+ return false;
330
+ },
331
+
332
+ markRange(minDate, maxDate) {
333
+ minDate = getDateTimestamp(minDate);
334
+ maxDate = getDateTimestamp(maxDate) || minDate;
335
+ [minDate, maxDate] = [Math.min(minDate, maxDate), Math.max(minDate, maxDate)];
336
+
337
+ const startDate = this.startDate;
338
+ const rows = this.rows;
339
+ for (let i = 0, k = rows.length; i < k; i++) {
340
+ const row = rows[i];
341
+ for (let j = 0, l = row.length; j < l; j++) {
342
+ if (this.showWeekNumber && j === 0) continue;
343
+
344
+ const cell = row[j];
345
+ const index = i * 7 + j + (this.showWeekNumber ? -1 : 0);
346
+ const time = nextDate(startDate, index - this.offsetDay).getTime();
347
+
348
+ cell.inRange = minDate && time >= minDate && time <= maxDate;
349
+ cell.start = minDate && time === minDate;
350
+ cell.end = maxDate && time === maxDate;
351
+ }
352
+ }
353
+ },
354
+
355
+ handleMouseMove(event) {
356
+ if (!this.rangeState.selecting) return;
357
+
358
+ let target = event.target;
359
+ if (target.tagName === 'SPAN') {
360
+ target = target.parentNode.parentNode;
361
+ }
362
+ if (target.tagName === 'DIV') {
363
+ target = target.parentNode;
364
+ }
365
+ if (target.tagName !== 'TD') return;
366
+
367
+ const row = target.parentNode.rowIndex - 1;
368
+ const column = target.cellIndex;
369
+
370
+ // can not select disabled date
371
+ if (this.rows[row][column].disabled) return;
372
+
373
+ // only update rangeState when mouse moves to a new cell
374
+ // this avoids frequent Date object creation and improves performance
375
+ if (row !== this.lastRow || column !== this.lastColumn) {
376
+ this.lastRow = row;
377
+ this.lastColumn = column;
378
+ this.$emit('changerange', {
379
+ minDate: this.minDate,
380
+ maxDate: this.maxDate,
381
+ rangeState: {
382
+ selecting: true,
383
+ endDate: this.getDateOfCell(row, column)
384
+ }
385
+ });
386
+ }
387
+ },
388
+
389
+ handleClick(event) {
390
+ let target = event.target;
391
+ if (target.tagName === 'SPAN') {
392
+ target = target.parentNode.parentNode;
393
+ }
394
+ if (target.tagName === 'DIV') {
395
+ target = target.parentNode;
396
+ }
397
+
398
+ if (target.tagName !== 'TD') return;
399
+
400
+ const row = target.parentNode.rowIndex - 1;
401
+ const column = this.selectionMode === 'week' ? 1 : target.cellIndex;
402
+ const cell = this.rows[row][column];
403
+
404
+ if (cell.disabled || cell.type === 'week') return;
405
+
406
+ const newDate = this.getDateOfCell(row, column);
407
+
408
+ if (this.selectionMode === 'range') {
409
+ if (!this.rangeState.selecting) {
410
+ this.$emit('pick', {minDate: newDate, maxDate: null});
411
+ this.rangeState.selecting = true;
412
+ } else {
413
+ if (newDate >= this.minDate) {
414
+ this.$emit('pick', {minDate: this.minDate, maxDate: newDate});
415
+ } else {
416
+ this.$emit('pick', {minDate: newDate, maxDate: this.minDate});
417
+ }
418
+ this.rangeState.selecting = false;
419
+ }
420
+ } else if (this.selectionMode === 'day') {
421
+ this.$emit('pick', newDate);
422
+ } else if (this.selectionMode === 'week') {
423
+ const weekNumber = getWeekNumber(newDate);
424
+ const value = newDate.getFullYear() + 'w' + weekNumber;
425
+ this.$emit('pick', {
426
+ year: newDate.getFullYear(),
427
+ week: weekNumber,
428
+ value: value,
429
+ date: newDate
430
+ });
431
+ } else if (this.selectionMode === 'dates') {
432
+ const value = this.value || [];
433
+ const newValue = cell.selected
434
+ ? removeFromArray(value, date => date.getTime() === newDate.getTime())
435
+ : [...value, newDate];
436
+ this.$emit('pick', newValue);
437
+ }
438
+ }
439
+ }
440
+ };
441
+ </script>