需求:小程序中手机获取验证码后,自动弹出数字键盘,弹出输入验证码弹窗并且有光标闪烁效果
验证码弹窗组件:
<template>
<van-popup custom-style="border-radius:4px;height:460rpx;top:30%" show="{
{showPayPwdInput}}" close-on-click-overlay="{
{false}}" closeable bind:close="closeFn">
<div class="code">
<div class="input_main">
<div class="input_tip">
<p class="input_tip_tit">输入短信验证码</p>
<span class="input_tip_content">验证码已发送至{
{phoneNumber}}</span>
</div>
<div class="input_row" @tap="$emit('payFocus')">
<div class="pwd_item" v-for="(item,index) in 4" :key="index" :class="{'get_focus':(value_length == index) && payFocus}">
<div v-if="(value_length == index) && payFocus" class="cursor"></div>
<div v-if="(value_length >= index-1)">{
{val_arr[index]}}</div>
</div>
</div>
<p v-if="isSendCode" class="input_code">{
{time}}s后可重新获取</p>
<p v-else class="forget_pwd" @tap="$emit('resend')">重新发送</p>
</div>
</div>
</van-popup>
</template>
<config>
{
"navigationBarTitleText": "授权登录",
"usingComponents": {
"van-popup": "~@vant/popup/index",
}
}
</config>>
<script>
import wepy from '@wepy/core';
wepy.component({
props: {
payFocus: {
type: Boolean,
default: () => {
return []
}
},
val_arr: {
type: Array,
default: () => {
return []
}
},
value_length: {
type: String
},
showPayPwdInput: {
type: Boolean,
default: false
},
phoneNumber: {
type: Number
},
countDown: {
type: Number,
default: 60
}
},
data: {
timeout: null,
time: 60,
isSendCode: true // 是否已经发送验证码
},
watch: {
countDown(val) {
if (val > 0) this.isSendCode = true
if (val === 60) {
this.timeDown(val)
}
}
},
methods: {
closeFn() {
this.$emit('closeFn', this.isSendCode ? this.time : null);
},
// 倒计时
timeDown(time) {
this.timeout = setInter