1
1
<template >
2
2
<view class =" wrap" >
3
3
<u-form :model =" model" :rules =" rules" ref =" uForm" >
4
- <u-form-item label =" 姓名" prop =" name" >
4
+ <u-form-item left-icon = " map " label-width = " 120 " :label-position = " labelPosition " label =" 姓名" prop =" name" >
5
5
<u-input :border =" border" placeholder =" 请输入姓名" v-model =" model.name" type =" text" ></u-input >
6
6
</u-form-item >
7
- <u-form-item label =" 性别" prop =" sex" >
7
+ <u-form-item :label-position = " labelPosition " label =" 性别" prop =" sex" >
8
8
<u-input :border =" border" type =" select" :select-open =" actionSheetShow" v-model =" model.sex" placeholder =" 请选择性别" @click =" actionSheetShow = true" ></u-input >
9
9
</u-form-item >
10
- <u-form-item label =" 简介" prop =" intro" >
11
- <u-input type =" textarea" placeholder =" 请填写简介" v-model =" model.intro" />
10
+ <u-form-item :label-position = " labelPosition " label =" 简介" prop =" intro" >
11
+ <u-input type =" textarea" :border = " border " placeholder =" 请填写简介" v-model =" model.intro" />
12
12
</u-form-item >
13
- <u-form-item label =" 水果品种" label-width =" 150" prop =" likeFruit" >
14
- <u-checkbox-group @change =" checkboxGroupChange" >
13
+ <u-form-item :label-position =" labelPosition" label =" 密码" prop =" password" >
14
+ <u-input :border =" border" type =" text" :password =" true" v-model =" model.password" placeholder =" 请输入密码" ></u-input >
15
+ </u-form-item >
16
+ <u-form-item :label-position =" labelPosition" label =" 确认密码" label-width =" 150" prop =" rePassword" >
17
+ <u-input :border =" border" type =" text" :password =" true" v-model =" model.rePassword" placeholder =" 请确认密码" ></u-input >
18
+ </u-form-item >
19
+ <u-form-item :label-position =" labelPosition" label =" 水果品种" label-width =" 150" prop =" likeFruit" >
20
+ <u-checkbox-group @change =" checkboxGroupChange" :width =" radioCheckWidth" :wrap =" radioCheckWrap" >
15
21
<u-checkbox v-model =" item.checked" v-for =" (item, index) in checkboxList" :key =" index" :name =" item.name" >{{ item.name }}</u-checkbox >
16
22
</u-checkbox-group >
17
23
</u-form-item >
18
- <u-form-item label =" 结算方式" prop =" payType" label-width =" 150" >
19
- <u-radio-group v-model =" radio" @change =" radioGroupChange" >
24
+ <u-form-item :label-position = " labelPosition " label =" 结算方式" prop =" payType" label-width =" 150" >
25
+ <u-radio-group v-model =" radio" @change =" radioGroupChange" :width = " radioCheckWidth " :wrap = " radioCheckWrap " >
20
26
<u-radio shape =" circle" v-model =" item.checked" v-for =" (item, index) in radioList" :key =" index" :name =" item.name" >{{ item.name }}</u-radio >
21
27
</u-radio-group >
22
28
</u-form-item >
23
- <u-form-item label =" 所在地区" prop =" region" label-width =" 150" >
29
+ <u-form-item :label-position = " labelPosition " label =" 所在地区" prop =" region" label-width =" 150" >
24
30
<u-input :border =" border" type =" select" :select-open =" pickerShow" v-model =" model.region" placeholder =" 请选择地区" @click =" pickerShow = true" ></u-input >
25
31
</u-form-item >
26
- <u-form-item label = " 所在地区 " prop =" goodsType" label-width =" 150" >
32
+ <u-form-item : label-position = " labelPosition " label = " 商品类型 " prop =" goodsType" label-width =" 150" >
27
33
<u-input :border =" border" type =" select" :select-open =" selectShow" v-model =" model.goodsType" placeholder =" 请选择商品类型" @click =" selectShow = true" ></u-input >
28
34
</u-form-item >
35
+ <u-form-item :label-position =" labelPosition" label =" 手机号码" prop =" phone" label-width =" 150" >
36
+ <u-input :border =" border" placeholder =" 请输入手机号" v-model =" model.phone" type =" number" ></u-input >
37
+ </u-form-item >
38
+ <u-form-item :label-position =" labelPosition" label =" 验证码" prop =" code" label-width =" 150" >
39
+ <u-input :border =" border" placeholder =" 请输入验证码" v-model =" model.code" type =" text" ></u-input >
40
+ <u-button slot =" right" type =" success" size =" mini" @click =" getCode" >{{codeTips}}</u-button >
41
+ </u-form-item >
29
42
</u-form >
30
43
<view class =" agreement" >
31
44
<u-checkbox v-model =" check" @change =" checkboxChange" ></u-checkbox >
37
50
<u-action-sheet :list =" actionSheetList" v-model =" actionSheetShow" @click =" actionSheetCallback" ></u-action-sheet >
38
51
<u-select mode =" single-column" :list =" selectList" v-model =" selectShow" @confirm =" selectConfirm" ></u-select >
39
52
<u-picker mode =" region" v-model =" pickerShow" @confirm =" regionConfirm" ></u-picker >
53
+ <u-verification-code seconds =" 60" ref =" uCode" @change =" codeChange" ></u-verification-code >
54
+ <view class =" u-config-wrap" >
55
+ <view class =" u-config-title u-border-bottom" >
56
+ 参数配置
57
+ </view >
58
+ <view class =" u-config-item" >
59
+ <view class =" u-item-title" >label对齐方式</view >
60
+ <u-subsection vibrateShort :list =" ['左边', '上方']" @change =" labelPositionChange" ></u-subsection >
61
+ </view >
62
+ <view class =" u-config-item" >
63
+ <view class =" u-item-title" >边框</view >
64
+ <u-subsection vibrateShort current =" 1" :list =" ['显示', '隐藏']" @change =" borderChange" ></u-subsection >
65
+ </view >
66
+ <view class =" u-config-item" >
67
+ <view class =" u-item-title" >radio、checkbox样式</view >
68
+ <u-subsection vibrateShort :list =" ['自适应', '换行', '50%宽度']" @change =" radioCheckboxChange" ></u-subsection >
69
+ </view >
70
+ <view class =" u-config-item" >
71
+ <view class =" u-item-title" >打乱顺序</view >
72
+ <u-subsection vibrateShort :current =" 1" :list =" ['是', '否']" @change =" randomChange" ></u-subsection >
73
+ </view >
74
+ <view class =" u-config-item" >
75
+ <view class =" u-item-title" >上方工具条</view >
76
+ <u-subsection vibrateShort :list =" ['显示', '隐藏']" @change =" tooltipChange" ></u-subsection >
77
+ </view >
78
+ <view class =" u-config-item" >
79
+ <view class =" u-item-title" >是否显示遮罩</view >
80
+ <u-subsection vibrateShort :list =" ['显示', '隐藏']" @change =" maskChange" ></u-subsection >
81
+ </view >
82
+ </view >
40
83
</view >
41
84
</template >
42
85
@@ -54,6 +97,10 @@ export default {
54
97
agreement: false ,
55
98
region: ' ' ,
56
99
goodsType: ' ' ,
100
+ phone: ' ' ,
101
+ code: ' ' ,
102
+ password: ' ' ,
103
+ rePassword: ' ' ,
57
104
58
105
},
59
106
selectList: [
@@ -86,9 +133,8 @@ export default {
86
133
{
87
134
validator : (rule , value , callback ) => {
88
135
// 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
89
- // return that .$u.test.chinese(value);
136
+ return this .$u .test .chinese (value);
90
137
},
91
- validator1: 33 ,
92
138
message: ' 姓名必须为中文' ,
93
139
// 触发器可以同时用blur和change,二者之间用英文逗号隔开
94
140
trigger: ' change,blur' ,
@@ -113,7 +159,7 @@ export default {
113
159
},
114
160
// 正则校验示例,此处用正则校验是否中文,此处仅为示例,因为uView有this.$u.test.chinese可以判断是否中文
115
161
{
116
- pattern: " /^[\u4e00 -\u9fa5 ]+$/gi" ,
162
+ pattern: / ^ [\u4e00 -\u9fa5 ] + $ / gi ,
117
163
message: ' 简介只能为中文' ,
118
164
trigger: ' change' ,
119
165
},
@@ -147,6 +193,61 @@ export default {
147
193
trigger: ' change' ,
148
194
}
149
195
],
196
+ phone: [
197
+ {
198
+ required: true ,
199
+ message: ' 请输入手机号' ,
200
+ trigger: ' change,blur' ,
201
+ },
202
+ {
203
+ validator : (rule , value , callback ) => {
204
+ // 调用uView自带的js验证规则,详见:https://www.uviewui.com/js/test.html
205
+ return this .$u .test .mobile (value);
206
+ },
207
+ message: ' 手机号码不正确' ,
208
+ // 触发器可以同时用blur和change,二者之间用英文逗号隔开
209
+ trigger: ' change,blur' ,
210
+ }
211
+ ],
212
+ code: [
213
+ {
214
+ required: true ,
215
+ message: ' 请输入验证码' ,
216
+ trigger: ' change,blur' ,
217
+ },
218
+ {
219
+ type: ' number' ,
220
+ message: ' 验证码只能为数字' ,
221
+ trigger: ' change,blur' ,
222
+ }
223
+ ],
224
+ password: [
225
+ {
226
+ required: true ,
227
+ message: ' 请输入密码' ,
228
+ trigger: ' change,blur' ,
229
+ },
230
+ {
231
+ // 正则不能含有两边的引号
232
+ pattern: / ^ (?![0-9 ] + $ )(?![a-zA-Z ] + $ )[0-9A-Za-z ] + \S {6,12} $ / ,
233
+ message: ' 需同时含有字母和数字,长度在6-12之间' ,
234
+ trigger: ' change,blur' ,
235
+ }
236
+ ],
237
+ rePassword: [
238
+ {
239
+ required: true ,
240
+ message: ' 请重新输入密码' ,
241
+ trigger: ' change,blur' ,
242
+ },
243
+ {
244
+ validator : (rule , value , callback ) => {
245
+ return value === this .model .password ;
246
+ },
247
+ message: ' 两次输入的密码不相等' ,
248
+ trigger: ' change,blur' ,
249
+ }
250
+ ],
150
251
},
151
252
border: false ,
152
253
check: false ,
@@ -210,17 +311,19 @@ export default {
210
311
actionSheetShow: false ,
211
312
pickerShow: false ,
212
313
selectShow: false ,
314
+ radioCheckWidth: ' auto' ,
315
+ radioCheckWrap: false ,
316
+ labelPosition: ' left' ,
317
+ codeTips: ' ' ,
213
318
214
319
215
320
};
216
321
},
217
- computed: {
218
- current () {
219
- return this .show ? 0 : 1 ;
220
- }
221
- },
222
322
onLoad () {
223
323
324
+ },
325
+ onReady () {
326
+ this .$refs .uForm .setRules (this .rules );
224
327
},
225
328
methods: {
226
329
submit () {
@@ -259,7 +362,46 @@ export default {
259
362
e .map ((val , index ) => {
260
363
this .model .goodsType += this .model .goodsType == ' ' ? val .label : ' -' + val .label ;
261
364
})
262
- }
365
+ },
366
+ borderChange (index ) {
367
+ this .border = ! index;
368
+ },
369
+ radioCheckboxChange (index ) {
370
+ if (index == 0 ) {
371
+ this .radioCheckWrap = false ;
372
+ this .radioCheckWidth = ' auto' ;
373
+ } else if (index == 1 ) {
374
+ this .radioCheckWrap = true ;
375
+ this .radioCheckWidth = ' auto' ;
376
+ } else if (index == 2 ) {
377
+ this .radioCheckWrap = false ;
378
+ this .radioCheckWidth = ' 50%' ;
379
+ }
380
+ },
381
+ labelPositionChange (index ) {
382
+ this .labelPosition = index == 0 ? ' left' : ' right' ;
383
+ },
384
+ codeChange (text ) {
385
+ this .codeTips = text;
386
+ },
387
+ // 获取验证码
388
+ getCode () {
389
+ if (this .$refs .uCode .canGetCode ) {
390
+ // 模拟向后端请求验证码
391
+ uni .showLoading ({
392
+ title: ' 正在获取验证码'
393
+ })
394
+ setTimeout (() => {
395
+ uni .hideLoading ();
396
+ // 这里此提示会被this.start()方法中的提示覆盖
397
+ this .$u .toast (' 验证码已发送' );
398
+ // 通知验证码组件内部开始倒计时
399
+ this .$refs .uCode .start ();
400
+ }, 2000 );
401
+ } else {
402
+ this .$u .toast (' 倒计时结束后再发送' );
403
+ }
404
+ },
263
405
}
264
406
};
265
407
</script >
0 commit comments