1
+ import { AtForm , AtInput } from 'taro-ui'
2
+ import { Image , View } from '@tarojs/components'
3
+ import { BaseEventOrig } from '@tarojs/components/types/common'
4
+ import { InputProps } from '@tarojs/components/types/Input'
1
5
import Taro from '@tarojs/taro'
2
- import { View , Image } from '@tarojs/components'
3
- import { AtInput , AtForm } from 'taro-ui'
4
- import DocsHeader from '../../components/doc-header'
5
6
import verificationCode from '../../../assets/images/verification_code.png'
7
+ import DocsHeader from '../../components/doc-header'
6
8
import './index.scss'
7
9
8
10
interface IndexState {
@@ -20,17 +22,15 @@ interface IndexState {
20
22
value13 : string
21
23
value14 : string
22
24
value15 : string
25
+ value16 : string
26
+ value17 : string
23
27
disabled : boolean
24
28
second : number
25
29
[ key : string ] : string | boolean | number
26
30
}
27
31
28
32
export default class Index extends Taro . Component < { } , IndexState > {
29
- public config : Taro . PageConfig = {
30
- navigationBarTitleText : 'Taro UI'
31
- }
32
-
33
- public constructor ( ) {
33
+ public constructor ( ) {
34
34
super ( ...arguments )
35
35
this . state = {
36
36
value1 : '' ,
@@ -48,16 +48,21 @@ export default class Index extends Taro.Component<{}, IndexState> {
48
48
value14 : '' ,
49
49
value15 : '' ,
50
50
value16 : '' ,
51
+ value17 : '' ,
51
52
disabled : false ,
52
53
second : 60
53
54
}
54
55
}
55
56
56
- private showTipText ( ) : string {
57
+ public config : Taro . PageConfig = {
58
+ navigationBarTitleText : 'Taro UI'
59
+ }
60
+
61
+ private showTipText ( ) : string {
57
62
return this . state . disabled ? `${ this . state . second } s后重试` : '发送验证码'
58
63
}
59
64
60
- private sendCode ( ) : void {
65
+ private sendCode ( ) : void {
61
66
if ( this . state . disabled ) return
62
67
this . setState ( {
63
68
disabled : true
@@ -78,29 +83,39 @@ export default class Index extends Taro.Component<{}, IndexState> {
78
83
} , 1000 )
79
84
}
80
85
81
- private handleInput ( stateName : string , value : string ) : void {
86
+ private handleInput ( stateName : string , value : string ) : void {
82
87
this . setState ( {
83
88
[ stateName ] : value
84
89
} )
85
90
}
86
91
87
- private handleClick ( ) : void {
92
+ // private handleClick(): void {
93
+ // Taro.showToast({
94
+ // title: '已发送验证码',
95
+ // icon: 'success',
96
+ // duration: 2000
97
+ // })
98
+ // }
99
+
100
+ private onClickErrorIcon ( ) : void {
88
101
Taro . showToast ( {
89
- title : '已发送验证码 ' ,
102
+ title : '请输入数字 ' ,
90
103
icon : 'success' ,
91
104
duration : 2000
92
105
} )
93
106
}
94
107
95
- private onClickErrorIcon ( ) : void {
108
+ private handleKeyboardHeightChange (
109
+ event : BaseEventOrig < InputProps . onKeyboardHeightChangeEventDetail >
110
+ ) : void {
96
111
Taro . showToast ( {
97
- title : '请输入数字' ,
112
+ title : `高度 ${ event . detail . height } ` ,
98
113
icon : 'success' ,
99
114
duration : 2000
100
115
} )
101
116
}
102
117
103
- public render ( ) : JSX . Element {
118
+ public render ( ) : JSX . Element {
104
119
return (
105
120
< View className = 'page' >
106
121
{ /* S Header */ }
@@ -115,9 +130,28 @@ export default class Index extends Taro.Component<{}, IndexState> {
115
130
< View className = 'panel__content no-padding' >
116
131
< View className = 'component-item' >
117
132
< AtForm >
118
- < AtInput name = 'value1' title = '标准五个字' type = 'text' placeholder = '标准五个字' value = { this . state . value1 } onChange = { this . handleInput . bind ( this , 'value1' ) } />
119
- < AtInput name = 'value2' title = '标题实在特别长就换行' placeholder = '其他列保持正常间距' value = { this . state . value2 } onChange = { this . handleInput . bind ( this , 'value2' ) } />
120
- < AtInput name = 'value3' border = { false } placeholder = '无标题' value = { this . state . value3 } onChange = { this . handleInput . bind ( this , 'value3' ) } />
133
+ < AtInput
134
+ name = 'value1'
135
+ title = '标准五个字'
136
+ type = 'text'
137
+ placeholder = '标准五个字'
138
+ value = { this . state . value1 }
139
+ onChange = { this . handleInput . bind ( this , 'value1' ) }
140
+ />
141
+ < AtInput
142
+ name = 'value2'
143
+ title = '标题实在特别长就换行'
144
+ placeholder = '其他列保持正常间距'
145
+ value = { this . state . value2 }
146
+ onChange = { this . handleInput . bind ( this , 'value2' ) }
147
+ />
148
+ < AtInput
149
+ name = 'value3'
150
+ border = { false }
151
+ placeholder = '无标题'
152
+ value = { this . state . value3 }
153
+ onChange = { this . handleInput . bind ( this , 'value3' ) }
154
+ />
121
155
</ AtForm >
122
156
</ View >
123
157
</ View >
@@ -129,12 +163,55 @@ export default class Index extends Taro.Component<{}, IndexState> {
129
163
< View className = 'panel__content no-padding' >
130
164
< View className = 'component-item' >
131
165
< AtForm >
132
- < AtInput name = 'value4' title = '文本' type = 'text' placeholder = '单行文本' value = { this . state . value4 } onChange = { this . handleInput . bind ( this , 'value4' ) } />
133
- < AtInput name = 'value5' title = '数字' type = 'number' placeholder = '请输入数字' value = { this . state . value5 } onChange = { this . handleInput . bind ( this , 'value5' ) } />
134
- < AtInput name = 'value6' title = '密码' type = 'password' placeholder = '密码不能少于10位数' value = { this . state . value6 } onChange = { this . handleInput . bind ( this , 'value6' ) } />
135
- < AtInput name = 'value7' title = '身份证' type = 'idcard' placeholder = '身份证号码' value = { this . state . value7 } onChange = { this . handleInput . bind ( this , 'value7' ) } />
136
- < AtInput name = 'value8' title = '小数' type = 'digit' placeholder = '请输入小数' value = { this . state . value8 } onChange = { this . handleInput . bind ( this , 'value8' ) } />
137
- < AtInput name = 'value9' border = { false } title = '手机号码' type = 'phone' placeholder = '手机号码' value = { this . state . value9 } onChange = { this . handleInput . bind ( this , 'value9' ) } />
166
+ < AtInput
167
+ name = 'value4'
168
+ title = '文本'
169
+ type = 'text'
170
+ placeholder = '单行文本'
171
+ value = { this . state . value4 }
172
+ onChange = { this . handleInput . bind ( this , 'value4' ) }
173
+ />
174
+ < AtInput
175
+ name = 'value5'
176
+ title = '数字'
177
+ type = 'number'
178
+ placeholder = '请输入数字'
179
+ value = { this . state . value5 }
180
+ onChange = { this . handleInput . bind ( this , 'value5' ) }
181
+ />
182
+ < AtInput
183
+ name = 'value6'
184
+ title = '密码'
185
+ type = 'password'
186
+ placeholder = '密码不能少于10位数'
187
+ value = { this . state . value6 }
188
+ onChange = { this . handleInput . bind ( this , 'value6' ) }
189
+ />
190
+ < AtInput
191
+ name = 'value7'
192
+ title = '身份证'
193
+ type = 'idcard'
194
+ placeholder = '身份证号码'
195
+ value = { this . state . value7 }
196
+ onChange = { this . handleInput . bind ( this , 'value7' ) }
197
+ />
198
+ < AtInput
199
+ name = 'value8'
200
+ title = '小数'
201
+ type = 'digit'
202
+ placeholder = '请输入小数'
203
+ value = { this . state . value8 }
204
+ onChange = { this . handleInput . bind ( this , 'value8' ) }
205
+ />
206
+ < AtInput
207
+ name = 'value9'
208
+ border = { false }
209
+ title = '手机号码'
210
+ type = 'phone'
211
+ placeholder = '手机号码'
212
+ value = { this . state . value9 }
213
+ onChange = { this . handleInput . bind ( this , 'value9' ) }
214
+ />
138
215
</ AtForm >
139
216
</ View >
140
217
</ View >
@@ -146,12 +223,65 @@ export default class Index extends Taro.Component<{}, IndexState> {
146
223
< View className = 'panel__content no-padding' >
147
224
< View className = 'component-item' >
148
225
< AtForm >
149
- < AtInput name = 'value10' disabled title = '禁用' type = 'text' placeholder = '禁止输入' value = { this . state . value10 } onChange = { this . handleInput . bind ( this , 'value10' ) } />
150
- < AtInput name = 'value11' error title = '出现错误' type = 'text' placeholder = '点击按钮触发回调' value = { this . state . value11 } onChange = { this . handleInput . bind ( this , 'value11' ) } onErrorClick = { this . onClickErrorIcon . bind ( this ) } />
151
- < AtInput name = 'value12' editable = { false } title = '不可编辑' type = 'text' placeholder = '不可编辑' value = '不可编辑的内容' />
152
- < AtInput name = 'value13' border = { false } clear title = '清除按钮' type = 'text' placeholder = '点击清除按钮清空内容' value = { this . state . value13 } onChange = { this . handleInput . bind ( this , 'value13' ) } />
153
- < AtInput name = 'value16' border = { false } required title = '必填项' type = 'text' placeholder = '必填项' value = { this . state . value16 } onChange = { this . handleInput . bind ( this , 'value16' ) } />
154
-
226
+ < AtInput
227
+ name = 'value10'
228
+ disabled
229
+ title = '禁用'
230
+ type = 'text'
231
+ placeholder = '禁止输入'
232
+ value = { this . state . value10 }
233
+ onChange = { this . handleInput . bind ( this , 'value10' ) }
234
+ />
235
+ < AtInput
236
+ name = 'value11'
237
+ error
238
+ title = '出现错误'
239
+ type = 'text'
240
+ placeholder = '点击按钮触发回调'
241
+ value = { this . state . value11 }
242
+ onChange = { this . handleInput . bind ( this , 'value11' ) }
243
+ onErrorClick = { this . onClickErrorIcon . bind ( this ) }
244
+ />
245
+ < AtInput
246
+ name = 'value12'
247
+ editable = { false }
248
+ title = '不可编辑'
249
+ type = 'text'
250
+ placeholder = '不可编辑'
251
+ value = '不可编辑的内容'
252
+ />
253
+ < AtInput
254
+ name = 'value13'
255
+ border = { false }
256
+ clear
257
+ title = '清除按钮'
258
+ type = 'text'
259
+ placeholder = '点击清除按钮清空内容'
260
+ value = { this . state . value13 }
261
+ onChange = { this . handleInput . bind ( this , 'value13' ) }
262
+ />
263
+ < AtInput
264
+ name = 'value16'
265
+ border = { false }
266
+ required
267
+ title = '必填项'
268
+ type = 'text'
269
+ placeholder = '必填项'
270
+ value = { this . state . value16 }
271
+ onChange = { this . handleInput . bind ( this , 'value16' ) }
272
+ />
273
+ < AtInput
274
+ name = 'value17'
275
+ border = { false }
276
+ title = '监听事件'
277
+ type = 'text'
278
+ placeholder = '监听键盘高度事件'
279
+ value = { this . state . value17 }
280
+ onChange = { this . handleInput . bind ( this , 'value17' ) }
281
+ onKeyboardHeightChange = { this . handleKeyboardHeightChange . bind (
282
+ this
283
+ ) }
284
+ />
155
285
</ AtForm >
156
286
</ View >
157
287
</ View >
@@ -163,15 +293,32 @@ export default class Index extends Taro.Component<{}, IndexState> {
163
293
< View className = 'panel__content no-padding' >
164
294
< View className = 'component-item' >
165
295
< AtForm >
166
- < AtInput name = 'value14' title = '验证码' type = 'text' maxLength = { 4 } clear placeholder = '验证码' value = { this . state . value14 } onChange = { this . handleInput . bind ( this , 'value14' ) } >
296
+ < AtInput
297
+ name = 'value14'
298
+ title = '验证码'
299
+ type = 'text'
300
+ maxLength = { 4 }
301
+ clear
302
+ placeholder = '验证码'
303
+ value = { this . state . value14 }
304
+ onChange = { this . handleInput . bind ( this , 'value14' ) }
305
+ >
167
306
< Image src = { verificationCode } />
168
307
</ AtInput >
169
- < AtInput name = 'value15' border = { false } type = 'phone' clear placeholder = '请输入手机号码' value = { this . state . value15 } onChange = { this . handleInput . bind ( this , 'value15' ) } >
308
+ < AtInput
309
+ name = 'value15'
310
+ border = { false }
311
+ type = 'phone'
312
+ clear
313
+ placeholder = '请输入手机号码'
314
+ value = { this . state . value15 }
315
+ onChange = { this . handleInput . bind ( this , 'value15' ) }
316
+ >
170
317
< View
171
318
style = { {
172
- ' color' : this . state . disabled ? '#FF4949' : '' ,
173
- ' fontSize' : '12px' ,
174
- ' width' : '90px'
319
+ color : this . state . disabled ? '#FF4949' : '' ,
320
+ fontSize : '12px' ,
321
+ width : '90px'
175
322
} }
176
323
onClick = { this . sendCode . bind ( this ) }
177
324
>
0 commit comments