@nutui/nutui-react-taro 2.7.7 → 2.7.9
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/CHANGELOG.md +26 -10
- package/dist/esm/Animate/style/style.css +1 -1
- package/dist/esm/Animate.js +1 -1
- package/dist/esm/AvatarCropper.js +1 -1
- package/dist/esm/Calendar/style/style.css +1 -1
- package/dist/esm/Calendar.js +1 -1
- package/dist/esm/CalendarCard.js +1 -1
- package/dist/esm/CalendarItem.js +1 -1
- package/dist/esm/Drag.js +1 -1
- package/dist/esm/ImagePreview/style/style.css +1 -1
- package/dist/esm/Menu.js +1 -1
- package/dist/esm/MenuItem.js +1 -1
- package/dist/esm/PullToRefresh.js +1 -1
- package/dist/esm/Sticky.js +1 -1
- package/dist/esm/Swiper/style/style.css +1 -1
- package/dist/esm/VirtualList.js +1 -1
- package/dist/esm/{animate.taro-CQVEyDKL.js → animate.taro-BHDZMzJF.js} +9 -12
- package/dist/esm/{avatarcropper.taro-meD2sizv.js → avatarcropper.taro-5JSFH7Q9.js} +2 -1
- package/dist/esm/{calendar.taro-CM4yWFlF.js → calendar.taro-CUDVpJBa.js} +3 -3
- package/dist/esm/{calendarcard.taro-CvWyBqnr.js → calendarcard.taro-BiOnui_b.js} +4 -4
- package/dist/esm/{calendaritem.taro-BGbbuJOS.js → calendaritem.taro-DveeC4_t.js} +237 -219
- package/dist/esm/date-BmUWlDuN.js +147 -0
- package/dist/esm/{drag.taro-r5Lmncrq.js → drag.taro-CHPSfySz.js} +2 -2
- package/dist/esm/get-system-info-D27xNglo.js +11 -0
- package/dist/esm/{menu.taro-2APk--BX.js → menu.taro-9N8A5UoN.js} +1 -1
- package/dist/esm/{menuitem.taro-BMlSqBSc.js → menuitem.taro-CnsORm5-.js} +5 -4
- package/dist/esm/nutui-react.es.js +11 -11
- package/dist/esm/{pulltorefresh.taro-BiSDwLpA.js → pulltorefresh.taro-DAFv7upo.js} +2 -1
- package/dist/esm/{sticky.taro-DtUAawu_.js → sticky.taro-l66r7WFn.js} +3 -2
- package/dist/esm/{virtuallist.taro-BlPW8ibd.js → virtuallist.taro-CQDtOwWn.js} +2 -2
- package/dist/locales/base.js +1 -1
- package/dist/locales/en-US.js +1 -1
- package/dist/locales/id-ID.js +1 -1
- package/dist/locales/tr-TR.js +1 -1
- package/dist/locales/zh-CN.js +1 -1
- package/dist/locales/zh-TW.js +1 -1
- package/dist/locales/zh-UG.js +1 -1
- package/dist/nutui.react.es.js +384 -465
- package/dist/nutui.react.umd.js +383 -464
- package/dist/packages/animate/animate.scss +63 -105
- package/dist/packages/calendar/calendar.scss +9 -9
- package/dist/packages/swiper/swiper.scss +11 -0
- package/dist/style.css +1 -1
- package/dist/types/packages/animate/animate.taro.d.ts +2 -1
- package/dist/types/utils/date.d.ts +54 -52
- package/dist/types/utils/get-system-info.d.ts +19 -0
- package/package.json +1 -1
- package/dist/esm/date-CYwRNlGq.js +0 -219
|
@@ -3,7 +3,7 @@ import classNames from "classnames";
|
|
|
3
3
|
import { ScrollView } from "@tarojs/components";
|
|
4
4
|
import Taro, { nextTick } from "@tarojs/taro";
|
|
5
5
|
import { C as ComponentDefaults } from "./typings-DV9RBfhj.js";
|
|
6
|
-
import {
|
|
6
|
+
import { i as isEqual, d as date2Str, a as getNumTwoBit, g as getDateString, c as compareDate, b as getPreMonthDates, e as getDaysStatus, f as getMonthDays, h as getCurrMonthData, j as getWeekDate, k as getWhatDay, l as formatResultDate } from "./date-BmUWlDuN.js";
|
|
7
7
|
import { r as requestAniFrame } from "./raf-Di10dXPS.js";
|
|
8
8
|
import { u as useConfig } from "./configprovider.taro-C3WyeHSO.js";
|
|
9
9
|
import { u as usePropsValue } from "./use-props-value-SH9krhkx.js";
|
|
@@ -14,35 +14,37 @@ const splitDate = (date) => {
|
|
|
14
14
|
const isMultiple = (day, days) => {
|
|
15
15
|
if (days.length > 0) {
|
|
16
16
|
return days.some((item) => {
|
|
17
|
-
return
|
|
17
|
+
return isEqual(item, day);
|
|
18
18
|
});
|
|
19
19
|
}
|
|
20
20
|
return false;
|
|
21
21
|
};
|
|
22
22
|
const isCurrDay = (month, day) => {
|
|
23
23
|
const date = `${month.curData[0]}/${month.curData[1]}/${day}`;
|
|
24
|
-
return
|
|
24
|
+
return isEqual(date, date2Str(/* @__PURE__ */ new Date(), "/"));
|
|
25
25
|
};
|
|
26
26
|
const getCurrDate = (day, month) => {
|
|
27
|
-
return `${month.curData[0]}/${month.curData[1]}/${
|
|
27
|
+
return `${month.curData[0]}/${month.curData[1]}/${getNumTwoBit(+day.day)}`;
|
|
28
28
|
};
|
|
29
29
|
const isStart = (day, days) => {
|
|
30
|
-
return
|
|
30
|
+
return isEqual(days[0], day);
|
|
31
31
|
};
|
|
32
32
|
const isEnd = (day, days) => {
|
|
33
|
-
return
|
|
33
|
+
return isEqual(days[1], day);
|
|
34
34
|
};
|
|
35
35
|
const isStartAndEnd = (days) => {
|
|
36
|
-
return days.length >= 2 &&
|
|
36
|
+
return days.length >= 2 && isEqual(days[0], days[1]);
|
|
37
37
|
};
|
|
38
|
-
const defaultProps = Object.assign(Object.assign({}, ComponentDefaults), { type: "single", autoBackfill: false, popup: true, title: "", startDate:
|
|
38
|
+
const defaultProps = Object.assign(Object.assign({}, ComponentDefaults), { type: "single", autoBackfill: false, popup: true, title: "", startDate: getDateString(0), endDate: getDateString(365), showToday: true, startText: "", endText: "", confirmText: "", showTitle: true, showSubTitle: true, scrollAnimation: true, firstDayOfWeek: 0, disableDate: (date) => false, renderHeaderButtons: void 0, renderDay: void 0, renderDayTop: void 0, renderDayBottom: void 0, onConfirm: (data) => {
|
|
39
39
|
}, onUpdate: () => {
|
|
40
40
|
}, onDayClick: (data) => {
|
|
41
41
|
}, onPageChange: (data) => {
|
|
42
42
|
} });
|
|
43
43
|
const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
44
44
|
const { locale } = useConfig();
|
|
45
|
-
const { style, className, children, popup, type, autoBackfill, title, defaultValue, startDate, endDate, showToday, startText, endText, confirmText, showTitle, showSubTitle, scrollAnimation, firstDayOfWeek, disableDate, renderHeaderButtons, renderDay, renderDayTop, renderDayBottom, renderBottomButton,
|
|
45
|
+
const { style, className, children, popup, type, autoBackfill, title, value, defaultValue, startDate, endDate, showToday, startText, endText, confirmText, showTitle, showSubTitle, scrollAnimation, firstDayOfWeek, disableDate, renderHeaderButtons, renderDay, renderDayTop, renderDayBottom, renderBottomButton, onConfirm, onUpdate, onDayClick, onPageChange } = Object.assign(Object.assign({}, defaultProps), props);
|
|
46
|
+
const classPrefix = "nut-calendar";
|
|
47
|
+
const dayPrefix = "nut-calendar-day";
|
|
46
48
|
const weekdays = locale.calendaritem.weekdays;
|
|
47
49
|
const weeks = [
|
|
48
50
|
...weekdays.slice(firstDayOfWeek, 7),
|
|
@@ -56,19 +58,13 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
56
58
|
const [monthDefaultRange, setMonthDefaultRange] = useState([]);
|
|
57
59
|
const [scrollTop, setScrollTop] = useState(0);
|
|
58
60
|
const [scrollWithAnimation, setScrollWithAnimation] = useState(false);
|
|
59
|
-
const propStartDate = startDate ||
|
|
60
|
-
const propEndDate = endDate ||
|
|
61
|
+
const propStartDate = startDate || getDateString(0);
|
|
62
|
+
const propEndDate = endDate || getDateString(365);
|
|
61
63
|
const startDates = splitDate(propStartDate);
|
|
62
64
|
const endDates = splitDate(propEndDate);
|
|
63
65
|
const [state] = useState({
|
|
64
66
|
currDateArray: []
|
|
65
67
|
});
|
|
66
|
-
const getMonthsPanel = () => {
|
|
67
|
-
return monthsPanel.current;
|
|
68
|
-
};
|
|
69
|
-
const getMonthsRef = () => {
|
|
70
|
-
return monthsRef.current;
|
|
71
|
-
};
|
|
72
68
|
const resetDefaultValue = () => {
|
|
73
69
|
if (defaultValue || Array.isArray(defaultValue) && defaultValue.length > 0) {
|
|
74
70
|
return type !== "single" ? [...defaultValue] : defaultValue;
|
|
@@ -88,9 +84,7 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
88
84
|
const viewAreaRef = useRef(null);
|
|
89
85
|
const [avgHeight, setAvgHeight] = useState(0);
|
|
90
86
|
let viewHeight = 0;
|
|
91
|
-
const
|
|
92
|
-
const dayPrefix = "nut-calendar-day";
|
|
93
|
-
const getMonthData = (curData, monthNum, type2) => {
|
|
87
|
+
const getMonthData = (curData, monthNum) => {
|
|
94
88
|
let i = 0;
|
|
95
89
|
let date = curData;
|
|
96
90
|
const monthData = monthsData;
|
|
@@ -101,12 +95,12 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
101
95
|
...getPreMonthDates("prev", y, m, firstDayOfWeek),
|
|
102
96
|
...getDaysStatus("active", y, m)
|
|
103
97
|
];
|
|
104
|
-
const cssHeight = 39 + (days.length > 35 ? 384 : 320);
|
|
105
98
|
let scrollTop2 = 0;
|
|
106
99
|
if (monthData.length > 0) {
|
|
107
100
|
const monthEle = monthData[monthData.length - 1];
|
|
108
101
|
scrollTop2 = monthEle.scrollTop + monthEle.cssHeight;
|
|
109
102
|
}
|
|
103
|
+
const cssHeight = 39 + (days.length > 35 ? 384 : 320);
|
|
110
104
|
const monthInfo = {
|
|
111
105
|
curData: date,
|
|
112
106
|
title: monthTitle(y, m),
|
|
@@ -114,10 +108,8 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
114
108
|
cssHeight,
|
|
115
109
|
scrollTop: scrollTop2
|
|
116
110
|
};
|
|
117
|
-
{
|
|
118
|
-
|
|
119
|
-
monthData.push(monthInfo);
|
|
120
|
-
}
|
|
111
|
+
if (!endDates || !compareDate(`${endDates[0]}/${endDates[1]}/${getMonthDays(endDates[0], endDates[1])}`, `${curData[0]}/${curData[1]}/${curData[2]}`)) {
|
|
112
|
+
monthData.push(monthInfo);
|
|
121
113
|
}
|
|
122
114
|
date = getCurrMonthData("next", y, m);
|
|
123
115
|
} while (i++ < monthNum);
|
|
@@ -125,9 +117,9 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
125
117
|
};
|
|
126
118
|
const setReachedYearMonthInfo = (current) => {
|
|
127
119
|
const currentMonthsData = monthsData[current];
|
|
128
|
-
const [year, month] = currentMonthsData.curData;
|
|
129
120
|
if (currentMonthsData.title === yearMonthTitle)
|
|
130
121
|
return;
|
|
122
|
+
const [year, month] = currentMonthsData.curData;
|
|
131
123
|
onPageChange && onPageChange([year, month, `${year}-${month}`]);
|
|
132
124
|
setYearMonthTitle(currentMonthsData.title);
|
|
133
125
|
};
|
|
@@ -153,75 +145,67 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
153
145
|
setTranslateY(monthsData[start].scrollTop);
|
|
154
146
|
setReachedYearMonthInfo(current);
|
|
155
147
|
};
|
|
156
|
-
const getMonthNum = () => {
|
|
157
|
-
let monthNum = Number(endDates[1]) - Number(startDates[1]);
|
|
158
|
-
const yearNum = Number(endDates[0]) - Number(startDates[0]);
|
|
159
|
-
if (yearNum > 0) {
|
|
160
|
-
monthNum += 12 * yearNum;
|
|
161
|
-
}
|
|
162
|
-
if (monthNum <= 0) {
|
|
163
|
-
monthNum = 1;
|
|
164
|
-
}
|
|
165
|
-
setMonthsNum(monthNum);
|
|
166
|
-
return monthNum;
|
|
167
|
-
};
|
|
168
148
|
const setDefaultDate = () => {
|
|
169
149
|
let defaultData = [];
|
|
170
|
-
if (type === "
|
|
171
|
-
if (currentDate.length
|
|
172
|
-
|
|
173
|
-
currentDate.splice(0, 1, propStartDate);
|
|
174
|
-
}
|
|
175
|
-
if (propEndDate && Utils.compareDate(propEndDate, currentDate[1])) {
|
|
176
|
-
currentDate.splice(1, 1, propEndDate);
|
|
177
|
-
}
|
|
178
|
-
defaultData = [
|
|
179
|
-
...splitDate(currentDate[0]),
|
|
180
|
-
...splitDate(currentDate[1])
|
|
181
|
-
];
|
|
150
|
+
if (type === "single" && typeof currentDate === "string") {
|
|
151
|
+
if (!currentDate.length) {
|
|
152
|
+
return defaultData;
|
|
182
153
|
}
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
if (!Object.hasOwnProperty.call(obj, item)) {
|
|
190
|
-
defaultArr.push(item);
|
|
191
|
-
obj[item] = item;
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
currentDate.splice(0) && currentDate.push(...defaultArr);
|
|
196
|
-
defaultData = [...splitDate(defaultArr[0])];
|
|
154
|
+
if (compareDate(currentDate, propStartDate)) {
|
|
155
|
+
defaultData = [...splitDate(propStartDate)];
|
|
156
|
+
} else if (!compareDate(currentDate, propEndDate)) {
|
|
157
|
+
defaultData = [...splitDate(propEndDate)];
|
|
158
|
+
} else {
|
|
159
|
+
defaultData = [...splitDate(currentDate)];
|
|
197
160
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
161
|
+
return defaultData;
|
|
162
|
+
}
|
|
163
|
+
if (Array.isArray(currentDate) && currentDate.length) {
|
|
164
|
+
switch (type) {
|
|
165
|
+
case "range": {
|
|
166
|
+
if (compareDate(currentDate[0], propStartDate)) {
|
|
167
|
+
currentDate[0] = propStartDate;
|
|
168
|
+
}
|
|
169
|
+
if (compareDate(propEndDate, currentDate[1])) {
|
|
170
|
+
currentDate[1] = propEndDate;
|
|
171
|
+
}
|
|
172
|
+
defaultData = [
|
|
173
|
+
...splitDate(currentDate[0]),
|
|
174
|
+
...splitDate(currentDate[1])
|
|
175
|
+
];
|
|
176
|
+
break;
|
|
205
177
|
}
|
|
206
|
-
|
|
207
|
-
|
|
178
|
+
case "multiple": {
|
|
179
|
+
const defaultArr = [];
|
|
180
|
+
const obj = {};
|
|
181
|
+
currentDate.forEach((item) => {
|
|
182
|
+
if (!compareDate(item, propStartDate) && !compareDate(propEndDate, item)) {
|
|
183
|
+
if (!Object.hasOwnProperty.call(obj, item)) {
|
|
184
|
+
defaultArr.push(item);
|
|
185
|
+
obj[item] = item;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
currentDate.splice(0, currentDate.length, ...defaultArr);
|
|
190
|
+
defaultData = [...splitDate(defaultArr[0])];
|
|
191
|
+
break;
|
|
208
192
|
}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
defaultData = [
|
|
220
|
-
|
|
221
|
-
|
|
193
|
+
case "week": {
|
|
194
|
+
const [y, m, d] = splitDate(currentDate[0]);
|
|
195
|
+
const weekArr = getWeekDate(y, m, d, firstDayOfWeek);
|
|
196
|
+
currentDate.splice(0, currentDate.length, ...weekArr);
|
|
197
|
+
if (compareDate(currentDate[0], propStartDate)) {
|
|
198
|
+
currentDate.splice(0, 1, propStartDate);
|
|
199
|
+
}
|
|
200
|
+
if (compareDate(propEndDate, currentDate[1])) {
|
|
201
|
+
currentDate.splice(1, 1, propEndDate);
|
|
202
|
+
}
|
|
203
|
+
defaultData = [
|
|
204
|
+
...splitDate(currentDate[0]),
|
|
205
|
+
...splitDate(currentDate[1])
|
|
206
|
+
];
|
|
207
|
+
break;
|
|
222
208
|
}
|
|
223
|
-
} else {
|
|
224
|
-
defaultData = [];
|
|
225
209
|
}
|
|
226
210
|
}
|
|
227
211
|
return defaultData;
|
|
@@ -244,43 +228,49 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
244
228
|
const date = /* @__PURE__ */ new Date();
|
|
245
229
|
const year = date.getFullYear();
|
|
246
230
|
const month = date.getMonth() + 1;
|
|
247
|
-
const index = monthsData.findIndex((item) =>
|
|
248
|
-
|
|
249
|
-
});
|
|
250
|
-
if (index > -1) {
|
|
231
|
+
const index = monthsData.findIndex((item) => +item.curData[0] === year && +item.curData[1] === month);
|
|
232
|
+
if (index > -1)
|
|
251
233
|
current = index;
|
|
252
|
-
}
|
|
253
234
|
}
|
|
254
235
|
return {
|
|
255
236
|
current,
|
|
256
237
|
lastCurrent
|
|
257
238
|
};
|
|
258
239
|
};
|
|
259
|
-
const renderCurrentDate = () => {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
240
|
+
const renderCurrentDate = (defaultData, current) => {
|
|
241
|
+
if (!defaultData.length)
|
|
242
|
+
return;
|
|
243
|
+
const date = monthsData[current.current];
|
|
244
|
+
switch (type) {
|
|
245
|
+
case "range": {
|
|
246
|
+
handleDayClick({ day: defaultData[2], type: "active" }, date);
|
|
247
|
+
handleDayClick({ day: defaultData[5], type: "active" }, monthsData[current.lastCurrent]);
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
case "week": {
|
|
251
|
+
handleDayClick({ day: defaultData[2], type: "curr" }, date);
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
case "multiple": {
|
|
269
255
|
[...currentDate].forEach((item) => {
|
|
270
256
|
const dateArr = splitDate(item);
|
|
271
257
|
let currentIndex = current.current;
|
|
272
|
-
monthsData.
|
|
273
|
-
|
|
274
|
-
currentIndex = index;
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
chooseDay({ day: dateArr[2], type: "active" }, monthsData[currentIndex], true);
|
|
258
|
+
currentIndex = monthsData.findIndex((item2) => item2.title === monthTitle(dateArr[0], dateArr[1]));
|
|
259
|
+
handleDayClick({ day: dateArr[2], type: "active" }, monthsData[currentIndex]);
|
|
278
260
|
});
|
|
279
|
-
|
|
280
|
-
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
default: {
|
|
264
|
+
handleDayClick({ day: defaultData[2], type: "active" }, date);
|
|
265
|
+
break;
|
|
281
266
|
}
|
|
282
267
|
}
|
|
283
|
-
|
|
268
|
+
};
|
|
269
|
+
const getMonthsPanel = () => {
|
|
270
|
+
return monthsPanel.current;
|
|
271
|
+
};
|
|
272
|
+
const getMonthsRef = () => {
|
|
273
|
+
return monthsRef.current;
|
|
284
274
|
};
|
|
285
275
|
const requestAniFrameFunc = (current, monthNum) => {
|
|
286
276
|
const lastItem = monthsData[monthsData.length - 1];
|
|
@@ -289,19 +279,33 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
289
279
|
if (monthsRef && monthsPanel && viewAreaRef) {
|
|
290
280
|
viewHeight = getMonthsRef().clientHeight;
|
|
291
281
|
getMonthsPanel().style.height = `${containerHeight}px`;
|
|
292
|
-
|
|
293
|
-
|
|
282
|
+
const currTop = monthsData[current].scrollTop;
|
|
283
|
+
getMonthsRef().scrollTop = currTop;
|
|
284
|
+
setScrollTop(currTop);
|
|
294
285
|
nextTick(() => setScrollWithAnimation(true));
|
|
295
286
|
}
|
|
296
287
|
});
|
|
297
288
|
setAvgHeight(Math.floor(containerHeight / (monthNum + 1)));
|
|
298
289
|
};
|
|
290
|
+
const getMonthNum = () => {
|
|
291
|
+
let monthNum = Number(endDates[1]) - Number(startDates[1]);
|
|
292
|
+
const yearNum = Number(endDates[0]) - Number(startDates[0]);
|
|
293
|
+
if (yearNum > 0)
|
|
294
|
+
monthNum += 12 * yearNum;
|
|
295
|
+
if (monthNum <= 0)
|
|
296
|
+
monthNum = 1;
|
|
297
|
+
setMonthsNum(monthNum);
|
|
298
|
+
return monthNum;
|
|
299
|
+
};
|
|
299
300
|
const initData = () => {
|
|
300
301
|
const monthNum = getMonthNum();
|
|
301
302
|
getMonthData(startDates, monthNum);
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
303
|
+
const defaultData = setDefaultDate();
|
|
304
|
+
const current = getCurrentIndex(defaultData);
|
|
305
|
+
const currentIndex = current.current;
|
|
306
|
+
renderCurrentDate(defaultData, current);
|
|
307
|
+
setDefaultRange(monthNum, currentIndex);
|
|
308
|
+
requestAniFrameFunc(currentIndex, monthNum);
|
|
305
309
|
};
|
|
306
310
|
useEffect(() => {
|
|
307
311
|
initData();
|
|
@@ -318,9 +322,9 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
318
322
|
popup && resetRender();
|
|
319
323
|
}, [currentDate]);
|
|
320
324
|
const scrollToDate = (date) => {
|
|
321
|
-
if (
|
|
325
|
+
if (compareDate(date, propStartDate)) {
|
|
322
326
|
date = propStartDate;
|
|
323
|
-
} else if (!
|
|
327
|
+
} else if (!compareDate(date, propEndDate)) {
|
|
324
328
|
date = propEndDate;
|
|
325
329
|
}
|
|
326
330
|
const dateArr = splitDate(date);
|
|
@@ -341,22 +345,21 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
341
345
|
clearInterval(interval);
|
|
342
346
|
if (monthsRef.current) {
|
|
343
347
|
monthsRef.current.scrollTop = currTop;
|
|
344
|
-
setScrollTop(
|
|
348
|
+
setScrollTop(currTop);
|
|
345
349
|
}
|
|
346
350
|
}
|
|
347
351
|
}, 40);
|
|
348
352
|
} else {
|
|
349
353
|
monthsRef.current.scrollTop = currTop;
|
|
350
|
-
setScrollTop(
|
|
354
|
+
setScrollTop(currTop);
|
|
351
355
|
}
|
|
352
356
|
}
|
|
353
357
|
}
|
|
354
358
|
});
|
|
355
359
|
};
|
|
356
360
|
const monthsViewScroll = (e) => {
|
|
357
|
-
if (monthsData.length <= 1)
|
|
361
|
+
if (monthsData.length <= 1)
|
|
358
362
|
return;
|
|
359
|
-
}
|
|
360
363
|
const scrollTop2 = e.target.scrollTop;
|
|
361
364
|
Taro.getEnv() === "WEB" && setScrollTop(scrollTop2);
|
|
362
365
|
let current = Math.floor(scrollTop2 / avgHeight);
|
|
@@ -367,16 +370,13 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
367
370
|
const nextTop = monthsData[current + 1].scrollTop;
|
|
368
371
|
const nextHeight = monthsData[current + 1].cssHeight;
|
|
369
372
|
if (current === 0) {
|
|
370
|
-
if (scrollTop2 >= nextTop)
|
|
373
|
+
if (scrollTop2 >= nextTop)
|
|
371
374
|
current += 1;
|
|
372
|
-
}
|
|
373
375
|
} else if (current > 0 && current < monthsNum - 1) {
|
|
374
|
-
if (scrollTop2 >= nextTop)
|
|
376
|
+
if (scrollTop2 >= nextTop)
|
|
375
377
|
current += 1;
|
|
376
|
-
|
|
377
|
-
if (scrollTop2 < monthsData[current].scrollTop) {
|
|
378
|
+
if (scrollTop2 < monthsData[current].scrollTop)
|
|
378
379
|
current -= 1;
|
|
379
|
-
}
|
|
380
380
|
} else {
|
|
381
381
|
const viewPosition = Math.round(scrollTop2 + viewHeight);
|
|
382
382
|
if (current + 1 <= monthsNum && viewPosition >= nextTop + nextHeight) {
|
|
@@ -391,90 +391,102 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
391
391
|
React__default.useImperativeHandle(ref, () => ({
|
|
392
392
|
scrollToDate
|
|
393
393
|
}));
|
|
394
|
+
const isDisable = (day, month) => {
|
|
395
|
+
if (day.type !== "active")
|
|
396
|
+
return true;
|
|
397
|
+
const dateStr = getCurrDate(day, month);
|
|
398
|
+
if (compareDate(dateStr, propStartDate))
|
|
399
|
+
return true;
|
|
400
|
+
if (compareDate(propEndDate, dateStr))
|
|
401
|
+
return true;
|
|
402
|
+
return false;
|
|
403
|
+
};
|
|
394
404
|
const getClasses = (day, month) => {
|
|
395
405
|
const dateStr = getCurrDate(day, month);
|
|
396
|
-
if (day
|
|
397
|
-
|
|
398
|
-
|
|
406
|
+
if (isDisable(day, month))
|
|
407
|
+
return `${dayPrefix}-disabled`;
|
|
408
|
+
const activeCls = `${dayPrefix}-active`;
|
|
409
|
+
if (type === "range" || type === "week") {
|
|
410
|
+
if (isStart(dateStr, currentDate))
|
|
411
|
+
return `${activeCls} active-start`;
|
|
412
|
+
if (isEnd(dateStr, currentDate)) {
|
|
413
|
+
return `${activeCls} active-end`;
|
|
399
414
|
}
|
|
400
|
-
if (
|
|
401
|
-
|
|
402
|
-
return `${dayPrefix}-active ${isStart(dateStr, currentDate) ? "active-start" : ""} ${isEnd(dateStr, currentDate) ? "active-end" : ""}`;
|
|
403
|
-
}
|
|
404
|
-
if (Array.isArray(currentDate) && Object.values(currentDate).length === 2 && Utils.compareDate(currentDate[0], dateStr) && Utils.compareDate(dateStr, currentDate[1])) {
|
|
405
|
-
if (disableDate(day)) {
|
|
406
|
-
return `${dayPrefix}-choose-disabled`;
|
|
407
|
-
}
|
|
408
|
-
return `${dayPrefix}-choose`;
|
|
409
|
-
}
|
|
410
|
-
} else if (type === "multiple" && isMultiple(dateStr, currentDate) || !Array.isArray(currentDate) && Utils.isEqual(currentDate, dateStr)) {
|
|
411
|
-
return `${dayPrefix}-active`;
|
|
415
|
+
if (currentDate.length === 2 && compareDate(currentDate[0], dateStr) && compareDate(dateStr, currentDate[1])) {
|
|
416
|
+
return disableDate(day) ? `${dayPrefix}-choose-disabled` : `${dayPrefix}-choose`;
|
|
412
417
|
}
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
}
|
|
416
|
-
return null;
|
|
418
|
+
} else if (type === "multiple" && isMultiple(dateStr, currentDate) || !Array.isArray(currentDate) && isEqual(currentDate, dateStr)) {
|
|
419
|
+
return activeCls;
|
|
417
420
|
}
|
|
418
|
-
|
|
421
|
+
if (disableDate(day))
|
|
422
|
+
return `${dayPrefix}-disabled`;
|
|
423
|
+
return null;
|
|
419
424
|
};
|
|
420
|
-
const
|
|
421
|
-
if (
|
|
425
|
+
const handleDayClick = (day, month, isFirst = true) => {
|
|
426
|
+
if (isDisable(day, month) || disableDate(day))
|
|
422
427
|
return;
|
|
423
|
-
}
|
|
424
428
|
const days = [...month.curData];
|
|
425
429
|
const [y, m] = month.curData;
|
|
426
|
-
days[2] = typeof day.day === "number" ?
|
|
430
|
+
days[2] = typeof day.day === "number" ? getNumTwoBit(day.day) : day.day;
|
|
427
431
|
days[3] = `${days[0]}/${days[1]}/${days[2]}`;
|
|
428
|
-
days[4] =
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
if (
|
|
434
|
-
hasIndex =
|
|
432
|
+
days[4] = getWhatDay(+days[0], +days[1], +days[2]);
|
|
433
|
+
const newDate = days[3];
|
|
434
|
+
switch (type) {
|
|
435
|
+
case "multiple": {
|
|
436
|
+
if (Array.isArray(currentDate)) {
|
|
437
|
+
if (currentDate.length > 0) {
|
|
438
|
+
const hasIndex = currentDate.findIndex((item) => item === newDate);
|
|
439
|
+
if (isFirst) {
|
|
440
|
+
state.currDateArray.push([...days]);
|
|
441
|
+
} else if (hasIndex > -1) {
|
|
442
|
+
currentDate.splice(hasIndex, 1);
|
|
443
|
+
state.currDateArray.splice(hasIndex, 1);
|
|
444
|
+
} else {
|
|
445
|
+
currentDate.push(newDate);
|
|
446
|
+
state.currDateArray.push([...days]);
|
|
447
|
+
}
|
|
448
|
+
} else {
|
|
449
|
+
currentDate.push(newDate);
|
|
450
|
+
state.currDateArray = [[...days]];
|
|
435
451
|
}
|
|
436
|
-
});
|
|
437
|
-
if (isFirst) {
|
|
438
|
-
state.currDateArray.push([...days]);
|
|
439
|
-
} else if (hasIndex !== "") {
|
|
440
|
-
currentDate.splice(hasIndex, 1);
|
|
441
|
-
state.currDateArray.splice(hasIndex, 1);
|
|
442
|
-
} else {
|
|
443
|
-
currentDate.push(days[3]);
|
|
444
|
-
state.currDateArray.push([...days]);
|
|
445
452
|
}
|
|
446
|
-
|
|
447
|
-
currentDate.push(days[3]);
|
|
448
|
-
state.currDateArray = [[...days]];
|
|
453
|
+
break;
|
|
449
454
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
455
|
+
case "range": {
|
|
456
|
+
if (Array.isArray(currentDate)) {
|
|
457
|
+
if (currentDate.length === 2 || currentDate.length === 0) {
|
|
458
|
+
currentDate.splice(0, currentDate.length, newDate);
|
|
459
|
+
state.currDateArray = [[...days]];
|
|
460
|
+
} else if (compareDate(currentDate[0], newDate)) {
|
|
461
|
+
currentDate.push(newDate);
|
|
462
|
+
state.currDateArray = [...state.currDateArray, [...days]];
|
|
463
|
+
} else {
|
|
464
|
+
currentDate.unshift(newDate);
|
|
465
|
+
state.currDateArray = [[...days], ...state.currDateArray];
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
break;
|
|
461
469
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
470
|
+
case "week": {
|
|
471
|
+
const weekArr = getWeekDate(y, m, `${day.day}`, firstDayOfWeek);
|
|
472
|
+
if (compareDate(weekArr[0], propStartDate)) {
|
|
473
|
+
weekArr[0] = propStartDate;
|
|
474
|
+
}
|
|
475
|
+
if (compareDate(propEndDate, weekArr[1])) {
|
|
476
|
+
weekArr[1] = propEndDate;
|
|
477
|
+
}
|
|
478
|
+
currentDate.splice(0, currentDate.length, ...weekArr);
|
|
479
|
+
state.currDateArray = [
|
|
480
|
+
formatResultDate(weekArr[0]),
|
|
481
|
+
formatResultDate(weekArr[1])
|
|
482
|
+
];
|
|
483
|
+
break;
|
|
466
484
|
}
|
|
467
|
-
|
|
468
|
-
|
|
485
|
+
default: {
|
|
486
|
+
setCurrentDate(newDate);
|
|
487
|
+
state.currDateArray = [...days];
|
|
488
|
+
break;
|
|
469
489
|
}
|
|
470
|
-
Array.isArray(currentDate) && currentDate.splice(0) && currentDate.push(...weekArr);
|
|
471
|
-
state.currDateArray = [
|
|
472
|
-
Utils.formatResultDate(weekArr[0]),
|
|
473
|
-
Utils.formatResultDate(weekArr[1])
|
|
474
|
-
];
|
|
475
|
-
} else {
|
|
476
|
-
setCurrentDate(days[3]);
|
|
477
|
-
state.currDateArray = [...days];
|
|
478
490
|
}
|
|
479
491
|
if (!isFirst) {
|
|
480
492
|
onDayClick && onDayClick(state.currDateArray);
|
|
@@ -493,10 +505,10 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
493
505
|
}
|
|
494
506
|
}
|
|
495
507
|
};
|
|
496
|
-
const classes = classNames({
|
|
508
|
+
const classes = classNames(classPrefix, {
|
|
497
509
|
[`${classPrefix}-title`]: !popup,
|
|
498
510
|
[`${classPrefix}-nofooter`]: !!autoBackfill
|
|
499
|
-
},
|
|
511
|
+
}, className);
|
|
500
512
|
const headerClasses = classNames({
|
|
501
513
|
[`${classPrefix}-header`]: true,
|
|
502
514
|
[`${classPrefix}-header-title`]: !popup
|
|
@@ -517,6 +529,31 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
517
529
|
React__default.createElement("div", { className: `${classPrefix}-weeks`, ref: weeksPanel }, weeks.map((item) => React__default.createElement("div", { className: `${classPrefix}-week-item`, key: item }, item)))
|
|
518
530
|
);
|
|
519
531
|
};
|
|
532
|
+
const renderItem = (month, day, index) => {
|
|
533
|
+
const startTip = isStartTip(day, month);
|
|
534
|
+
const endTip = isEndTip(day, month);
|
|
535
|
+
const noStartNorEnd = !startTip && !endTip;
|
|
536
|
+
return React__default.createElement(
|
|
537
|
+
"div",
|
|
538
|
+
{ className: classNames("nut-calendar-day", getClasses(day, month)), onClick: () => handleDayClick(day, month, false), key: index },
|
|
539
|
+
React__default.createElement("div", { className: `${classPrefix}-day-day` }, renderDay ? renderDay(day) : day.day),
|
|
540
|
+
!startTip && renderDayTop && React__default.createElement("div", { className: `${classPrefix}-day-info-top` }, renderDayTop(day)),
|
|
541
|
+
noStartNorEnd && renderDayBottom && React__default.createElement("div", { className: `${classPrefix}-day-info-bottom` }, renderDayBottom(day)),
|
|
542
|
+
noStartNorEnd && isCurrDay(month, day.day) && !renderDayBottom && showToday && React__default.createElement("div", { className: `${classPrefix}-day-info-curr` }, locale.calendaritem.today),
|
|
543
|
+
startTip && React__default.createElement("div", { className: classNames("nut-calendar-day-info", {
|
|
544
|
+
"nut-calendar-day-info-top": isStartAndEnd(currentDate)
|
|
545
|
+
}) }, startText || locale.calendaritem.start),
|
|
546
|
+
endTip && React__default.createElement("div", { className: `${classPrefix}-day-info` }, endText || locale.calendaritem.end)
|
|
547
|
+
);
|
|
548
|
+
};
|
|
549
|
+
const renderPanel = (month, key) => {
|
|
550
|
+
return React__default.createElement(
|
|
551
|
+
"div",
|
|
552
|
+
{ className: `${classPrefix}-month`, key },
|
|
553
|
+
React__default.createElement("div", { className: `${classPrefix}-month-title` }, month.title),
|
|
554
|
+
React__default.createElement("div", { className: `${classPrefix}-days` }, month.monthData.map((day, i) => renderItem(month, day, i)))
|
|
555
|
+
);
|
|
556
|
+
};
|
|
520
557
|
const renderContent = () => {
|
|
521
558
|
return React__default.createElement(
|
|
522
559
|
ScrollView,
|
|
@@ -525,26 +562,7 @@ const CalendarItem = React__default.forwardRef((props, ref) => {
|
|
|
525
562
|
"div",
|
|
526
563
|
{ className: `${classPrefix}-pannel`, ref: monthsPanel },
|
|
527
564
|
React__default.createElement("div", { className: "viewArea", ref: viewAreaRef, style: { transform: `translateY(${translateY}px)` } }, monthsData.slice(monthDefaultRange[0], monthDefaultRange[1]).map((month, key) => {
|
|
528
|
-
return
|
|
529
|
-
"div",
|
|
530
|
-
{ className: `${classPrefix}-month`, key },
|
|
531
|
-
React__default.createElement("div", { className: `${classPrefix}-month-title` }, month.title),
|
|
532
|
-
React__default.createElement("div", { className: `${classPrefix}-days` }, month.monthData.map((day, i) => React__default.createElement(
|
|
533
|
-
"div",
|
|
534
|
-
{ className: [
|
|
535
|
-
`${classPrefix}-day`,
|
|
536
|
-
getClasses(day, month)
|
|
537
|
-
].join(" "), onClick: () => {
|
|
538
|
-
chooseDay(day, month);
|
|
539
|
-
}, key: i },
|
|
540
|
-
React__default.createElement("div", { className: `${classPrefix}-day-day` }, renderDay ? renderDay(day) : day.day),
|
|
541
|
-
!isStartTip(day, month) && renderDayTop && React__default.createElement("div", { className: `${classPrefix}-day-info-top` }, renderDayTop(day)),
|
|
542
|
-
!isStartTip(day, month) && !isEndTip(day, month) && renderDayBottom && React__default.createElement("div", { className: `${classPrefix}-day-info-bottom` }, renderDayBottom(day)),
|
|
543
|
-
!isStartTip(day, month) && !isEndTip(day, month) && !renderDayBottom && showToday && isCurrDay(month, day.day) && React__default.createElement("div", { className: `${classPrefix}-day-info-curr` }, locale.calendaritem.today),
|
|
544
|
-
isStartTip(day, month) && React__default.createElement("div", { className: `${classPrefix}-day-info ${isStartAndEnd(currentDate) ? `${classPrefix}-day-info-top` : ""}` }, startText || locale.calendaritem.start),
|
|
545
|
-
isEndTip(day, month) && React__default.createElement("div", { className: `${classPrefix}-day-info` }, endText || locale.calendaritem.end)
|
|
546
|
-
)))
|
|
547
|
-
);
|
|
565
|
+
return renderPanel(month, key);
|
|
548
566
|
}))
|
|
549
567
|
)
|
|
550
568
|
);
|