@94ai/nf-double-week 3.1.37 → 3.1.38
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.
- package/lib/nf-double-week.cjs.js +577 -3560
- package/lib/nf-double-week.esm-bundler.js +572 -3555
- package/package/index.ts +8 -0
- package/package/nf-double-week.vue +35 -0
- package/package/picker.vue +780 -0
- package/package/popper.js +1276 -0
- package/package/style/css.ts +1 -0
- package/package/style/index.ts +1 -0
- package/package/week-range.vue +436 -0
- package/package/week-table.vue +296 -0
- package/package.json +3 -3
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
import DateTable from 'element-ui/packages/date-picker/src/basic/date-table.vue'
|
|
3
|
+
import { getFirstDayOfMonth, getDayCountOfMonth, getWeekNumber, prevDate, nextDate, isDate, clearTime as _clearTime } from 'element-ui/src/utils/date-util'
|
|
4
|
+
import { arrayFind } from 'element-ui/src/utils/util'
|
|
5
|
+
|
|
6
|
+
const getDateTimestamp = function(time) {
|
|
7
|
+
if (typeof time === 'number' || typeof time === 'string') {
|
|
8
|
+
return _clearTime(new Date(time)).getTime()
|
|
9
|
+
} else if (time instanceof Date) {
|
|
10
|
+
return _clearTime(time).getTime()
|
|
11
|
+
} else {
|
|
12
|
+
return NaN
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default {
|
|
17
|
+
mixins: [DateTable],
|
|
18
|
+
computed: {
|
|
19
|
+
minDateTimestamp() {
|
|
20
|
+
return getDateTimestamp(this.minDate)
|
|
21
|
+
},
|
|
22
|
+
maxDateTimestamp() {
|
|
23
|
+
return getDateTimestamp(this.maxDate)
|
|
24
|
+
},
|
|
25
|
+
rows() {
|
|
26
|
+
const date = new Date(this.year, this.month, 1)
|
|
27
|
+
let day = getFirstDayOfMonth(date) // day of first day
|
|
28
|
+
const dateCountOfMonth = getDayCountOfMonth(date.getFullYear(), date.getMonth())
|
|
29
|
+
const dateCountOfLastMonth = getDayCountOfMonth(date.getFullYear(), (date.getMonth() === 0 ? 11 : date.getMonth() - 1))
|
|
30
|
+
|
|
31
|
+
day = (day === 0 ? 7 : day)
|
|
32
|
+
|
|
33
|
+
const offset = this.offsetDay
|
|
34
|
+
const rows = this.tableRows
|
|
35
|
+
let count = 1
|
|
36
|
+
|
|
37
|
+
const startDate = this.startDate
|
|
38
|
+
const disabledDate = this.disabledDate
|
|
39
|
+
const cellClassName = this.cellClassName
|
|
40
|
+
const selectedDate = []
|
|
41
|
+
const now = getDateTimestamp(new Date())
|
|
42
|
+
|
|
43
|
+
for (let i = 0; i < 6; i++) {
|
|
44
|
+
const row = rows[i]
|
|
45
|
+
|
|
46
|
+
if (this.showWeekNumber) {
|
|
47
|
+
if (!row[0]) {
|
|
48
|
+
row[0] = { type: 'week', text: getWeekNumber(nextDate(startDate, i * 7 + 1)) }
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
for (let j = 0; j < 7; j++) {
|
|
53
|
+
let cell = row[this.showWeekNumber ? j + 1 : j]
|
|
54
|
+
if (!cell) {
|
|
55
|
+
cell = { row: i, column: j, type: 'normal', inRange: false, start: false, end: false }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
cell.type = 'normal'
|
|
59
|
+
|
|
60
|
+
const index = i * 7 + j
|
|
61
|
+
const time = nextDate(startDate, index - offset).getTime()
|
|
62
|
+
cell.inRange = time >= this.minDateTimestamp && time <= this.maxDateTimestamp
|
|
63
|
+
cell.start = this.minDate && time === this.minDateTimestamp
|
|
64
|
+
cell.end = this.maxDate && time === this.maxDateTimestamp
|
|
65
|
+
const isToday = time === now
|
|
66
|
+
|
|
67
|
+
if (isToday) {
|
|
68
|
+
cell.type = 'today'
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (i >= 0 && i <= 1) {
|
|
72
|
+
const numberOfDaysFromPreviousMonth = day + offset < 0 ? 7 + day + offset : day + offset
|
|
73
|
+
|
|
74
|
+
if (j + i * 7 >= numberOfDaysFromPreviousMonth) {
|
|
75
|
+
cell.text = count++
|
|
76
|
+
} else {
|
|
77
|
+
cell.text = dateCountOfLastMonth - (numberOfDaysFromPreviousMonth - j % 7) + 1 + i * 7
|
|
78
|
+
cell.type = 'prev-month'
|
|
79
|
+
}
|
|
80
|
+
} else {
|
|
81
|
+
if (count <= dateCountOfMonth) {
|
|
82
|
+
cell.text = count++
|
|
83
|
+
} else {
|
|
84
|
+
cell.text = count++ - dateCountOfMonth
|
|
85
|
+
cell.type = 'next-month'
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const cellDate = new Date(time)
|
|
90
|
+
cell.disabled = typeof disabledDate === 'function' && disabledDate(cellDate)
|
|
91
|
+
cell.selected = arrayFind(selectedDate, date => date.getTime() === cellDate.getTime())
|
|
92
|
+
cell.customClass = typeof cellClassName === 'function' && cellClassName(cellDate)
|
|
93
|
+
this.$set(row, this.showWeekNumber ? j + 1 : j, cell)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return rows
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
methods: {
|
|
101
|
+
getCellClasses(cell) {
|
|
102
|
+
const defaultValue = this.defaultValue ? Array.isArray(this.defaultValue) ? this.defaultValue : [this.defaultValue] : []
|
|
103
|
+
|
|
104
|
+
const classes = []
|
|
105
|
+
if ((cell.type === 'normal' || cell.type === 'today') && !cell.disabled) {
|
|
106
|
+
classes.push('available')
|
|
107
|
+
if (cell.type === 'today') {
|
|
108
|
+
classes.push('today')
|
|
109
|
+
}
|
|
110
|
+
} else {
|
|
111
|
+
classes.push(cell.type)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
if (cell.type === 'normal' && defaultValue.some(date => this.cellMatchesDate(cell, date))) {
|
|
115
|
+
classes.push('default')
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if (cell.inRange && ((cell.type === 'normal' || cell.type === 'today'))) {
|
|
119
|
+
if (isDate(this.minDate) && isDate(this.maxDate) || this.rangeState.selecting) {
|
|
120
|
+
classes.push('in-range')
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (cell.start) {
|
|
124
|
+
classes.push('start-date')
|
|
125
|
+
} else if (cell.end) {
|
|
126
|
+
classes.push('end-date')
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
if (cell.disabled) {
|
|
131
|
+
classes.push('disabled')
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (cell.selected) {
|
|
135
|
+
classes.push('selected')
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (cell.customClass) {
|
|
139
|
+
classes.push(cell.customClass)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return classes.join(' ')
|
|
143
|
+
},
|
|
144
|
+
isWeekActive(cell) {
|
|
145
|
+
const newDate = new Date(this.year, this.month, 1)
|
|
146
|
+
const year = newDate.getFullYear()
|
|
147
|
+
const month = newDate.getMonth()
|
|
148
|
+
|
|
149
|
+
if (cell.type === 'prev-month') {
|
|
150
|
+
newDate.setMonth(month === 0 ? 11 : month - 1)
|
|
151
|
+
newDate.setFullYear(month === 0 ? year - 1 : year)
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (cell.type === 'next-month') {
|
|
155
|
+
newDate.setMonth(month === 11 ? 0 : month + 1)
|
|
156
|
+
newDate.setFullYear(month === 11 ? year + 1 : year)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
newDate.setDate(parseInt(cell.text, 10))
|
|
160
|
+
|
|
161
|
+
if (isDate(this.value)) {
|
|
162
|
+
const dayOffset = (this.value.getDay() - this.firstDayOfWeek + 7) % 7 - 1
|
|
163
|
+
const weekDate = prevDate(this.value, dayOffset)
|
|
164
|
+
return weekDate.getTime() === newDate.getTime()
|
|
165
|
+
}
|
|
166
|
+
return false
|
|
167
|
+
},
|
|
168
|
+
handleMouseMove(event, isManual) {
|
|
169
|
+
if (!this.rangeState.selecting) return
|
|
170
|
+
|
|
171
|
+
let target = event.target
|
|
172
|
+
if (target.tagName === 'SPAN') {
|
|
173
|
+
target = target.parentNode.parentNode
|
|
174
|
+
}
|
|
175
|
+
if (target.tagName === 'DIV') {
|
|
176
|
+
target = target.parentNode
|
|
177
|
+
}
|
|
178
|
+
if (target.tagName !== 'TD') return
|
|
179
|
+
|
|
180
|
+
const row = target.parentNode.rowIndex - 1
|
|
181
|
+
|
|
182
|
+
const isMinGreatMax = +new Date(this.rangeState.startDate) >= +new Date(this.getDateOfCell(row, 6))
|
|
183
|
+
|
|
184
|
+
let column = isMinGreatMax ? 0 : 6
|
|
185
|
+
|
|
186
|
+
const findIndex = this.rows[row].findIndex(item => !item.disabled)
|
|
187
|
+
const isExistDis = this.rows[row].some(item => item.disabled)
|
|
188
|
+
|
|
189
|
+
if (isExistDis && findIndex >= 0) {
|
|
190
|
+
column = findIndex
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// can not select disabled date
|
|
194
|
+
if (this.rows[row][column].disabled) return
|
|
195
|
+
|
|
196
|
+
// only update rangeState when mouse moves to a new cell
|
|
197
|
+
// this avoids frequent Date object creation and improves performance
|
|
198
|
+
if (row !== this.lastRow || column !== this.lastColumn) {
|
|
199
|
+
const minDateList = this.rangeState.minDateList
|
|
200
|
+
const endDate = this.getDateOfCell(row, column)
|
|
201
|
+
|
|
202
|
+
if (!isManual) {
|
|
203
|
+
if (isMinGreatMax && !this.isMinGreatMax && minDateList.length === 2 || this.minDate?.getTime() > endDate?.getTime()) {
|
|
204
|
+
this.$emit('pick', { minDate: minDateList[1], maxDate: null })
|
|
205
|
+
|
|
206
|
+
this.isMinGreatMax = true
|
|
207
|
+
} else if (this.isMinGreatMax && !isMinGreatMax || this.minDate?.getTime() < endDate?.getTime()) {
|
|
208
|
+
this.$emit('pick', { minDate: minDateList[0], maxDate: null })
|
|
209
|
+
|
|
210
|
+
this.isMinGreatMax = false
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
this.$nextTick(() => {
|
|
215
|
+
this.$emit('changerange', {
|
|
216
|
+
minDate: this.minDate,
|
|
217
|
+
maxDate: this.maxDate,
|
|
218
|
+
rangeState: {
|
|
219
|
+
selecting: true,
|
|
220
|
+
endDate,
|
|
221
|
+
startDate: this.rangeState.startDate,
|
|
222
|
+
minDateList: this.rangeState.minDateList
|
|
223
|
+
}
|
|
224
|
+
})
|
|
225
|
+
|
|
226
|
+
this.lastRow = row
|
|
227
|
+
this.lastColumn = target.cellIndex
|
|
228
|
+
})
|
|
229
|
+
}
|
|
230
|
+
},
|
|
231
|
+
handleClick(event) {
|
|
232
|
+
let target = event.target
|
|
233
|
+
if (target.tagName === 'SPAN') {
|
|
234
|
+
target = target.parentNode.parentNode
|
|
235
|
+
}
|
|
236
|
+
if (target.tagName === 'DIV') {
|
|
237
|
+
target = target.parentNode
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (target.tagName !== 'TD') return
|
|
241
|
+
|
|
242
|
+
const row = target.parentNode.rowIndex - 1
|
|
243
|
+
let column = this.rangeState.selecting ? 6 : 0
|
|
244
|
+
|
|
245
|
+
const findIndex = this.rows[row].findIndex(item => !item.disabled)
|
|
246
|
+
const isExistDis = this.rows[row].some(item => item.disabled)
|
|
247
|
+
|
|
248
|
+
if (this.rangeState.startDate && this.rangeState.selecting) {
|
|
249
|
+
column = +new Date(this.rangeState.startDate) >= +new Date(this.getDateOfCell(row, 6)) ? 0 : 6
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if (isExistDis && findIndex >= 0) {
|
|
253
|
+
column = findIndex
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const cell = this.rows[row][column]
|
|
257
|
+
|
|
258
|
+
if (cell.disabled || cell.type === 'week') return
|
|
259
|
+
|
|
260
|
+
const newDate = this.getDateOfCell(row, column)
|
|
261
|
+
|
|
262
|
+
if (!this.rangeState.selecting) {
|
|
263
|
+
this.rangeState.startDate = newDate
|
|
264
|
+
this.rangeState.minDateList = [
|
|
265
|
+
this.getDateOfCell(row, 0),
|
|
266
|
+
this.getDateOfCell(row, 6)
|
|
267
|
+
]
|
|
268
|
+
|
|
269
|
+
this.$emit('pick', { minDate: newDate, maxDate: null })
|
|
270
|
+
this.rangeState.selecting = true
|
|
271
|
+
|
|
272
|
+
this.$nextTick(() => {
|
|
273
|
+
this.handleMouseMove({
|
|
274
|
+
target: {
|
|
275
|
+
tagName: 'TD',
|
|
276
|
+
parentNode: {
|
|
277
|
+
rowIndex: row + 1,
|
|
278
|
+
cellIndex: column
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}, true)
|
|
282
|
+
})
|
|
283
|
+
} else {
|
|
284
|
+
if (newDate >= this.minDate) {
|
|
285
|
+
this.$emit('pick', { minDate: this.minDate, maxDate: newDate })
|
|
286
|
+
} else {
|
|
287
|
+
this.$emit('pick', { minDate: newDate, maxDate: this.minDate })
|
|
288
|
+
}
|
|
289
|
+
this.rangeState.selecting = false
|
|
290
|
+
}
|
|
291
|
+
this.handleMouseMove(event)
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
</script>
|
|
296
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@94ai/nf-double-week",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.38",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "zoujiahe <zoujiahe@94ai.com>",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "http://94ai.gitlab.com/zoujiahe/common-ui.git"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@94ai/nf-theme-chalk": "^
|
|
17
|
+
"@94ai/nf-theme-chalk": "^1.0.0",
|
|
18
18
|
"vue-demi": "^0.14.5"
|
|
19
19
|
},
|
|
20
20
|
"peerDependenciesMeta": {
|
|
@@ -30,5 +30,5 @@
|
|
|
30
30
|
"types": "lib/index.d.ts",
|
|
31
31
|
"main": "lib/nf-double-week.cjs.js",
|
|
32
32
|
"module": "lib/nf-double-week.esm-bundler.js",
|
|
33
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "2b60696b405feafbbaeed385e5bcf666ceefbf2c"
|
|
34
34
|
}
|