@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,147 +1,87 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import React, { forwardRef, useCallback, useImperativeHandle, useRef, useState } from 'react';
|
|
2
|
+
import { StyleSheet, Text } from 'react-native';
|
|
3
|
+
import MpxPickerView from '../mpx-picker-view';
|
|
4
|
+
import MpxPickerViewColumn from '../mpx-picker-view-column';
|
|
5
|
+
const styles = StyleSheet.create({
|
|
6
|
+
pickerContainer: {
|
|
7
|
+
height: 240,
|
|
8
|
+
paddingHorizontal: 10,
|
|
9
|
+
borderTopLeftRadius: 10,
|
|
10
|
+
borderTopRightRadius: 10
|
|
11
|
+
},
|
|
12
|
+
pickerIndicator: {
|
|
13
|
+
height: 45
|
|
14
|
+
},
|
|
15
|
+
pickerItem: {
|
|
16
|
+
fontSize: 18,
|
|
17
|
+
lineHeight: 45,
|
|
18
|
+
textAlign: 'center'
|
|
8
19
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return convertToObj(item, rangeKey);
|
|
23
|
-
});
|
|
24
|
-
tmp.forEach(item => {
|
|
25
|
-
item.children = nextColData;
|
|
26
|
-
});
|
|
27
|
-
tmp = nextColData;
|
|
28
|
-
}
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
function getIndexByValues(range = [], value = []) {
|
|
32
|
-
let tmp = range;
|
|
33
|
-
return value.map(v => {
|
|
34
|
-
for (let i = 0; i < tmp.length; i++) {
|
|
35
|
-
if (tmp[i].value === v) {
|
|
36
|
-
tmp = tmp[i].children || [];
|
|
37
|
-
return i;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
return 0;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
// [1,1,2] 寻找出[]
|
|
44
|
-
function getInnerValueByIndex(range = [], value = []) {
|
|
45
|
-
let tmp = range;
|
|
46
|
-
return value.map(v => {
|
|
47
|
-
const current = tmp[v].value;
|
|
48
|
-
tmp = tmp[v].children;
|
|
49
|
-
return current;
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
// column = 1 value = ['无脊柱动物', '扁性动物', '吸血虫'] 根据column 和value 获取到当前列变动选择的值所在当前列的索引
|
|
53
|
-
function getColumnIndexByValue(range = [], column, value = []) {
|
|
54
|
-
let curRange = range;
|
|
55
|
-
let changeIndex = 0;
|
|
56
|
-
let tmpRange = [];
|
|
57
|
-
value.map((item, index) => {
|
|
58
|
-
if (column === index) {
|
|
59
|
-
curRange.map((ritem, rindex) => {
|
|
60
|
-
if (ritem.value === item) {
|
|
61
|
-
changeIndex = rindex;
|
|
62
|
-
}
|
|
63
|
-
return ritem;
|
|
64
|
-
});
|
|
65
|
-
}
|
|
66
|
-
else {
|
|
67
|
-
curRange.map((citem, cindex) => {
|
|
68
|
-
if (citem.value === item) {
|
|
69
|
-
tmpRange = citem.children;
|
|
70
|
-
}
|
|
71
|
-
return citem;
|
|
72
|
-
});
|
|
73
|
-
curRange = tmpRange;
|
|
74
|
-
}
|
|
75
|
-
return item;
|
|
76
|
-
});
|
|
77
|
-
return changeIndex;
|
|
78
|
-
}
|
|
79
|
-
const _MultiSelectorPicker = forwardRef((props, ref) => {
|
|
80
|
-
const { range, value, disabled, bindchange, bindcancel, children, bindcolumnchange, style } = props;
|
|
81
|
-
const formatRange = formatRangeFun(range, props['range-key']);
|
|
82
|
-
const initValue = getInnerValueByIndex(formatRange, value);
|
|
83
|
-
// 选中的索引值
|
|
84
|
-
const [selected, setSelected] = useState(initValue);
|
|
85
|
-
// range数据源
|
|
86
|
-
const [data, setData] = useState(formatRange || []);
|
|
87
|
-
// 存储layout布局信息
|
|
88
|
-
const layoutRef = useRef({});
|
|
89
|
-
const viewRef = useRef(null);
|
|
20
|
+
});
|
|
21
|
+
const formatRangeFun = (range, rangeKey = '') => rangeKey ? range.map((item) => item[rangeKey]) : range;
|
|
22
|
+
const formatValueFn = (value) => {
|
|
23
|
+
return Array.isArray(value) ? value : [value];
|
|
24
|
+
};
|
|
25
|
+
const hasDiff = (a, b) => {
|
|
26
|
+
return a.length !== b.length || a.some((item, index) => item !== b[index]);
|
|
27
|
+
};
|
|
28
|
+
const PickerMultiSelector = forwardRef((props, ref) => {
|
|
29
|
+
const { value = [], range = [], bindchange, bindcolumnchange } = props;
|
|
30
|
+
const _value = formatValueFn(value);
|
|
31
|
+
const [formatValue, setFormatValue] = useState(_value);
|
|
32
|
+
const [formatRange, setFormatRange] = useState(formatRangeFun(range, props['range-key']));
|
|
90
33
|
const nodeRef = useRef(null);
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (range) {
|
|
96
|
-
const newFormatRange = formatRangeFun(range, props['range-key']);
|
|
97
|
-
setData(newFormatRange);
|
|
34
|
+
const updateValue = useCallback((value = []) => {
|
|
35
|
+
let newValue = formatValueFn(value);
|
|
36
|
+
if (newValue.length === 0) {
|
|
37
|
+
newValue = formatValue.map(() => 0);
|
|
98
38
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
value: strIndex
|
|
108
|
-
}
|
|
109
|
-
});
|
|
110
|
-
};
|
|
111
|
-
const onPickerChange = (value, column) => {
|
|
112
|
-
// onPickerChange--- ["无脊柱动物", "节肢动物", "吸血虫"] 1 拿着column
|
|
113
|
-
const changeIndex = getColumnIndexByValue(data, column, value);
|
|
114
|
-
bindcolumnchange && bindcolumnchange(changeIndex, column);
|
|
39
|
+
checkColumnChange(newValue, formatValue);
|
|
40
|
+
if (hasDiff(newValue, formatValue)) {
|
|
41
|
+
setFormatValue(newValue);
|
|
42
|
+
}
|
|
43
|
+
}, [formatValue]);
|
|
44
|
+
const updateRange = (newRange) => {
|
|
45
|
+
const range = formatRangeFun(newRange.slice(), props['range-key']);
|
|
46
|
+
setFormatRange(range);
|
|
115
47
|
};
|
|
116
|
-
const
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
48
|
+
const _props = useRef(props);
|
|
49
|
+
_props.current = props;
|
|
50
|
+
useImperativeHandle(ref, () => ({
|
|
51
|
+
updateValue,
|
|
52
|
+
updateRange,
|
|
53
|
+
getNodeInstance: () => ({
|
|
54
|
+
props: _props,
|
|
55
|
+
nodeRef,
|
|
56
|
+
instance: {
|
|
57
|
+
style: {}
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
}));
|
|
61
|
+
const onChange = (e) => {
|
|
62
|
+
const { value } = e.detail;
|
|
63
|
+
checkColumnChange(value, formatValue);
|
|
64
|
+
bindchange?.({ detail: { value: value } });
|
|
65
|
+
if (hasDiff(value, formatValue)) {
|
|
66
|
+
setFormatValue(value.slice());
|
|
67
|
+
}
|
|
121
68
|
};
|
|
122
|
-
const
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
defaultValue: initValue,
|
|
128
|
-
disabled,
|
|
129
|
-
itemHeight: 40,
|
|
130
|
-
onChange,
|
|
131
|
-
onDismiss: bindcancel && bindcancel,
|
|
132
|
-
onPickerChange: onPickerChange
|
|
69
|
+
const checkColumnChange = (value, formatValue) => {
|
|
70
|
+
const index = value.findIndex((v, i) => v !== formatValue[i]);
|
|
71
|
+
if (index !== -1) {
|
|
72
|
+
bindcolumnchange?.(index, value[index]);
|
|
73
|
+
}
|
|
133
74
|
};
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
|
|
75
|
+
const renderColumn = (columnData, index) => {
|
|
76
|
+
return (
|
|
77
|
+
// @ts-expect-error ignore
|
|
78
|
+
<MpxPickerViewColumn key={index}>
|
|
79
|
+
{columnData.map((item, index) => (<Text key={index} style={styles.pickerItem}>{item}</Text>))}
|
|
80
|
+
</MpxPickerViewColumn>);
|
|
137
81
|
};
|
|
138
|
-
return (<
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
{children}
|
|
142
|
-
</View>
|
|
143
|
-
</TouchableWithoutFeedback>
|
|
144
|
-
</Picker>);
|
|
82
|
+
return (<MpxPickerView style={styles.pickerContainer} indicator-style={styles.pickerIndicator} value={formatValue} bindchange={onChange}>
|
|
83
|
+
{formatRange.map((item, index) => (renderColumn(item, index)))}
|
|
84
|
+
</MpxPickerView>);
|
|
145
85
|
});
|
|
146
|
-
|
|
147
|
-
export default
|
|
86
|
+
PickerMultiSelector.displayName = 'MpxPickerMultiSelector';
|
|
87
|
+
export default PickerMultiSelector;
|
|
@@ -1,99 +1,199 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import React, { forwardRef, useCallback, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
2
|
+
import { StyleSheet, Text } from 'react-native';
|
|
3
|
+
import MpxPickerView from '../mpx-picker-view';
|
|
4
|
+
import MpxPickerViewColumn from '../mpx-picker-view-column';
|
|
3
5
|
import { regionData } from './regionData';
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
6
|
+
import { extendObject, useUpdateEffect } from '../utils';
|
|
7
|
+
const styles = StyleSheet.create({
|
|
8
|
+
pickerContainer: {
|
|
9
|
+
height: 240,
|
|
10
|
+
paddingHorizontal: 10,
|
|
11
|
+
borderTopLeftRadius: 10,
|
|
12
|
+
borderTopRightRadius: 10
|
|
13
|
+
},
|
|
14
|
+
pickerIndicator: {
|
|
15
|
+
height: 45
|
|
16
|
+
},
|
|
17
|
+
pickerItem: {
|
|
18
|
+
fontSize: 16,
|
|
19
|
+
lineHeight: 45,
|
|
20
|
+
textAlign: 'center'
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const rangeProvince = regionData.map(item => item.value);
|
|
24
|
+
const findIndex = (arr, val) => {
|
|
25
|
+
const res = arr.findIndex(item => item === val);
|
|
26
|
+
return res === -1 ? 0 : res;
|
|
27
|
+
};
|
|
28
|
+
const getColumnLength = (level) => {
|
|
29
|
+
if (level === 'province') {
|
|
30
|
+
return 1;
|
|
31
|
+
}
|
|
32
|
+
else if (level === 'city') {
|
|
33
|
+
return 2;
|
|
34
|
+
}
|
|
35
|
+
else {
|
|
36
|
+
return 3;
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
const valueStr2Obj = (value = [], limit, customItem = '') => {
|
|
40
|
+
const offsetIndex = customItem ? 1 : 0;
|
|
41
|
+
let indexProvince = 0;
|
|
42
|
+
if (customItem && value[0] === customItem) {
|
|
43
|
+
indexProvince = 0;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
indexProvince = findIndex(rangeProvince, value[0]) + offsetIndex;
|
|
47
|
+
}
|
|
48
|
+
const ans = {
|
|
49
|
+
indexArr: [indexProvince],
|
|
50
|
+
rangeArr: [customItem ? [customItem, ...rangeProvince] : rangeProvince]
|
|
51
|
+
};
|
|
52
|
+
for (let i = 1, lastIndex = indexProvince, lastData = regionData, lastRange = rangeProvince; i < limit; i++) {
|
|
53
|
+
if (customItem) {
|
|
54
|
+
if (lastIndex === 0) {
|
|
55
|
+
if (i === 1) {
|
|
56
|
+
ans.indexArr.push(0, 0);
|
|
57
|
+
ans.rangeArr.push([customItem], [customItem]);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
ans.indexArr.push(0);
|
|
61
|
+
ans.rangeArr.push([customItem]);
|
|
62
|
+
}
|
|
63
|
+
return ans;
|
|
64
|
+
}
|
|
22
65
|
}
|
|
23
|
-
|
|
66
|
+
lastData = lastData[lastIndex - offsetIndex].children;
|
|
67
|
+
lastRange = lastData.map((item) => item.value);
|
|
68
|
+
lastIndex = findIndex(lastRange, value[i]) + offsetIndex;
|
|
69
|
+
if (customItem && customItem === value[i]) {
|
|
70
|
+
lastIndex = 0;
|
|
71
|
+
}
|
|
72
|
+
ans.indexArr.push(Math.max(0, lastIndex));
|
|
73
|
+
ans.rangeArr.push(customItem ? [customItem, ...lastRange] : lastRange);
|
|
24
74
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
75
|
+
return ans;
|
|
76
|
+
};
|
|
77
|
+
const valueChanged2Obj = (currentObj, value, limit = 3, customItem = '') => {
|
|
78
|
+
const offsetIndex = customItem ? 1 : 0;
|
|
79
|
+
const newValue = new Array(limit).fill(0);
|
|
80
|
+
const currentValue = currentObj.indexArr;
|
|
81
|
+
for (let i = 0; i < limit; i++) {
|
|
82
|
+
if (i === limit - 1) {
|
|
83
|
+
return {
|
|
84
|
+
indexArr: value,
|
|
85
|
+
rangeArr: currentObj.rangeArr
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
newValue[i] = value[i];
|
|
89
|
+
if (currentValue[i] !== value[i]) {
|
|
90
|
+
break;
|
|
32
91
|
}
|
|
33
|
-
obj.push(region);
|
|
34
92
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
let tmp = regionData;
|
|
51
|
-
const postcode = [];
|
|
52
|
-
const code = value.map((item) => {
|
|
53
|
-
for (let i = 0; i < tmp.length; i++) {
|
|
54
|
-
if (tmp[i].value === item) {
|
|
55
|
-
const code = tmp[i].code;
|
|
56
|
-
postcode.push(tmp[i].postcode);
|
|
57
|
-
tmp = tmp[i].children || [];
|
|
58
|
-
return code;
|
|
93
|
+
const ans = {
|
|
94
|
+
indexArr: [newValue[0]],
|
|
95
|
+
rangeArr: [currentObj.rangeArr[0]]
|
|
96
|
+
};
|
|
97
|
+
let data = regionData;
|
|
98
|
+
for (let i = 1; i < limit; i++) {
|
|
99
|
+
if (customItem) {
|
|
100
|
+
if (newValue[i - 1] === 0) {
|
|
101
|
+
if (i === 1) {
|
|
102
|
+
ans.indexArr.push(0, 0);
|
|
103
|
+
ans.rangeArr.push([customItem], [customItem]);
|
|
104
|
+
}
|
|
105
|
+
else {
|
|
106
|
+
ans.indexArr.push(0);
|
|
107
|
+
ans.rangeArr.push([customItem]);
|
|
59
108
|
}
|
|
109
|
+
return ans;
|
|
60
110
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
111
|
+
}
|
|
112
|
+
data = data[newValue[i - 1] - offsetIndex].children;
|
|
113
|
+
const range = data.map(item => item.value);
|
|
114
|
+
ans.indexArr.push(newValue[i]);
|
|
115
|
+
ans.rangeArr.push(customItem ? [customItem, ...range] : range);
|
|
116
|
+
}
|
|
117
|
+
return ans;
|
|
118
|
+
};
|
|
119
|
+
const valueNum2String = (value, customItem = '') => {
|
|
120
|
+
let data = regionData;
|
|
121
|
+
return value.map(index => {
|
|
122
|
+
if (customItem) {
|
|
123
|
+
if (index === 0) {
|
|
124
|
+
return customItem;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
index -= 1;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
const item = data[index];
|
|
131
|
+
data = item.children;
|
|
132
|
+
return item.value;
|
|
133
|
+
});
|
|
134
|
+
};
|
|
135
|
+
const hasDiff = (currentValue, value, limit = 3) => {
|
|
136
|
+
for (let i = 0; i < limit; i++) {
|
|
137
|
+
if (currentValue[i] !== value[i]) {
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
};
|
|
143
|
+
const PickerRegion = forwardRef((props, ref) => {
|
|
144
|
+
const { value = [], level = 'region', 'custom-item': customItem = '', bindchange } = props;
|
|
145
|
+
const nodeRef = useRef(null);
|
|
146
|
+
const columnLength = useMemo(() => getColumnLength(level), [level]);
|
|
147
|
+
const [formatObj, setFormatObj] = useState(valueStr2Obj(value, columnLength, customItem));
|
|
148
|
+
const updateValue = useCallback((value = []) => {
|
|
149
|
+
const calibratedValue = valueStr2Obj(value, columnLength, customItem);
|
|
150
|
+
setFormatObj(calibratedValue);
|
|
151
|
+
}, [columnLength, customItem]);
|
|
152
|
+
const _props = useRef(props);
|
|
153
|
+
_props.current = props;
|
|
154
|
+
useImperativeHandle(ref, () => ({
|
|
155
|
+
updateValue,
|
|
156
|
+
getNodeInstance: () => ({
|
|
157
|
+
props: _props,
|
|
158
|
+
nodeRef,
|
|
159
|
+
instance: {
|
|
160
|
+
style: {}
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
}));
|
|
164
|
+
useUpdateEffect(() => {
|
|
165
|
+
const calibratedValue = valueStr2Obj(value, columnLength, customItem);
|
|
166
|
+
if (hasDiff(formatObj.indexArr, calibratedValue.indexArr, columnLength)) {
|
|
167
|
+
setFormatObj(calibratedValue);
|
|
168
|
+
}
|
|
169
|
+
}, [value, columnLength, customItem]);
|
|
170
|
+
const onChange = useCallback((e) => {
|
|
171
|
+
const { value } = e.detail;
|
|
172
|
+
const currentValue = formatObj.indexArr;
|
|
173
|
+
const newObj = valueChanged2Obj(formatObj, value, columnLength, customItem);
|
|
174
|
+
if (hasDiff(currentValue, value, columnLength)) {
|
|
175
|
+
setFormatObj(newObj);
|
|
176
|
+
}
|
|
177
|
+
bindchange?.({ detail: { value: valueNum2String(newObj.indexArr, customItem) } });
|
|
178
|
+
}, [formatObj, columnLength, customItem, bindchange]);
|
|
179
|
+
const renderColumn = () => {
|
|
180
|
+
return formatObj.rangeArr?.map((item, index) => (
|
|
181
|
+
// @ts-expect-error ignore
|
|
182
|
+
<MpxPickerViewColumn key={index}>
|
|
183
|
+
{item.map((item, index) => {
|
|
184
|
+
const len = item.length;
|
|
185
|
+
const style = extendObject({}, styles.pickerItem, {
|
|
186
|
+
fontSize: len > 5 ? 21 - len : 16
|
|
187
|
+
});
|
|
188
|
+
return <Text key={index} style={style}>
|
|
189
|
+
{item}
|
|
190
|
+
</Text>;
|
|
191
|
+
})}
|
|
192
|
+
</MpxPickerViewColumn>));
|
|
91
193
|
};
|
|
92
|
-
return (<
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
</TouchableWithoutFeedback>
|
|
96
|
-
</Picker>);
|
|
194
|
+
return (<MpxPickerView style={styles.pickerContainer} indicator-style={styles.pickerIndicator} value={formatObj.indexArr} bindchange={onChange}>
|
|
195
|
+
{renderColumn()}
|
|
196
|
+
</MpxPickerView>);
|
|
97
197
|
});
|
|
98
|
-
|
|
99
|
-
export default
|
|
198
|
+
PickerRegion.displayName = 'MpxPickerRegion';
|
|
199
|
+
export default PickerRegion;
|
|
@@ -1,81 +1,66 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
1
|
+
import React, { forwardRef, useImperativeHandle, useRef, useState } from 'react';
|
|
2
|
+
import { StyleSheet, Text } from 'react-native';
|
|
3
|
+
import MpxPickerView from '../mpx-picker-view';
|
|
4
|
+
import MpxPickerViewColumn from '../mpx-picker-view-column';
|
|
5
|
+
import { useUpdateEffect } from '../utils';
|
|
6
|
+
const styles = StyleSheet.create({
|
|
7
|
+
pickerContainer: {
|
|
8
|
+
height: 240,
|
|
9
|
+
paddingHorizontal: 10,
|
|
10
|
+
borderTopLeftRadius: 10,
|
|
11
|
+
borderTopRightRadius: 10
|
|
12
|
+
},
|
|
13
|
+
pickerIndicator: {
|
|
14
|
+
height: 45
|
|
15
|
+
},
|
|
16
|
+
pickerItem: {
|
|
17
|
+
fontSize: 18,
|
|
18
|
+
lineHeight: 45,
|
|
19
|
+
textAlign: 'center'
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
const formatRangeFun = (range, rangeKey = '') => rangeKey ? range.map((item) => item[rangeKey]) : range;
|
|
23
|
+
const formatValueFn = (value = 0) => {
|
|
24
|
+
const _value = Array.isArray(value) ? value[0] : value;
|
|
25
|
+
return +_value;
|
|
19
26
|
};
|
|
20
|
-
const
|
|
21
|
-
const {
|
|
22
|
-
|
|
27
|
+
const PickerSelector = forwardRef((props, ref) => {
|
|
28
|
+
const { value, range = [], bindchange } = props;
|
|
29
|
+
const [formatValue, setFormatValue] = useState(formatValueFn(value));
|
|
23
30
|
const formatRange = formatRangeFun(range, props['range-key']);
|
|
24
|
-
// 选中的索引值
|
|
25
|
-
const [selected, setSelected] = useState(value || 0);
|
|
26
|
-
// range数据源
|
|
27
|
-
const [data, setData] = useState(formatRange || []);
|
|
28
|
-
// 存储layout布局信息
|
|
29
|
-
const layoutRef = useRef({});
|
|
30
|
-
const viewRef = useRef(null);
|
|
31
31
|
const nodeRef = useRef(null);
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
if (range) {
|
|
37
|
-
const newFormatRange = formatRangeFun(range, props['range-key']);
|
|
38
|
-
setData(newFormatRange);
|
|
39
|
-
}
|
|
40
|
-
setSelected(() => {
|
|
41
|
-
return value;
|
|
42
|
-
});
|
|
43
|
-
}, [range, value]);
|
|
44
|
-
const defaultValue = [value];
|
|
45
|
-
const onChange = (value) => {
|
|
46
|
-
bindchange && bindchange({
|
|
47
|
-
detail: {
|
|
48
|
-
value: value && value[0]
|
|
49
|
-
}
|
|
50
|
-
});
|
|
32
|
+
const updateValue = (value = 0) => {
|
|
33
|
+
const newValue = formatValueFn(value);
|
|
34
|
+
setFormatValue(newValue);
|
|
51
35
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
36
|
+
useUpdateEffect(() => {
|
|
37
|
+
updateValue(value);
|
|
38
|
+
}, [value]);
|
|
39
|
+
const _props = useRef(props);
|
|
40
|
+
_props.current = props;
|
|
41
|
+
useImperativeHandle(ref, () => ({
|
|
42
|
+
updateValue,
|
|
43
|
+
getNodeInstance: () => ({
|
|
44
|
+
props: _props,
|
|
45
|
+
nodeRef,
|
|
46
|
+
instance: {
|
|
47
|
+
style: {}
|
|
48
|
+
}
|
|
49
|
+
})
|
|
50
|
+
}));
|
|
51
|
+
const onChange = (e) => {
|
|
52
|
+
const { value } = e.detail;
|
|
53
|
+
if (formatValue !== value[0]) {
|
|
54
|
+
setFormatValue(value[0]);
|
|
55
|
+
}
|
|
56
|
+
bindchange?.({ detail: { value: value[0] + '' } });
|
|
71
57
|
};
|
|
72
|
-
return (<
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
</Picker>);
|
|
58
|
+
return (<MpxPickerView style={styles.pickerContainer} indicator-style={styles.pickerIndicator} value={[formatValue]} bindchange={onChange}>
|
|
59
|
+
{/* @ts-expect-error ignore */}
|
|
60
|
+
<MpxPickerViewColumn>
|
|
61
|
+
{formatRange.map((item, index) => (<Text key={index} style={styles.pickerItem}>{item}</Text>))}
|
|
62
|
+
</MpxPickerViewColumn>
|
|
63
|
+
</MpxPickerView>);
|
|
79
64
|
});
|
|
80
|
-
|
|
81
|
-
export default
|
|
65
|
+
PickerSelector.displayName = 'MpxPickerSelector';
|
|
66
|
+
export default PickerSelector;
|