@mpxjs/webpack-plugin 2.10.3-beta.6 → 2.10.4-beta.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/index.js +1 -1
- package/lib/platform/json/wx/index.js +0 -1
- package/lib/platform/style/wx/index.js +22 -21
- package/lib/platform/template/wx/component-config/button.js +1 -1
- package/lib/platform/template/wx/component-config/index.js +5 -1
- package/lib/platform/template/wx/component-config/input.js +2 -2
- package/lib/platform/template/wx/component-config/sticky-header.js +23 -0
- package/lib/platform/template/wx/component-config/sticky-section.js +23 -0
- package/lib/platform/template/wx/component-config/text.js +18 -3
- package/lib/platform/template/wx/component-config/view.js +0 -2
- package/lib/platform/template/wx/index.js +41 -93
- package/lib/react/processJSON.js +7 -6
- package/lib/react/processScript.js +1 -18
- package/lib/runtime/components/react/context.ts +12 -3
- package/lib/runtime/components/react/dist/context.js +4 -1
- package/lib/runtime/components/react/dist/event.config.js +0 -1
- package/lib/runtime/components/react/dist/getInnerListeners.js +127 -142
- package/lib/runtime/components/react/dist/mpx-button.jsx +4 -5
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +4 -5
- package/lib/runtime/components/react/dist/mpx-checkbox-group.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-checkbox.jsx +2 -3
- package/lib/runtime/components/react/dist/mpx-form.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-icon/index.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-image.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-inline-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +6 -10
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-label.jsx +2 -3
- package/lib/runtime/components/react/dist/mpx-movable-area.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-movable-view.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-navigator.jsx +11 -3
- package/lib/runtime/components/react/dist/mpx-picker/date.jsx +194 -68
- package/lib/runtime/components/react/dist/mpx-picker/dateData.js +17 -0
- package/lib/runtime/components/react/dist/mpx-picker/index.jsx +180 -98
- package/lib/runtime/components/react/dist/mpx-picker/multiSelector.jsx +79 -139
- package/lib/runtime/components/react/dist/mpx-picker/region.jsx +190 -90
- package/lib/runtime/components/react/dist/mpx-picker/selector.jsx +60 -75
- package/lib/runtime/components/react/dist/mpx-picker/time.jsx +100 -228
- package/lib/runtime/components/react/dist/{mpx-picker-view.jsx → mpx-picker-view/index.jsx} +5 -6
- package/lib/runtime/components/react/dist/{mpx-picker-view-column.jsx → mpx-picker-view-column/index.jsx} +64 -16
- package/lib/runtime/components/react/dist/{mpx-picker-view-column-item.jsx → mpx-picker-view-column/pickerViewColumnItem.jsx} +8 -5
- package/lib/runtime/components/react/dist/{pickerFaces.js → mpx-picker-view-column/pickerViewFaces.js} +6 -0
- package/lib/runtime/components/react/dist/mpx-popup/index.jsx +61 -0
- package/lib/runtime/components/react/dist/mpx-popup/popupBase.jsx +92 -0
- package/lib/runtime/components/react/dist/mpx-radio-group.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-radio.jsx +2 -3
- package/lib/runtime/components/react/dist/mpx-rich-text/index.jsx +2 -2
- package/lib/runtime/components/react/dist/mpx-scroll-view.jsx +207 -29
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +7 -5
- package/lib/runtime/components/react/dist/mpx-simple-view.jsx +11 -15
- package/lib/runtime/components/react/dist/mpx-sticky-header.jsx +115 -0
- package/lib/runtime/components/react/dist/mpx-sticky-section.jsx +45 -0
- package/lib/runtime/components/react/dist/mpx-swiper-item.jsx +4 -5
- package/lib/runtime/components/react/dist/mpx-swiper.jsx +11 -11
- package/lib/runtime/components/react/dist/mpx-switch.jsx +3 -5
- package/lib/runtime/components/react/dist/mpx-text.jsx +4 -7
- package/lib/runtime/components/react/dist/mpx-video.jsx +5 -5
- package/lib/runtime/components/react/dist/mpx-view.jsx +23 -9
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +17 -17
- package/lib/runtime/components/react/dist/useAnimationHooks.js +26 -4
- package/lib/runtime/components/react/dist/utils.jsx +13 -2
- package/lib/runtime/components/react/event.config.ts +1 -6
- package/lib/runtime/components/react/getInnerListeners.ts +148 -191
- package/lib/runtime/components/react/mpx-button.tsx +7 -7
- package/lib/runtime/components/react/mpx-canvas/index.tsx +25 -17
- package/lib/runtime/components/react/mpx-checkbox-group.tsx +4 -3
- package/lib/runtime/components/react/mpx-checkbox.tsx +8 -9
- package/lib/runtime/components/react/mpx-form.tsx +25 -19
- package/lib/runtime/components/react/mpx-icon/index.tsx +4 -3
- package/lib/runtime/components/react/mpx-image.tsx +4 -3
- package/lib/runtime/components/react/mpx-inline-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-input.tsx +8 -14
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +2 -2
- package/lib/runtime/components/react/mpx-label.tsx +4 -5
- package/lib/runtime/components/react/mpx-movable-area.tsx +22 -13
- package/lib/runtime/components/react/mpx-movable-view.tsx +47 -40
- package/lib/runtime/components/react/mpx-navigator.tsx +4 -6
- package/lib/runtime/components/react/mpx-picker/date.tsx +226 -69
- package/lib/runtime/components/react/mpx-picker/dateData.ts +22 -0
- package/lib/runtime/components/react/mpx-picker/index.tsx +242 -118
- package/lib/runtime/components/react/mpx-picker/multiSelector.tsx +96 -139
- package/lib/runtime/components/react/mpx-picker/region.tsx +217 -89
- package/lib/runtime/components/react/mpx-picker/selector.tsx +75 -80
- package/lib/runtime/components/react/mpx-picker/time.tsx +119 -236
- package/lib/runtime/components/react/mpx-picker/type.ts +85 -71
- package/lib/runtime/components/react/{mpx-picker-view.tsx → mpx-picker-view/index.tsx} +24 -21
- package/lib/runtime/components/react/{mpx-picker-view-column.tsx → mpx-picker-view-column/index.tsx} +70 -19
- package/lib/runtime/components/react/{mpx-picker-view-column-item.tsx → mpx-picker-view-column/pickerViewColumnItem.tsx} +8 -5
- package/lib/runtime/components/react/{pickerFaces.ts → mpx-picker-view-column/pickerViewFaces.ts} +7 -0
- package/lib/runtime/components/react/mpx-popup/index.tsx +86 -0
- package/lib/runtime/components/react/mpx-popup/popupBase.tsx +130 -0
- package/lib/runtime/components/react/mpx-radio-group.tsx +4 -3
- package/lib/runtime/components/react/mpx-radio.tsx +8 -9
- package/lib/runtime/components/react/mpx-rich-text/index.tsx +15 -6
- package/lib/runtime/components/react/mpx-scroll-view.tsx +326 -96
- package/lib/runtime/components/react/mpx-simple-text.tsx +17 -8
- package/lib/runtime/components/react/mpx-simple-view.tsx +17 -16
- package/lib/runtime/components/react/mpx-sticky-header.tsx +179 -0
- package/lib/runtime/components/react/mpx-sticky-section.tsx +96 -0
- package/lib/runtime/components/react/mpx-swiper-item.tsx +31 -24
- package/lib/runtime/components/react/mpx-swiper.tsx +69 -65
- package/lib/runtime/components/react/mpx-switch.tsx +19 -14
- package/lib/runtime/components/react/mpx-text.tsx +16 -13
- package/lib/runtime/components/react/mpx-video.tsx +36 -35
- package/lib/runtime/components/react/mpx-view.tsx +41 -17
- package/lib/runtime/components/react/mpx-web-view.tsx +16 -16
- package/lib/runtime/components/react/types/getInnerListeners.d.ts +69 -35
- package/lib/runtime/components/react/useAnimationHooks.ts +29 -9
- package/lib/runtime/components/react/utils.tsx +13 -2
- package/lib/runtime/components/web/mpx-input.vue +1 -1
- package/lib/runtime/components/web/mpx-scroll-view.vue +21 -4
- package/lib/runtime/components/web/mpx-sticky-header.vue +91 -0
- package/lib/runtime/components/web/mpx-sticky-section.vue +15 -0
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/template-compiler/compiler.js +7 -7
- package/package.json +3 -4
- /package/lib/runtime/components/react/dist/{pickerVIewContext.js → mpx-picker-view/pickerVIewContext.js} +0 -0
- /package/lib/runtime/components/react/dist/{pickerViewIndicator.jsx → mpx-picker-view-column/pickerViewIndicator.jsx} +0 -0
- /package/lib/runtime/components/react/dist/{pickerViewMask.jsx → mpx-picker-view-column/pickerViewMask.jsx} +0 -0
- /package/lib/runtime/components/react/{pickerVIewContext.ts → mpx-picker-view/pickerVIewContext.ts} +0 -0
- /package/lib/runtime/components/react/{pickerViewIndicator.tsx → mpx-picker-view-column/pickerViewIndicator.tsx} +0 -0
- /package/lib/runtime/components/react/{pickerViewMask.tsx → mpx-picker-view-column/pickerViewMask.tsx} +0 -0
|
@@ -1,86 +1,243 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import { DateProps,
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import React, { forwardRef, useCallback, useMemo, useRef, useState, useEffect, useImperativeHandle } from 'react'
|
|
2
|
+
import { StyleSheet, Text, View } from 'react-native'
|
|
3
|
+
import MpxPickerView from '../mpx-picker-view'
|
|
4
|
+
import MpxPickerViewColumn from '../mpx-picker-view-column'
|
|
5
|
+
import { DateProps, TimeValue } from './type'
|
|
6
|
+
import { HandlerRef } from '../useNodesRef'
|
|
7
|
+
import { useUpdateEffect } from '../utils'
|
|
8
|
+
import { years, months, daysInMonth, wrapDate, daysInMonthLength, START_YEAR, END_YEAR } from './dateData'
|
|
9
|
+
|
|
10
|
+
type FormatObj = {
|
|
11
|
+
indexArr: number[]
|
|
12
|
+
rangeArr: string[][]
|
|
13
|
+
nameArr?: string[]
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
16
|
+
const START_DATE: TimeValue = `${START_YEAR}-01-01`
|
|
17
|
+
const END_DATE: TimeValue = `${END_YEAR}-12-31`
|
|
18
|
+
const START_DATE_ARR = [START_YEAR, 1, 1]
|
|
19
|
+
const END_DATE_ARR = [END_YEAR, 12, 31]
|
|
20
|
+
|
|
21
|
+
const styles = StyleSheet.create({
|
|
22
|
+
pickerContainer: {
|
|
23
|
+
height: 240,
|
|
24
|
+
paddingHorizontal: 10,
|
|
25
|
+
borderTopLeftRadius: 10,
|
|
26
|
+
borderTopRightRadius: 10
|
|
27
|
+
},
|
|
28
|
+
pickerIndicator: {
|
|
29
|
+
height: 45
|
|
30
|
+
},
|
|
31
|
+
pickerItem: {
|
|
32
|
+
fontSize: 16,
|
|
33
|
+
lineHeight: 45,
|
|
34
|
+
textAlign: 'center'
|
|
35
|
+
}
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
const getColumnLength = (fields: DateProps['fields'] = 'day') => {
|
|
39
|
+
return fields === 'year' ? 1 : fields === 'month' ? 2 : 3
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const compareDateStr = (date1: TimeValue | number[], date2: TimeValue | number[]) => {
|
|
43
|
+
const [y1 = START_YEAR, m1 = 0, d1 = 0] = typeof date1 === 'string' ? date1.split('-').map(Number) : date1
|
|
44
|
+
const [y2 = START_YEAR, m2 = 0, d2 = 0] = typeof date2 === 'string' ? date2.split('-').map(Number) : date2
|
|
45
|
+
const num1 = y1 * 10000 + m1 * 100 + d1
|
|
46
|
+
const num2 = y2 * 10000 + m2 * 100 + d2
|
|
47
|
+
if (num1 === num2) {
|
|
48
|
+
return 0
|
|
25
49
|
}
|
|
26
|
-
return
|
|
50
|
+
return num1 > num2 ? 1 : -1
|
|
27
51
|
}
|
|
28
52
|
|
|
29
|
-
const
|
|
30
|
-
const
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const layoutRef = useRef({})
|
|
34
|
-
const viewRef = useRef<View>(null)
|
|
35
|
-
const nodeRef = useRef<View>(null)
|
|
36
|
-
useNodesRef<View, DateProps>(props, ref, nodeRef, {
|
|
37
|
-
style
|
|
38
|
-
})
|
|
53
|
+
const getDateArr = (date: TimeValue | number[]): number[] => {
|
|
54
|
+
const [y, m, d] = typeof date === 'string' ? date.split('-').map(Number) : date
|
|
55
|
+
return [y || 0, m || 0, d || 0]
|
|
56
|
+
}
|
|
39
57
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
58
|
+
const calibrateDate = (date: TimeValue | number[], start: TimeValue, end: TimeValue): number[] => {
|
|
59
|
+
let startArr = getDateArr(start)
|
|
60
|
+
let endArr = getDateArr(end)
|
|
61
|
+
let dateArr = getDateArr(date)
|
|
62
|
+
if (compareDateStr(startArr, endArr) > 0) {
|
|
63
|
+
startArr = START_DATE_ARR
|
|
64
|
+
}
|
|
65
|
+
if (compareDateStr(endArr, startArr) < 0) {
|
|
66
|
+
endArr = END_DATE_ARR
|
|
67
|
+
}
|
|
68
|
+
if (compareDateStr(start, end) > 0) {
|
|
69
|
+
startArr = START_DATE_ARR
|
|
70
|
+
endArr = END_DATE_ARR
|
|
49
71
|
}
|
|
72
|
+
if (compareDateStr(dateArr, endArr) > 0) {
|
|
73
|
+
dateArr = endArr
|
|
74
|
+
}
|
|
75
|
+
if (compareDateStr(dateArr, startArr) < 0) {
|
|
76
|
+
dateArr = startArr
|
|
77
|
+
}
|
|
78
|
+
return dateArr
|
|
79
|
+
}
|
|
50
80
|
|
|
51
|
-
|
|
52
|
-
|
|
81
|
+
const initDateStr2Arr = (dateStr: TimeValue | number[], start: TimeValue, end: TimeValue): number[] => {
|
|
82
|
+
if (!dateStr) {
|
|
83
|
+
const today = new Date()
|
|
84
|
+
const todayYear = today.getFullYear()
|
|
85
|
+
const todayMonth = today.getMonth() + 1
|
|
86
|
+
const todayDay = today.getDate()
|
|
87
|
+
dateStr = [todayYear, todayMonth, todayDay]
|
|
53
88
|
}
|
|
89
|
+
const [y, m, d] = getDateArr(dateStr)
|
|
90
|
+
const year = Math.min(Math.max(START_YEAR, y), END_YEAR)
|
|
91
|
+
const month = Math.min(Math.max(1, m), 12)
|
|
92
|
+
const day = Math.min(Math.max(1, d), daysInMonthLength(year, month))
|
|
93
|
+
const res = [year, month, day]
|
|
94
|
+
return calibrateDate(res, start, end)
|
|
95
|
+
}
|
|
54
96
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
97
|
+
const valueStr2Obj = (
|
|
98
|
+
_value: TimeValue | number[] = '', // eg: 2025-2-12
|
|
99
|
+
limit: number,
|
|
100
|
+
start: TimeValue,
|
|
101
|
+
end: TimeValue
|
|
102
|
+
): FormatObj => {
|
|
103
|
+
const [y, m, d] = initDateStr2Arr(_value, start, end)
|
|
104
|
+
const ans = {
|
|
105
|
+
indexArr: [y - START_YEAR],
|
|
106
|
+
rangeArr: [years]
|
|
107
|
+
}
|
|
108
|
+
if (limit === 2) {
|
|
109
|
+
ans.indexArr.push(m - 1)
|
|
110
|
+
ans.rangeArr.push(months)
|
|
111
|
+
} else if (limit === 3) {
|
|
112
|
+
const days = daysInMonth(y, m)
|
|
113
|
+
ans.indexArr.push(m - 1, d - 1)
|
|
114
|
+
ans.rangeArr.push(months, days)
|
|
60
115
|
}
|
|
116
|
+
return ans
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const valueChanged2Obj = (currentObj: FormatObj, value: number[], limit = 3) => {
|
|
120
|
+
const currentValue = currentObj.indexArr
|
|
121
|
+
const rangeArr = currentObj.rangeArr
|
|
61
122
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
onDismiss,
|
|
70
|
-
disabled
|
|
123
|
+
if (limit === 3 && (currentValue[0] !== value[0] || currentValue[1] !== value[1])) {
|
|
124
|
+
const days = daysInMonth(value[0], value[1] + 1)
|
|
125
|
+
rangeArr[2] = days
|
|
126
|
+
const maxIndex = days.length - 1
|
|
127
|
+
if (value[2] > maxIndex) {
|
|
128
|
+
value[2] = maxIndex
|
|
129
|
+
}
|
|
71
130
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
indexArr: value,
|
|
134
|
+
rangeArr
|
|
75
135
|
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const valueChanged2Obj2 = (value: number[], limit = 3, start: TimeValue, end: TimeValue) => {
|
|
139
|
+
const y = value[0] + START_YEAR
|
|
140
|
+
const m = value[1] + 1
|
|
141
|
+
const d = value[2] + 1
|
|
142
|
+
return valueStr2Obj([y, m, d], limit, start, end)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const valueNum2String = (value: number[]) => {
|
|
146
|
+
return value.map((item, index) => {
|
|
147
|
+
if (index === 0) {
|
|
148
|
+
return item + START_YEAR
|
|
149
|
+
} else {
|
|
150
|
+
return wrapDate()(item + 1)
|
|
151
|
+
}
|
|
152
|
+
}).join('-')
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const hasDiff = (currentValue: number[], value: number[], limit = 3) => {
|
|
156
|
+
for (let i = 0; i < limit; i++) {
|
|
157
|
+
if (currentValue[i] !== value[i]) {
|
|
158
|
+
return true
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return false
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const PickerDate = forwardRef<
|
|
165
|
+
HandlerRef<View, DateProps>,
|
|
166
|
+
DateProps
|
|
167
|
+
>((props: DateProps, ref): React.JSX.Element => {
|
|
168
|
+
const { value = '', start = START_DATE, end = END_DATE, fields, bindchange } = props
|
|
169
|
+
const nodeRef = useRef(null)
|
|
170
|
+
const columnLength = useMemo(() => getColumnLength(fields), [fields])
|
|
171
|
+
const [formatObj, setFormatObj] = useState<FormatObj>(valueStr2Obj(value, columnLength, start, end))
|
|
172
|
+
const timerRef = useRef<NodeJS.Timeout | null>(null)
|
|
173
|
+
|
|
174
|
+
useEffect(() => {
|
|
175
|
+
return () => {
|
|
176
|
+
timerRef.current && clearTimeout(timerRef.current)
|
|
177
|
+
}
|
|
178
|
+
}, [])
|
|
179
|
+
|
|
180
|
+
useUpdateEffect(() => {
|
|
181
|
+
const calibratedValue = valueStr2Obj(value, columnLength, start, end)
|
|
182
|
+
setFormatObj(calibratedValue)
|
|
183
|
+
}, [value, columnLength, start, end])
|
|
184
|
+
|
|
185
|
+
const updateValue = useCallback((value: TimeValue = '') => {
|
|
186
|
+
const calibratedValue = valueStr2Obj(value, columnLength, start, end)
|
|
187
|
+
setFormatObj(calibratedValue)
|
|
188
|
+
}, [columnLength, start, end])
|
|
189
|
+
|
|
190
|
+
const _props = useRef(props)
|
|
191
|
+
_props.current = props
|
|
192
|
+
useImperativeHandle(ref, () => ({
|
|
193
|
+
updateValue,
|
|
194
|
+
getNodeInstance: () => ({
|
|
195
|
+
props: _props,
|
|
196
|
+
nodeRef,
|
|
197
|
+
instance: {
|
|
198
|
+
style: {}
|
|
199
|
+
}
|
|
200
|
+
})
|
|
201
|
+
}))
|
|
202
|
+
|
|
203
|
+
const onChange = useCallback((e: { detail: { value: number[] } }) => {
|
|
204
|
+
const { value } = e.detail
|
|
205
|
+
const currentValue = formatObj.indexArr
|
|
206
|
+
const newObj = valueChanged2Obj(formatObj, value, columnLength)
|
|
207
|
+
if (hasDiff(currentValue, value, columnLength)) {
|
|
208
|
+
setFormatObj(newObj)
|
|
209
|
+
const newObj2 = valueChanged2Obj2(value, columnLength, start, end)
|
|
210
|
+
if (hasDiff(newObj.indexArr, newObj2.indexArr, columnLength)) {
|
|
211
|
+
timerRef.current && clearTimeout(timerRef.current)
|
|
212
|
+
timerRef.current = setTimeout(() => setFormatObj(newObj2))
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
bindchange?.({ detail: { value: valueNum2String(newObj.indexArr) } })
|
|
216
|
+
}, [formatObj, columnLength, bindchange, start, end])
|
|
217
|
+
|
|
218
|
+
const renderColumn = () => {
|
|
219
|
+
return formatObj.rangeArr?.map((item, index) => (
|
|
220
|
+
// @ts-expect-error ignore
|
|
221
|
+
<MpxPickerViewColumn key={index}>
|
|
222
|
+
{item.map((item, index) => {
|
|
223
|
+
return <Text key={index} style={styles.pickerItem}>
|
|
224
|
+
{item}
|
|
225
|
+
</Text>
|
|
226
|
+
})}
|
|
227
|
+
</MpxPickerViewColumn>
|
|
228
|
+
))
|
|
229
|
+
}
|
|
230
|
+
|
|
76
231
|
return (
|
|
77
|
-
<
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
232
|
+
<MpxPickerView
|
|
233
|
+
style={styles.pickerContainer}
|
|
234
|
+
indicator-style={styles.pickerIndicator}
|
|
235
|
+
value={formatObj.indexArr}
|
|
236
|
+
bindchange={onChange}
|
|
237
|
+
>
|
|
238
|
+
{renderColumn()}
|
|
239
|
+
</MpxPickerView>)
|
|
83
240
|
})
|
|
84
241
|
|
|
85
|
-
|
|
86
|
-
export default
|
|
242
|
+
PickerDate.displayName = 'MpxPickerDate'
|
|
243
|
+
export default PickerDate
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const wrapDate = (union = '') => (num: number) => String(num).padStart(2, '0') + union
|
|
2
|
+
|
|
3
|
+
export const START_YEAR = 1900
|
|
4
|
+
export const END_YEAR = 2099
|
|
5
|
+
|
|
6
|
+
export const years = Array.from({ length: 200 }, (_, index) => index + START_YEAR + '年')
|
|
7
|
+
|
|
8
|
+
export const months = Array.from({ length: 12 }, (_, index) => index + 1).map(wrapDate('月'))
|
|
9
|
+
|
|
10
|
+
export const daysInMonthLength = (year: number, month: number) => {
|
|
11
|
+
return month === 2
|
|
12
|
+
? year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)
|
|
13
|
+
? 29
|
|
14
|
+
: 28
|
|
15
|
+
: [4, 6, 9, 11].includes(month)
|
|
16
|
+
? 30
|
|
17
|
+
: 31
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const daysInMonth = (year: number, month: number) => {
|
|
21
|
+
return Array.from({ length: daysInMonthLength(year, month) }, (_, index) => index + 1).map(wrapDate('日'))
|
|
22
|
+
}
|