@mpxjs/webpack-plugin 2.10.3 → 2.10.4
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/config.js +2 -1
- package/lib/index.js +1 -1
- package/lib/platform/json/wx/index.js +6 -3
- package/lib/platform/style/wx/index.js +23 -12
- package/lib/platform/template/wx/component-config/button.js +19 -2
- package/lib/platform/template/wx/component-config/canvas.js +4 -0
- package/lib/platform/template/wx/component-config/checkbox-group.js +4 -0
- package/lib/platform/template/wx/component-config/checkbox.js +4 -0
- package/lib/platform/template/wx/component-config/cover-image.js +7 -1
- package/lib/platform/template/wx/component-config/cover-view.js +4 -0
- package/lib/platform/template/wx/component-config/fix-component-name.js +3 -2
- package/lib/platform/template/wx/component-config/form.js +7 -1
- package/lib/platform/template/wx/component-config/icon.js +4 -0
- package/lib/platform/template/wx/component-config/image.js +7 -1
- package/lib/platform/template/wx/component-config/input.js +18 -3
- package/lib/platform/template/wx/component-config/label.js +4 -0
- package/lib/platform/template/wx/component-config/movable-area.js +7 -1
- package/lib/platform/template/wx/component-config/movable-view.js +12 -3
- package/lib/platform/template/wx/component-config/navigator.js +4 -0
- package/lib/platform/template/wx/component-config/picker-view-column.js +4 -0
- package/lib/platform/template/wx/component-config/picker-view.js +7 -1
- package/lib/platform/template/wx/component-config/picker.js +7 -1
- package/lib/platform/template/wx/component-config/radio-group.js +4 -0
- package/lib/platform/template/wx/component-config/radio.js +4 -0
- package/lib/platform/template/wx/component-config/rich-text.js +4 -0
- package/lib/platform/template/wx/component-config/root-portal.js +4 -0
- package/lib/platform/template/wx/component-config/scroll-view.js +10 -2
- package/lib/platform/template/wx/component-config/swiper-item.js +7 -1
- package/lib/platform/template/wx/component-config/swiper.js +12 -3
- package/lib/platform/template/wx/component-config/switch.js +4 -0
- package/lib/platform/template/wx/component-config/text.js +24 -3
- package/lib/platform/template/wx/component-config/textarea.js +17 -2
- package/lib/platform/template/wx/component-config/unsupported.js +7 -0
- package/lib/platform/template/wx/component-config/video.js +10 -2
- package/lib/platform/template/wx/component-config/view.js +11 -1
- package/lib/platform/template/wx/component-config/web-view.js +4 -0
- package/lib/platform/template/wx/index.js +42 -75
- package/lib/react/processScript.js +1 -18
- package/lib/runtime/components/react/dist/event.config.js +1 -0
- package/lib/runtime/components/react/dist/getInnerListeners.js +18 -7
- package/lib/runtime/components/react/dist/mpx-canvas/index.jsx +1 -1
- package/lib/runtime/components/react/dist/mpx-inline-text.jsx +11 -0
- package/lib/runtime/components/react/dist/mpx-input.jsx +3 -6
- package/lib/runtime/components/react/dist/mpx-keyboard-avoiding-view.jsx +2 -2
- 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 +178 -96
- 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} +3 -3
- 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-scroll-view.jsx +192 -25
- package/lib/runtime/components/react/dist/mpx-simple-text.jsx +8 -7
- package/lib/runtime/components/react/dist/mpx-simple-view.jsx +11 -15
- package/lib/runtime/components/react/dist/mpx-video.jsx +3 -3
- package/lib/runtime/components/react/dist/mpx-web-view.jsx +7 -4
- package/lib/runtime/components/react/dist/utils.jsx +2 -1
- package/lib/runtime/components/react/event.config.ts +2 -0
- package/lib/runtime/components/react/getInnerListeners.ts +28 -25
- package/lib/runtime/components/react/mpx-canvas/index.tsx +2 -2
- package/lib/runtime/components/react/mpx-inline-text.tsx +18 -0
- package/lib/runtime/components/react/mpx-input.tsx +2 -6
- package/lib/runtime/components/react/mpx-keyboard-avoiding-view.tsx +1 -1
- 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 +239 -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} +7 -7
- 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-scroll-view.tsx +249 -43
- package/lib/runtime/components/react/mpx-simple-text.tsx +10 -8
- package/lib/runtime/components/react/mpx-simple-view.tsx +11 -16
- package/lib/runtime/components/react/mpx-video.tsx +2 -2
- package/lib/runtime/components/react/mpx-web-view.tsx +7 -4
- package/lib/runtime/components/react/types/getInnerListeners.d.ts +5 -1
- package/lib/runtime/components/react/types/global.d.ts +1 -1
- package/lib/runtime/components/react/utils.tsx +3 -2
- package/lib/runtime/components/web/mini-video-controls.min.js +1 -1
- package/lib/runtime/components/web/mpx-input.vue +1 -1
- package/lib/runtime/stringify.wxs +2 -2
- package/lib/template-compiler/compiler.js +8 -8
- package/lib/utils/env.js +1 -1
- package/package.json +4 -5
- /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,268 +1,151 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import React, { forwardRef, useState, useRef, useEffect } from 'react'
|
|
5
|
-
import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
|
|
1
|
+
import React, { forwardRef, useRef, useState, useEffect, useImperativeHandle } from 'react'
|
|
2
|
+
import { StyleSheet, Text, View } from 'react-native'
|
|
3
|
+
import { warn } from '@mpxjs/utils'
|
|
6
4
|
import { TimeProps } from './type'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
hideModal: {
|
|
21
|
-
opacity: 1,
|
|
22
|
-
height: 0
|
|
23
|
-
},
|
|
24
|
-
modal: {
|
|
25
|
-
backgroundColor: 'black',
|
|
26
|
-
opacity: 0.5
|
|
27
|
-
},
|
|
28
|
-
centeredView: {
|
|
29
|
-
position: 'absolute',
|
|
30
|
-
bottom: 0,
|
|
31
|
-
width: '100%',
|
|
32
|
-
overflow: 'scroll'
|
|
33
|
-
},
|
|
34
|
-
btnLine: {
|
|
35
|
-
width: '100%',
|
|
36
|
-
flex: 1,
|
|
37
|
-
flexDirection: 'row',
|
|
38
|
-
justifyContent: 'space-between',
|
|
39
|
-
borderColor: 20,
|
|
40
|
-
borderBottomWidth: 1,
|
|
41
|
-
backgroundColor: 'white',
|
|
42
|
-
paddingLeft: 40,
|
|
43
|
-
paddingRight: 40
|
|
5
|
+
import MpxPickerView from '../mpx-picker-view'
|
|
6
|
+
import MpxPickerViewColumn from '../mpx-picker-view-column'
|
|
7
|
+
import { HandlerRef } from '../useNodesRef'
|
|
8
|
+
import { useUpdateEffect } from '../utils'
|
|
9
|
+
|
|
10
|
+
const styles = StyleSheet.create({
|
|
11
|
+
pickerContainer: {
|
|
12
|
+
width: 120,
|
|
13
|
+
height: 240,
|
|
14
|
+
alignSelf: 'center',
|
|
15
|
+
paddingHorizontal: 10,
|
|
16
|
+
borderTopLeftRadius: 10,
|
|
17
|
+
borderTopRightRadius: 10
|
|
44
18
|
},
|
|
45
|
-
|
|
46
|
-
height:
|
|
47
|
-
display: 'flex',
|
|
48
|
-
justifyContent: 'center'
|
|
19
|
+
pickerIndicator: {
|
|
20
|
+
height: 45
|
|
49
21
|
},
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
},
|
|
55
|
-
btntext: {
|
|
56
|
-
color: '#0ae',
|
|
57
|
-
fontSize: 18
|
|
22
|
+
pickerItem: {
|
|
23
|
+
fontSize: 20,
|
|
24
|
+
lineHeight: 45,
|
|
25
|
+
textAlign: 'center'
|
|
58
26
|
}
|
|
59
|
-
}
|
|
27
|
+
})
|
|
60
28
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
// [9, 59] to 09:59
|
|
66
|
-
function formatStr (arr: any[]) {
|
|
67
|
-
let [hour, minute] = arr
|
|
68
|
-
if (hour < 10) {
|
|
69
|
-
hour = '0' + hour
|
|
70
|
-
}
|
|
71
|
-
if (minute < 10) {
|
|
72
|
-
minute = '0' + minute
|
|
73
|
-
}
|
|
74
|
-
return hour + ':' + minute
|
|
75
|
-
}
|
|
29
|
+
type Hour = number
|
|
30
|
+
type Minute = number
|
|
31
|
+
type TimeArray = [Hour, Minute]
|
|
76
32
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
label: toSingleStr(i),
|
|
82
|
-
value: i,
|
|
83
|
-
children: []
|
|
84
|
-
}
|
|
85
|
-
arrMinute.push(obj)
|
|
33
|
+
const time2Array = (time: string, defaultValue: TimeArray = [0, 0]): TimeArray => {
|
|
34
|
+
if (typeof time !== 'string') {
|
|
35
|
+
warn('[mpx runtime warn]: mpx-picker prop time must be a string')
|
|
36
|
+
return defaultValue
|
|
86
37
|
}
|
|
87
|
-
|
|
38
|
+
let [hour = 0, minute = 0] = time.split(':').map(Number)
|
|
39
|
+
hour = Math.min(Math.max(hour, 0), 23)
|
|
40
|
+
minute = Math.min(Math.max(minute, 0), 59)
|
|
41
|
+
return [hour, minute]
|
|
88
42
|
}
|
|
89
|
-
function generateColumns (): any[] {
|
|
90
|
-
const pickData: any[] = []
|
|
91
|
-
for (let i = 0; i <= 23; i++) {
|
|
92
|
-
const obj = {
|
|
93
|
-
label: toSingleStr(i),
|
|
94
|
-
value: i,
|
|
95
|
-
children: generateMinute()
|
|
96
|
-
}
|
|
97
|
-
pickData.push(obj)
|
|
98
|
-
}
|
|
99
43
|
|
|
100
|
-
|
|
44
|
+
const time2String = (time: TimeArray): string => {
|
|
45
|
+
return time.map(i => i.toString().padStart(2, '0')).join(':')
|
|
101
46
|
}
|
|
102
47
|
|
|
103
|
-
|
|
104
|
-
return
|
|
48
|
+
const time2Minutes = (time: TimeArray): number => {
|
|
49
|
+
return time[0] * 60 + time[1]
|
|
105
50
|
}
|
|
106
51
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
52
|
+
const calibrateTime = (
|
|
53
|
+
time: string | TimeArray,
|
|
54
|
+
start: string | TimeArray = [0, 0],
|
|
55
|
+
end: string | TimeArray = [23, 59]
|
|
56
|
+
): TimeArray => {
|
|
57
|
+
time = typeof time === 'string' ? time2Array(time) : time
|
|
58
|
+
start = typeof start === 'string' ? time2Array(start) : start
|
|
59
|
+
end = typeof end === 'string' ? time2Array(end) : end
|
|
60
|
+
const current = time2Minutes(time)
|
|
61
|
+
if (current < time2Minutes(start)) {
|
|
62
|
+
return start
|
|
63
|
+
} else if (current > time2Minutes(end)) {
|
|
64
|
+
return end
|
|
65
|
+
} else {
|
|
66
|
+
return time
|
|
67
|
+
}
|
|
112
68
|
}
|
|
113
69
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (strSel < strStart || strSel > strEnd) return false
|
|
117
|
-
return true
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* [{label:'', value: '', key: '', children: []}]
|
|
121
|
-
label: string | ReactNode
|
|
122
|
-
value: string | number
|
|
123
|
-
key?: string | number
|
|
124
|
-
children?: PickerColumnItem[]
|
|
125
|
-
*/
|
|
126
|
-
// start="02:10" end = 23:01
|
|
70
|
+
const hoursRange = Array.from({ length: 24 }, (_, i) => i.toString().padStart(2, '0'))
|
|
71
|
+
const minutesRange = Array.from({ length: 60 }, (_, i) => i.toString().padStart(2, '0'))
|
|
127
72
|
|
|
128
|
-
const
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
}
|
|
134
|
-
const defaultValue = formatStrToInt(value)
|
|
135
|
-
const [timevalue, setTimeValue] = useState(defaultValue)
|
|
136
|
-
// 存储layout布局信息
|
|
137
|
-
const layoutRef = useRef({})
|
|
138
|
-
const viewRef = useRef<View>(null)
|
|
139
|
-
const nodeRef = useRef<View>(null)
|
|
140
|
-
useNodesRef<View, TimeProps>(props, ref, nodeRef, { style })
|
|
141
|
-
// 存储modal的布局信息
|
|
142
|
-
const modalLayoutRef = useRef({})
|
|
143
|
-
const modalRef = useRef<View>(null)
|
|
144
|
-
const [visible, setVisible] = useState(false)
|
|
145
|
-
const columnData = generateColumns()
|
|
146
|
-
const [data, setData] = useState(columnData)
|
|
147
|
-
const [offsetTop, setOffsetTop] = useState(0)
|
|
148
|
-
const strStart = toStr(start)
|
|
149
|
-
const strEnd = toStr(end)
|
|
73
|
+
const PickerTime = forwardRef<
|
|
74
|
+
HandlerRef<View, TimeProps>,
|
|
75
|
+
TimeProps
|
|
76
|
+
>((props: TimeProps, ref): React.JSX.Element => {
|
|
77
|
+
const { value = '00:00', start = '00:00', end = '23:59', bindchange } = props
|
|
150
78
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
79
|
+
const nodeRef = useRef(null)
|
|
80
|
+
const timerRef = useRef<NodeJS.Timeout | null>(null)
|
|
81
|
+
const startArray = time2Array(start)
|
|
82
|
+
const endArray = time2Array(end, [23, 59])
|
|
83
|
+
const [formatValue, setFormatValue] = useState<TimeArray>(calibrateTime(value, startArray, endArray))
|
|
155
84
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
nValue && setTimeValue(nValue)
|
|
160
|
-
}
|
|
161
|
-
}, [value])
|
|
162
|
-
|
|
163
|
-
// console.log('---------------visible---', visible, JSON.stringify(columnData))
|
|
164
|
-
const handleModalStatus = (status: boolean) => {
|
|
165
|
-
setVisible(status)
|
|
85
|
+
const updateValue = (value = '00:00') => {
|
|
86
|
+
const calibratedValue = calibrateTime(value, startArray, endArray)
|
|
87
|
+
setFormatValue(calibratedValue)
|
|
166
88
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
89
|
+
|
|
90
|
+
const _props = useRef(props)
|
|
91
|
+
_props.current = props
|
|
92
|
+
useImperativeHandle(ref, () => ({
|
|
93
|
+
updateValue,
|
|
94
|
+
getNodeInstance: () => ({
|
|
95
|
+
props: _props,
|
|
96
|
+
nodeRef,
|
|
97
|
+
instance: {
|
|
98
|
+
style: {}
|
|
172
99
|
}
|
|
173
100
|
})
|
|
174
|
-
}
|
|
101
|
+
}))
|
|
175
102
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
const handleChildClick = () => {
|
|
182
|
-
handleModalStatus(true)
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
const handlePickChange = (date: number[]): void => {
|
|
186
|
-
// 不是有效的值
|
|
187
|
-
if (!checkSelectedIsValid(strStart, strEnd, date)) {
|
|
188
|
-
setTimeValue(timevalue)
|
|
189
|
-
} else {
|
|
190
|
-
// [9, 13]
|
|
191
|
-
setTimeValue(date)
|
|
103
|
+
useEffect(() => {
|
|
104
|
+
return () => {
|
|
105
|
+
timerRef.current && clearTimeout(timerRef.current)
|
|
192
106
|
}
|
|
193
|
-
}
|
|
107
|
+
}, [])
|
|
194
108
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
})
|
|
200
|
-
}
|
|
109
|
+
useUpdateEffect(() => {
|
|
110
|
+
const calibratedValue = calibrateTime(value, startArray, endArray)
|
|
111
|
+
setFormatValue(calibratedValue)
|
|
112
|
+
}, [value])
|
|
201
113
|
|
|
202
|
-
const
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
})
|
|
207
|
-
}
|
|
114
|
+
const onChange = (e: { detail: { value: TimeArray } }) => {
|
|
115
|
+
const { value } = e.detail
|
|
116
|
+
const calibratedValue = calibrateTime(value, startArray, endArray)
|
|
117
|
+
bindchange?.({ detail: { value: time2String(calibratedValue) } })
|
|
208
118
|
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
ref: nodeRef,
|
|
212
|
-
data,
|
|
213
|
-
value: timevalue,
|
|
214
|
-
defaultValue: timevalue,
|
|
215
|
-
cols: 2,
|
|
216
|
-
onChange: handlePickChange
|
|
119
|
+
if (value[0] !== formatValue[0] || value[1] !== formatValue[1]) {
|
|
120
|
+
setFormatValue(value)
|
|
217
121
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
<View style={styles.cancel}>
|
|
222
|
-
<TouchableWithoutFeedback onPress={handleCancel}>
|
|
223
|
-
<Text style={styles.btntext}>取消</Text>
|
|
224
|
-
</TouchableWithoutFeedback>
|
|
225
|
-
</View>
|
|
226
|
-
<View style={styles.ok}>
|
|
227
|
-
<TouchableWithoutFeedback onPress={handleConfirm}>
|
|
228
|
-
<Text style={styles.btntext}>确定</Text>
|
|
229
|
-
</TouchableWithoutFeedback>
|
|
230
|
-
</View>
|
|
231
|
-
</View>
|
|
232
|
-
<PickerView {...pickerProps}></PickerView>
|
|
233
|
-
</View>
|
|
234
|
-
)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
const renderChildren = () => {
|
|
238
|
-
const touchProps = {
|
|
239
|
-
onLayout: onElementLayout,
|
|
240
|
-
ref: viewRef
|
|
122
|
+
if (value[0] !== calibratedValue[0] || value[1] !== calibratedValue[1]) {
|
|
123
|
+
timerRef.current && clearTimeout(timerRef.current)
|
|
124
|
+
timerRef.current = setTimeout(() => setFormatValue(calibratedValue))
|
|
241
125
|
}
|
|
242
|
-
return <View>
|
|
243
|
-
<TouchableWithoutFeedback onPress={handleChildClick}>
|
|
244
|
-
<View {...touchProps}>{children}</View>
|
|
245
|
-
</TouchableWithoutFeedback>
|
|
246
|
-
</View>
|
|
247
126
|
}
|
|
248
127
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
>
|
|
258
|
-
{
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
128
|
+
return (
|
|
129
|
+
<MpxPickerView
|
|
130
|
+
style={styles.pickerContainer}
|
|
131
|
+
indicator-style={styles.pickerIndicator}
|
|
132
|
+
value={formatValue}
|
|
133
|
+
bindchange={onChange}
|
|
134
|
+
>
|
|
135
|
+
{/* @ts-expect-error ignore */}
|
|
136
|
+
<MpxPickerViewColumn key='hour'>
|
|
137
|
+
{hoursRange.map((item, index) => (
|
|
138
|
+
<Text key={index} style={styles.pickerItem}>{item}</Text>
|
|
139
|
+
))}
|
|
140
|
+
</MpxPickerViewColumn>
|
|
141
|
+
{/* @ts-expect-error ignore */}
|
|
142
|
+
<MpxPickerViewColumn key='minute'>
|
|
143
|
+
{minutesRange.map((item, index) => (
|
|
144
|
+
<Text key={index} style={styles.pickerItem}>{item}</Text>
|
|
145
|
+
))}
|
|
146
|
+
</MpxPickerViewColumn>
|
|
147
|
+
</MpxPickerView>)
|
|
264
148
|
})
|
|
265
149
|
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
export default _TimePicker
|
|
150
|
+
PickerTime.displayName = 'MpxPickerTime'
|
|
151
|
+
export default PickerTime
|
|
@@ -1,112 +1,126 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { PickerValue } from '@ant-design/react-native'
|
|
1
|
+
import React from 'react'
|
|
3
2
|
|
|
3
|
+
export const enum PickerMode {
|
|
4
|
+
SELECTOR = 'selector',
|
|
5
|
+
MULTI_SELECTOR = 'multiSelector',
|
|
6
|
+
TIME = 'time',
|
|
7
|
+
DATE = 'date',
|
|
8
|
+
REGION = 'region',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export type PickerValue = number
|
|
4
12
|
export type Obj = Record<string, any>
|
|
5
|
-
export type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
13
|
+
export type RangeItem = Obj | number | string
|
|
14
|
+
export type TimeValue = `${number}-${number}-${number}` | ''
|
|
15
|
+
|
|
16
|
+
/** 通用属性 */
|
|
17
|
+
export interface BasePickerProps {
|
|
18
|
+
/** --- 小程序属性 --- */
|
|
19
|
+
/** 选择器类型, 默认值 selector */
|
|
20
|
+
mode?: PickerMode
|
|
21
|
+
/** 是否禁用, 默认值 false */
|
|
9
22
|
disabled?: boolean
|
|
10
|
-
|
|
23
|
+
/** 点击取消按钮时触发 */
|
|
11
24
|
bindcancel?: Function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
getInnerLayout: Function
|
|
25
|
+
/** 头部标题 */
|
|
26
|
+
'header-text'?: string
|
|
27
|
+
/** --- 内部组件属性 --- */
|
|
28
|
+
/** 作为表单组件时的名称 */
|
|
29
|
+
name?: string
|
|
18
30
|
style?: Record<string, any>
|
|
19
|
-
|
|
31
|
+
children?: React.ReactNode
|
|
32
|
+
range?: RangeItem[]
|
|
33
|
+
ref?: any
|
|
20
34
|
}
|
|
21
35
|
|
|
22
|
-
export
|
|
23
|
-
mode:
|
|
24
|
-
|
|
25
|
-
value
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
36
|
+
export interface SelectorProps extends BasePickerProps {
|
|
37
|
+
mode: PickerMode.SELECTOR
|
|
38
|
+
/** 默认值 0 */
|
|
39
|
+
value?: number
|
|
40
|
+
/** 默认值 [] */
|
|
41
|
+
range?: RangeItem[]
|
|
42
|
+
'range-key'?: string
|
|
43
|
+
/** 点击确认按钮后触发 change 事件, event.detail = {value} */
|
|
44
|
+
bindchange?: Function
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export interface MultiSelectorProps extends BasePickerProps {
|
|
48
|
+
mode: PickerMode.MULTI_SELECTOR
|
|
49
|
+
/** 默认值 [] */
|
|
50
|
+
value?: number[]
|
|
51
|
+
range?: RangeItem[]
|
|
52
|
+
'range-key'?: string
|
|
53
|
+
bindchange?: Function
|
|
30
54
|
bindcolumnchange?: Function
|
|
31
|
-
// mode 为 selector 或 multiSelector 时,range 有效
|
|
32
|
-
range: Array<Array<any>>
|
|
33
|
-
// 当 range 是一个 Object Array 时,通过 range-key 来指定 Object 中 key 的值作为选择器《显示内容》 对象中的属性
|
|
34
|
-
'range-key': string
|
|
35
|
-
getInnerLayout: Function
|
|
36
|
-
style?: Record<string, any>
|
|
37
55
|
}
|
|
38
56
|
|
|
39
|
-
export
|
|
40
|
-
mode:
|
|
41
|
-
|
|
42
|
-
value
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
bindchange: Function
|
|
47
|
-
start: string
|
|
48
|
-
end: string
|
|
49
|
-
getInnerLayout: Function
|
|
50
|
-
style?: Record<string, any>
|
|
57
|
+
export interface TimeProps extends BasePickerProps {
|
|
58
|
+
mode: PickerMode.TIME
|
|
59
|
+
/** 表示选中的时间,格式为"hh:mm" */
|
|
60
|
+
value?: string
|
|
61
|
+
start?: string
|
|
62
|
+
end?: string
|
|
63
|
+
bindchange?: Function
|
|
51
64
|
}
|
|
52
65
|
|
|
53
|
-
export
|
|
54
|
-
mode:
|
|
55
|
-
|
|
56
|
-
value
|
|
66
|
+
export interface DateProps extends BasePickerProps {
|
|
67
|
+
mode: PickerMode.DATE
|
|
68
|
+
/** 默认值 '' */
|
|
69
|
+
value?: TimeValue
|
|
70
|
+
start?: TimeValue
|
|
71
|
+
end?: TimeValue
|
|
72
|
+
/** 有效值 year,month,day,表示选择器的粒度 */
|
|
57
73
|
fields?: 'day' | 'month' | 'year'
|
|
58
|
-
|
|
59
|
-
children: ReactNode
|
|
60
|
-
bindcancel?: Function
|
|
61
|
-
bindchange: Function
|
|
62
|
-
start: string
|
|
63
|
-
end: string
|
|
64
|
-
getInnerLayout: Function
|
|
65
|
-
style?: Record<string, any>
|
|
74
|
+
bindchange?: Function
|
|
66
75
|
}
|
|
67
76
|
|
|
68
|
-
export
|
|
69
|
-
mode:
|
|
70
|
-
|
|
71
|
-
value
|
|
72
|
-
|
|
77
|
+
export interface RegionProps extends BasePickerProps {
|
|
78
|
+
mode: PickerMode.REGION
|
|
79
|
+
/** 表示选中的省市区,默认选中每一列的第一个值, 默认值 [] */
|
|
80
|
+
value?: string[]
|
|
81
|
+
/** 默认值 region */
|
|
82
|
+
level?: 'province' | 'city' | 'region' | 'sub-district'
|
|
83
|
+
/** 可为每一列的顶部添加一个自定义的项 */
|
|
73
84
|
'custom-item'?: string
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
bindchange: Function
|
|
78
|
-
getInnerLayout: Function
|
|
79
|
-
style?: Record<string, any>
|
|
85
|
+
/** value 改变时触发 change 事件, event.detail = {value, code, postcode},
|
|
86
|
+
* 其中字段 code 是统计用区划代码, postcode 是邮政编码 */
|
|
87
|
+
bindchange?: Function
|
|
80
88
|
}
|
|
81
89
|
|
|
82
|
-
export
|
|
90
|
+
export interface RegionObj {
|
|
83
91
|
value: string
|
|
84
92
|
code: string
|
|
85
93
|
postcode?: string
|
|
86
94
|
children?: RegionObj[]
|
|
87
95
|
}
|
|
88
96
|
|
|
89
|
-
export
|
|
97
|
+
export interface PickerData {
|
|
90
98
|
value: string
|
|
91
99
|
label: string
|
|
92
|
-
children?:
|
|
100
|
+
children?: Object[]
|
|
93
101
|
}
|
|
94
102
|
|
|
95
|
-
export
|
|
103
|
+
export interface EventType {
|
|
96
104
|
detail: {
|
|
97
105
|
value: PickerValue[]
|
|
98
106
|
}
|
|
99
107
|
}
|
|
100
108
|
|
|
101
|
-
export
|
|
109
|
+
export interface LayoutType {
|
|
102
110
|
nativeEvent: {
|
|
103
111
|
layout: Obj
|
|
104
112
|
}
|
|
105
113
|
}
|
|
106
114
|
|
|
107
|
-
|
|
115
|
+
export interface FormType {
|
|
108
116
|
name: string
|
|
109
117
|
}
|
|
110
118
|
|
|
111
|
-
export type PickerProps =
|
|
112
|
-
|
|
119
|
+
export type PickerProps =
|
|
120
|
+
| SelectorProps
|
|
121
|
+
| MultiSelectorProps
|
|
122
|
+
| TimeProps
|
|
123
|
+
| DateProps
|
|
124
|
+
| RegionProps
|
|
125
|
+
|
|
126
|
+
export type LanguageCode = 'zh-CN' | 'en-US'
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { View } from 'react-native'
|
|
2
2
|
import React, { forwardRef, useRef } from 'react'
|
|
3
|
-
import useInnerProps, { getCustomEvent } from '
|
|
4
|
-
import useNodesRef, { HandlerRef } from '
|
|
3
|
+
import useInnerProps, { getCustomEvent } from '../getInnerListeners'
|
|
4
|
+
import useNodesRef, { HandlerRef } from '../useNodesRef'
|
|
5
5
|
import {
|
|
6
6
|
useLayout,
|
|
7
7
|
splitProps,
|
|
@@ -9,9 +9,9 @@ import {
|
|
|
9
9
|
wrapChildren,
|
|
10
10
|
useTransformStyle,
|
|
11
11
|
extendObject
|
|
12
|
-
} from '
|
|
12
|
+
} from '../utils'
|
|
13
13
|
import { PickerViewStyleContext } from './pickerVIewContext'
|
|
14
|
-
import type { AnyFunc } from '
|
|
14
|
+
import type { AnyFunc } from '../types/common'
|
|
15
15
|
/**
|
|
16
16
|
* ✔ value
|
|
17
17
|
* ✔ bindchange
|
|
@@ -29,14 +29,14 @@ interface PickerViewProps {
|
|
|
29
29
|
children: React.ReactNode
|
|
30
30
|
value?: Array<number>
|
|
31
31
|
bindchange?: AnyFunc
|
|
32
|
-
style
|
|
32
|
+
style?: {
|
|
33
33
|
[key: string]: any
|
|
34
34
|
}
|
|
35
35
|
'indicator-style'?: Record<string, any>,
|
|
36
36
|
'mask-style'?: Record<string, any>,
|
|
37
|
-
'enable-var'
|
|
37
|
+
'enable-var'?: boolean
|
|
38
38
|
'external-var-context'?: Record<string, any>,
|
|
39
|
-
'enable-offset'
|
|
39
|
+
'enable-offset'?: boolean
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
interface PickerLayout {
|