@94ai/nf-double-week 3.1.37 → 3.1.39

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.
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/css/nf-double-week.css'
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/nf-double-week.scss'
@@ -0,0 +1,436 @@
1
+ <template>
2
+ <transition name="el-zoom-in-top" @after-leave="$emit('dodestroy')">
3
+ <div
4
+ v-show="visible"
5
+ class="el-picker-panel el-date-range-picker el-popper nf-double-week nf-double-week-week-range"
6
+ :class="[{
7
+ 'has-sidebar': $slots.sidebar || shortcuts
8
+ }, popperClass]"
9
+ >
10
+ <div class="el-picker-panel__body-wrapper">
11
+ <slot name="sidebar" class="el-picker-panel__sidebar" />
12
+ <div v-if="shortcuts" class="el-picker-panel__sidebar">
13
+ <button
14
+ v-for="(shortcut, key) in shortcuts"
15
+ :key="key"
16
+ type="button"
17
+ class="el-picker-panel__shortcut"
18
+ @click="handleShortcutClick(shortcut)"
19
+ >{{ shortcut.text }}</button>
20
+ </div>
21
+ <div class="el-picker-panel__body">
22
+ <div class="el-picker-panel__content el-date-range-picker__content is-left">
23
+ <div class="el-date-range-picker__header">
24
+ <button
25
+ type="button"
26
+ class="el-picker-panel__icon-btn el-icon-d-arrow-left"
27
+ @click="leftPrevYear"
28
+ />
29
+ <button
30
+ type="button"
31
+ class="el-picker-panel__icon-btn el-icon-arrow-left"
32
+ @click="leftPrevMonth"
33
+ />
34
+ <button
35
+ v-if="unlinkPanels"
36
+ type="button"
37
+ :disabled="!enableYearArrow"
38
+ :class="{ 'is-disabled': !enableYearArrow }"
39
+ class="el-picker-panel__icon-btn el-icon-d-arrow-right"
40
+ @click="leftNextYear"
41
+ />
42
+ <button
43
+ v-if="unlinkPanels"
44
+ type="button"
45
+ :disabled="!enableMonthArrow"
46
+ :class="{ 'is-disabled': !enableMonthArrow }"
47
+ class="el-picker-panel__icon-btn el-icon-arrow-right"
48
+ @click="leftNextMonth"
49
+ />
50
+ <div>{{ leftLabel }}</div>
51
+ </div>
52
+ <week-table
53
+ selection-mode="weekrange"
54
+ :date="leftDate"
55
+ :default-value="defaultValue"
56
+ :min-date="minDate"
57
+ :max-date="maxDate"
58
+ :range-state="rangeState"
59
+ :disabled-date="disabledDate"
60
+ :cell-class-name="cellClassName"
61
+ :first-day-of-week="firstDayOfWeek"
62
+ @changerange="handleChangeRange"
63
+ @pick="handleRangePick"
64
+ />
65
+ </div>
66
+ <div class="el-picker-panel__content el-date-range-picker__content is-right">
67
+ <div class="el-date-range-picker__header">
68
+ <button
69
+ v-if="unlinkPanels"
70
+ type="button"
71
+ :disabled="!enableYearArrow"
72
+ :class="{ 'is-disabled': !enableYearArrow }"
73
+ class="el-picker-panel__icon-btn el-icon-d-arrow-left"
74
+ @click="rightPrevYear"
75
+ />
76
+ <button
77
+ v-if="unlinkPanels"
78
+ type="button"
79
+ :disabled="!enableMonthArrow"
80
+ :class="{ 'is-disabled': !enableMonthArrow }"
81
+ class="el-picker-panel__icon-btn el-icon-arrow-left"
82
+ @click="rightPrevMonth"
83
+ />
84
+ <button
85
+ type="button"
86
+ class="el-picker-panel__icon-btn el-icon-d-arrow-right"
87
+ @click="rightNextYear"
88
+ />
89
+ <button
90
+ type="button"
91
+ class="el-picker-panel__icon-btn el-icon-arrow-right"
92
+ @click="rightNextMonth"
93
+ />
94
+ <div>{{ rightLabel }}</div>
95
+ </div>
96
+ <week-table
97
+ selection-mode="weekrange"
98
+ :date="rightDate"
99
+ :default-value="defaultValue"
100
+ :min-date="minDate"
101
+ :max-date="maxDate"
102
+ :range-state="rangeState"
103
+ :disabled-date="disabledDate"
104
+ :cell-class-name="cellClassName"
105
+ :first-day-of-week="firstDayOfWeek"
106
+ @changerange="handleChangeRange"
107
+ @pick="handleRangePick"
108
+ />
109
+ </div>
110
+ </div>
111
+ </div>
112
+ </div>
113
+ </transition>
114
+ </template>
115
+
116
+ <script type="text/babel">
117
+ import {
118
+ formatDate,
119
+ parseDate,
120
+ isDate,
121
+ modifyWithTimeString,
122
+ prevYear,
123
+ nextYear,
124
+ prevMonth,
125
+ nextMonth,
126
+ nextDate
127
+ } from 'element-ui/src/utils/date-util'
128
+ import Clickoutside from 'element-ui/src/utils/clickoutside'
129
+ import Locale from 'element-ui/src/mixins/locale'
130
+ import WeekTable from './week-table.vue'
131
+
132
+ const calcDefaultValue = (defaultValue) => {
133
+ if (Array.isArray(defaultValue)) {
134
+ return [new Date(defaultValue[0]), new Date(defaultValue[1])]
135
+ } else if (defaultValue) {
136
+ return [new Date(defaultValue), nextDate(new Date(defaultValue), 1)]
137
+ } else {
138
+ return [new Date(), nextDate(new Date(), 1)]
139
+ }
140
+ }
141
+
142
+ export default {
143
+
144
+ directives: { Clickoutside },
145
+
146
+ components: { WeekTable },
147
+ mixins: [Locale],
148
+
149
+ data() {
150
+ return {
151
+ popperClass: '',
152
+ value: [],
153
+ defaultValue: null,
154
+ defaultTime: null,
155
+ minDate: '',
156
+ maxDate: '',
157
+ leftDate: new Date(),
158
+ rightDate: nextMonth(new Date()),
159
+ rangeState: {
160
+ endDate: null,
161
+ selecting: false,
162
+ row: null,
163
+ column: null
164
+ },
165
+ shortcuts: '',
166
+ visible: '',
167
+ disabledDate: '',
168
+ cellClassName: '',
169
+ firstDayOfWeek: 7,
170
+ format: '',
171
+ arrowControl: false,
172
+ unlinkPanels: false,
173
+ dateUserInput: {
174
+ min: null,
175
+ max: null
176
+ },
177
+ timeUserInput: {
178
+ min: null,
179
+ max: null
180
+ }
181
+ }
182
+ },
183
+
184
+ computed: {
185
+ leftLabel() {
186
+ return this.leftDate.getFullYear() + ' ' + this.t('el.datepicker.year') + ' ' + this.t(`el.datepicker.month${this.leftDate.getMonth() + 1}`)
187
+ },
188
+
189
+ rightLabel() {
190
+ return this.rightDate.getFullYear() + ' ' + this.t('el.datepicker.year') + ' ' + this.t(`el.datepicker.month${this.rightDate.getMonth() + 1}`)
191
+ },
192
+
193
+ leftYear() {
194
+ return this.leftDate.getFullYear()
195
+ },
196
+
197
+ leftMonth() {
198
+ return this.leftDate.getMonth()
199
+ },
200
+
201
+ rightYear() {
202
+ return this.rightDate.getFullYear()
203
+ },
204
+
205
+ rightMonth() {
206
+ return this.rightDate.getMonth()
207
+ },
208
+
209
+ enableMonthArrow() {
210
+ const nextMonth = (this.leftMonth + 1) % 12
211
+ const yearOffset = this.leftMonth + 1 >= 12 ? 1 : 0
212
+ return this.unlinkPanels && new Date(this.leftYear + yearOffset, nextMonth) < new Date(this.rightYear, this.rightMonth)
213
+ },
214
+
215
+ enableYearArrow() {
216
+ return this.unlinkPanels && this.rightYear * 12 + this.rightMonth - (this.leftYear * 12 + this.leftMonth + 1) >= 12
217
+ }
218
+ },
219
+
220
+ watch: {
221
+ minDate() {
222
+ this.dateUserInput.min = null
223
+ this.timeUserInput.min = null
224
+ this.$nextTick(() => {
225
+ if (this.$refs.maxTimePicker && this.maxDate && this.maxDate < this.minDate) {
226
+ const format = 'HH:mm:ss'
227
+ this.$refs.maxTimePicker.selectableRange = [
228
+ [
229
+ parseDate(formatDate(this.minDate, format), format),
230
+ parseDate('23:59:59', format)
231
+ ]
232
+ ]
233
+ }
234
+ })
235
+ },
236
+
237
+ maxDate(val) {
238
+ this.dateUserInput.max = null
239
+ this.timeUserInput.max = null
240
+ if (val && this.$refs.maxTimePicker) {
241
+ this.$refs.maxTimePicker.date = val
242
+ this.$refs.maxTimePicker.value = val
243
+ }
244
+ },
245
+
246
+ value(newVal) {
247
+ if (!newVal) {
248
+ this.minDate = null
249
+ this.maxDate = null
250
+ } else if (Array.isArray(newVal)) {
251
+ if (newVal?.length < 2) {
252
+ return
253
+ }
254
+ this.minDate = isDate(newVal[0]) ? new Date(newVal[0]) : null
255
+ this.maxDate = isDate(newVal[1]) ? new Date(newVal[1]) : null
256
+
257
+ if (this.minDate && this.maxDate) {
258
+ if (this.minDate.getTime() > this.maxDate.getTime()) {
259
+ const maxDate = this.minDate
260
+
261
+ this.minDate = this.maxDate
262
+ this.maxDate = maxDate
263
+ }
264
+
265
+ const prevWeekDay = Math.abs(7 - this.firstDayOfWeek + this.minDate.getDay()) % 7
266
+ this.minDate = new Date(this.minDate.getTime() - prevWeekDay * 60 * 60 * 24 * 1000)
267
+
268
+ const nextWeekDay = Math.abs(this.firstDayOfWeek - 1 - this.maxDate.getDay()) % 7
269
+ this.maxDate = new Date(this.maxDate.getTime() + nextWeekDay * 60 * 60 * 24 * 1000)
270
+ }
271
+
272
+ this.handleMinMaxDateWeek()
273
+
274
+ if (this.minDate) {
275
+ this.leftDate = this.minDate
276
+ if (this.unlinkPanels && this.maxDate) {
277
+ const minDateYear = this.minDate.getFullYear()
278
+ const minDateMonth = this.minDate.getMonth()
279
+ const maxDateYear = this.maxDate.getFullYear()
280
+ const maxDateMonth = this.maxDate.getMonth()
281
+ this.rightDate = minDateYear === maxDateYear && minDateMonth === maxDateMonth
282
+ ? nextMonth(this.maxDate)
283
+ : this.maxDate
284
+ } else {
285
+ this.rightDate = nextMonth(this.leftDate)
286
+ }
287
+ } else {
288
+ this.leftDate = calcDefaultValue(this.defaultValue)[0]
289
+ this.rightDate = nextMonth(this.leftDate)
290
+ }
291
+ }
292
+ },
293
+
294
+ defaultValue(val) {
295
+ if (!Array.isArray(this.value)) {
296
+ const [left, right] = calcDefaultValue(val)
297
+ this.leftDate = left
298
+ this.rightDate = val && val[1] && this.unlinkPanels
299
+ ? right
300
+ : nextMonth(this.leftDate)
301
+ }
302
+ }
303
+ },
304
+
305
+ methods: {
306
+ handleMinMaxDateWeek() {
307
+ if (this.minDate && this.maxDate) {
308
+ if (this.minDate.getTime() > this.maxDate.getTime()) {
309
+ const maxDate = this.minDate
310
+
311
+ this.minDate = this.maxDate
312
+ this.maxDate = maxDate
313
+ }
314
+
315
+ const prevWeekDay = Math.abs(7 - this.firstDayOfWeek + this.minDate.getDay()) % 7
316
+ this.minDate = new Date(this.minDate.getTime() - prevWeekDay * 60 * 60 * 24 * 1000)
317
+
318
+ const nextWeekDay = Math.abs(this.firstDayOfWeek - 1 - this.maxDate.getDay()) % 7
319
+ this.maxDate = new Date(this.maxDate.getTime() + nextWeekDay * 60 * 60 * 24 * 1000)
320
+ }
321
+ },
322
+
323
+ handleChangeRange(val) {
324
+ this.minDate = val.minDate
325
+ this.maxDate = val.maxDate
326
+ this.rangeState = val.rangeState
327
+ },
328
+
329
+ handleRangePick(val, close = true) {
330
+ const defaultTime = this.defaultTime || []
331
+ const minDate = modifyWithTimeString(val.minDate, defaultTime[0])
332
+ const maxDate = modifyWithTimeString(val.maxDate, defaultTime[1])
333
+ if (this.maxDate === maxDate && this.minDate === minDate) {
334
+ return
335
+ }
336
+ this.onPick && this.onPick(val)
337
+ this.maxDate = maxDate
338
+ this.minDate = minDate
339
+
340
+ // workaround for https://github.com/ElemeFE/element/issues/7539, should remove this block when we don't have to care about Chromium 55 - 57
341
+ let timer = setTimeout(() => {
342
+ this.maxDate = maxDate
343
+ this.minDate = minDate
344
+ clearTimeout(timer)
345
+ timer = null
346
+ }, 10)
347
+ if (!close) return
348
+ this.handleConfirm()
349
+ },
350
+
351
+ handleShortcutClick(shortcut) {
352
+ if (shortcut.onClick) {
353
+ shortcut.onClick(this)
354
+ }
355
+ },
356
+
357
+ // leftPrev*, rightNext* need to take care of `unlinkPanels`
358
+ leftPrevYear() {
359
+ this.leftDate = prevYear(this.leftDate)
360
+ if (!this.unlinkPanels) {
361
+ this.rightDate = nextMonth(this.leftDate)
362
+ }
363
+ },
364
+
365
+ leftPrevMonth() {
366
+ this.leftDate = prevMonth(this.leftDate)
367
+ if (!this.unlinkPanels) {
368
+ this.rightDate = nextMonth(this.leftDate)
369
+ }
370
+ },
371
+
372
+ rightNextYear() {
373
+ if (!this.unlinkPanels) {
374
+ this.leftDate = nextYear(this.leftDate)
375
+ this.rightDate = nextMonth(this.leftDate)
376
+ } else {
377
+ this.rightDate = nextYear(this.rightDate)
378
+ }
379
+ },
380
+
381
+ rightNextMonth() {
382
+ if (!this.unlinkPanels) {
383
+ this.leftDate = nextMonth(this.leftDate)
384
+ this.rightDate = nextMonth(this.leftDate)
385
+ } else {
386
+ this.rightDate = nextMonth(this.rightDate)
387
+ }
388
+ },
389
+
390
+ // leftNext*, rightPrev* are called when `unlinkPanels` is true
391
+ leftNextYear() {
392
+ this.leftDate = nextYear(this.leftDate)
393
+ },
394
+
395
+ leftNextMonth() {
396
+ this.leftDate = nextMonth(this.leftDate)
397
+ },
398
+
399
+ rightPrevYear() {
400
+ this.rightDate = prevYear(this.rightDate)
401
+ },
402
+
403
+ rightPrevMonth() {
404
+ this.rightDate = prevMonth(this.rightDate)
405
+ },
406
+
407
+ handleConfirm(visible = false) {
408
+ if (this.isValidValue([this.minDate, this.maxDate])) {
409
+ this.$emit('pick', [this.minDate, this.maxDate], visible)
410
+ }
411
+ },
412
+
413
+ isValidValue(value) {
414
+ return Array.isArray(value) &&
415
+ value && value[0] && value[1] &&
416
+ isDate(value[0]) && isDate(value[1]) &&
417
+ value[0].getTime() <= value[1].getTime() && (
418
+ typeof this.disabledDate === 'function'
419
+ ? !this.disabledDate(value[0]) && !this.disabledDate(value[1])
420
+ : true
421
+ )
422
+ },
423
+
424
+ resetView() {
425
+ // NOTE: this is a hack to reset {min, max}Date on picker open.
426
+ // TODO: correct way of doing so is to refactor {min, max}Date to be dependent on value and internal selection state
427
+ // an alternative would be resetView whenever picker becomes visible, should also investigate date-panel's resetView
428
+ if (this.minDate && this.maxDate == null) this.rangeState.selecting = false
429
+ this.minDate = this.value && isDate(this.value[0]) ? new Date(this.value[0]) : null
430
+ this.maxDate = this.value && isDate(this.value[0]) ? new Date(this.value[1]) : null
431
+
432
+ this.handleMinMaxDateWeek()
433
+ }
434
+ }
435
+ }
436
+ </script>