一、业务场景:像ios手机上的获取到验证码,,会在键盘上显示,点击,会自动填入到输入框里面;这时候输入框是一个input还好,,他会自动填入,但是现在要求是验证码的6位数字是分开的,原生的一个input不能实现,所以,数字用6个view来实现,这样验证码需要经过一些列处理,才会填入到6个view里面;
二、实现:
wxml:
{{code.length>=1?code[index]:""}}
js:
data:{
code: '', // 验证码
codeLength: 6, // 验证码的长度
type: 'number',
isPass: false, // input的属性password,没有用到吧
isFocus: true // 是否聚焦
}
方法:
focusBox() {
console.log("聚焦")
this.setData({
isFocus: true
})
},
blurFn() {
console.log("失焦")
this.setData({
isFocus: false
})
}
inputPhoneNum(e){
console.log(e.detail.value) // 输入的数字
}
css:光标闪烁的是模拟的光标,详见动画
.indentify-code{
display: flex;
justify-content: space-around;
border-bottom: 1px solid #999;
}
.indentify-code>block{
border: 1px solid #999;
}
.indentify-code .code-box{
width: 80rpx;
height: 80rpx;
line-height: 80rpx;
/* border: 1px solid #999;
border-radius: 20rpx; */
text-align: center;
}
.realCode{
width: 0rpx;
height: 0px;
}
.shining{
width: 2rpx;
/* border: 1rpx solid #588DED; */
background: #588DED;
height: 60rpx;
animation: shining 1s linear infinite;
margin: 0 auto;
margin-top: 10rpx;
}
@keyframes shining {
0%,100% {
opacity: 0
}
50% {
opacity: 1
}
}
效果这样:那个光标是闪烁的
发现这样有一个bug,就是聚焦之后,键盘弹起,然后自动灭屏之后,又打开屏幕,依然是聚焦状态,但是键盘调不起来,失焦也失焦不了,看了其他的这样的小程序也是有同样问题?????