@mijadesign/nut-mcp 1.0.0-alpha.0
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/README.md +147 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +16 -0
- package/dist/services/aliases.service.d.ts +1 -0
- package/dist/services/aliases.service.js +19 -0
- package/dist/services/doc-parser.service.d.ts +3 -0
- package/dist/services/doc-parser.service.js +162 -0
- package/dist/services/index.services.d.ts +3 -0
- package/dist/services/index.services.js +71 -0
- package/dist/services/paths.service.d.ts +5 -0
- package/dist/services/paths.service.js +18 -0
- package/dist/tools/base.tool.d.ts +8 -0
- package/dist/tools/base.tool.js +27 -0
- package/dist/tools/get-component-doc.tool.d.ts +12 -0
- package/dist/tools/get-component-doc.tool.js +40 -0
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.js +4 -0
- package/dist/tools/list-components.tool.d.ts +8 -0
- package/dist/tools/list-components.tool.js +32 -0
- package/dist/tools/search-components.tool.d.ts +12 -0
- package/dist/tools/search-components.tool.js +61 -0
- package/dist/types/index.d.ts +33 -0
- package/dist/types/index.js +1 -0
- package/docs/docs/aliases.json +59 -0
- package/docs/docs/components/base/button/index.md +415 -0
- package/docs/docs/components/base/cell/index.md +279 -0
- package/docs/docs/components/base/configprovider/index.md +215 -0
- package/docs/docs/components/base/image/index.md +282 -0
- package/docs/docs/components/base/overlay/index.md +288 -0
- package/docs/docs/components/dentry/cascader/index.md +1080 -0
- package/docs/docs/components/dentry/checkbox/index.md +842 -0
- package/docs/docs/components/dentry/datepicker/index.md +489 -0
- package/docs/docs/components/dentry/form/index.md +457 -0
- package/docs/docs/components/dentry/input/index.md +257 -0
- package/docs/docs/components/dentry/picker/index.md +621 -0
- package/docs/docs/components/dentry/radio/index.md +364 -0
- package/docs/docs/components/dentry/searchbar/index.md +317 -0
- package/docs/docs/components/dentry/selector/index.md +295 -0
- package/docs/docs/components/dentry/switch/index.md +300 -0
- package/docs/docs/components/dentry/textarea/index.md +231 -0
- package/docs/docs/components/dentry/uploader/index.md +745 -0
- package/docs/docs/components/exhibition/collapse/index.md +339 -0
- package/docs/docs/components/exhibition/swiper/index.md +385 -0
- package/docs/docs/components/exhibition/tag/index.md +253 -0
- package/docs/docs/components/feedback/dialog/index.md +306 -0
- package/docs/docs/components/feedback/drag/index.md +164 -0
- package/docs/docs/components/feedback/empty/index.md +211 -0
- package/docs/docs/components/feedback/infiniteloading/index.md +397 -0
- package/docs/docs/components/feedback/noticebar/index.md +175 -0
- package/docs/docs/components/feedback/popup/index.md +563 -0
- package/docs/docs/components/feedback/pulltorefresh/index.md +254 -0
- package/docs/docs/components/feedback/toast/index.md +355 -0
- package/docs/docs/components/layout/divider/index.md +162 -0
- package/docs/docs/components/layout/grid/index.md +386 -0
- package/docs/docs/components/layout/space/index.md +196 -0
- package/docs/docs/components/nav/tabs/index.md +955 -0
- package/docs/docs/components-index.json +233 -0
- package/package.json +34 -0
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
---
|
|
2
|
+
order: 16
|
|
3
|
+
demoUrl: 'https://frontend.mishudata.com/mobile/demo/#/dentry/pages/picker/index'
|
|
4
|
+
group:
|
|
5
|
+
title: 数据录入
|
|
6
|
+
order: 5
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
# Picker 选择器 <Badge>2.0.0</Badge>
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
提供多个选项集合供用户选择其中一项。
|
|
13
|
+
|
|
14
|
+
## 引入
|
|
15
|
+
|
|
16
|
+
```tsx
|
|
17
|
+
import { Picker } from '@mijadesign/mjui-react-taro';
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## 示例代码
|
|
21
|
+
|
|
22
|
+
### 基础用法
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
```tsx
|
|
26
|
+
import { Cell, Picker, PickerOnChangeCallbackParameter, PickerOption, PickerValue } from '@mijadesign/mjui-react-taro'
|
|
27
|
+
import React, { useState } from 'react'
|
|
28
|
+
|
|
29
|
+
const Demo1 = () => {
|
|
30
|
+
const [visible, setVisible] = useState(false)
|
|
31
|
+
const [isVisible, setIsVisible] = useState(false)
|
|
32
|
+
const [isVisible1, setIsVisible1] = useState(false)
|
|
33
|
+
const [value0, setValue0] = useState<PickerValue[]>([1])
|
|
34
|
+
const [value, setValue] = useState<PickerValue[]>([2, 1, 1])
|
|
35
|
+
const [value1, setValue1] = useState<PickerValue[]>(['Wednesday', 'Morning'])
|
|
36
|
+
const [baseDesc, setBaseDesc] = useState('南京')
|
|
37
|
+
const [cityCustom, setCityCustom] = useState('浙江省 杭州市 西湖区')
|
|
38
|
+
const [mutilDesc, setMutilDesc] = useState('周三 上午')
|
|
39
|
+
|
|
40
|
+
const options = [
|
|
41
|
+
[
|
|
42
|
+
{ value: 1, text: '南京市' },
|
|
43
|
+
{ value: 2, text: '无锡市' },
|
|
44
|
+
{ value: 3, text: '海北藏族自治区' },
|
|
45
|
+
{ value: 4, text: '北京市' },
|
|
46
|
+
{ value: 5, text: '连云港市' },
|
|
47
|
+
{ value: 8, text: '大庆市' },
|
|
48
|
+
{ value: 9, text: '绥化市' },
|
|
49
|
+
{ value: 10, text: '潍坊市' },
|
|
50
|
+
{ value: 12, text: '乌鲁木齐市' },
|
|
51
|
+
],
|
|
52
|
+
]
|
|
53
|
+
const customCityData = [
|
|
54
|
+
[
|
|
55
|
+
{
|
|
56
|
+
value: 1,
|
|
57
|
+
text: '江苏省',
|
|
58
|
+
children: [
|
|
59
|
+
{
|
|
60
|
+
value: 1,
|
|
61
|
+
text: '南京市',
|
|
62
|
+
children: [
|
|
63
|
+
{ value: 1, text: '雨花台区' },
|
|
64
|
+
{ value: 2, text: '雨花台区' },
|
|
65
|
+
{ value: 3, text: '雨花台区' },
|
|
66
|
+
{ value: 4, text: '雨花台区' },
|
|
67
|
+
{ value: 5, text: '雨花台区' },
|
|
68
|
+
],
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
value: 2,
|
|
72
|
+
text: '南京市',
|
|
73
|
+
children: [
|
|
74
|
+
{ value: 1, text: '雨花台区' },
|
|
75
|
+
{ value: 2, text: '雨花台区' },
|
|
76
|
+
{ value: 3, text: '雨花台区' },
|
|
77
|
+
{ value: 4, text: '雨花台区' },
|
|
78
|
+
{ value: 5, text: '雨花台区' },
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
value: 3,
|
|
83
|
+
text: '南京市',
|
|
84
|
+
children: [
|
|
85
|
+
{ value: 1, text: '雨花台区' },
|
|
86
|
+
{ value: 2, text: '雨花台区' },
|
|
87
|
+
{ value: 3, text: '雨花台区' },
|
|
88
|
+
{ value: 4, text: '雨花台区' },
|
|
89
|
+
{ value: 5, text: '雨花台区' },
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
value: 4,
|
|
94
|
+
text: '南京市',
|
|
95
|
+
children: [
|
|
96
|
+
{ value: 1, text: '雨花台区' },
|
|
97
|
+
{ value: 2, text: '雨花台区' },
|
|
98
|
+
{ value: 3, text: '雨花台区' },
|
|
99
|
+
{ value: 4, text: '雨花台区' },
|
|
100
|
+
{ value: 5, text: '雨花台区' },
|
|
101
|
+
],
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
value: 5,
|
|
105
|
+
text: '西城区',
|
|
106
|
+
children: [
|
|
107
|
+
{ value: 1, text: '雨花台区' },
|
|
108
|
+
{ value: 2, text: '雨花台区' },
|
|
109
|
+
{ value: 3, text: '雨花台区' },
|
|
110
|
+
{ value: 4, text: '西湖区' },
|
|
111
|
+
{ value: 5, text: '雨花台区' },
|
|
112
|
+
],
|
|
113
|
+
},
|
|
114
|
+
{
|
|
115
|
+
value: 6,
|
|
116
|
+
text: '南京市',
|
|
117
|
+
children: [
|
|
118
|
+
{ value: 1, text: '雨花台区' },
|
|
119
|
+
{ value: 2, text: '雨花台区' },
|
|
120
|
+
{ value: 3, text: '雨花台区' },
|
|
121
|
+
{ value: 4, text: '雨花台区' },
|
|
122
|
+
{ value: 5, text: '雨花台区' },
|
|
123
|
+
],
|
|
124
|
+
},
|
|
125
|
+
],
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
value: 2,
|
|
129
|
+
text: '浙江省',
|
|
130
|
+
children: [
|
|
131
|
+
{
|
|
132
|
+
value: 1,
|
|
133
|
+
text: '杭州市',
|
|
134
|
+
children: [
|
|
135
|
+
{ value: 1, text: '西湖区' },
|
|
136
|
+
{ value: 2, text: '雨花台区' },
|
|
137
|
+
{ value: 3, text: '雨花台区' },
|
|
138
|
+
{ value: 4, text: '雨花台区' },
|
|
139
|
+
{ value: 5, text: '雨花台区' },
|
|
140
|
+
],
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
value: 2,
|
|
144
|
+
text: '南京市',
|
|
145
|
+
children: [
|
|
146
|
+
{ value: 1, text: '西湖区' },
|
|
147
|
+
{ value: 2, text: '雨花台区' },
|
|
148
|
+
{ value: 3, text: '雨花台区' },
|
|
149
|
+
{ value: 4, text: '雨花台区' },
|
|
150
|
+
{ value: 5, text: '雨花台区' },
|
|
151
|
+
],
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
value: 3,
|
|
155
|
+
text: '南京市',
|
|
156
|
+
children: [
|
|
157
|
+
{ value: 1, text: '雨花台区' },
|
|
158
|
+
{ value: 2, text: '雨花台区' },
|
|
159
|
+
{ value: 3, text: '雨花台区' },
|
|
160
|
+
{ value: 4, text: '雨花台区' },
|
|
161
|
+
{ value: 5, text: '西湖区' },
|
|
162
|
+
],
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
value: 4,
|
|
166
|
+
text: '南京市',
|
|
167
|
+
children: [
|
|
168
|
+
{ value: 1, text: '雨花台区' },
|
|
169
|
+
{ value: 2, text: '雨花台区' },
|
|
170
|
+
{ value: 3, text: '雨花台区' },
|
|
171
|
+
{ value: 4, text: '西湖区' },
|
|
172
|
+
{ value: 5, text: '雨花台区' },
|
|
173
|
+
],
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
value: 5,
|
|
177
|
+
text: '南京市',
|
|
178
|
+
children: [
|
|
179
|
+
{ value: 1, text: '雨花台区' },
|
|
180
|
+
{ value: 2, text: '西湖区' },
|
|
181
|
+
{ value: 3, text: '雨花台区' },
|
|
182
|
+
{ value: 4, text: '雨花台区' },
|
|
183
|
+
{ value: 5, text: '雨花台区' },
|
|
184
|
+
],
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
]
|
|
190
|
+
const options1 = [
|
|
191
|
+
[
|
|
192
|
+
{
|
|
193
|
+
text: '周一',
|
|
194
|
+
value: 'Monday',
|
|
195
|
+
children: [
|
|
196
|
+
{ text: '上午', value: 'Morning' },
|
|
197
|
+
{ text: '下午', value: 'Afternoon' },
|
|
198
|
+
{ text: '晚上', value: 'Evening' },
|
|
199
|
+
],
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
text: '周二',
|
|
203
|
+
value: 'Tuesday',
|
|
204
|
+
children: [
|
|
205
|
+
{ text: '上午', value: 'Morning' },
|
|
206
|
+
{ text: '下午', value: 'Afternoon' },
|
|
207
|
+
{ text: '晚上', value: 'Evening' },
|
|
208
|
+
],
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
text: '周三',
|
|
212
|
+
value: 'Wednesday',
|
|
213
|
+
children: [
|
|
214
|
+
{ text: '上午', value: 'Morning' },
|
|
215
|
+
{ text: '下午', value: 'Afternoon' },
|
|
216
|
+
{ text: '晚上', value: 'Evening' },
|
|
217
|
+
],
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
text: '周四',
|
|
221
|
+
value: 'Thursday',
|
|
222
|
+
children: [
|
|
223
|
+
{ text: '上午', value: 'Morning' },
|
|
224
|
+
{ text: '下午', value: 'Afternoon' },
|
|
225
|
+
{ text: '晚上', value: 'Evening' },
|
|
226
|
+
],
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
text: '周五',
|
|
230
|
+
value: 'Friday',
|
|
231
|
+
children: [
|
|
232
|
+
{ text: '上午', value: 'Morning' },
|
|
233
|
+
{ text: '下午', value: 'Afternoon' },
|
|
234
|
+
{ text: '晚上', value: 'Evening' },
|
|
235
|
+
],
|
|
236
|
+
},
|
|
237
|
+
],
|
|
238
|
+
]
|
|
239
|
+
|
|
240
|
+
const changePicker = ({ value, index, selectedOptions }: PickerOnChangeCallbackParameter) => {
|
|
241
|
+
console.log('changePicker', value, index, selectedOptions)
|
|
242
|
+
}
|
|
243
|
+
const confirmPicker = (selectedOptions: PickerOption[], selectedValue: PickerValue[]) => {
|
|
244
|
+
let description = ''
|
|
245
|
+
selectedOptions.forEach((option: PickerOption) => {
|
|
246
|
+
description += ` ${option.text}`
|
|
247
|
+
})
|
|
248
|
+
setBaseDesc(description)
|
|
249
|
+
setValue0(selectedValue)
|
|
250
|
+
}
|
|
251
|
+
const setChooseValueCustom = (selectedOptions: PickerOption[], selectedValue: PickerValue[]) => {
|
|
252
|
+
console.log('onconfirm', selectedOptions, selectedValue)
|
|
253
|
+
const city = selectedOptions.map((item: PickerOption) => item.text).join(' ')
|
|
254
|
+
setCityCustom(city)
|
|
255
|
+
setValue(selectedValue)
|
|
256
|
+
}
|
|
257
|
+
const confirmPicker1 = (selectedOptions: PickerOption[], selectedValue: PickerValue[]) => {
|
|
258
|
+
console.log('confirmPicker', selectedOptions, selectedValue)
|
|
259
|
+
const description = selectedOptions.map((item: PickerOption) => item.text).join(' ')
|
|
260
|
+
setMutilDesc(description)
|
|
261
|
+
setValue1(selectedValue)
|
|
262
|
+
}
|
|
263
|
+
return (
|
|
264
|
+
<Cell.Group>
|
|
265
|
+
<Cell title="城市" extra={baseDesc} onClick={() => setVisible(!visible)} />
|
|
266
|
+
<Cell title="时间" extra={mutilDesc} onClick={() => setIsVisible1(!isVisible1)} />
|
|
267
|
+
<Cell title="多级联动" extra={cityCustom} onClick={() => setIsVisible(!isVisible)} />
|
|
268
|
+
<Picker
|
|
269
|
+
title="请选择城市"
|
|
270
|
+
visible={visible}
|
|
271
|
+
options={options}
|
|
272
|
+
onConfirm={confirmPicker}
|
|
273
|
+
onClose={() => setVisible(false)}
|
|
274
|
+
value={value0}
|
|
275
|
+
onChange={changePicker}
|
|
276
|
+
/>
|
|
277
|
+
<Picker
|
|
278
|
+
title="请选择"
|
|
279
|
+
visible={isVisible1}
|
|
280
|
+
options={options1}
|
|
281
|
+
onClose={() => setIsVisible1(false)}
|
|
282
|
+
value={value1}
|
|
283
|
+
onConfirm={confirmPicker1}
|
|
284
|
+
onChange={({ value, index, selectedOptions }) => console.log('多级联动', value, index, selectedOptions)}
|
|
285
|
+
/>
|
|
286
|
+
<Picker
|
|
287
|
+
title="请选择"
|
|
288
|
+
visible={isVisible}
|
|
289
|
+
options={customCityData}
|
|
290
|
+
value={value}
|
|
291
|
+
onClose={() => setIsVisible(false)}
|
|
292
|
+
onConfirm={setChooseValueCustom}
|
|
293
|
+
onChange={({ value, index, selectedOptions }) => console.log('多级联动', value, index, selectedOptions)}
|
|
294
|
+
/>
|
|
295
|
+
</Cell.Group>
|
|
296
|
+
)
|
|
297
|
+
}
|
|
298
|
+
export default Demo1
|
|
299
|
+
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### 受控
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
```tsx
|
|
306
|
+
import { Cell, Picker, PickerOption, PickerValue } from '@mijadesign/mjui-react-taro'
|
|
307
|
+
import React, { useState } from 'react'
|
|
308
|
+
|
|
309
|
+
const Demo3 = () => {
|
|
310
|
+
const [visible, setVisible] = useState(false)
|
|
311
|
+
const [baseDesc, setBaseDesc] = useState('')
|
|
312
|
+
const [value, setValue] = useState<PickerValue[]>([] as PickerValue[])
|
|
313
|
+
const options = [
|
|
314
|
+
[
|
|
315
|
+
{ value: 1, text: '南京市' },
|
|
316
|
+
{ value: 2, text: '无锡市' },
|
|
317
|
+
{ value: 3, text: '海北藏族自治区' },
|
|
318
|
+
{ value: 4, text: '北京市' },
|
|
319
|
+
{ value: 5, text: '连云港市' },
|
|
320
|
+
{ value: 8, text: '大庆市' },
|
|
321
|
+
{ value: 9, text: '绥化市' },
|
|
322
|
+
{ value: 10, text: '潍坊市' },
|
|
323
|
+
{ value: 12, text: '乌鲁木齐市' },
|
|
324
|
+
],
|
|
325
|
+
]
|
|
326
|
+
|
|
327
|
+
const changePicker = ({ value, index, selectedOptions }: any) => {
|
|
328
|
+
console.log('changePicker', value, index, selectedOptions)
|
|
329
|
+
}
|
|
330
|
+
const confirmPicker = (selectedOptions: PickerOption[], selectedValue: PickerValue[]) => {
|
|
331
|
+
setValue(selectedValue)
|
|
332
|
+
let description = ''
|
|
333
|
+
selectedOptions.forEach((option: any) => {
|
|
334
|
+
description += ` ${option.text}`
|
|
335
|
+
})
|
|
336
|
+
setBaseDesc(description)
|
|
337
|
+
}
|
|
338
|
+
return (
|
|
339
|
+
<Cell.Group>
|
|
340
|
+
<Cell title="请选择城市" extra={baseDesc} onClick={() => setVisible(!visible)} />
|
|
341
|
+
<Picker
|
|
342
|
+
title="请选择城市"
|
|
343
|
+
visible={visible}
|
|
344
|
+
value={value}
|
|
345
|
+
options={options}
|
|
346
|
+
onChange={changePicker}
|
|
347
|
+
onConfirm={confirmPicker}
|
|
348
|
+
onClose={() => setVisible(false)}
|
|
349
|
+
/>
|
|
350
|
+
</Cell.Group>
|
|
351
|
+
)
|
|
352
|
+
}
|
|
353
|
+
export default Demo3
|
|
354
|
+
|
|
355
|
+
```
|
|
356
|
+
|
|
357
|
+
### 平铺展示
|
|
358
|
+
|
|
359
|
+
通过设置 `threeDimensional` 取消 3D 展示效果,并且通过设置 `duration` 可以控制快速滚动的时长。
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
```tsx
|
|
363
|
+
import { Cell, Picker, PickerOption } from '@mijadesign/mjui-react-taro'
|
|
364
|
+
import React, { useState } from 'react'
|
|
365
|
+
|
|
366
|
+
const Demo5 = () => {
|
|
367
|
+
const [isVisible, setIsVisible] = useState(false)
|
|
368
|
+
const [tileDesc, settileDesc] = useState('无锡市')
|
|
369
|
+
const options = [
|
|
370
|
+
[
|
|
371
|
+
{ value: 1, text: '南京市' },
|
|
372
|
+
{ value: 2, text: '无锡市' },
|
|
373
|
+
{ value: 3, text: '海北藏族自治区' },
|
|
374
|
+
{ value: 4, text: '北京市' },
|
|
375
|
+
{ value: 5, text: '连云港市' },
|
|
376
|
+
{ value: 8, text: '大庆市' },
|
|
377
|
+
{ value: 9, text: '绥化市' },
|
|
378
|
+
{ value: 10, text: '潍坊市' },
|
|
379
|
+
{ value: 12, text: '乌鲁木齐市' },
|
|
380
|
+
],
|
|
381
|
+
]
|
|
382
|
+
|
|
383
|
+
const confirmPicker = (options: PickerOption[]) => {
|
|
384
|
+
let description = ''
|
|
385
|
+
options.forEach((option: any) => {
|
|
386
|
+
description += ` ${option.text}`
|
|
387
|
+
})
|
|
388
|
+
settileDesc(description)
|
|
389
|
+
setIsVisible(false)
|
|
390
|
+
}
|
|
391
|
+
return (
|
|
392
|
+
<Cell.Group>
|
|
393
|
+
<Cell title="请选择城市" extra={tileDesc} onClick={() => setIsVisible(!isVisible)} />
|
|
394
|
+
<Picker
|
|
395
|
+
title="请选择城市"
|
|
396
|
+
visible={isVisible}
|
|
397
|
+
options={options}
|
|
398
|
+
onConfirm={confirmPicker}
|
|
399
|
+
defaultValue={[2]}
|
|
400
|
+
threeDimensional={false}
|
|
401
|
+
duration={1000}
|
|
402
|
+
onClose={() => setIsVisible(false)}
|
|
403
|
+
/>
|
|
404
|
+
</Cell.Group>
|
|
405
|
+
)
|
|
406
|
+
}
|
|
407
|
+
export default Demo5
|
|
408
|
+
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
### 异步获取
|
|
412
|
+
|
|
413
|
+
|
|
414
|
+
```tsx
|
|
415
|
+
import { Cell, Picker, PickerOnChangeCallbackParameter, PickerOption, PickerValue } from '@mijadesign/mjui-react-taro'
|
|
416
|
+
import React, { useState } from 'react'
|
|
417
|
+
|
|
418
|
+
const Demo7 = () => {
|
|
419
|
+
const [isVisible, setIsVisible] = useState(false)
|
|
420
|
+
const [value, setValue] = useState<PickerValue[]>([1])
|
|
421
|
+
const [asyncDesc, setasyncDesc] = useState('北京')
|
|
422
|
+
const [asyncData, setAsyncData] = useState([
|
|
423
|
+
[
|
|
424
|
+
{
|
|
425
|
+
value: 1,
|
|
426
|
+
text: '北京',
|
|
427
|
+
children: [
|
|
428
|
+
{
|
|
429
|
+
value: 1,
|
|
430
|
+
text: '朝阳区',
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
value: 2,
|
|
434
|
+
text: '海淀区',
|
|
435
|
+
},
|
|
436
|
+
{
|
|
437
|
+
value: 3,
|
|
438
|
+
text: '大兴区',
|
|
439
|
+
},
|
|
440
|
+
{
|
|
441
|
+
value: 4,
|
|
442
|
+
text: '东城区',
|
|
443
|
+
},
|
|
444
|
+
{
|
|
445
|
+
value: 5,
|
|
446
|
+
text: '西城区',
|
|
447
|
+
},
|
|
448
|
+
{
|
|
449
|
+
value: 6,
|
|
450
|
+
text: '丰台区',
|
|
451
|
+
},
|
|
452
|
+
],
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
value: 2,
|
|
456
|
+
text: '上海',
|
|
457
|
+
children: [],
|
|
458
|
+
},
|
|
459
|
+
],
|
|
460
|
+
])
|
|
461
|
+
const updateChooseValueCustmer = ({ value, index, selectedOptions }: PickerOnChangeCallbackParameter) => {
|
|
462
|
+
if (value[0] === 2 && asyncData[0]?.[1].children.length === 0) {
|
|
463
|
+
console.log('updateChooseValueCustmer', index, value, selectedOptions)
|
|
464
|
+
setTimeout(() => {
|
|
465
|
+
asyncData[0][1].children = [
|
|
466
|
+
{
|
|
467
|
+
value: 1,
|
|
468
|
+
text: '黄埔区',
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
value: 2,
|
|
472
|
+
text: '长宁区',
|
|
473
|
+
},
|
|
474
|
+
{
|
|
475
|
+
value: 3,
|
|
476
|
+
text: '普陀区',
|
|
477
|
+
},
|
|
478
|
+
{
|
|
479
|
+
value: 4,
|
|
480
|
+
text: '杨浦区',
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
value: 5,
|
|
484
|
+
text: '浦东新区',
|
|
485
|
+
},
|
|
486
|
+
]
|
|
487
|
+
setAsyncData([...[...asyncData]])
|
|
488
|
+
}, 0)
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
const setAsyncConfirm = (selectedOptions: PickerOption[], selectedValue: PickerValue[]) => {
|
|
492
|
+
console.log('onconfirm', selectedOptions, selectedValue)
|
|
493
|
+
const city = selectedOptions.map((item: PickerOption) => item.text).join('-')
|
|
494
|
+
setasyncDesc(city)
|
|
495
|
+
setValue(selectedValue)
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return (
|
|
499
|
+
<Cell.Group>
|
|
500
|
+
<Cell title="请选择城市" extra={asyncDesc} onClick={() => setIsVisible(!isVisible)} />
|
|
501
|
+
|
|
502
|
+
<Picker
|
|
503
|
+
title="请选择城市"
|
|
504
|
+
visible={isVisible}
|
|
505
|
+
options={asyncData}
|
|
506
|
+
value={value}
|
|
507
|
+
onClose={() => setIsVisible(false)}
|
|
508
|
+
onConfirm={setAsyncConfirm}
|
|
509
|
+
onChange={updateChooseValueCustmer}
|
|
510
|
+
/>
|
|
511
|
+
</Cell.Group>
|
|
512
|
+
)
|
|
513
|
+
}
|
|
514
|
+
export default Demo7
|
|
515
|
+
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
### 自定义主题
|
|
519
|
+
|
|
520
|
+
|
|
521
|
+
```tsx
|
|
522
|
+
import { Cell, ConfigProvider, Picker, PickerOption, PickerValue } from '@mijadesign/mjui-react-taro'
|
|
523
|
+
import React, { useState } from 'react'
|
|
524
|
+
|
|
525
|
+
const Demo8 = () => {
|
|
526
|
+
const [visible, setVisible] = useState(false)
|
|
527
|
+
const [baseDesc, setBaseDesc] = useState('')
|
|
528
|
+
const options = [
|
|
529
|
+
[
|
|
530
|
+
{ value: 1, text: '南京市' },
|
|
531
|
+
{ value: 2, text: '无锡市' },
|
|
532
|
+
{ value: 3, text: '海北藏族自治区' },
|
|
533
|
+
{ value: 4, text: '北京市' },
|
|
534
|
+
{ value: 5, text: '连云港市' },
|
|
535
|
+
{ value: 8, text: '大庆市' },
|
|
536
|
+
{ value: 9, text: '绥化市' },
|
|
537
|
+
{ value: 10, text: '潍坊市' },
|
|
538
|
+
{ value: 12, text: '乌鲁木齐市' },
|
|
539
|
+
],
|
|
540
|
+
]
|
|
541
|
+
|
|
542
|
+
const confirmPicker = (selectedOptions: PickerOption[], selectedValue: PickerValue[]) => {
|
|
543
|
+
console.log('confirmPicker', selectedOptions, selectedValue)
|
|
544
|
+
let description = ''
|
|
545
|
+
selectedOptions.forEach((option: PickerOption) => {
|
|
546
|
+
description += ` ${option?.text}`
|
|
547
|
+
})
|
|
548
|
+
setBaseDesc(description)
|
|
549
|
+
}
|
|
550
|
+
return (
|
|
551
|
+
<Cell.Group>
|
|
552
|
+
<Cell title="请选择城市" extra={baseDesc} onClick={() => setVisible(!visible)} />
|
|
553
|
+
<ConfigProvider
|
|
554
|
+
theme={{
|
|
555
|
+
nutuiPickerItemHeight: '48px',
|
|
556
|
+
nutuiPickerItemActiveLineBorder: '1px dashed var(--nutui-color-primary)',
|
|
557
|
+
nutuiPickerItemTextColor: 'var(--nutui-color-primary)',
|
|
558
|
+
}}
|
|
559
|
+
>
|
|
560
|
+
<Picker
|
|
561
|
+
title="请选择城市"
|
|
562
|
+
visible={visible}
|
|
563
|
+
options={options}
|
|
564
|
+
onConfirm={confirmPicker}
|
|
565
|
+
onClose={() => setVisible(false)}
|
|
566
|
+
/>
|
|
567
|
+
</ConfigProvider>
|
|
568
|
+
</Cell.Group>
|
|
569
|
+
)
|
|
570
|
+
}
|
|
571
|
+
export default Demo8
|
|
572
|
+
|
|
573
|
+
```
|
|
574
|
+
|
|
575
|
+
## Picker
|
|
576
|
+
|
|
577
|
+
### Props
|
|
578
|
+
|
|
579
|
+
| 属性 | 说明 | 类型 | 默认值 |
|
|
580
|
+
| --- | --- | --- | --- |
|
|
581
|
+
| visible | 是否可见 | `boolean` | `false` |
|
|
582
|
+
| title | 设置标题 | `string` | `-` |
|
|
583
|
+
| options | 列表数据 | `Array` | `[]` |
|
|
584
|
+
| value | 选中值,受控 | `Array` | `[]` |
|
|
585
|
+
| defaultValue | 默认选中 | `Array` | `[]` |
|
|
586
|
+
| threeDimensional | 是否开启3D效果 | `boolean` | `true` |
|
|
587
|
+
| duration | 快速滑动时惯性滚动的时长,单位 ms | `string` \| `number` | `1000` |
|
|
588
|
+
| popupProps | 透传popup属性 | `object` | `-` |
|
|
589
|
+
| closeOnOverlayClick | 是否点击遮罩关闭 | `boolean` | `true` |
|
|
590
|
+
| onConfirm | 点击确认按钮时候回调 | `(options, value) => void` | `-` |
|
|
591
|
+
| onChange | 每一列值变更时调用 | `(options, value) => void` | `-` |
|
|
592
|
+
| onCancel | 点击取消按钮时触发 | `() => void` | `-` |
|
|
593
|
+
| onClose | 确定和取消时,都触发 | `(options, value) => void` | `-` |
|
|
594
|
+
| afterClose | 联动时,关闭时回调 | `(options, value) => void` | `-` |
|
|
595
|
+
|
|
596
|
+
### options 数据结构
|
|
597
|
+
|
|
598
|
+
| 属性 | 说明 | 类型 | 默认值 |
|
|
599
|
+
| --- | --- | --- | --- |
|
|
600
|
+
| text | 选项的文字内容 | `string` \| `number` | `-` |
|
|
601
|
+
| value | 选项对应的值,且唯一 | `string` \| `number` | `-` |
|
|
602
|
+
| children | 用于级联选项 | `Array` | `-` |
|
|
603
|
+
|
|
604
|
+
## 主题定制
|
|
605
|
+
|
|
606
|
+
### 样式变量
|
|
607
|
+
|
|
608
|
+
组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 [ConfigProvider 组件](#/zh-CN/component/configprovider)。
|
|
609
|
+
|
|
610
|
+
| 名称 | 说明 | 默认值 |
|
|
611
|
+
| --- | --- | --- |
|
|
612
|
+
| \--nutui-picker-item-active-font-weight | 面板当前选中字体权重 | `$font-weight-bold` |
|
|
613
|
+
| \--nutui-picker-item-active-line-border | 面板当前选中的border值 | `0.5px solid $color-border` |
|
|
614
|
+
| \--nutui-picker-item-height | 面板每一条数据高度 | `48px` |
|
|
615
|
+
| \--nutui-picker-item-text-color | 面板每一条数据的字色 | `$color-title` |
|
|
616
|
+
| \--nutui-picker-item-text-font-size | 面板每条数据字号 | `$font-size-base` |
|
|
617
|
+
| \--nutui-picker-list-height | 面板高度 | `calc(36vh - 64px)` |
|
|
618
|
+
| \--nutui-picker-title-cancel-color | 取消文案的色值 | `$color-text` |
|
|
619
|
+
| \--nutui-picker-title-cancel-font-size | 取消字号 | `$font-size-2` |
|
|
620
|
+
| \--nutui-picker-title-ok-color | 確認文案的色值 | `$color-primary` |
|
|
621
|
+
| \--nutui-picker-title-ok-font-size | 确认字号 | `$font-size-2` |
|