huiyi-time 0.1.17 → 0.1.23
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/huiyi-time.es.js +272 -321
- package/huiyi-time.umd.js +1 -1
- package/index.d.ts +26 -0
- package/package.json +2 -1
- package/style.css +1 -1
- package/favicon.ico +0 -0
- package/huiyi-time-0.1.16.tgz +0 -0
- package/index.html +0 -17
package/huiyi-time.es.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { resolveComponent as
|
|
2
|
-
const
|
|
3
|
-
const n =
|
|
4
|
-
for (const [
|
|
5
|
-
n[
|
|
1
|
+
import { resolveComponent as S, openBlock as c, createElementBlock as p, createElementVNode as a, createVNode as w, normalizeClass as v, withModifiers as m, withCtx as M, createTextVNode as I, Fragment as C, renderList as k, toDisplayString as f } from "vue";
|
|
2
|
+
const F = (e, t) => {
|
|
3
|
+
const n = e.__vccOpts || e;
|
|
4
|
+
for (const [l, r] of t)
|
|
5
|
+
n[l] = r;
|
|
6
6
|
return n;
|
|
7
7
|
}, O = {
|
|
8
8
|
name: "TimeComponentsUp",
|
|
@@ -32,19 +32,16 @@ const S = (t, e) => {
|
|
|
32
32
|
endCalendarViewDate: /* @__PURE__ */ new Date(),
|
|
33
33
|
quickOptions: {
|
|
34
34
|
common: [
|
|
35
|
+
{ name: "近3天", type: "days", value: 3, active: !1 },
|
|
36
|
+
{ name: "近7天", type: "days", value: 7, active: !1 },
|
|
37
|
+
{ name: "近1月", type: "months", value: 1, active: !1 },
|
|
35
38
|
{ name: "近3月", type: "months", value: 3, active: !1 },
|
|
36
39
|
{ name: "近1年", type: "years", value: 1, active: !1 }
|
|
37
40
|
],
|
|
38
|
-
today: []
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
]
|
|
42
|
-
thisWeek: [
|
|
43
|
-
{ name: "本周", type: "thisWeek", value: "full", active: !1 }
|
|
44
|
-
],
|
|
45
|
-
thisMonth: [
|
|
46
|
-
{ name: "本月", type: "thisMonth", value: "full", active: !1 }
|
|
47
|
-
]
|
|
41
|
+
today: []
|
|
42
|
+
// thisMonth: [
|
|
43
|
+
// { name: '本月', type: 'thisMonth', value: 'full', active: false }
|
|
44
|
+
// ]
|
|
48
45
|
},
|
|
49
46
|
dateFormatter: new Intl.DateTimeFormat("en-US", { year: "numeric", month: "long", day: "2-digit" }),
|
|
50
47
|
clickOutsideHandler: null
|
|
@@ -52,12 +49,12 @@ const S = (t, e) => {
|
|
|
52
49
|
},
|
|
53
50
|
computed: {
|
|
54
51
|
startDateMonthYear() {
|
|
55
|
-
const
|
|
56
|
-
return `${
|
|
52
|
+
const e = this.startCalendarViewDate.getFullYear(), t = this.startCalendarViewDate.getMonth() + 1;
|
|
53
|
+
return `${e}年${t}月`;
|
|
57
54
|
},
|
|
58
55
|
endDateMonthYear() {
|
|
59
|
-
const
|
|
60
|
-
return `${
|
|
56
|
+
const e = this.endCalendarViewDate.getFullYear(), t = this.endCalendarViewDate.getMonth() + 1;
|
|
57
|
+
return `${e}年${t}月`;
|
|
61
58
|
},
|
|
62
59
|
startCalendarDays() {
|
|
63
60
|
return this.generateCalendarDays(this.startCalendarViewDate, this.startDate, this.endDate, "start");
|
|
@@ -81,24 +78,24 @@ const S = (t, e) => {
|
|
|
81
78
|
this.inputValue = this.initTime, this.updateQuickOptionsActiveState();
|
|
82
79
|
},
|
|
83
80
|
methods: {
|
|
84
|
-
setActiveControl(
|
|
85
|
-
this.activeControl =
|
|
81
|
+
setActiveControl(e) {
|
|
82
|
+
this.activeControl = e;
|
|
86
83
|
},
|
|
87
84
|
// 更新输入框的值
|
|
88
85
|
updateInputValue() {
|
|
89
|
-
const
|
|
90
|
-
const n =
|
|
91
|
-
return `${n}-${
|
|
86
|
+
const e = (t) => {
|
|
87
|
+
const n = t.getFullYear(), l = String(t.getMonth() + 1).padStart(2, "0"), r = String(t.getDate()).padStart(2, "0");
|
|
88
|
+
return `${n}-${l}-${r}`;
|
|
92
89
|
};
|
|
93
|
-
this.inputValue = `${
|
|
90
|
+
this.inputValue = `${e(this.startDate)} ~ ${e(this.endDate)}`, this.modelClick();
|
|
94
91
|
},
|
|
95
92
|
// 输入框获得焦点时
|
|
96
|
-
onInputFocus(
|
|
93
|
+
onInputFocus(e) {
|
|
97
94
|
setTimeout(() => {
|
|
98
95
|
this.inputSelection = {
|
|
99
|
-
start:
|
|
100
|
-
end:
|
|
101
|
-
}, this.selectCurrentField(this.inputSelection.start);
|
|
96
|
+
start: e.target.selectionStart,
|
|
97
|
+
end: e.target.selectionEnd
|
|
98
|
+
}, this.inputSelection.start === this.inputSelection.end && this.selectCurrentField(this.inputSelection.start);
|
|
102
99
|
}, 0);
|
|
103
100
|
},
|
|
104
101
|
// 输入框失去焦点时
|
|
@@ -110,55 +107,59 @@ const S = (t, e) => {
|
|
|
110
107
|
this.validateInput();
|
|
111
108
|
},
|
|
112
109
|
// 输入框键盘事件
|
|
113
|
-
onInputKeydown(
|
|
114
|
-
const
|
|
115
|
-
["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(
|
|
110
|
+
onInputKeydown(e) {
|
|
111
|
+
const t = e.key;
|
|
112
|
+
["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(t) && (e.preventDefault(), t === "ArrowLeft" ? this.navigateLeft() : t === "ArrowRight" ? this.navigateRight() : t === "ArrowUp" ? this.incrementValue() : t === "ArrowDown" && this.decrementValue()), t === "Tab" && (e.preventDefault(), e.shiftKey ? this.navigateLeft() : this.navigateRight()), t === "Enter" && (e.preventDefault(), this.showPanel = !1);
|
|
116
113
|
},
|
|
117
114
|
// 向左导航
|
|
118
115
|
navigateLeft() {
|
|
119
|
-
const
|
|
120
|
-
let
|
|
116
|
+
const e = this.inputSelection.start;
|
|
117
|
+
let t = null;
|
|
121
118
|
for (let n = 0; n < this.fieldPositions.length; n++)
|
|
122
|
-
if (
|
|
123
|
-
n > 0 ?
|
|
119
|
+
if (e >= this.fieldPositions[n].start && e <= this.fieldPositions[n].end) {
|
|
120
|
+
n > 0 ? t = this.fieldPositions[n - 1] : t = this.fieldPositions[this.fieldPositions.length - 1];
|
|
124
121
|
break;
|
|
125
122
|
}
|
|
126
|
-
|
|
123
|
+
t || (t = this.fieldPositions[0]), this.selectField(t);
|
|
127
124
|
},
|
|
128
125
|
// 向右导航
|
|
129
126
|
navigateRight() {
|
|
130
|
-
const
|
|
131
|
-
let
|
|
127
|
+
const e = this.inputSelection.start;
|
|
128
|
+
let t = null;
|
|
132
129
|
for (let n = 0; n < this.fieldPositions.length; n++)
|
|
133
|
-
if (
|
|
134
|
-
n < this.fieldPositions.length - 1 ?
|
|
130
|
+
if (e >= this.fieldPositions[n].start && e <= this.fieldPositions[n].end) {
|
|
131
|
+
n < this.fieldPositions.length - 1 ? t = this.fieldPositions[n + 1] : t = this.fieldPositions[0];
|
|
135
132
|
break;
|
|
136
133
|
}
|
|
137
|
-
|
|
134
|
+
t || (t = this.fieldPositions[0]), this.selectField(t);
|
|
138
135
|
},
|
|
139
136
|
// 选择当前字段
|
|
140
|
-
selectCurrentField(
|
|
141
|
-
for (const
|
|
142
|
-
if (
|
|
143
|
-
this.selectField(
|
|
137
|
+
selectCurrentField(e) {
|
|
138
|
+
for (const t of this.fieldPositions)
|
|
139
|
+
if (e >= t.start && e <= t.end) {
|
|
140
|
+
this.selectField(t);
|
|
144
141
|
return;
|
|
145
142
|
}
|
|
146
143
|
this.selectField(this.fieldPositions[0]);
|
|
147
144
|
},
|
|
148
145
|
// 选择指定字段
|
|
149
|
-
selectField(
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
}
|
|
146
|
+
selectField(e) {
|
|
147
|
+
if (this.$refs.datetimeInputRef && this.$refs.datetimeInputRef.$el) {
|
|
148
|
+
const t = this.$refs.datetimeInputRef.$el.querySelector("input");
|
|
149
|
+
t && t.setSelectionRange(e.start, e.end);
|
|
150
|
+
}
|
|
151
|
+
this.inputSelection = {
|
|
152
|
+
start: e.start,
|
|
153
|
+
end: e.end
|
|
154
|
+
}, this.activeControl = e.name;
|
|
154
155
|
},
|
|
155
156
|
// 增加当前字段的值
|
|
156
157
|
incrementValue() {
|
|
157
|
-
const
|
|
158
|
-
if (!
|
|
158
|
+
const e = this.getCurrentField();
|
|
159
|
+
if (!e)
|
|
159
160
|
return;
|
|
160
|
-
let n = parseInt(this.inputValue.substring(
|
|
161
|
-
switch (
|
|
161
|
+
let n = parseInt(this.inputValue.substring(e.start, e.end)) + 1;
|
|
162
|
+
switch (e.name) {
|
|
162
163
|
case "startYear":
|
|
163
164
|
case "endYear":
|
|
164
165
|
break;
|
|
@@ -171,15 +172,15 @@ const S = (t, e) => {
|
|
|
171
172
|
n > 31 && (n = 1);
|
|
172
173
|
break;
|
|
173
174
|
}
|
|
174
|
-
this.updateFieldValue(
|
|
175
|
+
this.updateFieldValue(e, n);
|
|
175
176
|
},
|
|
176
177
|
// 减少当前字段的值
|
|
177
178
|
decrementValue() {
|
|
178
|
-
const
|
|
179
|
-
if (!
|
|
179
|
+
const e = this.getCurrentField();
|
|
180
|
+
if (!e)
|
|
180
181
|
return;
|
|
181
|
-
let n = parseInt(this.inputValue.substring(
|
|
182
|
-
switch (
|
|
182
|
+
let n = parseInt(this.inputValue.substring(e.start, e.end)) - 1;
|
|
183
|
+
switch (e.name) {
|
|
183
184
|
case "startYear":
|
|
184
185
|
case "endYear":
|
|
185
186
|
n < 1 && (n = 9999);
|
|
@@ -193,35 +194,35 @@ const S = (t, e) => {
|
|
|
193
194
|
n < 1 && (n = 31);
|
|
194
195
|
break;
|
|
195
196
|
}
|
|
196
|
-
this.updateFieldValue(
|
|
197
|
+
this.updateFieldValue(e, n);
|
|
197
198
|
},
|
|
198
199
|
// 获取当前字段
|
|
199
200
|
getCurrentField() {
|
|
200
|
-
for (const
|
|
201
|
-
if (this.inputSelection.start >=
|
|
202
|
-
return
|
|
201
|
+
for (const e of this.fieldPositions)
|
|
202
|
+
if (this.inputSelection.start >= e.start && this.inputSelection.start <= e.end)
|
|
203
|
+
return e;
|
|
203
204
|
return null;
|
|
204
205
|
},
|
|
205
206
|
// 更新字段值
|
|
206
|
-
updateFieldValue(
|
|
207
|
-
const n = String(
|
|
208
|
-
this.inputValue =
|
|
209
|
-
this.selectField(
|
|
207
|
+
updateFieldValue(e, t) {
|
|
208
|
+
const n = String(t).padStart(e.length, "0"), l = this.inputValue.substring(0, e.start) + n + this.inputValue.substring(e.end);
|
|
209
|
+
this.inputValue = l, this.$nextTick(() => {
|
|
210
|
+
this.selectField(e);
|
|
210
211
|
}), this.updateDateFromInput();
|
|
211
212
|
},
|
|
212
213
|
// 从输入框更新日期对象
|
|
213
214
|
updateDateFromInput() {
|
|
214
215
|
if (!this.validateInputFormat())
|
|
215
216
|
return;
|
|
216
|
-
const
|
|
217
|
-
if (
|
|
217
|
+
const e = this.inputValue.split(/[''~-]/);
|
|
218
|
+
if (e.length !== 6)
|
|
218
219
|
return;
|
|
219
|
-
const
|
|
220
|
-
if (isNaN(
|
|
220
|
+
const t = parseInt(e[0]), n = parseInt(e[1]) - 1, l = parseInt(e[2]), r = parseInt(e[3]), s = parseInt(e[4]) - 1, h = parseInt(e[5]), u = new Date(t, n, l), i = new Date(r, s, h);
|
|
221
|
+
if (isNaN(u.getTime()) || isNaN(i.getTime())) {
|
|
221
222
|
this.isInvalid = !0;
|
|
222
223
|
return;
|
|
223
224
|
}
|
|
224
|
-
this.startDate =
|
|
225
|
+
this.startDate = u, this.endDate = i, this.isInvalid = !1, this.updateQuickOptionsActiveState(), this.startCalendarViewDate = new Date(this.startDate), this.endCalendarViewDate = new Date(this.endDate);
|
|
225
226
|
},
|
|
226
227
|
// 验证输入格式
|
|
227
228
|
validateInputFormat() {
|
|
@@ -233,163 +234,148 @@ const S = (t, e) => {
|
|
|
233
234
|
this.isInvalid = !0;
|
|
234
235
|
return;
|
|
235
236
|
}
|
|
236
|
-
const
|
|
237
|
-
if (n < 1 || n > 12 ||
|
|
237
|
+
const e = this.inputValue.split(/[ ~-]/), t = parseInt(e[0]), n = parseInt(e[1]), l = parseInt(e[2]), r = parseInt(e[3]), s = parseInt(e[4]), h = parseInt(e[5]);
|
|
238
|
+
if (n < 1 || n > 12 || s < 1 || s > 12) {
|
|
238
239
|
this.isInvalid = !0;
|
|
239
240
|
return;
|
|
240
241
|
}
|
|
241
|
-
if (
|
|
242
|
+
if (l < 1 || l > 31 || h < 1 || h > 31) {
|
|
242
243
|
this.isInvalid = !0;
|
|
243
244
|
return;
|
|
244
245
|
}
|
|
245
|
-
const
|
|
246
|
-
if (
|
|
246
|
+
const u = new Date(t, n - 1, l), i = new Date(r, s - 1, h);
|
|
247
|
+
if (u.getMonth() !== n - 1 || u.getDate() !== l || i.getMonth() !== s - 1 || i.getDate() !== h) {
|
|
247
248
|
this.isInvalid = !0;
|
|
248
249
|
return;
|
|
249
250
|
}
|
|
250
251
|
this.isInvalid = !1;
|
|
251
252
|
},
|
|
252
253
|
// 前一年
|
|
253
|
-
prevYear(
|
|
254
|
-
if (
|
|
255
|
-
const
|
|
256
|
-
|
|
254
|
+
prevYear(e) {
|
|
255
|
+
if (e === "start") {
|
|
256
|
+
const t = new Date(this.startCalendarViewDate);
|
|
257
|
+
t.setFullYear(t.getFullYear() - 1), this.startCalendarViewDate = t;
|
|
257
258
|
} else {
|
|
258
|
-
const
|
|
259
|
-
|
|
259
|
+
const t = new Date(this.endCalendarViewDate);
|
|
260
|
+
t.setFullYear(t.getFullYear() - 1), this.endCalendarViewDate = t;
|
|
260
261
|
}
|
|
261
262
|
},
|
|
262
263
|
// 后一年
|
|
263
|
-
nextYear(
|
|
264
|
-
if (
|
|
265
|
-
const
|
|
266
|
-
|
|
264
|
+
nextYear(e) {
|
|
265
|
+
if (e === "start") {
|
|
266
|
+
const t = new Date(this.startCalendarViewDate);
|
|
267
|
+
t.setFullYear(t.getFullYear() + 1), this.startCalendarViewDate = t;
|
|
267
268
|
} else {
|
|
268
|
-
const
|
|
269
|
-
|
|
269
|
+
const t = new Date(this.endCalendarViewDate);
|
|
270
|
+
t.setFullYear(t.getFullYear() + 1), this.endCalendarViewDate = t;
|
|
270
271
|
}
|
|
271
272
|
},
|
|
272
|
-
prevMonth(
|
|
273
|
-
if (
|
|
274
|
-
const
|
|
275
|
-
|
|
273
|
+
prevMonth(e) {
|
|
274
|
+
if (e === "start") {
|
|
275
|
+
const t = new Date(this.startCalendarViewDate);
|
|
276
|
+
t.setMonth(t.getMonth() - 1), this.startCalendarViewDate = t;
|
|
276
277
|
} else {
|
|
277
|
-
const
|
|
278
|
-
|
|
278
|
+
const t = new Date(this.endCalendarViewDate);
|
|
279
|
+
t.setMonth(t.getMonth() - 1), this.endCalendarViewDate = t;
|
|
279
280
|
}
|
|
280
281
|
},
|
|
281
|
-
nextMonth(
|
|
282
|
-
if (
|
|
283
|
-
const
|
|
284
|
-
|
|
282
|
+
nextMonth(e) {
|
|
283
|
+
if (e === "start") {
|
|
284
|
+
const t = new Date(this.startCalendarViewDate);
|
|
285
|
+
t.setMonth(t.getMonth() + 1), this.startCalendarViewDate = t;
|
|
285
286
|
} else {
|
|
286
|
-
const
|
|
287
|
-
|
|
287
|
+
const t = new Date(this.endCalendarViewDate);
|
|
288
|
+
t.setMonth(t.getMonth() + 1), this.endCalendarViewDate = t;
|
|
288
289
|
}
|
|
289
290
|
},
|
|
290
|
-
selectDate(
|
|
291
|
-
|
|
291
|
+
selectDate(e, t) {
|
|
292
|
+
e === "start" ? this.startDate = t : this.endDate = t, this.updateInputValue(), this.updateQuickOptionsActiveState();
|
|
292
293
|
},
|
|
293
|
-
generateCalendarDays(
|
|
294
|
-
const
|
|
294
|
+
generateCalendarDays(e, t, n, l) {
|
|
295
|
+
const r = e.getFullYear(), s = e.getMonth(), h = new Date(r, s, 1), u = new Date(r, s + 1, 0), i = h.getDay(), D = new Date(r, s, 0).getDate(), y = [], V = /* @__PURE__ */ new Date();
|
|
295
296
|
for (let o = i - 1; o >= 0; o--) {
|
|
296
|
-
const
|
|
297
|
-
|
|
298
|
-
id: `prev-${o}-${
|
|
297
|
+
const d = new Date(r, s - 1, D - o);
|
|
298
|
+
y.push({
|
|
299
|
+
id: `prev-${o}-${l}`,
|
|
299
300
|
day: D - o,
|
|
300
|
-
date:
|
|
301
|
+
date: d,
|
|
301
302
|
isCurrentMonth: !1,
|
|
302
|
-
isSelected: this.isSameDay(
|
|
303
|
-
isToday: this.isSameDay(
|
|
304
|
-
isInRange: this.isDateInRange(
|
|
303
|
+
isSelected: this.isSameDay(d, l === "start" ? t : n),
|
|
304
|
+
isToday: this.isSameDay(d, V),
|
|
305
|
+
isInRange: this.isDateInRange(d, t, n)
|
|
305
306
|
});
|
|
306
307
|
}
|
|
307
|
-
for (let o = 1; o <=
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
id: `current-${o}-${
|
|
308
|
+
for (let o = 1; o <= u.getDate(); o++) {
|
|
309
|
+
const d = new Date(r, s, o);
|
|
310
|
+
y.push({
|
|
311
|
+
id: `current-${o}-${l}`,
|
|
311
312
|
day: o,
|
|
312
|
-
date:
|
|
313
|
+
date: d,
|
|
313
314
|
isCurrentMonth: !0,
|
|
314
|
-
isSelected: this.isSameDay(
|
|
315
|
-
isToday: this.isSameDay(
|
|
316
|
-
isInRange: this.isDateInRange(
|
|
315
|
+
isSelected: this.isSameDay(d, l === "start" ? t : n),
|
|
316
|
+
isToday: this.isSameDay(d, V),
|
|
317
|
+
isInRange: this.isDateInRange(d, t, n)
|
|
317
318
|
});
|
|
318
319
|
}
|
|
319
|
-
const
|
|
320
|
-
for (let o = 1; o <=
|
|
321
|
-
const
|
|
322
|
-
|
|
323
|
-
id: `next-${o}-${
|
|
320
|
+
const Y = 42 - y.length;
|
|
321
|
+
for (let o = 1; o <= Y; o++) {
|
|
322
|
+
const d = new Date(r, s + 1, o);
|
|
323
|
+
y.push({
|
|
324
|
+
id: `next-${o}-${l}`,
|
|
324
325
|
day: o,
|
|
325
|
-
date:
|
|
326
|
+
date: d,
|
|
326
327
|
isCurrentMonth: !1,
|
|
327
|
-
isSelected: this.isSameDay(
|
|
328
|
-
isToday: this.isSameDay(
|
|
329
|
-
isInRange: this.isDateInRange(
|
|
328
|
+
isSelected: this.isSameDay(d, l === "start" ? t : n),
|
|
329
|
+
isToday: this.isSameDay(d, V),
|
|
330
|
+
isInRange: this.isDateInRange(d, t, n)
|
|
330
331
|
});
|
|
331
332
|
}
|
|
332
|
-
return
|
|
333
|
+
return y;
|
|
333
334
|
},
|
|
334
|
-
isSameDay(
|
|
335
|
-
return
|
|
335
|
+
isSameDay(e, t) {
|
|
336
|
+
return e.getFullYear() === t.getFullYear() && e.getMonth() === t.getMonth() && e.getDate() === t.getDate();
|
|
336
337
|
},
|
|
337
|
-
isDateInRange(
|
|
338
|
-
return
|
|
338
|
+
isDateInRange(e, t, n) {
|
|
339
|
+
return e >= t && e <= n;
|
|
339
340
|
},
|
|
340
|
-
applyQuickOption(
|
|
341
|
-
const
|
|
342
|
-
let n = /* @__PURE__ */ new Date(),
|
|
343
|
-
switch (
|
|
341
|
+
applyQuickOption(e) {
|
|
342
|
+
const t = /* @__PURE__ */ new Date();
|
|
343
|
+
let n = /* @__PURE__ */ new Date(), l = /* @__PURE__ */ new Date();
|
|
344
|
+
switch (e.type) {
|
|
344
345
|
case "days":
|
|
345
|
-
n = new Date(
|
|
346
|
+
n = new Date(t.getTime() - e.value * 24 * 60 * 60 * 1e3);
|
|
346
347
|
break;
|
|
347
348
|
case "months":
|
|
348
|
-
n = new Date(
|
|
349
|
+
n = new Date(t.getFullYear(), t.getMonth() - e.value, t.getDate());
|
|
349
350
|
break;
|
|
350
351
|
case "years":
|
|
351
|
-
n = new Date(
|
|
352
|
+
n = new Date(t.getFullYear() - e.value, t.getMonth(), t.getDate());
|
|
352
353
|
break;
|
|
353
354
|
case "today":
|
|
354
|
-
|
|
355
|
-
break;
|
|
356
|
-
case "yesterday":
|
|
357
|
-
if (t.value === "full") {
|
|
358
|
-
const l = new Date(e.getTime() - 864e5);
|
|
359
|
-
n = new Date(l.getFullYear(), l.getMonth(), l.getDate()), r = new Date(l.getFullYear(), l.getMonth(), l.getDate());
|
|
360
|
-
}
|
|
361
|
-
break;
|
|
362
|
-
case "thisWeek": {
|
|
363
|
-
const l = e.getDay(), a = new Date(e.getTime() - l * 24 * 60 * 60 * 1e3);
|
|
364
|
-
if (t.value === "full") {
|
|
365
|
-
n = new Date(a.getFullYear(), a.getMonth(), a.getDate());
|
|
366
|
-
const d = new Date(a.getTime() + 6 * 24 * 60 * 60 * 1e3);
|
|
367
|
-
r = new Date(d.getFullYear(), d.getMonth(), d.getDate());
|
|
368
|
-
}
|
|
355
|
+
e.value === "full" && (n = new Date(t.getFullYear(), t.getMonth(), t.getDate()), l = new Date(t.getFullYear(), t.getMonth(), t.getDate()));
|
|
369
356
|
break;
|
|
370
|
-
}
|
|
371
357
|
case "thisMonth":
|
|
372
|
-
|
|
358
|
+
e.value === "full" && (n = new Date(t.getFullYear(), t.getMonth(), 1), l = new Date(t.getFullYear(), t.getMonth() + 1, 0));
|
|
373
359
|
break;
|
|
374
360
|
}
|
|
375
|
-
this.startDate = n, this.endDate =
|
|
361
|
+
this.startDate = n, this.endDate = l, this.updateInputValue(), this.updateQuickOptionsActiveState(), this.startCalendarViewDate = new Date(this.startDate), this.endCalendarViewDate = new Date(this.endDate);
|
|
376
362
|
},
|
|
377
363
|
updateQuickOptionsActiveState() {
|
|
378
|
-
Object.keys(this.quickOptions).forEach((
|
|
379
|
-
this.quickOptions[
|
|
380
|
-
|
|
364
|
+
Object.keys(this.quickOptions).forEach((e) => {
|
|
365
|
+
this.quickOptions[e].forEach((t) => {
|
|
366
|
+
t.active = !1;
|
|
381
367
|
});
|
|
382
368
|
});
|
|
383
369
|
},
|
|
384
370
|
formatRangeDisplay() {
|
|
385
|
-
const
|
|
386
|
-
const n =
|
|
387
|
-
return `${n}-${
|
|
371
|
+
const e = (t) => {
|
|
372
|
+
const n = t.getFullYear(), l = String(t.getMonth() + 1).padStart(2, "0"), r = String(t.getDate()).padStart(2, "0");
|
|
373
|
+
return `${n}-${l}-${r}`;
|
|
388
374
|
};
|
|
389
|
-
return `${
|
|
375
|
+
return `${e(this.startDate)} ~ ${e(this.endDate)}`;
|
|
390
376
|
},
|
|
391
|
-
clickStop(
|
|
392
|
-
|
|
377
|
+
clickStop(e) {
|
|
378
|
+
e.stopPropagation();
|
|
393
379
|
},
|
|
394
380
|
confirmSelection() {
|
|
395
381
|
this.selectedRange = this.formatRangeDisplay(), this.inputValue = this.selectedRange, this.showPanel = !1;
|
|
@@ -405,15 +391,17 @@ const S = (t, e) => {
|
|
|
405
391
|
},
|
|
406
392
|
modelClick() {
|
|
407
393
|
this.showPanel = !1;
|
|
408
|
-
const
|
|
409
|
-
this.$emit("changeTime",
|
|
394
|
+
const t = this.inputValue.split("~").map((n) => n.trim());
|
|
395
|
+
this.$emit("changeTime", t);
|
|
410
396
|
},
|
|
411
397
|
handleListener() {
|
|
412
398
|
this.clickOutsideHandler && document.removeEventListener("click", this.clickOutsideHandler);
|
|
413
|
-
const
|
|
399
|
+
const e = this.$refs.contentRef, t = this.$refs.timePanelRef;
|
|
414
400
|
this.clickOutsideHandler = (n) => {
|
|
415
|
-
|
|
416
|
-
|
|
401
|
+
if (!this.showPanel)
|
|
402
|
+
return;
|
|
403
|
+
const l = e && e.contains(n.target), r = t && t.contains(n.target);
|
|
404
|
+
!l && !r && this.modelClick();
|
|
417
405
|
}, document.addEventListener("click", this.clickOutsideHandler);
|
|
418
406
|
},
|
|
419
407
|
cleanupEventListener() {
|
|
@@ -426,176 +414,139 @@ const S = (t, e) => {
|
|
|
426
414
|
beforeUnmount() {
|
|
427
415
|
this.cleanupEventListener();
|
|
428
416
|
}
|
|
429
|
-
},
|
|
417
|
+
}, P = {
|
|
430
418
|
class: "container",
|
|
431
419
|
ref: "contentRef"
|
|
432
|
-
},
|
|
433
|
-
function
|
|
434
|
-
const
|
|
420
|
+
}, b = { class: "content" }, R = { class: "huiyi-time-input-section" }, x = { class: "huiyi-time-input-field" }, T = { class: "huiyi-time-panel-body" }, E = { class: "huiyi-time-quick-options" }, A = { class: "option-group" }, L = { class: "option-group" }, $ = ["onClick"], q = { class: "option-group" }, Q = ["onClick"], U = { class: "huiyi-time-panels-container" }, H = { class: "huiyi-time-date-panel" }, N = { class: "calendar-section" }, B = { class: "huiyi-time-calendar-header" }, K = { class: "huiyi-time-current-month" }, j = { class: "huiyi-time-calendar-days" }, z = ["onClick"], W = { class: "huiyi-time-date-panel" }, G = { class: "calendar-section" }, J = { class: "huiyi-time-calendar-header" }, X = { class: "huiyi-time-current-month" }, Z = { class: "huiyi-time-calendar-days" }, tt = ["onClick"];
|
|
421
|
+
function et(e, t, n, l, r, s) {
|
|
422
|
+
const h = S("el-input"), u = S("el-button");
|
|
435
423
|
return c(), p("div", {
|
|
436
424
|
id: "huiyi-time-app",
|
|
437
|
-
onMouseover:
|
|
438
|
-
onMouseleave:
|
|
425
|
+
onMouseover: t[12] || (t[12] = (...i) => s.handleMouseOver && s.handleMouseOver(...i)),
|
|
426
|
+
onMouseleave: t[13] || (t[13] = (...i) => s.handleMouseOut && s.handleMouseOut(...i))
|
|
439
427
|
}, [
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
428
|
+
a("div", P, [
|
|
429
|
+
a("div", b, [
|
|
430
|
+
a("div", R, [
|
|
431
|
+
a("div", x, [
|
|
432
|
+
w(h, {
|
|
445
433
|
type: "text",
|
|
446
|
-
class: v(["huiyi-time-datetime-input", { invalid:
|
|
447
|
-
modelValue:
|
|
448
|
-
"onUpdate:modelValue":
|
|
434
|
+
class: v(["huiyi-time-datetime-input", { invalid: r.isInvalid }]),
|
|
435
|
+
modelValue: r.inputValue,
|
|
436
|
+
"onUpdate:modelValue": t[0] || (t[0] = (i) => r.inputValue = i),
|
|
449
437
|
placeholder: "YYYY-MM-DD ~ YYYY-MM-DD",
|
|
450
|
-
onMouseup:
|
|
451
|
-
onBlur:
|
|
452
|
-
onKeydown:
|
|
453
|
-
onInput:
|
|
454
|
-
onClick:
|
|
438
|
+
onMouseup: s.onInputFocus,
|
|
439
|
+
onBlur: s.onInputBlur,
|
|
440
|
+
onKeydown: s.onInputKeydown,
|
|
441
|
+
onInput: s.onInputChange,
|
|
442
|
+
onClick: t[1] || (t[1] = (i) => s.openShowPanel()),
|
|
443
|
+
ref: "datetimeInputRef"
|
|
455
444
|
}, null, 8, ["class", "modelValue", "onMouseup", "onBlur", "onKeydown", "onInput"])
|
|
456
445
|
])
|
|
457
446
|
])
|
|
458
447
|
])
|
|
459
448
|
], 512),
|
|
460
|
-
|
|
461
|
-
class: v(["huiyi-time-time-panel",
|
|
449
|
+
a("div", {
|
|
450
|
+
class: v(["huiyi-time-time-panel", r.showPanel ? "huiyi-time-time-panel-visible" : "huiyi-time-time-panel-none"]),
|
|
462
451
|
ref: "timePanelRef"
|
|
463
452
|
}, [
|
|
464
|
-
|
|
453
|
+
a("div", {
|
|
465
454
|
class: "huiyi-time-panel-container",
|
|
466
|
-
onClick:
|
|
455
|
+
onClick: t[11] || (t[11] = m((...i) => s.clickStop && s.clickStop(...i), ["stop"]))
|
|
467
456
|
}, [
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
457
|
+
a("div", T, [
|
|
458
|
+
a("div", E, [
|
|
459
|
+
a("div", A, [
|
|
460
|
+
a("div", {
|
|
472
461
|
class: "huiyi-time-quick-option",
|
|
473
|
-
onClick:
|
|
462
|
+
onClick: t[2] || (t[2] = m((i) => s.applyQuickOption({ name: "今天", type: "today", value: "full", active: !1 }), ["stop"]))
|
|
474
463
|
}, [
|
|
475
|
-
|
|
464
|
+
w(u, {
|
|
476
465
|
style: { width: "60px" },
|
|
477
466
|
type: "primary",
|
|
478
467
|
plain: "",
|
|
479
468
|
text: "",
|
|
480
469
|
bg: ""
|
|
481
470
|
}, {
|
|
482
|
-
default:
|
|
483
|
-
|
|
471
|
+
default: M(() => [...t[14] || (t[14] = [
|
|
472
|
+
I(" 今天 ", -1)
|
|
484
473
|
])]),
|
|
485
474
|
_: 1
|
|
486
475
|
})
|
|
487
476
|
])
|
|
488
477
|
]),
|
|
489
|
-
|
|
490
|
-
(c(!0), p(
|
|
491
|
-
key: i.name,
|
|
492
|
-
class: v(["huiyi-time-quick-option", { active: i.active }]),
|
|
493
|
-
onClick: m((D) => a.applyQuickOption(i), ["stop"])
|
|
494
|
-
}, [
|
|
495
|
-
g(h, {
|
|
496
|
-
style: { width: "60px" },
|
|
497
|
-
type: "primary",
|
|
498
|
-
text: "",
|
|
499
|
-
bg: ""
|
|
500
|
-
}, {
|
|
501
|
-
default: C(() => [
|
|
502
|
-
M(y(i.name), 1)
|
|
503
|
-
]),
|
|
504
|
-
_: 2
|
|
505
|
-
}, 1024)
|
|
506
|
-
], 10, q))), 128))
|
|
507
|
-
]),
|
|
508
|
-
s("div", Q, [
|
|
509
|
-
(c(!0), p(f, null, w(l.quickOptions.thisWeek, (i) => (c(), p("div", {
|
|
510
|
-
key: i.name,
|
|
511
|
-
class: v(["huiyi-time-quick-option", { active: i.active }]),
|
|
512
|
-
onClick: m((D) => a.applyQuickOption(i), ["stop"])
|
|
513
|
-
}, [
|
|
514
|
-
g(h, {
|
|
515
|
-
style: { width: "60px" },
|
|
516
|
-
type: "primary",
|
|
517
|
-
text: "",
|
|
518
|
-
bg: ""
|
|
519
|
-
}, {
|
|
520
|
-
default: C(() => [
|
|
521
|
-
M(y(i.name), 1)
|
|
522
|
-
]),
|
|
523
|
-
_: 2
|
|
524
|
-
}, 1024)
|
|
525
|
-
], 10, U))), 128))
|
|
526
|
-
]),
|
|
527
|
-
s("div", H, [
|
|
528
|
-
(c(!0), p(f, null, w(l.quickOptions.thisMonth, (i) => (c(), p("div", {
|
|
478
|
+
a("div", L, [
|
|
479
|
+
(c(!0), p(C, null, k(r.quickOptions.thisMonth, (i) => (c(), p("div", {
|
|
529
480
|
key: i.name,
|
|
530
481
|
class: v(["huiyi-time-quick-option", { active: i.active }]),
|
|
531
|
-
onClick: m((D) =>
|
|
482
|
+
onClick: m((D) => s.applyQuickOption(i), ["stop"])
|
|
532
483
|
}, [
|
|
533
|
-
|
|
484
|
+
w(u, {
|
|
534
485
|
style: { width: "60px" },
|
|
535
486
|
type: "primary",
|
|
536
487
|
text: "",
|
|
537
488
|
bg: ""
|
|
538
489
|
}, {
|
|
539
|
-
default:
|
|
540
|
-
|
|
490
|
+
default: M(() => [
|
|
491
|
+
I(f(i.name), 1)
|
|
541
492
|
]),
|
|
542
493
|
_: 2
|
|
543
494
|
}, 1024)
|
|
544
|
-
], 10,
|
|
495
|
+
], 10, $))), 128))
|
|
545
496
|
]),
|
|
546
|
-
|
|
547
|
-
(c(!0), p(
|
|
497
|
+
a("div", q, [
|
|
498
|
+
(c(!0), p(C, null, k(r.quickOptions.common, (i) => (c(), p("div", {
|
|
548
499
|
key: i.name,
|
|
549
500
|
class: v(["huiyi-time-quick-option", { active: i.active }]),
|
|
550
|
-
onClick: m((D) =>
|
|
501
|
+
onClick: m((D) => s.applyQuickOption(i), ["stop"])
|
|
551
502
|
}, [
|
|
552
|
-
|
|
503
|
+
w(u, {
|
|
553
504
|
style: { width: "60px" },
|
|
554
505
|
type: "primary",
|
|
555
506
|
text: "",
|
|
556
507
|
bg: ""
|
|
557
508
|
}, {
|
|
558
|
-
default:
|
|
559
|
-
|
|
509
|
+
default: M(() => [
|
|
510
|
+
I(f(i.name), 1)
|
|
560
511
|
]),
|
|
561
512
|
_: 2
|
|
562
513
|
}, 1024)
|
|
563
|
-
], 10,
|
|
514
|
+
], 10, Q))), 128))
|
|
564
515
|
])
|
|
565
516
|
]),
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
517
|
+
a("div", U, [
|
|
518
|
+
a("div", H, [
|
|
519
|
+
a("div", N, [
|
|
520
|
+
a("div", B, [
|
|
521
|
+
a("div", {
|
|
571
522
|
class: "huiyi-time-year-nav",
|
|
572
|
-
onClick:
|
|
523
|
+
onClick: t[3] || (t[3] = (i) => s.prevYear("start"))
|
|
573
524
|
}, "<<"),
|
|
574
|
-
|
|
525
|
+
a("div", {
|
|
575
526
|
class: "huiyi-time-month-nav",
|
|
576
|
-
onClick:
|
|
527
|
+
onClick: t[4] || (t[4] = (i) => s.prevMonth("start"))
|
|
577
528
|
}, "<"),
|
|
578
|
-
|
|
579
|
-
|
|
529
|
+
a("div", K, f(s.startDateMonthYear), 1),
|
|
530
|
+
a("div", {
|
|
580
531
|
class: "huiyi-time-month-nav",
|
|
581
|
-
onClick:
|
|
532
|
+
onClick: t[5] || (t[5] = (i) => s.nextMonth("start"))
|
|
582
533
|
}, ">"),
|
|
583
|
-
|
|
534
|
+
a("div", {
|
|
584
535
|
class: "huiyi-time-year-nav",
|
|
585
|
-
onClick:
|
|
536
|
+
onClick: t[6] || (t[6] = (i) => s.nextYear("start"))
|
|
586
537
|
}, ">>")
|
|
587
538
|
]),
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
539
|
+
t[15] || (t[15] = a("div", { class: "huiyi-time-week-days" }, [
|
|
540
|
+
a("div", null, "日"),
|
|
541
|
+
a("div", null, "一"),
|
|
542
|
+
a("div", null, "二"),
|
|
543
|
+
a("div", null, "三"),
|
|
544
|
+
a("div", null, "四"),
|
|
545
|
+
a("div", null, "五"),
|
|
546
|
+
a("div", null, "六")
|
|
596
547
|
], -1)),
|
|
597
|
-
|
|
598
|
-
(c(!0), p(
|
|
548
|
+
a("div", j, [
|
|
549
|
+
(c(!0), p(C, null, k(s.startCalendarDays, (i) => (c(), p("div", {
|
|
599
550
|
key: i.id,
|
|
600
551
|
class: v(["huiyi-time-calendar-day", {
|
|
601
552
|
"other-month": !i.isCurrentMonth,
|
|
@@ -603,43 +554,43 @@ function se(t, e, n, r, l, a) {
|
|
|
603
554
|
today: i.isToday,
|
|
604
555
|
"in-range": i.isInRange
|
|
605
556
|
}]),
|
|
606
|
-
onClick: m((D) =>
|
|
607
|
-
},
|
|
557
|
+
onClick: m((D) => s.selectDate("start", i.date), ["stop"])
|
|
558
|
+
}, f(i.day), 11, z))), 128))
|
|
608
559
|
])
|
|
609
560
|
])
|
|
610
561
|
]),
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
562
|
+
a("div", W, [
|
|
563
|
+
a("div", G, [
|
|
564
|
+
a("div", J, [
|
|
565
|
+
a("div", {
|
|
615
566
|
class: "huiyi-time-year-nav",
|
|
616
|
-
onClick:
|
|
567
|
+
onClick: t[7] || (t[7] = (i) => s.prevYear("end"))
|
|
617
568
|
}, "<<"),
|
|
618
|
-
|
|
569
|
+
a("div", {
|
|
619
570
|
class: "huiyi-time-month-nav",
|
|
620
|
-
onClick:
|
|
571
|
+
onClick: t[8] || (t[8] = m((i) => s.prevMonth("end"), ["stop"]))
|
|
621
572
|
}, "<"),
|
|
622
|
-
|
|
623
|
-
|
|
573
|
+
a("div", X, f(s.endDateMonthYear), 1),
|
|
574
|
+
a("div", {
|
|
624
575
|
class: "huiyi-time-month-nav",
|
|
625
|
-
onClick:
|
|
576
|
+
onClick: t[9] || (t[9] = m((i) => s.nextMonth("end"), ["stop"]))
|
|
626
577
|
}, ">"),
|
|
627
|
-
|
|
578
|
+
a("div", {
|
|
628
579
|
class: "huiyi-time-year-nav",
|
|
629
|
-
onClick:
|
|
580
|
+
onClick: t[10] || (t[10] = (i) => s.nextYear("end"))
|
|
630
581
|
}, ">>")
|
|
631
582
|
]),
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
583
|
+
t[16] || (t[16] = a("div", { class: "huiyi-time-week-days" }, [
|
|
584
|
+
a("div", null, "日"),
|
|
585
|
+
a("div", null, "一"),
|
|
586
|
+
a("div", null, "二"),
|
|
587
|
+
a("div", null, "三"),
|
|
588
|
+
a("div", null, "四"),
|
|
589
|
+
a("div", null, "五"),
|
|
590
|
+
a("div", null, "六")
|
|
640
591
|
], -1)),
|
|
641
|
-
|
|
642
|
-
(c(!0), p(
|
|
592
|
+
a("div", Z, [
|
|
593
|
+
(c(!0), p(C, null, k(s.endCalendarDays, (i) => (c(), p("div", {
|
|
643
594
|
key: i.id,
|
|
644
595
|
class: v(["huiyi-time-calendar-day", {
|
|
645
596
|
"other-month": !i.isCurrentMonth,
|
|
@@ -647,8 +598,8 @@ function se(t, e, n, r, l, a) {
|
|
|
647
598
|
today: i.isToday,
|
|
648
599
|
"in-range": i.isInRange
|
|
649
600
|
}]),
|
|
650
|
-
onClick: m((D) =>
|
|
651
|
-
},
|
|
601
|
+
onClick: m((D) => s.selectDate("end", i.date), ["stop"])
|
|
602
|
+
}, f(i.day), 11, tt))), 128))
|
|
652
603
|
])
|
|
653
604
|
])
|
|
654
605
|
])
|
|
@@ -658,24 +609,24 @@ function se(t, e, n, r, l, a) {
|
|
|
658
609
|
], 2)
|
|
659
610
|
], 32);
|
|
660
611
|
}
|
|
661
|
-
const
|
|
662
|
-
|
|
663
|
-
|
|
612
|
+
const g = /* @__PURE__ */ F(O, [["render", et], ["__scopeId", "data-v-7cba3967"]]);
|
|
613
|
+
g.install = (e) => {
|
|
614
|
+
e.component(g.name, g);
|
|
664
615
|
};
|
|
665
|
-
const
|
|
666
|
-
|
|
667
|
-
],
|
|
668
|
-
|
|
669
|
-
|
|
616
|
+
const nt = [
|
|
617
|
+
g
|
|
618
|
+
], _ = function(e) {
|
|
619
|
+
_.installed || nt.forEach((t) => {
|
|
620
|
+
e.component(t.name, t);
|
|
670
621
|
});
|
|
671
622
|
};
|
|
672
|
-
typeof window < "u" && window.Vue &&
|
|
673
|
-
const
|
|
674
|
-
install:
|
|
675
|
-
TimeComponentsUp:
|
|
623
|
+
typeof window < "u" && window.Vue && _(window.Vue);
|
|
624
|
+
const st = {
|
|
625
|
+
install: _,
|
|
626
|
+
TimeComponentsUp: g
|
|
676
627
|
};
|
|
677
628
|
export {
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
629
|
+
g as TimeComponentsUp,
|
|
630
|
+
st as default,
|
|
631
|
+
_ as install
|
|
681
632
|
};
|
package/huiyi-time.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(u,t){typeof exports=="object"&&typeof module<"u"?t(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],t):(u=typeof globalThis<"u"?globalThis:u||self,t(u.HuiyiTime={},u.Vue))})(this,function(u,t){"use strict";const X="",Z="",g=(n,e)=>{const a=n.__vccOpts||n;for(const[r,l]of e)a[r]=l;return a},w={name:"TimeComponentsUp",props:{initTime:{type:String,default:""}},data(){return{showPanel:!1,startDate:new Date,endDate:new Date,activeControl:"startYear",selectedRange:null,inputValue:"",isInvalid:!1,inputSelection:{start:0,end:0},mouseOver:!1,startCalendarViewDate:new Date,endCalendarViewDate:new Date,quickOptions:{common:[{name:"近3月",type:"months",value:3,active:!1},{name:"近1年",type:"years",value:1,active:!1}],today:[],yesterday:[{name:"昨天",type:"yesterday",value:"full",active:!1}],thisWeek:[{name:"本周",type:"thisWeek",value:"full",active:!1}],thisMonth:[{name:"本月",type:"thisMonth",value:"full",active:!1}]},dateFormatter:new Intl.DateTimeFormat("en-US",{year:"numeric",month:"long",day:"2-digit"}),clickOutsideHandler:null}},computed:{startDateMonthYear(){const n=this.startCalendarViewDate.getFullYear(),e=this.startCalendarViewDate.getMonth()+1;return`${n}年${e}月`},endDateMonthYear(){const n=this.endCalendarViewDate.getFullYear(),e=this.endCalendarViewDate.getMonth()+1;return`${n}年${e}月`},startCalendarDays(){return this.generateCalendarDays(this.startCalendarViewDate,this.startDate,this.endDate,"start")},endCalendarDays(){return this.generateCalendarDays(this.endCalendarViewDate,this.startDate,this.endDate,"end")},fieldPositions(){return[{name:"startYear",start:0,end:4,length:4},{name:"startMonth",start:5,end:7,length:2},{name:"startDay",start:8,end:10,length:2},{name:"endYear",start:13,end:17,length:4},{name:"endMonth",start:18,end:20,length:2},{name:"endDay",start:21,end:23,length:2}]}},mounted(){this.inputValue=this.initTime,this.updateQuickOptionsActiveState()},methods:{setActiveControl(n){this.activeControl=n},updateInputValue(){const n=e=>{const a=e.getFullYear(),r=String(e.getMonth()+1).padStart(2,"0"),l=String(e.getDate()).padStart(2,"0");return`${a}-${r}-${l}`};this.inputValue=`${n(this.startDate)} ~ ${n(this.endDate)}`,this.modelClick()},onInputFocus(n){setTimeout(()=>{this.inputSelection={start:n.target.selectionStart,end:n.target.selectionEnd},this.selectCurrentField(this.inputSelection.start)},0)},onInputBlur(){this.validateInput()},onInputChange(){this.validateInput()},onInputKeydown(n){const e=n.key;["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(e)&&(n.preventDefault(),e==="ArrowLeft"?this.navigateLeft():e==="ArrowRight"?this.navigateRight():e==="ArrowUp"?this.incrementValue():e==="ArrowDown"&&this.decrementValue()),e==="Tab"&&(n.preventDefault(),n.shiftKey?this.navigateLeft():this.navigateRight()),e==="Enter"&&(n.preventDefault(),this.showPanel=!1)},navigateLeft(){const n=this.inputSelection.start;let e=null;for(let a=0;a<this.fieldPositions.length;a++)if(n>=this.fieldPositions[a].start&&n<=this.fieldPositions[a].end){a>0?e=this.fieldPositions[a-1]:e=this.fieldPositions[this.fieldPositions.length-1];break}e||(e=this.fieldPositions[0]),this.selectField(e)},navigateRight(){const n=this.inputSelection.start;let e=null;for(let a=0;a<this.fieldPositions.length;a++)if(n>=this.fieldPositions[a].start&&n<=this.fieldPositions[a].end){a<this.fieldPositions.length-1?e=this.fieldPositions[a+1]:e=this.fieldPositions[0];break}e||(e=this.fieldPositions[0]),this.selectField(e)},selectCurrentField(n){for(const e of this.fieldPositions)if(n>=e.start&&n<=e.end){this.selectField(e);return}this.selectField(this.fieldPositions[0])},selectField(n){document.getElementById("datetime-input").setSelectionRange(n.start,n.end),this.inputSelection={start:n.start,end:n.end},this.activeControl=n.name},incrementValue(){const n=this.getCurrentField();if(!n)return;let a=parseInt(this.inputValue.substring(n.start,n.end))+1;switch(n.name){case"startYear":case"endYear":break;case"startMonth":case"endMonth":a>12&&(a=1);break;case"startDay":case"endDay":a>31&&(a=1);break}this.updateFieldValue(n,a)},decrementValue(){const n=this.getCurrentField();if(!n)return;let a=parseInt(this.inputValue.substring(n.start,n.end))-1;switch(n.name){case"startYear":case"endYear":a<1&&(a=9999);break;case"startMonth":case"endMonth":a<1&&(a=12);break;case"startDay":case"endDay":a<1&&(a=31);break}this.updateFieldValue(n,a)},getCurrentField(){for(const n of this.fieldPositions)if(this.inputSelection.start>=n.start&&this.inputSelection.start<=n.end)return n;return null},updateFieldValue(n,e){const a=String(e).padStart(n.length,"0"),r=this.inputValue.substring(0,n.start)+a+this.inputValue.substring(n.end);this.inputValue=r,this.$nextTick(()=>{this.selectField(n)}),this.updateDateFromInput()},updateDateFromInput(){if(!this.validateInputFormat())return;const n=this.inputValue.split(/[''~-]/);if(n.length!==6)return;const e=parseInt(n[0]),a=parseInt(n[1])-1,r=parseInt(n[2]),l=parseInt(n[3]),s=parseInt(n[4])-1,d=parseInt(n[5]),h=new Date(e,a,r),i=new Date(l,s,d);if(isNaN(h.getTime())||isNaN(i.getTime())){this.isInvalid=!0;return}this.startDate=h,this.endDate=i,this.isInvalid=!1,this.updateQuickOptionsActiveState(),this.startCalendarViewDate=new Date(this.startDate),this.endCalendarViewDate=new Date(this.endDate)},validateInputFormat(){return/^\d{4}-\d{2}-\d{2} ~ \d{4}-\d{2}-\d{2}$/.test(this.inputValue)},validateInput(){if(!this.validateInputFormat()){this.isInvalid=!0;return}const n=this.inputValue.split(/[ ~-]/),e=parseInt(n[0]),a=parseInt(n[1]),r=parseInt(n[2]),l=parseInt(n[3]),s=parseInt(n[4]),d=parseInt(n[5]);if(a<1||a>12||s<1||s>12){this.isInvalid=!0;return}if(r<1||r>31||d<1||d>31){this.isInvalid=!0;return}const h=new Date(e,a-1,r),i=new Date(l,s-1,d);if(h.getMonth()!==a-1||h.getDate()!==r||i.getMonth()!==s-1||i.getDate()!==d){this.isInvalid=!0;return}this.isInvalid=!1},prevYear(n){if(n==="start"){const e=new Date(this.startCalendarViewDate);e.setFullYear(e.getFullYear()-1),this.startCalendarViewDate=e}else{const e=new Date(this.endCalendarViewDate);e.setFullYear(e.getFullYear()-1),this.endCalendarViewDate=e}},nextYear(n){if(n==="start"){const e=new Date(this.startCalendarViewDate);e.setFullYear(e.getFullYear()+1),this.startCalendarViewDate=e}else{const e=new Date(this.endCalendarViewDate);e.setFullYear(e.getFullYear()+1),this.endCalendarViewDate=e}},prevMonth(n){if(n==="start"){const e=new Date(this.startCalendarViewDate);e.setMonth(e.getMonth()-1),this.startCalendarViewDate=e}else{const e=new Date(this.endCalendarViewDate);e.setMonth(e.getMonth()-1),this.endCalendarViewDate=e}},nextMonth(n){if(n==="start"){const e=new Date(this.startCalendarViewDate);e.setMonth(e.getMonth()+1),this.startCalendarViewDate=e}else{const e=new Date(this.endCalendarViewDate);e.setMonth(e.getMonth()+1),this.endCalendarViewDate=e}},selectDate(n,e){n==="start"?this.startDate=e:this.endDate=e,this.updateInputValue(),this.updateQuickOptionsActiveState()},generateCalendarDays(n,e,a,r){const l=n.getFullYear(),s=n.getMonth(),d=new Date(l,s,1),h=new Date(l,s+1,0),i=d.getDay(),m=new Date(l,s,0).getDate(),D=[],y=new Date;for(let o=i-1;o>=0;o--){const c=new Date(l,s-1,m-o);D.push({id:`prev-${o}-${r}`,day:m-o,date:c,isCurrentMonth:!1,isSelected:this.isSameDay(c,r==="start"?e:a),isToday:this.isSameDay(c,y),isInRange:this.isDateInRange(c,e,a)})}for(let o=1;o<=h.getDate();o++){const c=new Date(l,s,o);D.push({id:`current-${o}-${r}`,day:o,date:c,isCurrentMonth:!0,isSelected:this.isSameDay(c,r==="start"?e:a),isToday:this.isSameDay(c,y),isInRange:this.isDateInRange(c,e,a)})}const J=42-D.length;for(let o=1;o<=J;o++){const c=new Date(l,s+1,o);D.push({id:`next-${o}-${r}`,day:o,date:c,isCurrentMonth:!1,isSelected:this.isSameDay(c,r==="start"?e:a),isToday:this.isSameDay(c,y),isInRange:this.isDateInRange(c,e,a)})}return D},isSameDay(n,e){return n.getFullYear()===e.getFullYear()&&n.getMonth()===e.getMonth()&&n.getDate()===e.getDate()},isDateInRange(n,e,a){return n>=e&&n<=a},applyQuickOption(n){const e=new Date;let a=new Date,r=new Date;switch(n.type){case"days":a=new Date(e.getTime()-n.value*24*60*60*1e3);break;case"months":a=new Date(e.getFullYear(),e.getMonth()-n.value,e.getDate());break;case"years":a=new Date(e.getFullYear()-n.value,e.getMonth(),e.getDate());break;case"today":n.value==="full"&&(a=new Date(e.getFullYear(),e.getMonth(),e.getDate()),r=new Date(e.getFullYear(),e.getMonth(),e.getDate()));break;case"yesterday":if(n.value==="full"){const l=new Date(e.getTime()-864e5);a=new Date(l.getFullYear(),l.getMonth(),l.getDate()),r=new Date(l.getFullYear(),l.getMonth(),l.getDate())}break;case"thisWeek":{const l=e.getDay(),s=new Date(e.getTime()-l*24*60*60*1e3);if(n.value==="full"){a=new Date(s.getFullYear(),s.getMonth(),s.getDate());const d=new Date(s.getTime()+6*24*60*60*1e3);r=new Date(d.getFullYear(),d.getMonth(),d.getDate())}break}case"thisMonth":n.value==="full"&&(a=new Date(e.getFullYear(),e.getMonth(),1),r=new Date(e.getFullYear(),e.getMonth()+1,0));break}this.startDate=a,this.endDate=r,this.updateInputValue(),this.updateQuickOptionsActiveState(),this.startCalendarViewDate=new Date(this.startDate),this.endCalendarViewDate=new Date(this.endDate)},updateQuickOptionsActiveState(){Object.keys(this.quickOptions).forEach(n=>{this.quickOptions[n].forEach(e=>{e.active=!1})})},formatRangeDisplay(){const n=e=>{const a=e.getFullYear(),r=String(e.getMonth()+1).padStart(2,"0"),l=String(e.getDate()).padStart(2,"0");return`${a}-${r}-${l}`};return`${n(this.startDate)} ~ ${n(this.endDate)}`},clickStop(n){n.stopPropagation()},confirmSelection(){this.selectedRange=this.formatRangeDisplay(),this.inputValue=this.selectedRange,this.showPanel=!1},blurInput(){this.mouseOver==!1&&(this.showPanel=!1)},handleMouseOver(){this.mouseOver=!0},handleMouseOut(){this.mouseOver=!1},modelClick(){this.showPanel=!1;const e=this.inputValue.split("~").map(a=>a.trim());this.$emit("changeTime",e)},handleListener(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler);const n=this.$refs.contentRef,e=this.$refs.timePanelRef;this.clickOutsideHandler=a=>{const r=n&&n.contains(a.target),l=e&&e.contains(a.target);!r&&!l&&this.modelClick()},document.addEventListener("click",this.clickOutsideHandler)},cleanupEventListener(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)},openShowPanel(){this.showPanel=!0,this.handleListener(),this.updateDateFromInput()}},beforeUnmount(){this.cleanupEventListener()}},V={class:"container",ref:"contentRef"},k={class:"content"},C={class:"huiyi-time-input-section"},M={class:"huiyi-time-input-field"},E={class:"huiyi-time-panel-body"},N={class:"huiyi-time-quick-options"},_={class:"option-group"},I={class:"option-group"},F=["onClick"],S={class:"option-group"},Y=["onClick"],v={class:"option-group"},O=["onClick"],b={class:"option-group"},x=["onClick"],P={class:"huiyi-time-panels-container"},T={class:"huiyi-time-date-panel"},B={class:"calendar-section"},R={class:"huiyi-time-calendar-header"},L={class:"huiyi-time-current-month"},q={class:"huiyi-time-calendar-days"},A=["onClick"],Q={class:"huiyi-time-date-panel"},U={class:"calendar-section"},H={class:"huiyi-time-calendar-header"},z={class:"huiyi-time-current-month"},W={class:"huiyi-time-calendar-days"},$=["onClick"];function K(n,e,a,r,l,s){const d=t.resolveComponent("el-input"),h=t.resolveComponent("el-button");return t.openBlock(),t.createElementBlock("div",{id:"huiyi-time-app",onMouseover:e[12]||(e[12]=(...i)=>s.handleMouseOver&&s.handleMouseOver(...i)),onMouseleave:e[13]||(e[13]=(...i)=>s.handleMouseOut&&s.handleMouseOut(...i))},[t.createElementVNode("div",V,[t.createElementVNode("div",k,[t.createElementVNode("div",C,[t.createElementVNode("div",M,[t.createVNode(d,{type:"text",class:t.normalizeClass(["huiyi-time-datetime-input",{invalid:l.isInvalid}]),modelValue:l.inputValue,"onUpdate:modelValue":e[0]||(e[0]=i=>l.inputValue=i),placeholder:"YYYY-MM-DD ~ YYYY-MM-DD",onMouseup:s.onInputFocus,onBlur:s.onInputBlur,onKeydown:s.onInputKeydown,onInput:s.onInputChange,onClick:e[1]||(e[1]=i=>s.openShowPanel())},null,8,["class","modelValue","onMouseup","onBlur","onKeydown","onInput"])])])])],512),t.createElementVNode("div",{class:t.normalizeClass(["huiyi-time-time-panel",l.showPanel?"huiyi-time-time-panel-visible":"huiyi-time-time-panel-none"]),ref:"timePanelRef"},[t.createElementVNode("div",{class:"huiyi-time-panel-container",onClick:e[11]||(e[11]=t.withModifiers((...i)=>s.clickStop&&s.clickStop(...i),["stop"]))},[t.createElementVNode("div",E,[t.createElementVNode("div",N,[t.createElementVNode("div",_,[t.createElementVNode("div",{class:"huiyi-time-quick-option",onClick:e[2]||(e[2]=t.withModifiers(i=>s.applyQuickOption({name:"今天",type:"today",value:"full",active:!1}),["stop"]))},[t.createVNode(h,{style:{width:"60px"},type:"primary",plain:"",text:"",bg:""},{default:t.withCtx(()=>[...e[14]||(e[14]=[t.createTextVNode(" 今天 ",-1)])]),_:1})])]),t.createElementVNode("div",I,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(l.quickOptions.yesterday,i=>(t.openBlock(),t.createElementBlock("div",{key:i.name,class:t.normalizeClass(["huiyi-time-quick-option",{active:i.active}]),onClick:t.withModifiers(m=>s.applyQuickOption(i),["stop"])},[t.createVNode(h,{style:{width:"60px"},type:"primary",text:"",bg:""},{default:t.withCtx(()=>[t.createTextVNode(t.toDisplayString(i.name),1)]),_:2},1024)],10,F))),128))]),t.createElementVNode("div",S,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(l.quickOptions.thisWeek,i=>(t.openBlock(),t.createElementBlock("div",{key:i.name,class:t.normalizeClass(["huiyi-time-quick-option",{active:i.active}]),onClick:t.withModifiers(m=>s.applyQuickOption(i),["stop"])},[t.createVNode(h,{style:{width:"60px"},type:"primary",text:"",bg:""},{default:t.withCtx(()=>[t.createTextVNode(t.toDisplayString(i.name),1)]),_:2},1024)],10,Y))),128))]),t.createElementVNode("div",v,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(l.quickOptions.thisMonth,i=>(t.openBlock(),t.createElementBlock("div",{key:i.name,class:t.normalizeClass(["huiyi-time-quick-option",{active:i.active}]),onClick:t.withModifiers(m=>s.applyQuickOption(i),["stop"])},[t.createVNode(h,{style:{width:"60px"},type:"primary",text:"",bg:""},{default:t.withCtx(()=>[t.createTextVNode(t.toDisplayString(i.name),1)]),_:2},1024)],10,O))),128))]),t.createElementVNode("div",b,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(l.quickOptions.common,i=>(t.openBlock(),t.createElementBlock("div",{key:i.name,class:t.normalizeClass(["huiyi-time-quick-option",{active:i.active}]),onClick:t.withModifiers(m=>s.applyQuickOption(i),["stop"])},[t.createVNode(h,{style:{width:"60px"},type:"primary",text:"",bg:""},{default:t.withCtx(()=>[t.createTextVNode(t.toDisplayString(i.name),1)]),_:2},1024)],10,x))),128))])]),t.createElementVNode("div",P,[t.createElementVNode("div",T,[t.createElementVNode("div",B,[t.createElementVNode("div",R,[t.createElementVNode("div",{class:"huiyi-time-year-nav",onClick:e[3]||(e[3]=i=>s.prevYear("start"))},"<<"),t.createElementVNode("div",{class:"huiyi-time-month-nav",onClick:e[4]||(e[4]=i=>s.prevMonth("start"))},"<"),t.createElementVNode("div",L,t.toDisplayString(s.startDateMonthYear),1),t.createElementVNode("div",{class:"huiyi-time-month-nav",onClick:e[5]||(e[5]=i=>s.nextMonth("start"))},">"),t.createElementVNode("div",{class:"huiyi-time-year-nav",onClick:e[6]||(e[6]=i=>s.nextYear("start"))},">>")]),e[15]||(e[15]=t.createElementVNode("div",{class:"huiyi-time-week-days"},[t.createElementVNode("div",null,"日"),t.createElementVNode("div",null,"一"),t.createElementVNode("div",null,"二"),t.createElementVNode("div",null,"三"),t.createElementVNode("div",null,"四"),t.createElementVNode("div",null,"五"),t.createElementVNode("div",null,"六")],-1)),t.createElementVNode("div",q,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(s.startCalendarDays,i=>(t.openBlock(),t.createElementBlock("div",{key:i.id,class:t.normalizeClass(["huiyi-time-calendar-day",{"other-month":!i.isCurrentMonth,selected:i.isSelected,today:i.isToday,"in-range":i.isInRange}]),onClick:t.withModifiers(m=>s.selectDate("start",i.date),["stop"])},t.toDisplayString(i.day),11,A))),128))])])]),t.createElementVNode("div",Q,[t.createElementVNode("div",U,[t.createElementVNode("div",H,[t.createElementVNode("div",{class:"huiyi-time-year-nav",onClick:e[7]||(e[7]=i=>s.prevYear("end"))},"<<"),t.createElementVNode("div",{class:"huiyi-time-month-nav",onClick:e[8]||(e[8]=t.withModifiers(i=>s.prevMonth("end"),["stop"]))},"<"),t.createElementVNode("div",z,t.toDisplayString(s.endDateMonthYear),1),t.createElementVNode("div",{class:"huiyi-time-month-nav",onClick:e[9]||(e[9]=t.withModifiers(i=>s.nextMonth("end"),["stop"]))},">"),t.createElementVNode("div",{class:"huiyi-time-year-nav",onClick:e[10]||(e[10]=i=>s.nextYear("end"))},">>")]),e[16]||(e[16]=t.createElementVNode("div",{class:"huiyi-time-week-days"},[t.createElementVNode("div",null,"日"),t.createElementVNode("div",null,"一"),t.createElementVNode("div",null,"二"),t.createElementVNode("div",null,"三"),t.createElementVNode("div",null,"四"),t.createElementVNode("div",null,"五"),t.createElementVNode("div",null,"六")],-1)),t.createElementVNode("div",W,[(t.openBlock(!0),t.createElementBlock(t.Fragment,null,t.renderList(s.endCalendarDays,i=>(t.openBlock(),t.createElementBlock("div",{key:i.id,class:t.normalizeClass(["huiyi-time-calendar-day",{"other-month":!i.isCurrentMonth,selected:i.isSelected,today:i.isToday,"in-range":i.isInRange}]),onClick:t.withModifiers(m=>s.selectDate("end",i.date),["stop"])},t.toDisplayString(i.day),11,$))),128))])])])])])])],2)],32)}const p=g(w,[["render",K],["__scopeId","data-v-70fa0c5b"]]);p.install=n=>{n.component(p.name,p)};const j=[p],f=function(n){f.installed||j.forEach(e=>{n.component(e.name,e)})};typeof window<"u"&&window.Vue&&f(window.Vue);const G={install:f,TimeComponentsUp:p};u.TimeComponentsUp=p,u.default=G,u.install=f,Object.defineProperties(u,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
1
|
+
(function(u,n){typeof exports=="object"&&typeof module<"u"?n(exports,require("vue")):typeof define=="function"&&define.amd?define(["exports","vue"],n):(u=typeof globalThis<"u"?globalThis:u||self,n(u.HuiyiTime={},u.Vue))})(this,function(u,n){"use strict";const j="",W="",g=(t,e)=>{const i=t.__vccOpts||t;for(const[l,r]of e)i[l]=r;return i},w={name:"TimeComponentsUp",props:{initTime:{type:String,default:""}},data(){return{showPanel:!1,startDate:new Date,endDate:new Date,activeControl:"startYear",selectedRange:null,inputValue:"",isInvalid:!1,inputSelection:{start:0,end:0},mouseOver:!1,startCalendarViewDate:new Date,endCalendarViewDate:new Date,quickOptions:{common:[{name:"近3天",type:"days",value:3,active:!1},{name:"近7天",type:"days",value:7,active:!1},{name:"近1月",type:"months",value:1,active:!1},{name:"近3月",type:"months",value:3,active:!1},{name:"近1年",type:"years",value:1,active:!1}],today:[]},dateFormatter:new Intl.DateTimeFormat("en-US",{year:"numeric",month:"long",day:"2-digit"}),clickOutsideHandler:null}},computed:{startDateMonthYear(){const t=this.startCalendarViewDate.getFullYear(),e=this.startCalendarViewDate.getMonth()+1;return`${t}年${e}月`},endDateMonthYear(){const t=this.endCalendarViewDate.getFullYear(),e=this.endCalendarViewDate.getMonth()+1;return`${t}年${e}月`},startCalendarDays(){return this.generateCalendarDays(this.startCalendarViewDate,this.startDate,this.endDate,"start")},endCalendarDays(){return this.generateCalendarDays(this.endCalendarViewDate,this.startDate,this.endDate,"end")},fieldPositions(){return[{name:"startYear",start:0,end:4,length:4},{name:"startMonth",start:5,end:7,length:2},{name:"startDay",start:8,end:10,length:2},{name:"endYear",start:13,end:17,length:4},{name:"endMonth",start:18,end:20,length:2},{name:"endDay",start:21,end:23,length:2}]}},mounted(){this.inputValue=this.initTime,this.updateQuickOptionsActiveState()},methods:{setActiveControl(t){this.activeControl=t},updateInputValue(){const t=e=>{const i=e.getFullYear(),l=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0");return`${i}-${l}-${r}`};this.inputValue=`${t(this.startDate)} ~ ${t(this.endDate)}`,this.modelClick()},onInputFocus(t){setTimeout(()=>{this.inputSelection={start:t.target.selectionStart,end:t.target.selectionEnd},this.inputSelection.start===this.inputSelection.end&&this.selectCurrentField(this.inputSelection.start)},0)},onInputBlur(){this.validateInput()},onInputChange(){this.validateInput()},onInputKeydown(t){const e=t.key;["ArrowLeft","ArrowRight","ArrowUp","ArrowDown"].includes(e)&&(t.preventDefault(),e==="ArrowLeft"?this.navigateLeft():e==="ArrowRight"?this.navigateRight():e==="ArrowUp"?this.incrementValue():e==="ArrowDown"&&this.decrementValue()),e==="Tab"&&(t.preventDefault(),t.shiftKey?this.navigateLeft():this.navigateRight()),e==="Enter"&&(t.preventDefault(),this.showPanel=!1)},navigateLeft(){const t=this.inputSelection.start;let e=null;for(let i=0;i<this.fieldPositions.length;i++)if(t>=this.fieldPositions[i].start&&t<=this.fieldPositions[i].end){i>0?e=this.fieldPositions[i-1]:e=this.fieldPositions[this.fieldPositions.length-1];break}e||(e=this.fieldPositions[0]),this.selectField(e)},navigateRight(){const t=this.inputSelection.start;let e=null;for(let i=0;i<this.fieldPositions.length;i++)if(t>=this.fieldPositions[i].start&&t<=this.fieldPositions[i].end){i<this.fieldPositions.length-1?e=this.fieldPositions[i+1]:e=this.fieldPositions[0];break}e||(e=this.fieldPositions[0]),this.selectField(e)},selectCurrentField(t){for(const e of this.fieldPositions)if(t>=e.start&&t<=e.end){this.selectField(e);return}this.selectField(this.fieldPositions[0])},selectField(t){if(this.$refs.datetimeInputRef&&this.$refs.datetimeInputRef.$el){const e=this.$refs.datetimeInputRef.$el.querySelector("input");e&&e.setSelectionRange(t.start,t.end)}this.inputSelection={start:t.start,end:t.end},this.activeControl=t.name},incrementValue(){const t=this.getCurrentField();if(!t)return;let i=parseInt(this.inputValue.substring(t.start,t.end))+1;switch(t.name){case"startYear":case"endYear":break;case"startMonth":case"endMonth":i>12&&(i=1);break;case"startDay":case"endDay":i>31&&(i=1);break}this.updateFieldValue(t,i)},decrementValue(){const t=this.getCurrentField();if(!t)return;let i=parseInt(this.inputValue.substring(t.start,t.end))-1;switch(t.name){case"startYear":case"endYear":i<1&&(i=9999);break;case"startMonth":case"endMonth":i<1&&(i=12);break;case"startDay":case"endDay":i<1&&(i=31);break}this.updateFieldValue(t,i)},getCurrentField(){for(const t of this.fieldPositions)if(this.inputSelection.start>=t.start&&this.inputSelection.start<=t.end)return t;return null},updateFieldValue(t,e){const i=String(e).padStart(t.length,"0"),l=this.inputValue.substring(0,t.start)+i+this.inputValue.substring(t.end);this.inputValue=l,this.$nextTick(()=>{this.selectField(t)}),this.updateDateFromInput()},updateDateFromInput(){if(!this.validateInputFormat())return;const t=this.inputValue.split(/[''~-]/);if(t.length!==6)return;const e=parseInt(t[0]),i=parseInt(t[1])-1,l=parseInt(t[2]),r=parseInt(t[3]),s=parseInt(t[4])-1,h=parseInt(t[5]),c=new Date(e,i,l),a=new Date(r,s,h);if(isNaN(c.getTime())||isNaN(a.getTime())){this.isInvalid=!0;return}this.startDate=c,this.endDate=a,this.isInvalid=!1,this.updateQuickOptionsActiveState(),this.startCalendarViewDate=new Date(this.startDate),this.endCalendarViewDate=new Date(this.endDate)},validateInputFormat(){return/^\d{4}-\d{2}-\d{2} ~ \d{4}-\d{2}-\d{2}$/.test(this.inputValue)},validateInput(){if(!this.validateInputFormat()){this.isInvalid=!0;return}const t=this.inputValue.split(/[ ~-]/),e=parseInt(t[0]),i=parseInt(t[1]),l=parseInt(t[2]),r=parseInt(t[3]),s=parseInt(t[4]),h=parseInt(t[5]);if(i<1||i>12||s<1||s>12){this.isInvalid=!0;return}if(l<1||l>31||h<1||h>31){this.isInvalid=!0;return}const c=new Date(e,i-1,l),a=new Date(r,s-1,h);if(c.getMonth()!==i-1||c.getDate()!==l||a.getMonth()!==s-1||a.getDate()!==h){this.isInvalid=!0;return}this.isInvalid=!1},prevYear(t){if(t==="start"){const e=new Date(this.startCalendarViewDate);e.setFullYear(e.getFullYear()-1),this.startCalendarViewDate=e}else{const e=new Date(this.endCalendarViewDate);e.setFullYear(e.getFullYear()-1),this.endCalendarViewDate=e}},nextYear(t){if(t==="start"){const e=new Date(this.startCalendarViewDate);e.setFullYear(e.getFullYear()+1),this.startCalendarViewDate=e}else{const e=new Date(this.endCalendarViewDate);e.setFullYear(e.getFullYear()+1),this.endCalendarViewDate=e}},prevMonth(t){if(t==="start"){const e=new Date(this.startCalendarViewDate);e.setMonth(e.getMonth()-1),this.startCalendarViewDate=e}else{const e=new Date(this.endCalendarViewDate);e.setMonth(e.getMonth()-1),this.endCalendarViewDate=e}},nextMonth(t){if(t==="start"){const e=new Date(this.startCalendarViewDate);e.setMonth(e.getMonth()+1),this.startCalendarViewDate=e}else{const e=new Date(this.endCalendarViewDate);e.setMonth(e.getMonth()+1),this.endCalendarViewDate=e}},selectDate(t,e){t==="start"?this.startDate=e:this.endDate=e,this.updateInputValue(),this.updateQuickOptionsActiveState()},generateCalendarDays(t,e,i,l){const r=t.getFullYear(),s=t.getMonth(),h=new Date(r,s,1),c=new Date(r,s+1,0),a=h.getDay(),p=new Date(r,s,0).getDate(),f=[],y=new Date;for(let o=a-1;o>=0;o--){const d=new Date(r,s-1,p-o);f.push({id:`prev-${o}-${l}`,day:p-o,date:d,isCurrentMonth:!1,isSelected:this.isSameDay(d,l==="start"?e:i),isToday:this.isSameDay(d,y),isInRange:this.isDateInRange(d,e,i)})}for(let o=1;o<=c.getDate();o++){const d=new Date(r,s,o);f.push({id:`current-${o}-${l}`,day:o,date:d,isCurrentMonth:!0,isSelected:this.isSameDay(d,l==="start"?e:i),isToday:this.isSameDay(d,y),isInRange:this.isDateInRange(d,e,i)})}const K=42-f.length;for(let o=1;o<=K;o++){const d=new Date(r,s+1,o);f.push({id:`next-${o}-${l}`,day:o,date:d,isCurrentMonth:!1,isSelected:this.isSameDay(d,l==="start"?e:i),isToday:this.isSameDay(d,y),isInRange:this.isDateInRange(d,e,i)})}return f},isSameDay(t,e){return t.getFullYear()===e.getFullYear()&&t.getMonth()===e.getMonth()&&t.getDate()===e.getDate()},isDateInRange(t,e,i){return t>=e&&t<=i},applyQuickOption(t){const e=new Date;let i=new Date,l=new Date;switch(t.type){case"days":i=new Date(e.getTime()-t.value*24*60*60*1e3);break;case"months":i=new Date(e.getFullYear(),e.getMonth()-t.value,e.getDate());break;case"years":i=new Date(e.getFullYear()-t.value,e.getMonth(),e.getDate());break;case"today":t.value==="full"&&(i=new Date(e.getFullYear(),e.getMonth(),e.getDate()),l=new Date(e.getFullYear(),e.getMonth(),e.getDate()));break;case"thisMonth":t.value==="full"&&(i=new Date(e.getFullYear(),e.getMonth(),1),l=new Date(e.getFullYear(),e.getMonth()+1,0));break}this.startDate=i,this.endDate=l,this.updateInputValue(),this.updateQuickOptionsActiveState(),this.startCalendarViewDate=new Date(this.startDate),this.endCalendarViewDate=new Date(this.endDate)},updateQuickOptionsActiveState(){Object.keys(this.quickOptions).forEach(t=>{this.quickOptions[t].forEach(e=>{e.active=!1})})},formatRangeDisplay(){const t=e=>{const i=e.getFullYear(),l=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0");return`${i}-${l}-${r}`};return`${t(this.startDate)} ~ ${t(this.endDate)}`},clickStop(t){t.stopPropagation()},confirmSelection(){this.selectedRange=this.formatRangeDisplay(),this.inputValue=this.selectedRange,this.showPanel=!1},blurInput(){this.mouseOver==!1&&(this.showPanel=!1)},handleMouseOver(){this.mouseOver=!0},handleMouseOut(){this.mouseOver=!1},modelClick(){this.showPanel=!1;const e=this.inputValue.split("~").map(i=>i.trim());this.$emit("changeTime",e)},handleListener(){this.clickOutsideHandler&&document.removeEventListener("click",this.clickOutsideHandler);const t=this.$refs.contentRef,e=this.$refs.timePanelRef;this.clickOutsideHandler=i=>{if(!this.showPanel)return;const l=t&&t.contains(i.target),r=e&&e.contains(i.target);!l&&!r&&this.modelClick()},document.addEventListener("click",this.clickOutsideHandler)},cleanupEventListener(){this.clickOutsideHandler&&(document.removeEventListener("click",this.clickOutsideHandler),this.clickOutsideHandler=null)},openShowPanel(){this.showPanel=!0,this.handleListener(),this.updateDateFromInput()}},beforeUnmount(){this.cleanupEventListener()}},V={class:"container",ref:"contentRef"},k={class:"content"},C={class:"huiyi-time-input-section"},M={class:"huiyi-time-input-field"},E={class:"huiyi-time-panel-body"},I={class:"huiyi-time-quick-options"},N={class:"option-group"},v={class:"option-group"},S=["onClick"],_={class:"option-group"},F=["onClick"],Y={class:"huiyi-time-panels-container"},O={class:"huiyi-time-date-panel"},P={class:"calendar-section"},b={class:"huiyi-time-calendar-header"},R={class:"huiyi-time-current-month"},x={class:"huiyi-time-calendar-days"},T=["onClick"],B={class:"huiyi-time-date-panel"},L={class:"calendar-section"},A={class:"huiyi-time-calendar-header"},$={class:"huiyi-time-current-month"},q={class:"huiyi-time-calendar-days"},U=["onClick"];function H(t,e,i,l,r,s){const h=n.resolveComponent("el-input"),c=n.resolveComponent("el-button");return n.openBlock(),n.createElementBlock("div",{id:"huiyi-time-app",onMouseover:e[12]||(e[12]=(...a)=>s.handleMouseOver&&s.handleMouseOver(...a)),onMouseleave:e[13]||(e[13]=(...a)=>s.handleMouseOut&&s.handleMouseOut(...a))},[n.createElementVNode("div",V,[n.createElementVNode("div",k,[n.createElementVNode("div",C,[n.createElementVNode("div",M,[n.createVNode(h,{type:"text",class:n.normalizeClass(["huiyi-time-datetime-input",{invalid:r.isInvalid}]),modelValue:r.inputValue,"onUpdate:modelValue":e[0]||(e[0]=a=>r.inputValue=a),placeholder:"YYYY-MM-DD ~ YYYY-MM-DD",onMouseup:s.onInputFocus,onBlur:s.onInputBlur,onKeydown:s.onInputKeydown,onInput:s.onInputChange,onClick:e[1]||(e[1]=a=>s.openShowPanel()),ref:"datetimeInputRef"},null,8,["class","modelValue","onMouseup","onBlur","onKeydown","onInput"])])])])],512),n.createElementVNode("div",{class:n.normalizeClass(["huiyi-time-time-panel",r.showPanel?"huiyi-time-time-panel-visible":"huiyi-time-time-panel-none"]),ref:"timePanelRef"},[n.createElementVNode("div",{class:"huiyi-time-panel-container",onClick:e[11]||(e[11]=n.withModifiers((...a)=>s.clickStop&&s.clickStop(...a),["stop"]))},[n.createElementVNode("div",E,[n.createElementVNode("div",I,[n.createElementVNode("div",N,[n.createElementVNode("div",{class:"huiyi-time-quick-option",onClick:e[2]||(e[2]=n.withModifiers(a=>s.applyQuickOption({name:"今天",type:"today",value:"full",active:!1}),["stop"]))},[n.createVNode(c,{style:{width:"60px"},type:"primary",plain:"",text:"",bg:""},{default:n.withCtx(()=>[...e[14]||(e[14]=[n.createTextVNode(" 今天 ",-1)])]),_:1})])]),n.createElementVNode("div",v,[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(r.quickOptions.thisMonth,a=>(n.openBlock(),n.createElementBlock("div",{key:a.name,class:n.normalizeClass(["huiyi-time-quick-option",{active:a.active}]),onClick:n.withModifiers(p=>s.applyQuickOption(a),["stop"])},[n.createVNode(c,{style:{width:"60px"},type:"primary",text:"",bg:""},{default:n.withCtx(()=>[n.createTextVNode(n.toDisplayString(a.name),1)]),_:2},1024)],10,S))),128))]),n.createElementVNode("div",_,[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(r.quickOptions.common,a=>(n.openBlock(),n.createElementBlock("div",{key:a.name,class:n.normalizeClass(["huiyi-time-quick-option",{active:a.active}]),onClick:n.withModifiers(p=>s.applyQuickOption(a),["stop"])},[n.createVNode(c,{style:{width:"60px"},type:"primary",text:"",bg:""},{default:n.withCtx(()=>[n.createTextVNode(n.toDisplayString(a.name),1)]),_:2},1024)],10,F))),128))])]),n.createElementVNode("div",Y,[n.createElementVNode("div",O,[n.createElementVNode("div",P,[n.createElementVNode("div",b,[n.createElementVNode("div",{class:"huiyi-time-year-nav",onClick:e[3]||(e[3]=a=>s.prevYear("start"))},"<<"),n.createElementVNode("div",{class:"huiyi-time-month-nav",onClick:e[4]||(e[4]=a=>s.prevMonth("start"))},"<"),n.createElementVNode("div",R,n.toDisplayString(s.startDateMonthYear),1),n.createElementVNode("div",{class:"huiyi-time-month-nav",onClick:e[5]||(e[5]=a=>s.nextMonth("start"))},">"),n.createElementVNode("div",{class:"huiyi-time-year-nav",onClick:e[6]||(e[6]=a=>s.nextYear("start"))},">>")]),e[15]||(e[15]=n.createElementVNode("div",{class:"huiyi-time-week-days"},[n.createElementVNode("div",null,"日"),n.createElementVNode("div",null,"一"),n.createElementVNode("div",null,"二"),n.createElementVNode("div",null,"三"),n.createElementVNode("div",null,"四"),n.createElementVNode("div",null,"五"),n.createElementVNode("div",null,"六")],-1)),n.createElementVNode("div",x,[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(s.startCalendarDays,a=>(n.openBlock(),n.createElementBlock("div",{key:a.id,class:n.normalizeClass(["huiyi-time-calendar-day",{"other-month":!a.isCurrentMonth,selected:a.isSelected,today:a.isToday,"in-range":a.isInRange}]),onClick:n.withModifiers(p=>s.selectDate("start",a.date),["stop"])},n.toDisplayString(a.day),11,T))),128))])])]),n.createElementVNode("div",B,[n.createElementVNode("div",L,[n.createElementVNode("div",A,[n.createElementVNode("div",{class:"huiyi-time-year-nav",onClick:e[7]||(e[7]=a=>s.prevYear("end"))},"<<"),n.createElementVNode("div",{class:"huiyi-time-month-nav",onClick:e[8]||(e[8]=n.withModifiers(a=>s.prevMonth("end"),["stop"]))},"<"),n.createElementVNode("div",$,n.toDisplayString(s.endDateMonthYear),1),n.createElementVNode("div",{class:"huiyi-time-month-nav",onClick:e[9]||(e[9]=n.withModifiers(a=>s.nextMonth("end"),["stop"]))},">"),n.createElementVNode("div",{class:"huiyi-time-year-nav",onClick:e[10]||(e[10]=a=>s.nextYear("end"))},">>")]),e[16]||(e[16]=n.createElementVNode("div",{class:"huiyi-time-week-days"},[n.createElementVNode("div",null,"日"),n.createElementVNode("div",null,"一"),n.createElementVNode("div",null,"二"),n.createElementVNode("div",null,"三"),n.createElementVNode("div",null,"四"),n.createElementVNode("div",null,"五"),n.createElementVNode("div",null,"六")],-1)),n.createElementVNode("div",q,[(n.openBlock(!0),n.createElementBlock(n.Fragment,null,n.renderList(s.endCalendarDays,a=>(n.openBlock(),n.createElementBlock("div",{key:a.id,class:n.normalizeClass(["huiyi-time-calendar-day",{"other-month":!a.isCurrentMonth,selected:a.isSelected,today:a.isToday,"in-range":a.isInRange}]),onClick:n.withModifiers(p=>s.selectDate("end",a.date),["stop"])},n.toDisplayString(a.day),11,U))),128))])])])])])])],2)],32)}const m=g(w,[["render",H],["__scopeId","data-v-7cba3967"]]);m.install=t=>{t.component(m.name,m)};const Q=[m],D=function(t){D.installed||Q.forEach(e=>{t.component(e.name,e)})};typeof window<"u"&&window.Vue&&D(window.Vue);const z={install:D,TimeComponentsUp:m};u.TimeComponentsUp=m,u.default=z,u.install=D,Object.defineProperties(u,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { App, Plugin } from 'vue';
|
|
2
|
+
import type { PropType } from 'vue';
|
|
3
|
+
|
|
4
|
+
export interface TimeComponentsUpProps {
|
|
5
|
+
initTime?: string;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare const TimeComponentsUp: {
|
|
9
|
+
new (): {
|
|
10
|
+
$props: TimeComponentsUpProps;
|
|
11
|
+
};
|
|
12
|
+
__props: TimeComponentsUpProps;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export { TimeComponentsUp };
|
|
16
|
+
|
|
17
|
+
export interface HuiyiTimePlugin extends Plugin {
|
|
18
|
+
install(app: App, ...options: any[]): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare const HuiyiTime: HuiyiTimePlugin & {
|
|
22
|
+
TimeComponentsUp: typeof TimeComponentsUp;
|
|
23
|
+
install: (app: App, ...options: any[]) => void;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export default HuiyiTime;
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "huiyi-time",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
4
4
|
"description": "A Vue.js time range picker",
|
|
5
5
|
"main": "huiyi-time.umd.js",
|
|
6
6
|
"module": "huiyi-time.es.js",
|
|
7
7
|
"unpkg": "huiyi-time.umd.js",
|
|
8
8
|
"browser": "huiyi-time.umd.js",
|
|
9
|
+
"types": "index.d.ts",
|
|
9
10
|
"keywords": [
|
|
10
11
|
"vue",
|
|
11
12
|
"component",
|
package/style.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
#huiyi-time-app[data-v-
|
|
1
|
+
#huiyi-time-app[data-v-7cba3967]{position:relative}.huiyi-time-input-section[data-v-7cba3967]{display:flex;flex-direction:column;align-items:center}.huiyi-time-input-field[data-v-7cba3967]{width:100%;max-width:190px}.huiyi-time-time-panel[data-v-7cba3967]{width:600px;height:300px;justify-content:center;align-items:center;z-index:10000;position:fixed}.huiyi-time-panel-container[data-v-7cba3967]{background:white;border-radius:15px;width:98%;max-width:600px;box-shadow:0 15px 30px #0000004d;overflow:hidden;display:flex;flex-direction:column;max-height:90vh}.huiyi-time-panel-body[data-v-7cba3967]{display:flex;flex:1;overflow:hidden}.huiyi-time-quick-options[data-v-7cba3967]{width:80px;background:#fff;padding:26px 5px;border-right:1px solid #e9ecef;overflow-y:auto}.huiyi-time-quick-option[data-v-7cba3967]{display:block;width:69px;background:white;border-radius:8px;text-align:left;margin-bottom:8px;cursor:pointer;transition:all .2s;font-size:.9rem;text-align:center}.huiyi-time-quick-option.active[data-v-7cba3967]{background:#409eff;color:#fff;border-color:#409eff}.huiyi-time-panels-container[data-v-7cba3967]{flex:1;display:flex;overflow:hidden}.huiyi-time-date-panel[data-v-7cba3967]{flex:1;padding:10px;overflow-y:auto;width:360px;border-right:1px solid #e9ecef}.huiyi-time-date-panel[data-v-7cba3967]:last-child{border-right:none}.huiyi-time-calendar-header[data-v-7cba3967]{display:flex;justify-content:space-between;align-items:center;margin-bottom:11px}.huiyi-time-year-nav[data-v-7cba3967]{border:none;width:25px;height:25px;border-radius:50%;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:.8rem;transition:all .2s}.huiyi-time-year-nav[data-v-7cba3967]:hover{background:#e9ecef;cursor:pointer}.huiyi-time-month-nav[data-v-7cba3967]{border:none;width:25px;height:25px;border-radius:50%;display:flex;align-items:center;justify-content:center;cursor:pointer;font-size:.8rem;transition:all .2s}.huiyi-time-month-nav[data-v-7cba3967]:hover{background:#e9ecef;cursor:pointer}.huiyi-time-current-month[data-v-7cba3967]{font-size:1.1rem;font-weight:600;color:#333}.huiyi-time-week-days[data-v-7cba3967]{display:grid;grid-template-columns:repeat(7,1fr);text-align:center;margin-bottom:6px;font-weight:600;color:#666;font-size:.85rem}.huiyi-time-calendar-days[data-v-7cba3967]{display:grid;grid-template-columns:repeat(7,1fr);gap:5px}.huiyi-time-calendar-day[data-v-7cba3967]{height:30px;display:flex;align-items:center;justify-content:center;border-radius:6px;cursor:pointer;transition:all .2s;font-size:12px}.huiyi-time-calendar-day[data-v-7cba3967]:hover{background:#e9ecef;color:var(--el-color-primary)}.huiyi-time-calendar-day.other-month[data-v-7cba3967]{color:#ccc}.huiyi-time-calendar-day.selected[data-v-7cba3967]{background:var(--el-color-primary)!important;color:#fff!important}.huiyi-time-calendar-day.today[data-v-7cba3967]{background:#fff;color:var(--el-color-primary);font-weight:600}.huiyi-time-calendar-day.in-range[data-v-7cba3967]{background:#e6eeff}.huiyi-time-time-panel-visible[data-v-7cba3967]{display:block}.huiyi-time-time-panel-none[data-v-7cba3967]{display:none}@media (max-width: 900px){.huiyi-time-panel-body[data-v-7cba3967]{flex-direction:column;max-height:none}.huiyi-time-quick-options[data-v-7cba3967]{width:100%;border-right:none;border-bottom:1px solid #e9ecef;max-height:200px}.huiyi-time-panels-container[data-v-7cba3967]{flex-direction:column}.huiyi-time-date-panel[data-v-7cba3967]{border-right:none;border-bottom:1px solid #e9ecef}.huiyi-time-date-panel[data-v-7cba3967]:last-child{border-bottom:none}}
|
package/favicon.ico
DELETED
|
Binary file
|
package/huiyi-time-0.1.16.tgz
DELETED
|
Binary file
|
package/index.html
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
<!DOCTYPE html>
|
|
2
|
-
<html lang="">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="utf-8">
|
|
5
|
-
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
|
6
|
-
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
|
7
|
-
<link rel="icon" href="<%= BASE_URL %>favicon.ico">
|
|
8
|
-
<title><%= htmlWebpackPlugin.options.title %></title>
|
|
9
|
-
</head>
|
|
10
|
-
<body>
|
|
11
|
-
<noscript>
|
|
12
|
-
<strong>We're sorry but <%= htmlWebpackPlugin.options.title %> doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
|
|
13
|
-
</noscript>
|
|
14
|
-
<div id="app"></div>
|
|
15
|
-
<!-- built files will be auto injected -->
|
|
16
|
-
</body>
|
|
17
|
-
</html>
|