@nutui/nutui 4.3.2 → 4.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/nutui.es.js +2 -4
  3. package/dist/nutui.js +6502 -6815
  4. package/dist/nutui.umd.js +1 -1
  5. package/dist/packages/addresslist/AddressList.js +2 -2
  6. package/dist/packages/backtop/Backtop.js +79 -89
  7. package/dist/packages/calendar/Calendar.js +814 -3
  8. package/dist/packages/calendar/index.scss +0 -1
  9. package/dist/packages/calendarcard/CalendarCard.js +1 -1
  10. package/dist/packages/card/Card.js +2 -2
  11. package/dist/packages/circleprogress/CircleProgress.js +90 -97
  12. package/dist/packages/comment/Comment.js +2 -2
  13. package/dist/packages/ecard/Ecard.js +2 -2
  14. package/dist/packages/input/Input.js +7 -7
  15. package/dist/packages/inputnumber/InputNumber.js +83 -102
  16. package/dist/packages/invoice/Invoice.js +87 -138
  17. package/dist/packages/navbar/Navbar.js +103 -115
  18. package/dist/packages/progress/Progress.js +96 -115
  19. package/dist/packages/rate/Rate.js +98 -140
  20. package/dist/packages/sku/Sku.js +2 -2
  21. package/dist/packages/swipe/Swipe.js +96 -110
  22. package/dist/packages/swipegroup/SwipeGroup.js +41 -23
  23. package/dist/packages/tag/Tag.js +57 -66
  24. package/dist/packages/uploader/Uploader.js +4 -4
  25. package/dist/smartips/web-types.json +2 -2
  26. package/dist/styles/base-jdb.css +1 -1
  27. package/dist/styles/base-jddkh.css +1 -1
  28. package/dist/styles/base-jdt.css +1 -1
  29. package/dist/styles/themes/default.scss +0 -1
  30. package/dist/styles/themes/jdb.scss +0 -1
  31. package/dist/styles/themes/jddkh.scss +0 -1
  32. package/dist/styles/themes/jdt.scss +0 -1
  33. package/dist/styles/variables-jdb.scss +0 -1
  34. package/dist/styles/variables-jddkh.scss +0 -1
  35. package/dist/styles/variables-jdt.scss +0 -1
  36. package/dist/styles/variables.scss +0 -1
  37. package/dist/types/__VUE/backtop/backtop.vue.d.ts +87 -0
  38. package/dist/types/__VUE/backtop/index.d.ts +5 -0
  39. package/dist/types/__VUE/calendaritem/index.vue.d.ts +2 -12
  40. package/dist/types/__VUE/circleprogress/circle-progress.vue.d.ts +88 -0
  41. package/dist/types/__VUE/circleprogress/index.d.ts +6 -0
  42. package/dist/types/__VUE/inputnumber/index.d.ts +5 -0
  43. package/dist/types/__VUE/inputnumber/input-number.vue.d.ts +112 -0
  44. package/dist/types/__VUE/invoice/index.d.ts +6 -0
  45. package/dist/types/__VUE/invoice/invoice.vue.d.ts +59 -0
  46. package/dist/types/__VUE/invoice/types.d.ts +12 -0
  47. package/dist/types/__VUE/navbar/index.d.ts +5 -0
  48. package/dist/types/__VUE/navbar/navbar.vue.d.ts +125 -0
  49. package/dist/types/__VUE/progress/index.d.ts +6 -0
  50. package/dist/types/__VUE/progress/progress.vue.d.ts +91 -0
  51. package/dist/types/__VUE/rate/index.d.ts +5 -0
  52. package/dist/types/__VUE/rate/rate.vue.d.ts +208 -0
  53. package/dist/types/__VUE/swipe/index.d.ts +6 -0
  54. package/dist/types/__VUE/swipe/swipe.vue.d.ts +79 -0
  55. package/dist/types/__VUE/swipe/types.d.ts +1 -0
  56. package/dist/types/__VUE/swipegroup/index.d.ts +5 -0
  57. package/dist/types/__VUE/swipegroup/swipe-group.vue.d.ts +47 -0
  58. package/dist/types/__VUE/tag/index.d.ts +6 -0
  59. package/dist/types/__VUE/tag/tag.vue.d.ts +90 -0
  60. package/dist/types/__VUE/tag/types.d.ts +1 -1
  61. package/dist/types/index.d.ts +22 -13
  62. package/package.json +1 -1
  63. package/dist/packages/calendaritem/CalendarItem.js +0 -819
  64. package/dist/packages/calendaritem/index.css +0 -0
  65. package/dist/packages/calendaritem/index.mjs +0 -2
  66. package/dist/packages/calendaritem/index.scss +0 -0
  67. package/dist/packages/calendaritem/style/css.mjs +0 -2
  68. package/dist/packages/calendaritem/style/index.mjs +0 -2
  69. package/dist/types/__VUE/backtop/index.vue.d.ts +0 -98
  70. package/dist/types/__VUE/circleprogress/index.vue.d.ts +0 -95
  71. package/dist/types/__VUE/inputnumber/index.vue.d.ts +0 -117
  72. package/dist/types/__VUE/invoice/index.vue.d.ts +0 -53
  73. package/dist/types/__VUE/navbar/index.vue.d.ts +0 -129
  74. package/dist/types/__VUE/progress/index.vue.d.ts +0 -120
  75. package/dist/types/__VUE/rate/index.vue.d.ts +0 -240
  76. package/dist/types/__VUE/swipe/index.vue.d.ts +0 -70
  77. package/dist/types/__VUE/swipegroup/index.vue.d.ts +0 -26
  78. package/dist/types/__VUE/tag/index.vue.d.ts +0 -94
