Skip to content

Commit e729090

Browse files
committed
docs: picker docs done
1 parent 7c5a071 commit e729090

File tree

1 file changed

+310
-42
lines changed

1 file changed

+310
-42
lines changed

docs/feedbackComponent/picker.md

Lines changed: 310 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Picker
22

3-
选择器,基于 `picker-view``picker-view-column` 实现。
3+
选择器,基于 `picker-view``picker-view-column` 实现,来自于 [mpvue-picker](https://github.com/MPComponent/mpvue-picker)
44

55
<imgPreview imgUrl="/assets/picker.png"/>
66

@@ -18,63 +18,331 @@ export default {
1818
### 使用
1919

2020
``` html
21-
<mp-picker ref="mpvuePicker" :mode="mode" :deepLength=deepLength :pickerValueDefault="pickerValueDefault" @onChange="onChange" @onConfirm="onConfirm" @onCancel="onCancel" :pickerValueArray="pickerValueArray"></mp-picker>
21+
<button type="default" @click="showMulLinkageTwoPicker">二级联动选择</button>
22+
<mp-picker ref="mpPicker" :mode="mode" :deepLength=deepLength :pickerValueDefault="pickerValueDefault" @onChange="onChange" @onConfirm="onConfirm" @onCancel="onCancel" :pickerValueArray="pickerValueArray"></mp-picker>
23+
```
24+
25+
``` js
26+
export default {
27+
...
28+
data() {
29+
return {
30+
mode: 'multiLinkageSelector',
31+
pickerValueArray: [
32+
{
33+
label: '飞机票',
34+
value: 100,
35+
children: [
36+
{
37+
label: '经济舱',
38+
value: 101
39+
},
40+
{
41+
label: '商务舱',
42+
value: 102
43+
}
44+
]
45+
},
46+
{
47+
label: '火车票',
48+
value: 200,
49+
children: [
50+
{
51+
label: '卧铺',
52+
value: 210
53+
},
54+
{
55+
label: '坐票',
56+
value: 202
57+
},
58+
{
59+
label: '站票',
60+
value: 203
61+
}
62+
]
63+
},
64+
{
65+
label: '汽车票',
66+
value: 300,
67+
children: [
68+
{
69+
label: '快班',
70+
value: 301
71+
},
72+
{
73+
label: '普通',
74+
value: 302
75+
}
76+
]
77+
}
78+
],
79+
pickerValueDefault: [1, 0]
80+
};
81+
},
82+
methods: {
83+
showMulLinkageTwoPicker() {
84+
this.$refs.mpPicker.show();
85+
},
86+
onConfirm(e) {
87+
console.log(e);
88+
},
89+
onChange(e) {
90+
console.log(e);
91+
},
92+
onCancel(e) {
93+
console.log(e);
94+
}
95+
}
96+
};
97+
```
98+
99+
### 初始化
100+
101+
在父组件中调用 ` mpPicker` 实例中的 `show` 方法:
102+
103+
``` javascript
104+
this.$refs.mpPicker.show();
22105
```
23106

24107
### API
25108

109+
| 参数 | 说明 | 类型 | 默认值 |
110+
|-----------|-----------|-----------|-------------|
111+
| mode | picker 组件类型 | `String` | `selector` |
112+
| pickerValueArray | picker 渲染数据 | `Array` | `-` |
113+
| pickerValueDefault | picker 默认选中值 | `Array` | `[]` |
114+
| deepLength | 几级联动 | `Number` | `2` |
115+
26116

27-
### mode
28-
* 说明:picker 组件类型
29-
* 类型:String
117+
### 参数说明
118+
119+
#### mode
30120
* 可选值:
31121
* selector(单列)
32122
* timeSelector(时间选择)
33123
* multiSelector(多列)
34124
* multiLinkageSelector(级联)
35125
* 是否必填: 否
36-
* 默认值:selector
37126

38-
### pickerValueArray
39-
* 说明:picker 渲染数据
40-
* 类型:Array
41-
* 可选值:-
127+
#### pickerValueArray
128+
42129
* 是否必填: 是(当 mode 值为 timeSelector 不用填)
43-
* 默认值:-
44130

45-
### pickerValueDefault
46-
* 说明:picker 默认选中值
47-
* 类型:Array
48-
* 可选值:-
131+
#### pickerValueDefault
132+
49133
* 是否必填: 否 (当同一个组件使用多种 mode 来回切换使用时 pickerValueDefault 必填)
50-
* 默认值:[]
51134

52-
### deepLength
53-
* 说明:几级联动
54-
* 类型:Number
55-
* 可选值:
56-
* 2
57-
* 3
58-
* 是否必填: 否
59-
* 默认值:2
60135

61-
### onChange
62-
* 说明:picker 组件滚动时回调,返回选中的 label, value 和数组索引 index 的值
63-
* 类型:EventHandle
64-
* 可选值:-
65-
* 是否必填: 否
66-
* 默认值:-
136+
### Event
67137

68-
### onConfirm
69-
* 说明:picker 组件点击确定时回调,返回选中的 label, value 和数组索引 index 的值
70-
* 类型:EventHandle
71-
* 可选值:-
72-
* 是否必填: 否
73-
* 默认值:-
138+
| 事件名 | 说明 | 参数 |
139+
|-----------|-----------|-----------|
140+
| @onChange | 组件滚动时回调 | 返回选中的 label, value 和数组索引 index 的值 |
141+
| @onConfirm | 组件点击确定时回调 | 返回选中的 label, value 和数组索引 index 的值 |
142+
| @onCancel | 组件点击取消时回调 | 返回选中的 label, value 和数组索引 index 的值 |
74143

75-
### onCancel
76-
* 说明:picker 组件点击取消时回调,返回选中的 label, value 和数组索引 index 的值
77-
* 类型:EventHandle
78-
* 可选值:-
79-
* 是否必填: 否
80-
* 默认值:-
144+
145+
146+
### 相关数据结构说明
147+
148+
#### **单列**
149+
<details>
150+
<summary>点击展开单列数据结构</summary>
151+
152+
``` javascript
153+
pickerValueArray: [
154+
{
155+
label: '住宿费',
156+
value: 1
157+
},
158+
{
159+
label: '活动费',
160+
value: 2
161+
},
162+
{
163+
label: '通讯费',
164+
value: 3
165+
},
166+
{
167+
label: '补助',
168+
value: 4
169+
}
170+
],
171+
```
172+
</details>
173+
174+
175+
#### **多列**
176+
<details>
177+
<summary>点击展开多列数据结构</summary>
178+
179+
``` javascript
180+
pickerMulArray: [
181+
[
182+
{ label: '中国', value: 1 },
183+
{ label: '美国', value: 2 },
184+
{ label: '日本', value: 3 },
185+
{ label: '俄罗斯', value: 4 }
186+
],
187+
[
188+
{ label: '', value: 1 },
189+
{ label: '咖啡', value: 2 },
190+
{ label: '寿司', value: 3 },
191+
{ label: '奶酪', value: 4 }
192+
],
193+
[
194+
{ label: '歼20', value: 1 },
195+
{ label: 'F22', value: 2 },
196+
{ label: '秋月级', value: 3 },
197+
{ label: 'T50', value: 4 }
198+
]
199+
]
200+
```
201+
</details>
202+
203+
#### **二级联动**
204+
<details>
205+
<summary>点击展开二级联动数据结构</summary>
206+
207+
``` javascript
208+
pickerValueArray:
209+
[
210+
{
211+
label: '飞机票',
212+
value: 0,
213+
children: [{
214+
label: '经济舱',
215+
value: 1
216+
},
217+
{
218+
label: '商务舱',
219+
value: 2
220+
}
221+
]
222+
},
223+
{
224+
label: '火车票',
225+
value: 1,
226+
children: [{
227+
label: '卧铺',
228+
value: 1
229+
},
230+
{
231+
label: '坐票',
232+
value: 2
233+
},
234+
{
235+
label: '站票',
236+
value: 3
237+
}
238+
]
239+
},
240+
{
241+
label: '汽车票',
242+
value: 3,
243+
children: [{
244+
label: '快班',
245+
value: 1
246+
},
247+
{
248+
label: '普通',
249+
value: 2
250+
}
251+
]
252+
}
253+
]
254+
```
255+
</details>
256+
257+
258+
#### **三级联动**
259+
<details>
260+
<summary>点击展开三级联动数据结构</summary>
261+
262+
``` javascript
263+
pickerValueArray:
264+
[
265+
{
266+
label: 'phone',
267+
value: 0,
268+
children: [
269+
{
270+
label: 'iphone',
271+
value: 1,
272+
children: [{
273+
label: 'iphoneX',
274+
value: 1
275+
},
276+
{
277+
label: 'iphone8',
278+
value: 2
279+
}, {
280+
label: 'iphone8 Plus',
281+
value: 3
282+
}]
283+
},
284+
{
285+
label: 'android',
286+
value: 1,
287+
children: [
288+
{
289+
label: 'vivo',
290+
value: 1
291+
},
292+
{
293+
label: '魅族',
294+
value: 2
295+
}, {
296+
label: '小米',
297+
value: 3
298+
}
299+
]
300+
}
301+
]
302+
},
303+
{
304+
label: 'PC',
305+
value: 0,
306+
children: [
307+
{
308+
label: 'mac',
309+
value: 1,
310+
children: [
311+
{
312+
label: 'macbook Pro',
313+
value: 1
314+
},
315+
{
316+
label: 'iMac',
317+
value: 2
318+
}, {
319+
label: 'mackbook',
320+
value: 3
321+
}, {
322+
label: 'mackbook air',
323+
value: 3
324+
}
325+
]
326+
},
327+
{
328+
label: 'windows',
329+
value: 1,
330+
children: [
331+
{
332+
label: 'dell',
333+
value: 1
334+
},
335+
{
336+
label: 'surface',
337+
value: 2
338+
}, {
339+
label: 'thinkpad',
340+
value: 3
341+
}
342+
]
343+
}
344+
]
345+
}
346+
]
347+
```
348+
</details>

0 commit comments

Comments
 (0)