@nutui/nutui-react 1.3.5 → 1.3.6
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 +7 -0
- package/dist/esm/ActionSheet.js +15 -25
- package/dist/esm/Address.js +151 -221
- package/dist/esm/AnimatingNumbers.js +7 -31
- package/dist/esm/Audio.js +31 -66
- package/dist/esm/Avatar.js +25 -51
- package/dist/esm/AvatarGroup.js +2 -9
- package/dist/esm/BackTop.js +29 -55
- package/dist/esm/Badge.js +9 -20
- package/dist/esm/Barrage.js +8 -20
- package/dist/esm/Button.js +22 -37
- package/dist/esm/Calendar.js +23 -37
- package/dist/esm/CalendarItem.js +86 -186
- package/dist/esm/Card.js +14 -20
- package/dist/esm/Cascader.js +77 -197
- package/dist/esm/Cell.js +20 -30
- package/dist/esm/CellGroup.js +6 -12
- package/dist/esm/Checkbox.js +27 -48
- package/dist/esm/CheckboxGroup.js +12 -30
- package/dist/esm/CircleProgress.js +11 -28
- package/dist/esm/Col.js +11 -22
- package/dist/esm/Collapse.js +11 -27
- package/dist/esm/CollapseItem.js +33 -47
- package/dist/esm/ConfigProvider.js +4 -15
- package/dist/esm/CountDown.js +37 -74
- package/dist/esm/DatePicker.js +44 -106
- package/dist/esm/Dialog.js +31 -89
- package/dist/esm/Divider.js +8 -15
- package/dist/esm/Drag.js +30 -45
- package/dist/esm/Elevator.js +37 -74
- package/dist/esm/Empty.js +11 -24
- package/dist/esm/FixedNav.js +18 -29
- package/dist/esm/Grid.js +13 -28
- package/dist/esm/GridItem.js +18 -34
- package/dist/esm/ImagePreview.js +36 -71
- package/dist/esm/Indicator.js +9 -20
- package/dist/esm/Infiniteloading.js +26 -55
- package/dist/esm/Input.js +62 -106
- package/dist/esm/InputNumber.js +25 -52
- package/dist/esm/Layout.js +0 -6
- package/dist/esm/Menu.js +24 -46
- package/dist/esm/MenuItem.js +29 -52
- package/dist/esm/NavBar.js +18 -34
- package/dist/esm/NoticeBar.js +54 -102
- package/dist/esm/Notify.js +9 -38
- package/dist/esm/NumberKeyboard.js +21 -52
- package/dist/esm/Pagination.js +38 -71
- package/dist/esm/Picker.js +91 -178
- package/dist/esm/Popover.js +32 -72
- package/dist/esm/Popup.js +40 -72
- package/dist/esm/Price.js +7 -24
- package/dist/esm/Progress.js +35 -50
- package/dist/esm/PullToRefresh.js +28 -83
- package/dist/esm/Radio.js +24 -47
- package/dist/esm/RadioGroup.js +14 -24
- package/dist/esm/Range.js +44 -116
- package/dist/esm/Rate.js +21 -39
- package/dist/esm/Row.js +7 -16
- package/dist/esm/SearchBar.js +47 -68
- package/dist/esm/ShortPassword.js +29 -56
- package/dist/esm/SideNavBar.js +9 -16
- package/dist/esm/SideNavBarItem.js +4 -11
- package/dist/esm/Signature.js +13 -43
- package/dist/esm/Skeleton.js +13 -23
- package/dist/esm/Step.js +12 -28
- package/dist/esm/Steps.js +6 -14
- package/dist/esm/Sticky.js +24 -52
- package/dist/esm/SubSideNavBar.js +7 -22
- package/dist/esm/Swipe.js +15 -54
- package/dist/esm/Swiper.js +102 -186
- package/dist/esm/SwiperItem.js +2 -12
- package/dist/esm/Switch.js +13 -27
- package/dist/esm/Tabbar.js +13 -25
- package/dist/esm/TabbarItem.js +15 -23
- package/dist/esm/Table.js +19 -39
- package/dist/esm/Tag.js +19 -36
- package/dist/esm/TextArea.js +19 -43
- package/dist/esm/TimeDetail.js +15 -28
- package/dist/esm/TimePannel.js +5 -12
- package/dist/esm/TimeSelect.js +35 -59
- package/dist/esm/Toast.js +16 -49
- package/dist/esm/Uploader.js +57 -152
- package/dist/esm/Video.js +8 -19
- package/dist/esm/VirtualList.js +84 -118
- package/dist/esm/date-710f8c7c.js +9 -33
- package/dist/esm/get-scroll-parent-3dcd3f53.js +1 -9
- package/dist/esm/icon-8dc4de10.js +11 -21
- package/dist/esm/offsetContext-0e3d04b3.js +0 -3
- package/dist/esm/overlay-ed3eb37d.js +12 -23
- package/dist/esm/render-18227751.js +0 -11
- package/dist/esm/tabpane-c957ab14.js +4 -10
- package/dist/esm/tabs-0896a61b.js +28 -56
- package/dist/esm/types/src/packages/elevator/demo.d.ts +1 -0
- package/dist/esm/types/src/packages/searchbar/searchbar.d.ts +2 -0
- package/dist/esm/useClientRect-839d18c5.js +0 -5
- package/dist/esm/useTouch-a2ea68c6.js +27 -47
- 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/zh-CN.js +1 -1
- package/dist/locales/zh-TW.js +1 -1
- package/dist/nutui.react.es.js +424 -406
- package/dist/nutui.react.umd.js +416 -398
- package/dist/packages/searchbar/searchbar.scss +20 -3
- package/dist/style.css +1 -1
- package/dist/style.es.js +1 -1
- package/dist/types/index.d.ts +2 -0
- package/package.json +1 -1
package/dist/esm/CalendarItem.js
CHANGED
|
@@ -1,30 +1,24 @@
|
|
|
1
1
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
2
|
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
-
|
|
5
4
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
-
|
|
7
5
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
8
|
-
|
|
9
6
|
import React__default, { useState, useRef, useEffect } from 'react';
|
|
10
7
|
import classNames from 'classnames';
|
|
11
8
|
import { c as cn } from './bem-893ad28d.js';
|
|
12
9
|
import { U as Utils } from './date-710f8c7c.js';
|
|
13
10
|
import { useConfig } from './ConfigProvider.js';
|
|
14
11
|
import '@bem-react/classname';
|
|
15
|
-
|
|
16
12
|
function requestAniFrame() {
|
|
17
13
|
if (typeof window !== 'undefined') {
|
|
18
14
|
return window.requestAnimationFrame || function (callback) {
|
|
19
15
|
window.setTimeout(callback, 1000 / 60);
|
|
20
16
|
};
|
|
21
17
|
}
|
|
22
|
-
|
|
23
18
|
return function (callback) {
|
|
24
19
|
setTimeout(callback, 1000 / 60);
|
|
25
20
|
};
|
|
26
21
|
}
|
|
27
|
-
|
|
28
22
|
var requestAniFrame$1 = requestAniFrame();
|
|
29
23
|
var defaultProps = {
|
|
30
24
|
type: 'one',
|
|
@@ -52,83 +46,74 @@ var defaultProps = {
|
|
|
52
46
|
};
|
|
53
47
|
var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
54
48
|
var _classNames, _classNames2;
|
|
55
|
-
|
|
56
49
|
var _useConfig = useConfig(),
|
|
57
|
-
|
|
58
|
-
|
|
50
|
+
locale = _useConfig.locale;
|
|
59
51
|
var _defaultProps$props = _objectSpread(_objectSpread({}, defaultProps), props),
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
52
|
+
type = _defaultProps$props.type,
|
|
53
|
+
isAutoBackFill = _defaultProps$props.isAutoBackFill,
|
|
54
|
+
poppable = _defaultProps$props.poppable,
|
|
55
|
+
title = _defaultProps$props.title,
|
|
56
|
+
defaultValue = _defaultProps$props.defaultValue,
|
|
57
|
+
showToday = _defaultProps$props.showToday,
|
|
58
|
+
startText = _defaultProps$props.startText,
|
|
59
|
+
endText = _defaultProps$props.endText,
|
|
60
|
+
confirmText = _defaultProps$props.confirmText,
|
|
61
|
+
showTitle = _defaultProps$props.showTitle,
|
|
62
|
+
showSubTitle = _defaultProps$props.showSubTitle,
|
|
63
|
+
toDateAnimation = _defaultProps$props.toDateAnimation,
|
|
64
|
+
onBtn = _defaultProps$props.onBtn,
|
|
65
|
+
onDay = _defaultProps$props.onDay,
|
|
66
|
+
onTopInfo = _defaultProps$props.onTopInfo,
|
|
67
|
+
onBottomInfo = _defaultProps$props.onBottomInfo,
|
|
68
|
+
onChoose = _defaultProps$props.onChoose,
|
|
69
|
+
onUpdate = _defaultProps$props.onUpdate,
|
|
70
|
+
onSelected = _defaultProps$props.onSelected;
|
|
80
71
|
var weeks = locale.calendaritem.weekdays;
|
|
81
|
-
|
|
82
72
|
var _useState = useState(''),
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
73
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
74
|
+
yearMonthTitle = _useState2[0],
|
|
75
|
+
setYearMonthTitle = _useState2[1];
|
|
87
76
|
var _useState3 = useState([]),
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
77
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
78
|
+
monthsData = _useState4[0],
|
|
79
|
+
setMonthsData = _useState4[1];
|
|
92
80
|
var _useState5 = useState(0),
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
81
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
82
|
+
translateY = _useState6[0],
|
|
83
|
+
setTranslateY = _useState6[1];
|
|
97
84
|
var _useState7 = useState([]),
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
85
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
86
|
+
monthDefaultRange = _useState8[0],
|
|
87
|
+
setMonthDefaultRange = _useState8[1];
|
|
102
88
|
var _useState9 = useState({
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
89
|
+
currDate: '',
|
|
90
|
+
propStartDate: '',
|
|
91
|
+
propEndDate: '',
|
|
92
|
+
unLoadPrev: false,
|
|
93
|
+
touchParams: {
|
|
94
|
+
startY: 0,
|
|
95
|
+
endY: 0,
|
|
96
|
+
startTime: 0,
|
|
97
|
+
endTime: 0,
|
|
98
|
+
lastY: 0,
|
|
99
|
+
lastTime: 0
|
|
100
|
+
},
|
|
101
|
+
transformY: 0,
|
|
102
|
+
scrollDistance: 0,
|
|
103
|
+
defaultData: [],
|
|
104
|
+
chooseData: [],
|
|
105
|
+
monthsData: [],
|
|
106
|
+
dayPrefix: 'calendar-month-day',
|
|
107
|
+
startData: '',
|
|
108
|
+
endData: '',
|
|
109
|
+
isRange: props.type === 'range',
|
|
110
|
+
timer: 0,
|
|
111
|
+
currentIndex: 0,
|
|
112
|
+
avgHeight: 0,
|
|
113
|
+
monthsNum: 0
|
|
114
|
+
}),
|
|
115
|
+
_useState10 = _slicedToArray(_useState9, 1),
|
|
116
|
+
state = _useState10[0];
|
|
132
117
|
var weeksPanel = useRef(null);
|
|
133
118
|
var months = useRef(null);
|
|
134
119
|
var monthsPanel = useRef(null);
|
|
@@ -140,87 +125,66 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
140
125
|
var monthitemclasses = classNames(_defineProperty({
|
|
141
126
|
'calendar-month-item': true
|
|
142
127
|
}, "".concat(type === 'range' ? 'month-item-range' : ''), true));
|
|
143
|
-
|
|
144
128
|
var splitDate = function splitDate(date) {
|
|
145
129
|
return date.split('-');
|
|
146
130
|
};
|
|
147
|
-
|
|
148
131
|
var isStart = function isStart(currDate) {
|
|
149
132
|
return Utils.isEqual(state.currDate[0], currDate);
|
|
150
133
|
};
|
|
151
|
-
|
|
152
134
|
var isEnd = function isEnd(currDate) {
|
|
153
135
|
return Utils.isEqual(state.currDate[1], currDate);
|
|
154
136
|
};
|
|
155
|
-
|
|
156
137
|
var isMultiple = function isMultiple(currDate) {
|
|
157
138
|
if (state.currDate.length > 0) {
|
|
158
139
|
return state.currDate.some(function (item) {
|
|
159
140
|
return Utils.isEqual(item, currDate);
|
|
160
141
|
});
|
|
161
142
|
}
|
|
162
|
-
|
|
163
143
|
return false;
|
|
164
144
|
};
|
|
165
|
-
|
|
166
145
|
var getCurrDate = function getCurrDate(day, month) {
|
|
167
146
|
return "".concat(month.curData[0], "-").concat(month.curData[1], "-").concat(Utils.getNumTwoBit(+day.day));
|
|
168
147
|
};
|
|
169
|
-
|
|
170
148
|
var getClass = function getClass(day, month) {
|
|
171
149
|
var currDate = getCurrDate(day, month);
|
|
172
|
-
|
|
173
150
|
if (day.type === 'curr') {
|
|
174
151
|
if (Utils.isEqual(state.currDate, currDate) || type === 'range' && (isStart(currDate) || isEnd(currDate)) || type === 'multiple' && isMultiple(currDate)) {
|
|
175
152
|
return "".concat(state.dayPrefix, "-active");
|
|
176
153
|
}
|
|
177
|
-
|
|
178
154
|
if (state.propStartDate && Utils.compareDate(currDate, state.propStartDate) || state.propEndDate && Utils.compareDate(state.propEndDate, currDate)) {
|
|
179
155
|
return "".concat(state.dayPrefix, "-disabled");
|
|
180
156
|
}
|
|
181
|
-
|
|
182
157
|
if (type === 'range' && Array.isArray(state.currDate) && Object.values(state.currDate).length === 2 && Utils.compareDate(state.currDate[0], currDate) && Utils.compareDate(currDate, state.currDate[1])) {
|
|
183
158
|
return "".concat(state.dayPrefix, "-choose");
|
|
184
159
|
}
|
|
185
|
-
|
|
186
160
|
return null;
|
|
187
161
|
}
|
|
188
|
-
|
|
189
162
|
return "".concat(state.dayPrefix, "-disabled");
|
|
190
163
|
};
|
|
191
|
-
|
|
192
164
|
var isActive = function isActive(day, month) {
|
|
193
165
|
return state.isRange && day.type === 'curr' && getClass(day, month) === 'calendar-month-day-active';
|
|
194
166
|
};
|
|
195
|
-
|
|
196
167
|
var isCurrDay = function isCurrDay(month, day) {
|
|
197
168
|
var date = "".concat(month.curData[0], "-").concat(month.curData[1], "-").concat(day);
|
|
198
169
|
return Utils.isEqual(date, Utils.date2Str(new Date()));
|
|
199
170
|
};
|
|
200
|
-
|
|
201
171
|
var confirm = function confirm() {
|
|
202
172
|
var type = props.type;
|
|
203
|
-
|
|
204
173
|
if (type === 'range' && state.chooseData.length === 2 || type !== 'range') {
|
|
205
174
|
var chooseData = state.chooseData.slice(0);
|
|
206
175
|
onChoose && onChoose(chooseData);
|
|
207
|
-
|
|
208
176
|
if (poppable) {
|
|
209
177
|
onUpdate && onUpdate();
|
|
210
178
|
}
|
|
211
179
|
}
|
|
212
180
|
};
|
|
213
|
-
|
|
214
181
|
var chooseDay = function chooseDay(day, month, isFirst) {
|
|
215
182
|
if (getClass(day, month) !== "".concat(state.dayPrefix, "-disabled")) {
|
|
216
183
|
var _type = props.type;
|
|
217
|
-
|
|
218
184
|
var days = _toConsumableArray(month.curData);
|
|
219
|
-
|
|
220
185
|
days[2] = typeof day.day === 'number' ? Utils.getNumTwoBit(day.day) : day.day;
|
|
221
186
|
days[3] = "".concat(days[0], "-").concat(days[1], "-").concat(days[2]);
|
|
222
187
|
days[4] = Utils.getWhatDay(+days[0], +days[1], +days[2]);
|
|
223
|
-
|
|
224
188
|
if (_type === 'multiple') {
|
|
225
189
|
if (state.currDate.length > 0) {
|
|
226
190
|
var hasIndex = '';
|
|
@@ -229,7 +193,6 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
229
193
|
hasIndex = index;
|
|
230
194
|
}
|
|
231
195
|
});
|
|
232
|
-
|
|
233
196
|
if (isFirst) {
|
|
234
197
|
state.chooseData.push(_toConsumableArray(days));
|
|
235
198
|
} else if (hasIndex !== '') {
|
|
@@ -245,7 +208,6 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
245
208
|
}
|
|
246
209
|
} else if (_type === 'range') {
|
|
247
210
|
var curDataLength = Object.values(state.currDate).length;
|
|
248
|
-
|
|
249
211
|
if (curDataLength === 2 || curDataLength === 0) {
|
|
250
212
|
state.currDate = [days[3]];
|
|
251
213
|
} else if (Utils.compareDate(state.currDate[0], days[3])) {
|
|
@@ -253,7 +215,6 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
253
215
|
} else {
|
|
254
216
|
Array.isArray(state.currDate) && state.currDate.unshift(days[3]);
|
|
255
217
|
}
|
|
256
|
-
|
|
257
218
|
if (state.chooseData.length === 2 || !state.chooseData.length) {
|
|
258
219
|
state.chooseData = [_toConsumableArray(days)];
|
|
259
220
|
} else if (Utils.compareDate(state.chooseData[0][3], days[3])) {
|
|
@@ -265,73 +226,58 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
265
226
|
state.currDate = days[3];
|
|
266
227
|
state.chooseData = _toConsumableArray(days);
|
|
267
228
|
}
|
|
268
|
-
|
|
269
229
|
if (!isFirst) {
|
|
270
230
|
// 点击日期 触发
|
|
271
231
|
onSelected && onSelected(state.chooseData);
|
|
272
|
-
|
|
273
232
|
if (isAutoBackFill || !poppable) {
|
|
274
233
|
confirm();
|
|
275
234
|
}
|
|
276
235
|
}
|
|
277
|
-
|
|
278
236
|
setMonthsData(state.monthsData.slice());
|
|
279
237
|
}
|
|
280
238
|
};
|
|
281
|
-
|
|
282
239
|
var isStartTip = function isStartTip(day, month) {
|
|
283
240
|
return isActive(day, month) && isStart(getCurrDate(day, month));
|
|
284
|
-
};
|
|
285
|
-
|
|
286
|
-
|
|
241
|
+
};
|
|
242
|
+
// 是否有结束提示
|
|
287
243
|
var isEndTip = function isEndTip(day, month) {
|
|
288
244
|
if (state.currDate.length >= 2 && isEnd(getCurrDate(day, month))) {
|
|
289
245
|
return isActive(day, month);
|
|
290
246
|
}
|
|
291
|
-
|
|
292
247
|
return false;
|
|
293
|
-
};
|
|
294
|
-
|
|
295
|
-
|
|
248
|
+
};
|
|
249
|
+
// 开始结束时间是否相等
|
|
296
250
|
var rangeTip = function rangeTip() {
|
|
297
251
|
if (state.currDate.length >= 2) {
|
|
298
252
|
return Utils.isEqual(state.currDate[0], state.currDate[1]);
|
|
299
253
|
}
|
|
300
|
-
|
|
301
254
|
return false;
|
|
302
|
-
};
|
|
303
|
-
|
|
304
|
-
|
|
255
|
+
};
|
|
256
|
+
// 获取当前月数据
|
|
305
257
|
var getCurrData = function getCurrData(type) {
|
|
306
258
|
var monthData = type === 'prev' ? state.monthsData[0] : state.monthsData[state.monthsData.length - 1];
|
|
307
259
|
var year = parseInt(monthData.curData[0]);
|
|
308
260
|
var month = parseInt(monthData.curData[1].toString().replace(/^0/, ''));
|
|
309
|
-
|
|
310
261
|
switch (type) {
|
|
311
262
|
case 'prev':
|
|
312
263
|
month === 1 && (year -= 1);
|
|
313
264
|
month = month === 1 ? 12 : --month;
|
|
314
265
|
break;
|
|
315
|
-
|
|
316
266
|
case 'next':
|
|
317
267
|
month === 12 && (year += 1);
|
|
318
268
|
month = month === 12 ? 1 : ++month;
|
|
319
269
|
break;
|
|
320
270
|
}
|
|
321
|
-
|
|
322
271
|
return [year, Utils.getNumTwoBit(month), Utils.getMonthDays(String(year), String(month))];
|
|
323
|
-
};
|
|
324
|
-
|
|
325
|
-
|
|
272
|
+
};
|
|
273
|
+
// 获取日期状态
|
|
326
274
|
var getDaysStatus = function getDaysStatus(days, type, dateInfo) {
|
|
327
275
|
// 修复:当某个月的1号是周日时,月份下方会空出来一行
|
|
328
276
|
var year = dateInfo.year,
|
|
329
|
-
|
|
330
|
-
|
|
277
|
+
month = dateInfo.month;
|
|
331
278
|
if (type === 'prev' && days >= 7) {
|
|
332
279
|
days -= 7;
|
|
333
280
|
}
|
|
334
|
-
|
|
335
281
|
return Array.from(Array(days), function (v, k) {
|
|
336
282
|
return {
|
|
337
283
|
day: k + 1,
|
|
@@ -340,18 +286,15 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
340
286
|
month: month
|
|
341
287
|
};
|
|
342
288
|
});
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
|
|
289
|
+
};
|
|
290
|
+
// 获取上一个月的最后一周天数,填充当月空白
|
|
346
291
|
var getPreDaysStatus = function getPreDaysStatus(days, type, dateInfo, preCurrMonthDays) {
|
|
347
292
|
// 修复:当某个月的1号是周日时,月份下方会空出来一行
|
|
348
293
|
var year = dateInfo.year,
|
|
349
|
-
|
|
350
|
-
|
|
294
|
+
month = dateInfo.month;
|
|
351
295
|
if (type === 'prev' && days >= 7) {
|
|
352
296
|
days -= 7;
|
|
353
297
|
}
|
|
354
|
-
|
|
355
298
|
var months = Array.from(Array(preCurrMonthDays), function (v, k) {
|
|
356
299
|
return {
|
|
357
300
|
day: k + 1,
|
|
@@ -361,19 +304,16 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
361
304
|
};
|
|
362
305
|
});
|
|
363
306
|
return months.slice(preCurrMonthDays - days);
|
|
364
|
-
};
|
|
365
|
-
|
|
366
|
-
|
|
307
|
+
};
|
|
308
|
+
// 获取月数据
|
|
367
309
|
var getMonth = function getMonth(curData, type) {
|
|
368
310
|
var preMonthDays = Utils.getMonthPreDay(+curData[0], +curData[1]);
|
|
369
311
|
var preMonth = +curData[1] - 1;
|
|
370
312
|
var preYear = curData[0];
|
|
371
|
-
|
|
372
313
|
if (preMonth <= 0) {
|
|
373
314
|
preMonth = 12;
|
|
374
315
|
preYear += 1;
|
|
375
316
|
}
|
|
376
|
-
|
|
377
317
|
var currMonthDays = Utils.getMonthDays(curData[0], curData[1]);
|
|
378
318
|
var preCurrMonthDays = Utils.getMonthDays("".concat(preYear), "".concat(preMonth));
|
|
379
319
|
var title = {
|
|
@@ -390,13 +330,10 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
390
330
|
};
|
|
391
331
|
monthInfo.cssHeight = 39 + (monthInfo.monthData.length > 35 ? 384 : 320);
|
|
392
332
|
var cssScrollHeight = 0;
|
|
393
|
-
|
|
394
333
|
if (state.monthsData.length > 0) {
|
|
395
334
|
cssScrollHeight = state.monthsData[state.monthsData.length - 1].cssScrollHeight + state.monthsData[state.monthsData.length - 1].cssHeight;
|
|
396
335
|
}
|
|
397
|
-
|
|
398
336
|
monthInfo.cssScrollHeight = cssScrollHeight;
|
|
399
|
-
|
|
400
337
|
if (type === 'next') {
|
|
401
338
|
if (!state.endData || !Utils.compareDate("".concat(state.endData[0], "-").concat(state.endData[1], "-").concat(Utils.getMonthDays(state.endData[0], state.endData[1])), "".concat(curData[0], "-").concat(curData[1], "-").concat(curData[2]))) {
|
|
402
339
|
state.monthsData.push(monthInfo);
|
|
@@ -404,14 +341,11 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
404
341
|
} else if (!state.startData || !Utils.compareDate("".concat(curData[0], "-").concat(curData[1], "-").concat(curData[2]), "".concat(state.startData[0], "-").concat(state.startData[1], "-01"))) {
|
|
405
342
|
state.monthsData.unshift(monthInfo);
|
|
406
343
|
}
|
|
407
|
-
|
|
408
344
|
setMonthsData(state.monthsData);
|
|
409
345
|
};
|
|
410
|
-
|
|
411
346
|
var setDefaultRange = function setDefaultRange(monthsNum, current) {
|
|
412
347
|
var start = 0;
|
|
413
348
|
var end = 0;
|
|
414
|
-
|
|
415
349
|
if (monthsNum >= 3) {
|
|
416
350
|
if (current > 0 && current < monthsNum) {
|
|
417
351
|
start = current - 1;
|
|
@@ -427,20 +361,16 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
427
361
|
start = 0;
|
|
428
362
|
end = monthsNum + 2;
|
|
429
363
|
}
|
|
430
|
-
|
|
431
364
|
setMonthDefaultRange([start, end]);
|
|
432
365
|
setTranslateY(state.monthsData[start].cssScrollHeight);
|
|
433
366
|
};
|
|
434
|
-
|
|
435
367
|
var mothsViewScroll = function mothsViewScroll(e) {
|
|
436
368
|
if (state.monthsData.length <= 1) {
|
|
437
369
|
return;
|
|
438
370
|
}
|
|
439
|
-
|
|
440
371
|
var target = e.target;
|
|
441
372
|
var currentScrollTop = target.scrollTop;
|
|
442
373
|
var current = Math.floor(currentScrollTop / state.avgHeight);
|
|
443
|
-
|
|
444
374
|
if (current === 0) {
|
|
445
375
|
if (currentScrollTop >= state.monthsData[current + 1].cssScrollHeight) {
|
|
446
376
|
current += 1;
|
|
@@ -449,34 +379,27 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
449
379
|
if (currentScrollTop >= state.monthsData[current + 1].cssScrollHeight) {
|
|
450
380
|
current += 1;
|
|
451
381
|
}
|
|
452
|
-
|
|
453
382
|
if (currentScrollTop < state.monthsData[current].cssScrollHeight) {
|
|
454
383
|
current -= 1;
|
|
455
384
|
}
|
|
456
385
|
} else {
|
|
457
386
|
var viewPosition = Math.round(currentScrollTop + viewHeight);
|
|
458
|
-
|
|
459
387
|
if (viewPosition < state.monthsData[current].cssScrollHeight + state.monthsData[current].cssHeight && currentScrollTop > state.monthsData[current - 1].cssScrollHeight) {
|
|
460
388
|
current -= 1;
|
|
461
389
|
}
|
|
462
|
-
|
|
463
390
|
if (current + 1 <= state.monthsNum && viewPosition >= state.monthsData[current + 1].cssScrollHeight + state.monthsData[current + 1].cssHeight) {
|
|
464
391
|
current += 1;
|
|
465
392
|
}
|
|
466
|
-
|
|
467
393
|
if (current >= 1 && currentScrollTop < state.monthsData[current - 1].cssScrollHeight) {
|
|
468
394
|
current -= 1;
|
|
469
395
|
}
|
|
470
396
|
}
|
|
471
|
-
|
|
472
397
|
if (state.currentIndex !== current) {
|
|
473
398
|
state.currentIndex = current;
|
|
474
399
|
setDefaultRange(state.monthsNum, current);
|
|
475
400
|
}
|
|
476
|
-
|
|
477
401
|
setYearMonthTitle(state.monthsData[current].title);
|
|
478
402
|
};
|
|
479
|
-
|
|
480
403
|
var initData = function initData() {
|
|
481
404
|
// 初始化开始结束数据
|
|
482
405
|
var propStartDate = props.startDate ? props.startDate : Utils.getDay(0);
|
|
@@ -484,13 +407,12 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
484
407
|
state.propStartDate = propStartDate;
|
|
485
408
|
state.propEndDate = propEndDate;
|
|
486
409
|
state.startData = splitDate(propStartDate);
|
|
487
|
-
state.endData = splitDate(propEndDate);
|
|
488
|
-
|
|
410
|
+
state.endData = splitDate(propEndDate);
|
|
411
|
+
// 根据是否存在默认时间,初始化当前日期
|
|
489
412
|
if (defaultValue || Array.isArray(defaultValue) && defaultValue.length > 0) {
|
|
490
413
|
state.currDate = props.type !== 'one' ? _toConsumableArray(props.defaultValue) : props.defaultValue;
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
|
|
414
|
+
}
|
|
415
|
+
// 判断时间范围内存在多少个月
|
|
494
416
|
var startDate = {
|
|
495
417
|
year: Number(state.startData[0]),
|
|
496
418
|
month: Number(state.startData[1])
|
|
@@ -500,35 +422,28 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
500
422
|
month: Number(state.endData[1])
|
|
501
423
|
};
|
|
502
424
|
var monthsNum = endDate.month - startDate.month;
|
|
503
|
-
|
|
504
425
|
if (endDate.year - startDate.year > 0) {
|
|
505
426
|
monthsNum += 12 * (endDate.year - startDate.year);
|
|
506
427
|
}
|
|
507
|
-
|
|
508
428
|
if (monthsNum <= 0) {
|
|
509
429
|
monthsNum = 1;
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
|
|
430
|
+
}
|
|
431
|
+
// 设置月份数据
|
|
513
432
|
getMonth(state.startData, 'next');
|
|
514
433
|
var i = 1;
|
|
515
|
-
|
|
516
434
|
do {
|
|
517
435
|
getMonth(getCurrData('next'), 'next');
|
|
518
436
|
} while (i++ < monthsNum);
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
437
|
+
state.monthsNum = monthsNum;
|
|
438
|
+
// 日期转化为数组,限制初始日期。判断时间范围
|
|
522
439
|
if (type === 'range' && Array.isArray(state.currDate)) {
|
|
523
440
|
if (state.currDate.length > 0) {
|
|
524
441
|
if (propStartDate && Utils.compareDate(state.currDate[0], propStartDate)) {
|
|
525
442
|
state.currDate.splice(0, 1, propStartDate);
|
|
526
443
|
}
|
|
527
|
-
|
|
528
444
|
if (propEndDate && Utils.compareDate(propEndDate, state.currDate[1])) {
|
|
529
445
|
state.currDate.splice(1, 1, propEndDate);
|
|
530
446
|
}
|
|
531
|
-
|
|
532
447
|
state.defaultData = [].concat(_toConsumableArray(splitDate(state.currDate[0])), _toConsumableArray(splitDate(state.currDate[1])));
|
|
533
448
|
}
|
|
534
449
|
} else if (props.type === 'multiple' && Array.isArray(state.currDate)) {
|
|
@@ -552,20 +467,16 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
552
467
|
} else if (propEndDate && !Utils.compareDate(state.currDate, propEndDate)) {
|
|
553
468
|
state.currDate = propEndDate;
|
|
554
469
|
}
|
|
555
|
-
|
|
556
470
|
state.defaultData = _toConsumableArray(splitDate(state.currDate));
|
|
557
|
-
}
|
|
558
|
-
|
|
559
|
-
|
|
471
|
+
}
|
|
472
|
+
// 设置默认可见区域
|
|
560
473
|
var current = 0;
|
|
561
474
|
var lastCurrent = 0;
|
|
562
|
-
|
|
563
475
|
if (state.defaultData.length > 0) {
|
|
564
476
|
state.monthsData.forEach(function (item, index) {
|
|
565
477
|
if (item.title === locale.calendaritem.monthTitle(state.defaultData[0], state.defaultData[1])) {
|
|
566
478
|
current = index;
|
|
567
479
|
}
|
|
568
|
-
|
|
569
480
|
if (props.type === 'range') {
|
|
570
481
|
if (item.title === locale.calendaritem.monthTitle(state.defaultData[3], state.defaultData[4])) {
|
|
571
482
|
lastCurrent = index;
|
|
@@ -573,11 +484,9 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
573
484
|
}
|
|
574
485
|
});
|
|
575
486
|
}
|
|
576
|
-
|
|
577
487
|
setDefaultRange(monthsNum, current);
|
|
578
488
|
state.currentIndex = current;
|
|
579
489
|
setYearMonthTitle(state.monthsData[state.currentIndex].title);
|
|
580
|
-
|
|
581
490
|
if (state.defaultData.length > 0) {
|
|
582
491
|
// 设置当前选中日期
|
|
583
492
|
if (type === 'range') {
|
|
@@ -610,7 +519,6 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
610
519
|
}, state.monthsData[state.currentIndex], true);
|
|
611
520
|
}
|
|
612
521
|
}
|
|
613
|
-
|
|
614
522
|
var lastItem = state.monthsData[state.monthsData.length - 1];
|
|
615
523
|
var containerHeight = lastItem.cssHeight + lastItem.cssScrollHeight;
|
|
616
524
|
requestAniFrame$1(function () {
|
|
@@ -623,40 +531,33 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
623
531
|
});
|
|
624
532
|
state.avgHeight = Math.floor(containerHeight / (monthsNum + 1));
|
|
625
533
|
};
|
|
626
|
-
|
|
627
534
|
var resetRender = function resetRender() {
|
|
628
535
|
state.chooseData.splice(0);
|
|
629
536
|
state.monthsData.splice(0);
|
|
630
537
|
initData();
|
|
631
|
-
};
|
|
632
|
-
|
|
633
|
-
|
|
538
|
+
};
|
|
539
|
+
// 暴露出的API
|
|
634
540
|
var scrollToDate = function scrollToDate(date) {
|
|
635
541
|
if (Utils.compareDate(date, state.propStartDate)) {
|
|
636
542
|
date = state.propStartDate;
|
|
637
543
|
} else if (!Utils.compareDate(date, state.propEndDate)) {
|
|
638
544
|
date = state.propEndDate;
|
|
639
545
|
}
|
|
640
|
-
|
|
641
546
|
var dateArr = splitDate(date);
|
|
642
547
|
state.monthsData.forEach(function (item, index) {
|
|
643
548
|
if (item.title === locale.calendaritem.monthTitle(dateArr[0], dateArr[1])) {
|
|
644
549
|
if (months.current) {
|
|
645
550
|
var distance = state.monthsData[index].cssScrollHeight - months.current.scrollTop;
|
|
646
|
-
|
|
647
551
|
if (toDateAnimation) {
|
|
648
552
|
var flag = 0;
|
|
649
553
|
var interval = setInterval(function () {
|
|
650
554
|
flag++;
|
|
651
|
-
|
|
652
555
|
if (months.current) {
|
|
653
556
|
var offset = distance / 10;
|
|
654
557
|
months.current.scrollTop += offset;
|
|
655
558
|
}
|
|
656
|
-
|
|
657
559
|
if (flag >= 10) {
|
|
658
560
|
clearInterval(interval);
|
|
659
|
-
|
|
660
561
|
if (months.current) {
|
|
661
562
|
months.current.scrollTop = state.monthsData[index].cssScrollHeight;
|
|
662
563
|
}
|
|
@@ -669,7 +570,6 @@ var CalendarItem = React__default.forwardRef(function (props, ref) {
|
|
|
669
570
|
}
|
|
670
571
|
});
|
|
671
572
|
};
|
|
672
|
-
|
|
673
573
|
useEffect(function () {
|
|
674
574
|
initData();
|
|
675
575
|
}, []);
|