@@ -1,819 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import { ref, computed, reactive, onMounted, watch, toRefs, openBlock, createElementBlock, normalizeClass, createElementVNode, toDisplayString, createCommentVNode, renderSlot, Fragment, renderList, normalizeStyle, createTextVNode } from "vue";
21
- import { c as createComponent } from "../component-TCzwHGVq.js";
22
- import { U as Utils } from "../date-djiVNSnJ.js";
23
- import { r as requestAniFrame } from "../raf-MQjoO-Ag.js";
24
- import { u as useLocale } from "../index-s3RgMhc7.js";
25
- import { _ as _export_sfc } from "../_plugin-vue_export-helper-yVxbj29m.js";
26
- const { create } = createComponent("calendar-item");
27
- const cN = "NutCalendarItem";
28
- const _sfc_main = create({
29
- props: {
30
- type: {
31
- type: String,
32
- default: "one"
33
- },
34
- isAutoBackFill: {
35
- type: Boolean,
36
- default: false
37
- },
38
- toDateAnimation: {
39
- type: Boolean,
40
- default: true
41
- },
42
- poppable: {
43
- type: Boolean,
44
- default: true
45
- },
46
- showTitle: {
47
- type: Boolean,
48
- default: true
49
- },
50
- showSubTitle: {
51
- type: Boolean,
52
- default: true
53
- },
54
- showToday: {
55
- type: Boolean,
56
- default: true
57
- },
58
- title: {
59
- type: String,
60
- default: ""
61
- },
62
- confirmText: {
63
- type: String,
64
- default: ""
65
- },
66
- startText: {
67
- type: String,
68
- default: ""
69
- },
70
- endText: {
71
- type: String,
72
- default: ""
73
- },
74
- defaultValue: {
75
- type: [String, Array],
76
- default: ""
77
- },
78
- startDate: {
79
- type: String,
80
- default: Utils.getDay(0)
81
- },
82
- endDate: {
83
- type: String,
84
- default: Utils.getDay(365)
85
- },
86
- firstDayOfWeek: {
87
- type: Number,
88
- default: 0
89
- },
90
- disabledDate: Function
91
- },
92
- emits: ["choose", "update", "close", "select"],
93
- setup(props, { emit, slots, expose }) {
94
- const translate = useLocale(cN);
95
- const weekdays = translate("weekdays").map((day, index) => ({
96
- day,
97
- weekend: index === 0 || index === 6
98
- }));
99
- const weeks = ref([...weekdays.slice(props.firstDayOfWeek, 7), ...weekdays.slice(0, props.firstDayOfWeek)]);
100
- const months = ref(null);
101
- const monthsPanel = ref(null);
102
- const weeksPanel = ref(null);
103
- const viewArea = ref(null);
104
- const viewHeight = ref(0);
105
- const compConthsData = computed(() => {
106
- return state.monthsData.slice(state.defaultRange[0], state.defaultRange[1]);
107
- });
108
- const showTopBtn = computed(() => {
109
- return slots.btn;
110
- });
111
- const topInfo = computed(() => {
112
- return slots["top-info"];
113
- });
114
- const bottomInfo = computed(() => {
115
- return slots["bottom-info"];
116
- });
117
- const state = reactive({
118
- yearMonthTitle: "",
119
- defaultRange: [],
120
- currDate: "",
121
- propStartDate: "",
122
- propEndDate: "",
123
- unLoadPrev: false,
124
- touchParams: {
125
- startY: 0,
126
- endY: 0,
127
- startTime: 0,
128
- endTime: 0,
129
- lastY: 0,
130
- lastTime: 0
131
- },
132
- transformY: 0,
133
- translateY: 0,
134
- scrollDistance: 0,
135
- defaultData: [],
136
- chooseData: [],
137
- monthsData: [],
138
- dayPrefix: "nut-calendar__day",
139
- startData: "",
140
- endData: "",
141
- isRange: props.type === "range",
142
- timer: 0,
143
- currentIndex: 0,
144
- avgHeight: 0,
145
- monthsNum: 0
146
- });
147
- const splitDate = (date) => {
148
- return date.split("-");
149
- };
150
- const isStart = (currDate) => {
151
- return Utils.isEqual(state.currDate[0], currDate);
152
- };
153
- const isEnd = (currDate) => {
154
- return Utils.isEqual(state.currDate[1], currDate);
155
- };
156
- const isMultiple = (currDate) => {
157
- var _a, _b;
158
- if (((_a = state.currDate) == null ? void 0 : _a.length) > 0) {
159
- return (_b = state.currDate) == null ? void 0 : _b.some((item) => {
160
- return Utils.isEqual(item, currDate);
161
- });
162
- } else {
163
- return false;
164
- }
165
- };
166
- const getCurrDate = (day, month) => {
167
- return month.curData[0] + "-" + month.curData[1] + "-" + Utils.getNumTwoBit(+day.day);
168
- };
169
- const getClass = (day, month, index) => {
170
- const res = [];
171
- if (typeof index === "number" && ((index + 1 + props.firstDayOfWeek) % 7 === 0 || (index + props.firstDayOfWeek) % 7 === 0)) {
172
- res.push("weekend");
173
- }
174
- const currDate = getCurrDate(day, month);
175
- const { type } = props;
176
- if (day.type == "curr") {
177
- if (Utils.isEqual(state.currDate, currDate) || (type == "range" || type == "week") && (isStart(currDate) || isEnd(currDate)) || type == "multiple" && isMultiple(currDate)) {
178
- res.push(`${state.dayPrefix}--active`);
179
- } else if (state.propStartDate && Utils.compareDate(currDate, state.propStartDate) || state.propEndDate && Utils.compareDate(state.propEndDate, currDate) || props.disabledDate && props.disabledDate(currDate)) {
180
- res.push(`${state.dayPrefix}--disabled`);
181
- } else if ((type == "range" || type == "week") && Array.isArray(state.currDate) && Object.values(state.currDate).length == 2 && Utils.compareDate(state.currDate[0], currDate) && Utils.compareDate(currDate, state.currDate[1])) {
182
- res.push(`${state.dayPrefix}--choose`);
183
- }
184
- } else {
185
- res.push(`${state.dayPrefix}--disabled`);
186
- }
187
- return res;
188
- };
189
- const confirm = () => {
190
- const { type } = props;
191
- if (type == "range" && state.chooseData.length == 2 || type != "range") {
192
- let selectData = state.chooseData.slice(0);
193
- if (type == "week") {
194
- if (state.chooseData.length !== 2) {
195
- return;
196
- }
197
- selectData = {
198
- weekDate: [handleWeekDate(state.chooseData[0]), handleWeekDate(state.chooseData[1])]
199
- };
200
- }
201
- emit("choose", selectData);
202
- if (props.poppable) {
203
- emit("update");
204
- }
205
- }
206
- };
207
- const chooseDay = (day, month, isFirst = false) => {
208
- var _a, _b;
209
- if (!getClass(day, month).includes(`${state.dayPrefix}--disabled`)) {
210
- const { type } = props;
211
- let [y, m] = month.curData;
212
- let days = [...month.curData];
213
- days[2] = Utils.getNumTwoBit(Number(day.day));
214
- days[3] = `${days[0]}-${days[1]}-${days[2]}`;
215
- days[4] = Utils.getWhatDay(+days[0], +days[1], +days[2]);
216
- if (type == "multiple") {
217
- if (((_a = state.currDate) == null ? void 0 : _a.length) > 0) {
218
- let hasIndex = void 0;
219
- (_b = state.currDate) == null ? void 0 : _b.forEach((item, index) => {
220
- if (item == days[3]) {
221
- hasIndex = index;
222
- }
223
- });
224
- if (isFirst) {
225
- state.chooseData.push([...days]);
226
- } else {
227
- if (hasIndex !== void 0) {
228
- state.currDate.splice(hasIndex, 1);
229
- state.chooseData.splice(hasIndex, 1);
230
- } else {
231
- state.currDate.push(days[3]);
232
- state.chooseData.push([...days]);
233
- }
234
- }
235
- } else {
236
- state.currDate = [days[3]];
237
- state.chooseData = [[...days]];
238
- }
239
- } else if (type == "range") {
240
- let curDataLength = Object.values(state.currDate).length;
241
- if (curDataLength == 2 || curDataLength == 0) {
242
- state.currDate = [days[3]];
243
- } else {
244
- if (Utils.compareDate(state.currDate[0], days[3])) {
245
- Array.isArray(state.currDate) && state.currDate.push(days[3]);
246
- } else {
247
- Array.isArray(state.currDate) && state.currDate.unshift(days[3]);
248
- }
249
- }
250
- if (state.chooseData.length == 2 || !state.chooseData.length) {
251
- state.chooseData = [[...days]];
252
- } else {
253
- if (Utils.compareDate(state.chooseData[0][3], days[3])) {
254
- state.chooseData = [...state.chooseData, [...days]];
255
- } else {
256
- state.chooseData = [[...days], ...state.chooseData];
257
- }
258
- }
259
- } else if (type == "week") {
260
- let weekArr = Utils.getWeekDate(y, m, day.day, props.firstDayOfWeek);
261
- if (state.propStartDate && Utils.compareDate(weekArr[0], state.propStartDate)) {
262
- weekArr.splice(0, 1, state.propStartDate);
263
- }
264
- if (state.propEndDate && Utils.compareDate(state.propEndDate, weekArr[1])) {
265
- weekArr.splice(1, 1, state.propEndDate);
266
- }
267
- state.currDate = weekArr;
268
- state.chooseData = [Utils.formatResultDate(weekArr[0]), Utils.formatResultDate(weekArr[1])];
269
- } else {
270
- state.currDate = days[3];
271
- state.chooseData = [...days];
272
- }
273
- if (!isFirst) {
274
- let selectData = state.chooseData;
275
- if (type == "week") {
276
- selectData = {
277
- weekDate: [
278
- handleWeekDate(state.chooseData[0]),
279
- handleWeekDate(state.chooseData[1])
280
- ]
281
- };
282
- }
283
- emit("select", selectData);
284
- if (props.isAutoBackFill || !props.poppable) {
285
- confirm();
286
- }
287
- }
288
- }
289
- };
290
- const handleWeekDate = (weekDate) => {
291
- let [y, m, d] = weekDate;
292
- let obj = {
293
- date: weekDate,
294
- monthWeekNum: Utils.getMonthWeek(y, m, d, props.firstDayOfWeek),
295
- yearWeekNum: Utils.getYearWeek(y, m, d, props.firstDayOfWeek)
296
- };
297
- return obj;
298
- };
299
- const getCurrData = (type) => {
300
- const monthData = type == "prev" ? state.monthsData[0] : state.monthsData[state.monthsData.length - 1];
301
- let year = parseInt(monthData.curData[0]);
302
- let month = parseInt(monthData.curData[1].toString().replace(/^0/, ""));
303
- switch (type) {
304
- case "prev":
305
- month == 1 && (year -= 1);
306
- month = month == 1 ? 12 : --month;
307
- break;
308
- case "next":
309
- month == 12 && (year += 1);
310
- month = month == 12 ? 1 : ++month;
311
- break;
312
- }
313
- return [year + "", Utils.getNumTwoBit(month), Utils.getMonthDays(String(year), String(month)) + ""];
314
- };
315
- const getDaysStatus = (days, type, dateInfo) => {
316
- let { year, month } = dateInfo;
317
- if (type == "prev" && days >= 7) {
318
- days -= 7;
319
- }
320
- return Array.from(Array(days), (v, k) => {
321
- return {
322
- day: String(k + 1),
323
- type,
324
- year,
325
- month
326
- };
327
- });
328
- };
329
- const getPreDaysStatus = (days, type, dateInfo, preCurrMonthDays) => {
330
- days = days - props.firstDayOfWeek;
331
- let { year, month } = dateInfo;
332
- if (type == "prev" && days >= 7) {
333
- days -= 7;
334
- }
335
- let months2 = Array.from(Array(preCurrMonthDays), (v, k) => {
336
- return {
337
- day: String(k + 1),
338
- type,
339
- year,
340
- month
341
- };
342
- });
343
- return months2.slice(preCurrMonthDays - days);
344
- };
345
- const getMonth = (curData, type) => {
346
- const preMonthDays = Utils.getMonthPreDay(+curData[0], +curData[1]);
347
- let preMonth = Number(curData[1]) - 1;
348
- let preYear = Number(curData[0]);
349
- if (preMonth <= 0) {
350
- preMonth = 12;
351
- preYear += 1;
352
- }
353
- const currMonthDays = Utils.getMonthDays(String(curData[0]), String(curData[1]));
354
- const preCurrMonthDays = Utils.getMonthDays(preYear + "", preMonth + "");
355
- const title = {
356
- year: curData[0],
357
- month: curData[1]
358
- };
359
- const monthInfo = {
360
- curData,
361
- title: translate("monthTitle", title.year, title.month),
362
- monthData: [
363
- ...getPreDaysStatus(
364
- preMonthDays,
365
- "prev",
366
- { month: String(preMonth), year: String(preYear) },
367
- preCurrMonthDays
368
- ),
369
- ...getDaysStatus(currMonthDays, "curr", title)
370
- ],
371
- cssHeight: 0,
372
- cssScrollHeight: 0
373
- };
374
- monthInfo.cssHeight = 39 + (monthInfo.monthData.length > 35 ? 384 : 320);
375
- let cssScrollHeight = 0;
376
- if (state.monthsData.length > 0) {
377
- cssScrollHeight = state.monthsData[state.monthsData.length - 1].cssScrollHeight + state.monthsData[state.monthsData.length - 1].cssHeight;
378
- }
379
- monthInfo.cssScrollHeight = cssScrollHeight;
380
- if (type == "next") {
381
- if (!state.endData || !Utils.compareDate(
382
- `${state.endData[0]}-${state.endData[1]}-${Utils.getMonthDays(state.endData[0], state.endData[1])}`,
383
- `${curData[0]}-${curData[1]}-${curData[2]}`
384
- )) {
385
- state.monthsData.push(monthInfo);
386
- }
387
- } else {
388
- if (!state.startData || !Utils.compareDate(
389
- `${curData[0]}-${curData[1]}-${curData[2]}`,
390
- `${state.startData[0]}-${state.startData[1]}-01`
391
- )) {
392
- state.monthsData.unshift(monthInfo);
393
- } else {
394
- state.unLoadPrev = true;
395
- }
396
- }
397
- };
398
- const initData = () => {
399
- let propStartDate = props.startDate ? props.startDate : Utils.getDay(0);
400
- let propEndDate = props.endDate ? props.endDate : Utils.getDay(365);
401
- state.propStartDate = propStartDate;
402
- state.propEndDate = propEndDate;
403
- state.startData = splitDate(propStartDate);
404
- state.endData = splitDate(propEndDate);
405
- if (props.defaultValue || Array.isArray(props.defaultValue) && props.defaultValue.length > 0) {
406
- state.currDate = props.type !== "one" ? [...props.defaultValue] : props.defaultValue;
407
- }
408
- const startDate = {
409
- year: Number(state.startData[0]),
410
- month: Number(state.startData[1])
411
- };
412
- const endDate = {
413
- year: Number(state.endData[0]),
414
- month: Number(state.endData[1])
415
- };
416
- let monthsNum = endDate.month - startDate.month;
417
- if (endDate.year - startDate.year > 0) {
418
- monthsNum = monthsNum + 12 * (endDate.year - startDate.year);
419
- }
420
- if (monthsNum <= 0) {
421
- monthsNum = 1;
422
- }
423
- getMonth(state.startData, "next");
424
- let i = 1;
425
- do {
426
- getMonth(getCurrData("next"), "next");
427
- } while (i++ < monthsNum);
428
- state.monthsNum = monthsNum;
429
- if (props.type == "range" && Array.isArray(state.currDate)) {
430
- if (state.currDate.length > 0) {
431
- if (propStartDate && Utils.compareDate(state.currDate[0], propStartDate)) {
432
- state.currDate.splice(0, 1, propStartDate);
433
- }
434
- if (propEndDate && Utils.compareDate(propEndDate, state.currDate[1])) {
435
- state.currDate.splice(1, 1, propEndDate);
436
- }
437
- state.defaultData = [...splitDate(state.currDate[0]), ...splitDate(state.currDate[1])];
438
- }
439
- } else if (props.type == "multiple" && Array.isArray(state.currDate)) {
440
- if (state.currDate.length > 0) {
441
- let defaultArr = [];
442
- let obj = {};
443
- state.currDate.forEach((item) => {
444
- if (propStartDate && !Utils.compareDate(item, propStartDate) && propEndDate && !Utils.compareDate(propEndDate, item)) {
445
- if (!Object.hasOwnProperty.call(obj, item)) {
446
- defaultArr.push(item);
447
- obj[item] = item;
448
- }
449
- }
450
- });
451
- state.currDate = [...defaultArr];
452
- state.defaultData = [...splitDate(defaultArr[0])];
453
- }
454
- } else if (props.type == "week" && Array.isArray(state.currDate)) {
455
- if (state.currDate.length > 0) {
456
- let [y, m, d] = splitDate(state.currDate[0]);
457
- let weekArr = Utils.getWeekDate(y, m, d, props.firstDayOfWeek);
458
- state.currDate = weekArr;
459
- if (propStartDate && Utils.compareDate(state.currDate[0], propStartDate)) {
460
- state.currDate.splice(0, 1, propStartDate);
461
- }
462
- if (propEndDate && Utils.compareDate(propEndDate, state.currDate[1])) {
463
- state.currDate.splice(1, 1, propEndDate);
464
- }
465
- state.defaultData = [...splitDate(state.currDate[0]), ...splitDate(state.currDate[1])];
466
- }
467
- } else {
468
- if (state.currDate) {
469
- if (propStartDate && Utils.compareDate(state.currDate, propStartDate)) {
470
- state.currDate = propStartDate;
471
- } else if (propEndDate && !Utils.compareDate(state.currDate, propEndDate)) {
472
- state.currDate = propEndDate;
473
- }
474
- state.defaultData = [...splitDate(state.currDate)];
475
- }
476
- }
477
- let current = 0;
478
- let lastCurrent = 0;
479
- if (state.defaultData.length > 0) {
480
- state.monthsData.forEach((item, index) => {
481
- if (item.title == translate("monthTitle", state.defaultData[0], state.defaultData[1])) {
482
- current = index;
483
- }
484
- if (props.type == "range" || props.type == "week") {
485
- if (item.title == translate("monthTitle", state.defaultData[3], state.defaultData[4])) {
486
- lastCurrent = index;
487
- }
488
- }
489
- });
490
- }
491
- setDefaultRange(monthsNum, current);
492
- state.currentIndex = current;
493
- state.yearMonthTitle = state.monthsData[state.currentIndex].title;
494
- if (state.defaultData.length > 0) {
495
- if (state.isRange) {
496
- chooseDay({ day: state.defaultData[2], type: "curr" }, state.monthsData[state.currentIndex], true);
497
- chooseDay({ day: state.defaultData[5], type: "curr" }, state.monthsData[lastCurrent], true);
498
- } else if (props.type == "week") {
499
- chooseDay({ day: state.defaultData[2], type: "curr" }, state.monthsData[state.currentIndex], true);
500
- } else if (props.type == "multiple") {
501
- [...state.currDate].forEach((item) => {
502
- let dateArr = splitDate(item);
503
- let current2 = state.currentIndex;
504
- state.monthsData.forEach((item2, index) => {
505
- if (item2.title == translate("monthTitle", dateArr[0], dateArr[1])) {
506
- current2 = index;
507
- }
508
- });
509
- chooseDay({ day: dateArr[2], type: "curr" }, state.monthsData[current2], true);
510
- });
511
- } else {
512
- chooseDay({ day: state.defaultData[2], type: "curr" }, state.monthsData[state.currentIndex], true);
513
- }
514
- }
515
- let lastItem = state.monthsData[state.monthsData.length - 1];
516
- let containerHeight = lastItem.cssHeight + lastItem.cssScrollHeight;
517
- requestAniFrame(() => {
518
- if ((months == null ? void 0 : months.value) && (monthsPanel == null ? void 0 : monthsPanel.value) && (viewArea == null ? void 0 : viewArea.value)) {
519
- viewHeight.value = months.value.clientHeight;
520
- monthsPanel.value.style.height = `${containerHeight}px`;
521
- months.value.scrollTop = state.monthsData[state.currentIndex].cssScrollHeight;
522
- }
523
- });
524
- state.avgHeight = Math.floor(containerHeight / (monthsNum + 1));
525
- };
526
- const scrollToDate = (date) => {
527
- if (Utils.compareDate(date, state.propStartDate)) {
528
- date = state.propStartDate;
529
- } else if (!Utils.compareDate(date, state.propEndDate)) {
530
- date = state.propEndDate;
531
- }
532
- let dateArr = splitDate(date);
533
- state.monthsData.forEach((item, index) => {
534
- if (item.title == translate("monthTitle", dateArr[0], dateArr[1])) {
535
- if (months.value) {
536
- let distance = state.monthsData[index].cssScrollHeight - months.value.scrollTop;
537
- if (props.toDateAnimation) {
538
- let flag = 0;
539
- let interval = setInterval(() => {
540
- flag++;
541
- if (months.value) {
542
- let offset = distance / 10;
543
- months.value.scrollTop = months.value.scrollTop + offset;
544
- }
545
- if (flag >= 10) {
546
- clearInterval(interval);
547
- if (months.value) {
548
- months.value.scrollTop = state.monthsData[index].cssScrollHeight;
549
- }
550
- }
551
- }, 40);
552
- } else {
553
- months.value.scrollTop = state.monthsData[index].cssScrollHeight;
554
- }
555
- }
556
- }
557
- });
558
- };
559
- const initPosition = () => {
560
- if (months == null ? void 0 : months.value) {
561
- months.value.scrollTop = state.monthsData[state.currentIndex].cssScrollHeight;
562
- }
563
- };
564
- expose({
565
- scrollToDate,
566
- initPosition
567
- });
568
- const setDefaultRange = (monthsNum, current) => {
569
- if (monthsNum >= 3) {
570
- if (current > 0 && current < monthsNum) {
571
- state.defaultRange = [current - 1, current + 3];
572
- } else if (current == 0) {
573
- state.defaultRange = [current, current + 4];
574
- } else if (current == monthsNum) {
575
- state.defaultRange = [current - 2, current + 2];
576
- }
577
- } else {
578
- state.defaultRange = [0, monthsNum + 2];
579
- }
580
- let defaultScrollTop = state.monthsData[state.defaultRange[0]].cssScrollHeight;
581
- state.translateY = defaultScrollTop;
582
- };
583
- const isActive = (day, month) => {
584
- return (props.type == "range" || props.type == "week") && day.type == "curr" && getClass(day, month).includes("nut-calendar__day--active");
585
- };
586
- const isStartTip = (day, month) => {
587
- return isActive(day, month) && isStart(getCurrDate(day, month));
588
- };
589
- const isEndTip = (day, month) => {
590
- if (state.currDate.length >= 2 && isEnd(getCurrDate(day, month))) {
591
- return isActive(day, month);
592
- }
593
- return false;
594
- };
595
- const rangeTip = () => {
596
- if (state.currDate.length >= 2) {
597
- return Utils.isEqual(state.currDate[0], state.currDate[1]);
598
- }
599
- };
600
- const isCurrDay = (dateInfo) => {
601
- const date = `${dateInfo.year}-${dateInfo.month}-${Number(dateInfo.day) < 10 ? "0" + dateInfo.day : dateInfo.day}`;
602
- return Utils.isEqual(date, Utils.date2Str(/* @__PURE__ */ new Date()));
603
- };
604
- const mothsViewScroll = (e) => {
605
- if (state.monthsData.length <= 1) {
606
- return;
607
- }
608
- const currentScrollTop = e.target.scrollTop;
609
- let current = Math.floor(currentScrollTop / state.avgHeight);
610
- if (current == 0) {
611
- if (currentScrollTop >= state.monthsData[current + 1].cssScrollHeight) {
612
- current += 1;
613
- }
614
- } else if (current > 0 && current < state.monthsNum - 1) {
615
- if (currentScrollTop >= state.monthsData[current + 1].cssScrollHeight) {
616
- current += 1;
617
- }
618
- if (currentScrollTop < state.monthsData[current].cssScrollHeight) {
619
- current -= 1;
620
- }
621
- } else {
622
- const viewPosition = Math.round(currentScrollTop + viewHeight.value);
623
- if (viewPosition < state.monthsData[current].cssScrollHeight + state.monthsData[current].cssHeight && currentScrollTop > state.monthsData[current - 1].cssScrollHeight) {
624
- current -= 1;
625
- }
626
- if (current + 1 <= state.monthsNum && viewPosition >= state.monthsData[current + 1].cssScrollHeight + state.monthsData[current + 1].cssHeight) {
627
- current += 1;
628
- }
629
- if (current >= 1 && currentScrollTop < state.monthsData[current - 1].cssScrollHeight) {
630
- current -= 1;
631
- }
632
- }
633
- if (state.currentIndex !== current) {
634
- state.currentIndex = current;
635
- setDefaultRange(state.monthsNum, current);
636
- }
637
- state.yearMonthTitle = state.monthsData[current].title;
638
- };
639
- const resetRender = () => {
640
- state.chooseData.splice(0);
641
- state.monthsData.splice(0);
642
- initData();
643
- };
644
- onMounted(() => {
645
- initData();
646
- });
647
- watch(
648
- () => props.defaultValue,
649
- (val) => {
650
- if (val) {
651
- if (props.poppable) {
652
- resetRender();
653
- }
654
- }
655
- }
656
- );
657
- return __spreadProps(__spreadValues(__spreadValues({
658
- weeks,
659
- compConthsData,
660
- showTopBtn,
661
- topInfo,
662
- bottomInfo,
663
- rangeTip,
664
- mothsViewScroll,
665
- getClass,
666
- isStartTip,
667
- isEndTip,
668
- chooseDay,
669
- isCurrDay,
670
- confirm,
671
- months
672
- }, toRefs(state)), toRefs(props)), {
673
- translate,
674
- monthsPanel,
675
- weeksPanel,
676
- viewArea
677
- });
678
- }
679
- });
680
- const _hoisted_1 = { class: "nut-calendar__header" };
681
- const _hoisted_2 = {
682
- key: 0,
683
- class: "nut-calendar__header-title"
684
- };
685
- const _hoisted_3 = {
686
- key: 1,
687
- class: "nut-calendar__header-slot"
688
- };
689
- const _hoisted_4 = {
690
- key: 2,
691
- class: "nut-calendar__header-subtitle"
692
- };
693
- const _hoisted_5 = {
694
- ref: "weeksPanel",
695
- class: "nut-calendar__weekdays"
696
- };
697
- const _hoisted_6 = {
698
- ref: "monthsPanel",
699
- class: "nut-calendar__panel"
700
- };
701
- const _hoisted_7 = { class: "nut-calendar__month-title" };
702
- const _hoisted_8 = { class: "nut-calendar__days" };
703
- const _hoisted_9 = ["onClick"];
704
- const _hoisted_10 = { class: "nut-calendar__day-value" };
705
- const _hoisted_11 = {
706
- key: 0,
707
- class: "nut-calendar__day-tips nut-calendar__day-tips--top"
708
- };
709
- const _hoisted_12 = {
710
- key: 1,
711
- class: "nut-calendar__day-tips nut-calendar__day-tips--bottom"
712
- };
713
- const _hoisted_13 = {
714
- key: 2,
715
- class: "nut-calendar__day-tips--curr"
716
- };
717
- const _hoisted_14 = {
718
- key: 4,
719
- class: "nut-calendar__day-tip"
720
- };
721
- const _hoisted_15 = {
722
- key: 0,
723
- class: "nut-calendar__footer"
724
- };
725
- function _sfc_render(_ctx, _cache, $props, $setup, $data, $options) {
726
- return openBlock(), createElementBlock("view", {
727
- class: normalizeClass(["nut-calendar", {
728
- "nut-calendar--nopop": !_ctx.poppable,
729
- "nut-calendar--nofooter": _ctx.isAutoBackFill
730
- }])
731
- }, [
732
- createElementVNode("view", _hoisted_1, [
733
- _ctx.showTitle ? (openBlock(), createElementBlock("view", _hoisted_2, toDisplayString(_ctx.title || _ctx.translate("title")), 1)) : createCommentVNode("", true),
734
- _ctx.showTopBtn ? (openBlock(), createElementBlock("view", _hoisted_3, [
735
- renderSlot(_ctx.$slots, "btn")
736
- ])) : createCommentVNode("", true),
737
- _ctx.showSubTitle ? (openBlock(), createElementBlock("view", _hoisted_4, toDisplayString(_ctx.yearMonthTitle), 1)) : createCommentVNode("", true),
738
- createElementVNode("view", _hoisted_5, [
739
- (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.weeks, (item, index) => {
740
- return openBlock(), createElementBlock("view", {
741
- key: index,
742
- class: normalizeClass(["nut-calendar__weekday", { weekend: item.weekend }])
743
- }, toDisplayString(item.day), 3);
744
- }), 128))
745
- ], 512)
746
- ]),
747
- createElementVNode("view", {
748
- ref: "months",
749
- class: "nut-calendar__content",
750
- onScroll: _cache[0] || (_cache[0] = (...args) => _ctx.mothsViewScroll && _ctx.mothsViewScroll(...args))
751
- }, [
752
- createElementVNode("view", _hoisted_6, [
753
- createElementVNode("view", {
754
- ref: "viewArea",
755
- class: "nut-calendar__body",
756
- style: normalizeStyle({ transform: `translateY(${_ctx.translateY}px)` })
757
- }, [
758
- (openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.compConthsData, (month, index) => {
759
- return openBlock(), createElementBlock("view", {
760
- key: index,
761
- class: "nut-calendar__month"
762
- }, [
763
- createElementVNode("view", _hoisted_7, toDisplayString(month.title), 1),
764
- createElementVNode("view", _hoisted_8, [
765
- createElementVNode("view", {
766
- class: normalizeClass(["nut-calendar__days-item", _ctx.type === "range" ? "nut-calendar__days-item--range" : ""])
767
- }, [
768
- (openBlock(true), createElementBlock(Fragment, null, renderList(month.monthData, (day, i) => {
769
- return openBlock(), createElementBlock("view", {
770
- key: i,
771
- class: normalizeClass(["nut-calendar__day", _ctx.getClass(day, month, i)]),
772
- onClick: ($event) => _ctx.chooseDay(day, month)
773
- }, [
774
- createElementVNode("view", _hoisted_10, [
775
- renderSlot(_ctx.$slots, "day", {
776
- date: day.type == "curr" ? day : ""
777
- }, () => [
778
- createTextVNode(toDisplayString(day.type == "curr" ? day.day : ""), 1)
779
- ])
780
- ]),
781
- _ctx.topInfo ? (openBlock(), createElementBlock("view", _hoisted_11, [
782
- renderSlot(_ctx.$slots, "top-info", {
783
- date: day.type == "curr" ? day : ""
784
- })
785
- ])) : createCommentVNode("", true),
786
- _ctx.bottomInfo ? (openBlock(), createElementBlock("view", _hoisted_12, [
787
- renderSlot(_ctx.$slots, "bottom-info", {
788
- date: day.type == "curr" ? day : ""
789
- })
790
- ])) : createCommentVNode("", true),
791
- !_ctx.bottomInfo && _ctx.showToday && _ctx.isCurrDay(day) ? (openBlock(), createElementBlock("view", _hoisted_13, toDisplayString(_ctx.translate("today")), 1)) : createCommentVNode("", true),
792
- _ctx.isStartTip(day, month) ? (openBlock(), createElementBlock("view", {
793
- key: 3,
794
- class: normalizeClass(["nut-calendar__day-tip", { "nut-calendar__day-tips--top": _ctx.rangeTip() }])
795
- }, toDisplayString(_ctx.startText || _ctx.translate("start")), 3)) : createCommentVNode("", true),
796
- _ctx.isEndTip(day, month) ? (openBlock(), createElementBlock("view", _hoisted_14, toDisplayString(_ctx.endText || _ctx.translate("end")), 1)) : createCommentVNode("", true)
797
- ], 10, _hoisted_9);
798
- }), 128))
799
- ], 2)
800
- ])
801
- ]);
802
- }), 128))
803
- ], 4)
804
- ], 512)
805
- ], 544),
806
- _ctx.poppable && !_ctx.isAutoBackFill ? (openBlock(), createElementBlock("view", _hoisted_15, [
807
- renderSlot(_ctx.$slots, "footer-info", { date: _ctx.chooseData }, () => [
808
- createElementVNode("view", {
809
- class: "nut-calendar__confirm",
810
- onClick: _cache[1] || (_cache[1] = (...args) => _ctx.confirm && _ctx.confirm(...args))
811
- }, toDisplayString(_ctx.confirmText || _ctx.translate("confirm")), 1)
812
- ])
813
- ])) : createCommentVNode("", true)
814
- ], 2);
815
- }
816
- const NutCalendarItem = /* @__PURE__ */ _export_sfc(_sfc_main, [["render", _sfc_render]]);
817
- export {
818
- NutCalendarItem as default
819
- };