@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,111 +1,239 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import React, { forwardRef, useCallback, useImperativeHandle, useMemo, useRef, useState } 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 { RegionProps } from './type'
|
|
3
6
|
import { regionData } from './regionData'
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
import { HandlerRef } from '../useNodesRef'
|
|
8
|
+
import { extendObject, useUpdateEffect } from '../utils'
|
|
9
|
+
|
|
10
|
+
type FormatObj = {
|
|
11
|
+
indexArr: number[]
|
|
12
|
+
rangeArr: string[][]
|
|
13
|
+
nameArr?: string[]
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const styles = StyleSheet.create({
|
|
17
|
+
pickerContainer: {
|
|
18
|
+
height: 240,
|
|
19
|
+
paddingHorizontal: 10,
|
|
20
|
+
borderTopLeftRadius: 10,
|
|
21
|
+
borderTopRightRadius: 10
|
|
22
|
+
},
|
|
23
|
+
pickerIndicator: {
|
|
24
|
+
height: 45
|
|
25
|
+
},
|
|
26
|
+
pickerItem: {
|
|
27
|
+
fontSize: 16,
|
|
28
|
+
lineHeight: 45,
|
|
29
|
+
textAlign: 'center'
|
|
30
|
+
}
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const rangeProvince = regionData.map(item => item.value)
|
|
34
|
+
|
|
35
|
+
const findIndex = (arr: string[], val: string) => {
|
|
36
|
+
const res = arr.findIndex(item => item === val)
|
|
37
|
+
return res === -1 ? 0 : res
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const getColumnLength = (level: RegionProps['level']) => {
|
|
41
|
+
if (level === 'province') {
|
|
42
|
+
return 1
|
|
43
|
+
} else if (level === 'city') {
|
|
44
|
+
return 2
|
|
45
|
+
} else {
|
|
46
|
+
return 3
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const valueStr2Obj = (
|
|
51
|
+
value: string[] = [],
|
|
52
|
+
limit: number,
|
|
53
|
+
customItem = ''
|
|
54
|
+
): FormatObj => {
|
|
55
|
+
const offsetIndex = customItem ? 1 : 0
|
|
56
|
+
let indexProvince = 0
|
|
57
|
+
if (customItem && value[0] === customItem) {
|
|
58
|
+
indexProvince = 0
|
|
59
|
+
} else {
|
|
60
|
+
indexProvince = findIndex(rangeProvince, value[0]) + offsetIndex
|
|
61
|
+
}
|
|
62
|
+
const ans: FormatObj = {
|
|
63
|
+
indexArr: [indexProvince],
|
|
64
|
+
rangeArr: [customItem ? [customItem, ...rangeProvince] : rangeProvince]
|
|
65
|
+
}
|
|
66
|
+
for (
|
|
67
|
+
let i = 1,
|
|
68
|
+
lastIndex = indexProvince,
|
|
69
|
+
lastData = regionData,
|
|
70
|
+
lastRange = rangeProvince;
|
|
71
|
+
i < limit;
|
|
72
|
+
i++
|
|
73
|
+
) {
|
|
74
|
+
if (customItem) {
|
|
75
|
+
if (lastIndex === 0) {
|
|
76
|
+
if (i === 1) {
|
|
77
|
+
ans.indexArr.push(0, 0)
|
|
78
|
+
ans.rangeArr.push([customItem], [customItem])
|
|
79
|
+
} else {
|
|
80
|
+
ans.indexArr.push(0)
|
|
81
|
+
ans.rangeArr.push([customItem])
|
|
82
|
+
}
|
|
83
|
+
return ans
|
|
84
|
+
}
|
|
18
85
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
86
|
+
lastData = lastData[lastIndex - offsetIndex].children!
|
|
87
|
+
lastRange = lastData.map((item) => item.value)
|
|
88
|
+
lastIndex = findIndex(lastRange, value[i]) + offsetIndex
|
|
89
|
+
if (customItem && customItem === value[i]) {
|
|
90
|
+
lastIndex = 0
|
|
24
91
|
}
|
|
25
|
-
|
|
92
|
+
ans.indexArr.push(Math.max(0, lastIndex))
|
|
93
|
+
ans.rangeArr.push(customItem ? [customItem, ...lastRange] : lastRange)
|
|
26
94
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
95
|
+
return ans
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const valueChanged2Obj = (currentObj: FormatObj, value: number[], limit = 3, customItem = '') => {
|
|
99
|
+
const offsetIndex = customItem ? 1 : 0
|
|
100
|
+
const newValue = new Array(limit).fill(0)
|
|
101
|
+
const currentValue = currentObj.indexArr
|
|
102
|
+
for (let i = 0; i < limit; i++) {
|
|
103
|
+
if (i === limit - 1) {
|
|
104
|
+
return {
|
|
105
|
+
indexArr: value,
|
|
106
|
+
rangeArr: currentObj.rangeArr
|
|
107
|
+
}
|
|
31
108
|
}
|
|
32
|
-
|
|
33
|
-
|
|
109
|
+
newValue[i] = value[i]
|
|
110
|
+
if (currentValue[i] !== value[i]) {
|
|
111
|
+
break
|
|
34
112
|
}
|
|
35
|
-
obj.push(region)
|
|
36
113
|
}
|
|
37
|
-
return obj
|
|
38
|
-
}
|
|
39
114
|
|
|
40
|
-
const
|
|
41
|
-
|
|
42
|
-
|
|
115
|
+
const ans: FormatObj = {
|
|
116
|
+
indexArr: [newValue[0]],
|
|
117
|
+
rangeArr: [currentObj.rangeArr[0]]
|
|
118
|
+
}
|
|
119
|
+
let data = regionData
|
|
120
|
+
for (let i = 1; i < limit; i++) {
|
|
121
|
+
if (customItem) {
|
|
122
|
+
if (newValue[i - 1] === 0) {
|
|
123
|
+
if (i === 1) {
|
|
124
|
+
ans.indexArr.push(0, 0)
|
|
125
|
+
ans.rangeArr.push([customItem], [customItem])
|
|
126
|
+
} else {
|
|
127
|
+
ans.indexArr.push(0)
|
|
128
|
+
ans.rangeArr.push([customItem])
|
|
129
|
+
}
|
|
130
|
+
return ans
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
data = data[newValue[i - 1] - offsetIndex].children!
|
|
134
|
+
const range = data.map(item => item.value)
|
|
135
|
+
ans.indexArr.push(newValue[i])
|
|
136
|
+
ans.rangeArr.push(customItem ? [customItem, ...range] : range)
|
|
137
|
+
}
|
|
138
|
+
return ans
|
|
139
|
+
}
|
|
43
140
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
141
|
+
const valueNum2String = (value: number[], customItem = '') => {
|
|
142
|
+
let data = regionData
|
|
143
|
+
return value.map(index => {
|
|
144
|
+
if (customItem) {
|
|
145
|
+
if (index === 0) {
|
|
146
|
+
return customItem
|
|
147
|
+
} else {
|
|
148
|
+
index -= 1
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
const item = data[index]
|
|
152
|
+
data = item.children!
|
|
153
|
+
return item.value
|
|
51
154
|
})
|
|
155
|
+
}
|
|
52
156
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
for (let i = 0; i < tmp.length; i++) {
|
|
59
|
-
if (tmp[i].value === item) {
|
|
60
|
-
const code = tmp[i].code
|
|
61
|
-
postcode.push(tmp[i].postcode)
|
|
62
|
-
tmp = tmp[i].children || []
|
|
63
|
-
return code
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
return item
|
|
67
|
-
}).filter(code => !!code)
|
|
68
|
-
const detail: Record<string, any> = { value, code }
|
|
69
|
-
if (postcode[2]) detail.postcode = postcode[2]
|
|
70
|
-
setRegionValue(value)
|
|
71
|
-
bindchange && bindchange({
|
|
72
|
-
detail
|
|
73
|
-
})
|
|
157
|
+
const hasDiff = (currentValue: number[], value: number[], limit = 3) => {
|
|
158
|
+
for (let i = 0; i < limit; i++) {
|
|
159
|
+
if (currentValue[i] !== value[i]) {
|
|
160
|
+
return true
|
|
161
|
+
}
|
|
74
162
|
}
|
|
163
|
+
return false
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
const PickerRegion = forwardRef<
|
|
167
|
+
HandlerRef<View, RegionProps>,
|
|
168
|
+
RegionProps
|
|
169
|
+
>((props: RegionProps, ref): React.JSX.Element => {
|
|
170
|
+
const { value = [], level = 'region', 'custom-item': customItem = '', bindchange } = props
|
|
171
|
+
const nodeRef = useRef(null)
|
|
172
|
+
const columnLength = useMemo(() => getColumnLength(level), [level])
|
|
173
|
+
const [formatObj, setFormatObj] = useState<FormatObj>(valueStr2Obj(value, columnLength, customItem))
|
|
174
|
+
|
|
175
|
+
const updateValue = useCallback((value: string[] = []) => {
|
|
176
|
+
const calibratedValue = valueStr2Obj(value, columnLength, customItem)
|
|
177
|
+
setFormatObj(calibratedValue)
|
|
178
|
+
}, [columnLength, customItem])
|
|
75
179
|
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
180
|
+
const _props = useRef(props)
|
|
181
|
+
_props.current = props
|
|
182
|
+
useImperativeHandle(ref, () => ({
|
|
183
|
+
updateValue,
|
|
184
|
+
getNodeInstance: () => ({
|
|
185
|
+
props: _props,
|
|
186
|
+
nodeRef,
|
|
187
|
+
instance: {
|
|
188
|
+
style: {}
|
|
189
|
+
}
|
|
80
190
|
})
|
|
81
|
-
}
|
|
191
|
+
}))
|
|
82
192
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
193
|
+
useUpdateEffect(() => {
|
|
194
|
+
const calibratedValue = valueStr2Obj(value, columnLength, customItem)
|
|
195
|
+
if (hasDiff(formatObj.indexArr, calibratedValue.indexArr, columnLength)) {
|
|
196
|
+
setFormatObj(calibratedValue)
|
|
197
|
+
}
|
|
198
|
+
}, [value, columnLength, customItem])
|
|
86
199
|
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
value
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
200
|
+
const onChange = useCallback((e: { detail: { value: number[] } }) => {
|
|
201
|
+
const { value } = e.detail
|
|
202
|
+
const currentValue = formatObj.indexArr
|
|
203
|
+
const newObj = valueChanged2Obj(formatObj, value, columnLength, customItem)
|
|
204
|
+
if (hasDiff(currentValue, value, columnLength)) {
|
|
205
|
+
setFormatObj(newObj)
|
|
206
|
+
}
|
|
207
|
+
bindchange?.({ detail: { value: valueNum2String(newObj.indexArr, customItem) } })
|
|
208
|
+
}, [formatObj, columnLength, customItem, bindchange])
|
|
95
209
|
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
210
|
+
const renderColumn = () => {
|
|
211
|
+
return formatObj.rangeArr?.map((item, index) => (
|
|
212
|
+
// @ts-expect-error ignore
|
|
213
|
+
<MpxPickerViewColumn key={index}>
|
|
214
|
+
{item.map((item, index) => {
|
|
215
|
+
const len = item.length
|
|
216
|
+
const style = extendObject({}, styles.pickerItem, {
|
|
217
|
+
fontSize: len > 5 ? 21 - len : 16
|
|
218
|
+
})
|
|
219
|
+
return <Text key={index} style={style}>
|
|
220
|
+
{item}
|
|
221
|
+
</Text>
|
|
222
|
+
})}
|
|
223
|
+
</MpxPickerViewColumn>
|
|
224
|
+
))
|
|
99
225
|
}
|
|
100
226
|
|
|
101
227
|
return (
|
|
102
|
-
<
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
228
|
+
<MpxPickerView
|
|
229
|
+
style={styles.pickerContainer}
|
|
230
|
+
indicator-style={styles.pickerIndicator}
|
|
231
|
+
value={formatObj.indexArr}
|
|
232
|
+
bindchange={onChange}
|
|
233
|
+
>
|
|
234
|
+
{renderColumn()}
|
|
235
|
+
</MpxPickerView>)
|
|
108
236
|
})
|
|
109
237
|
|
|
110
|
-
|
|
111
|
-
export default
|
|
238
|
+
PickerRegion.displayName = 'MpxPickerRegion'
|
|
239
|
+
export default PickerRegion
|
|
@@ -1,95 +1,90 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import useNodesRef, { HandlerRef } from '../useNodesRef' // 引入辅助函数
|
|
1
|
+
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react'
|
|
2
|
+
import { StyleSheet, Text, View } from 'react-native'
|
|
3
|
+
import { SelectorProps, Obj, RangeItem } from './type'
|
|
4
|
+
import MpxPickerView from '../mpx-picker-view'
|
|
5
|
+
import MpxPickerViewColumn from '../mpx-picker-view-column'
|
|
6
|
+
import { HandlerRef } from '../useNodesRef'
|
|
7
|
+
import { useUpdateEffect } from '../utils'
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
const styles = StyleSheet.create({
|
|
10
|
+
pickerContainer: {
|
|
11
|
+
height: 240,
|
|
12
|
+
paddingHorizontal: 10,
|
|
13
|
+
borderTopLeftRadius: 10,
|
|
14
|
+
borderTopRightRadius: 10
|
|
15
|
+
},
|
|
16
|
+
pickerIndicator: {
|
|
17
|
+
height: 45
|
|
18
|
+
},
|
|
19
|
+
pickerItem: {
|
|
20
|
+
fontSize: 18,
|
|
21
|
+
lineHeight: 45,
|
|
22
|
+
textAlign: 'center'
|
|
23
|
+
}
|
|
24
|
+
})
|
|
11
25
|
|
|
12
|
-
const formatRangeFun = (range:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
return { value: index, label: item }
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
return newRange as PickerColumn
|
|
26
|
+
const formatRangeFun = (range: RangeItem[], rangeKey = '') =>
|
|
27
|
+
rangeKey ? range.map((item: Obj) => item[rangeKey]) : range
|
|
28
|
+
|
|
29
|
+
const formatValueFn = (value: number | number[] = 0) => {
|
|
30
|
+
const _value = Array.isArray(value) ? value[0] : value
|
|
31
|
+
return +_value
|
|
22
32
|
}
|
|
23
33
|
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const [
|
|
30
|
-
|
|
31
|
-
const [data, setData] = useState(formatRange || [])
|
|
32
|
-
// 存储layout布局信息
|
|
33
|
-
const layoutRef = useRef({})
|
|
34
|
-
const viewRef = useRef<View>(null)
|
|
34
|
+
const PickerSelector = forwardRef<
|
|
35
|
+
HandlerRef<View, SelectorProps>,
|
|
36
|
+
SelectorProps
|
|
37
|
+
>((props: SelectorProps, ref): React.JSX.Element => {
|
|
38
|
+
const { value, range = [], bindchange } = props
|
|
39
|
+
const [formatValue, setFormatValue] = useState<number>(formatValueFn(value))
|
|
40
|
+
const formatRange: Array<any> = formatRangeFun(range, props['range-key'])
|
|
35
41
|
const nodeRef = useRef(null)
|
|
36
|
-
useNodesRef<View, SelectorProps>(props, ref, nodeRef, {
|
|
37
|
-
style
|
|
38
|
-
})
|
|
39
42
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
setSelected(() => {
|
|
46
|
-
return value
|
|
47
|
-
})
|
|
48
|
-
}, [range, value])
|
|
49
|
-
const defaultValue = [value]
|
|
43
|
+
const updateValue = (value = 0) => {
|
|
44
|
+
const newValue = formatValueFn(value)
|
|
45
|
+
setFormatValue(newValue)
|
|
46
|
+
}
|
|
50
47
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
48
|
+
useUpdateEffect(() => {
|
|
49
|
+
updateValue(value)
|
|
50
|
+
}, [value])
|
|
51
|
+
|
|
52
|
+
const _props = useRef(props)
|
|
53
|
+
_props.current = props
|
|
54
|
+
useImperativeHandle(ref, () => ({
|
|
55
|
+
updateValue,
|
|
56
|
+
getNodeInstance: () => ({
|
|
57
|
+
props: _props,
|
|
58
|
+
nodeRef,
|
|
59
|
+
instance: {
|
|
60
|
+
style: {}
|
|
55
61
|
}
|
|
56
62
|
})
|
|
57
|
-
}
|
|
63
|
+
}))
|
|
58
64
|
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
65
|
+
const onChange = (e: { detail: { value: number[] } }) => {
|
|
66
|
+
const { value } = e.detail
|
|
67
|
+
if (formatValue !== value[0]) {
|
|
68
|
+
setFormatValue(value[0])
|
|
69
|
+
}
|
|
70
|
+
bindchange?.({ detail: { value: value[0] + '' } })
|
|
64
71
|
}
|
|
65
72
|
|
|
66
|
-
const antPickerProps = {
|
|
67
|
-
ref: nodeRef,
|
|
68
|
-
data,
|
|
69
|
-
value: [selected],
|
|
70
|
-
cols: 1,
|
|
71
|
-
defaultValue,
|
|
72
|
-
itemHeight: 40,
|
|
73
|
-
onChange,
|
|
74
|
-
onDismiss: bindcancel && bindcancel
|
|
75
|
-
} as any
|
|
76
|
-
|
|
77
|
-
const touchProps = {
|
|
78
|
-
onLayout: onElementLayout,
|
|
79
|
-
ref: viewRef
|
|
80
|
-
}
|
|
81
73
|
return (
|
|
82
|
-
<
|
|
83
|
-
{
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
74
|
+
<MpxPickerView
|
|
75
|
+
style={styles.pickerContainer}
|
|
76
|
+
indicator-style={styles.pickerIndicator}
|
|
77
|
+
value={[formatValue]}
|
|
78
|
+
bindchange={onChange}
|
|
79
|
+
>
|
|
80
|
+
{/* @ts-expect-error ignore */}
|
|
81
|
+
<MpxPickerViewColumn>
|
|
82
|
+
{formatRange.map((item, index) => (
|
|
83
|
+
<Text key={index} style={styles.pickerItem}>{item}</Text>
|
|
84
|
+
))}
|
|
85
|
+
</MpxPickerViewColumn>
|
|
86
|
+
</MpxPickerView>)
|
|
91
87
|
})
|
|
92
88
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
export default _SelectorPicker
|
|
89
|
+
PickerSelector.displayName = 'MpxPickerSelector'
|
|
90
|
+
export default PickerSelector
|