欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

微信小程序獲取驗(yàn)證碼60秒倒計(jì)時(shí)功能

 更新時(shí)間:2023年04月24日 10:27:36   作者:switch  
這篇文章主要介紹了微信小程序獲取驗(yàn)證碼60秒倒計(jì)時(shí)模板,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

效果圖

index.wxml

     <view class="Info">
            <view class="Num">
                <view>6位數(shù)字驗(yàn)證碼</view>
                <view class="verification_time">
                    <button bindtap='MosendSms' disabled='{{MoDisabled}}' class="Box_hid" style='color:{{MoColor}}' type="button">{{MoCodeMsg}}</button>
                </view>
            </view>
            <view class='verification'>
                <block wx:for="{{Length}}" wx:key="item">
                    <input class='frame' value="{{Showboxval.length>=index+1?Showboxval[index]:''}}" disabled catchtap='InputTap' />
                </block>
            </view>
            <view class="error" wx:if="{{error}}">驗(yàn)證碼輸入錯(cuò)誤</view>
            <input name="password" password="{{true}}" class='ipt' maxlength="{{Length}}" focus="{{isFocus}}" bindinput="FocuInput" />
      </view>

index.js

           data: {
                code: "", //后端驗(yàn)證碼
                Jurisdiction: true, //是否有權(quán)限
                error: false, //錯(cuò)誤提示
                Length: 6, //輸入框個(gè)數(shù)
                isFocus: true, //聚焦
                Showboxval: "", //輸入的內(nèi)容
                MoDisabled: false, //驗(yàn)證碼是否可點(diǎn)擊
                MoCodeMsg: '獲取驗(yàn)證碼', //文案
                MoMsgWait: 60, //時(shí)間秒
                MoColor: 'rgba(40, 200, 122, 1)', //默認(rèn)驗(yàn)證碼字體顏色
            },
             /**
             * 生命周期函數(shù)--監(jiān)聽(tīng)頁(yè)面加載 正常第一次進(jìn)來(lái)先調(diào)用一次
             */
            onLoad(options) {
               this.MosendSms() // 60秒后重新獲取驗(yàn)證碼
            },
            // 60秒后驗(yàn)證碼
            sendSbinms() {
                wx.showToast({
                    title: '短信驗(yàn)證碼發(fā)送成功,請(qǐng)注意查收',
                    icon: 'none'
                })
                this.setData({
                    MoCodeMsg: this.data.MoMsgWait + "  s",
                    MoColor: 'rgba(40, 200, 122, 1)',
                    MoMsgWait: this.data.MoMsgWait - 1,
                    MoDisabled: true
                });
                let inter = setInterval(function () {
                    this.setData({
                        MoCodeMsg: this.data.MoMsgWait + "  s",
                        MoColor: 'rgba(40, 200, 122, 1)',
                        MoMsgWait: this.data.MoMsgWait - 1,
                        MoDisabled: true
                    });
                    if (this.data.MoMsgWait < 0) {
                        clearInterval(inter)
                        this.setData({
                            MoCodeMsg: "重新獲取",
                            MoMsgWait: 60,
                            MoDisabled: false,
                            MoColor: 'rgba(40, 200, 122, 1)'
                        });
                    }
                    //注意后面的bind綁定,最關(guān)鍵。不然又是未定義,無(wú)法使用外圍的變量;
                }.bind(this), 1000);
            },
            // 點(diǎn)擊獲取驗(yàn)證碼
            MosendSms() {
               if (this.data.Jurisdiction) {
                   this.sendSbinms() // 60秒后重新獲取驗(yàn)證碼
                   this.obtain();  //后端接口 獲取驗(yàn)證碼
               } else {
                   wx.showToast({
                      title: this.data.massage ? this.data.massage : '手機(jī)號(hào)未注冊(cè)',
                       icon: 'error',
                       duration: 3000
                   })
               }
             },
             obtain() {
                    let params = {
                        phone: this.data.rstProduct,
                        type: 1
                    }
                    appletValidateCode(params).then((res) => {
                        this.setData({
                            code: res.data.data,
                        });
                    }).catch((res) => {})
                },
     //驗(yàn)證碼輸入框
        FocuInput(e) {
            let that = this;
            let inputValue = e.detail.value;
            that.setData({
                Showboxval: inputValue,
            })
            if (inputValue.length === 6) {
                if (inputValue == this.data.code) {
                    this.setData({
                        error: false,
                    });
                } else {
                    this.setData({
                        error: true,
                    });
                }
            }
        },
   //驗(yàn)證碼輸入框點(diǎn)擊
    InputTap() {
        let that = this;
        that.setData({
            isFocus: true,
        })
    },

index.wxss

.Info {
    padding: 138rpx 32rpx 0 32rpx;
}

.verification {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 30rpx;
    font-size: 32rpx;
}

.Num {
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: rgba(0, 0, 0, 0.65);
    font-size: 30rpx;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
}

.frame {
    width: 80rpx;
    height: 80rpx;
    border-radius: 2px;
    border: 2rpx solid #DEDEDE;
    display: flex;
    justify-content: center;
    align-items: center;
    text-align: center;
    font-size: 32rpx;
    font-family: PingFang SC-Medium, PingFang SC;
    font-weight: 500;
    color: rgba(0, 0, 0, 0.65);
}

.ipt {
    width: 0;
    height: 0;
}

.Box_hid {
    font-size: 30rpx;
    background: #fff !important;
    text-align: left;
    color: rgba(40, 200, 122, 1) !important;
    padding-right: 0 !important;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400 !important;
}

.Box_hid::after {
    border: none;
}

.error {
    color: #F24236;
    margin-top: 8rpx;
    font-size: 28rpx;
    font-family: PingFang SC-Regular, PingFang SC;
    font-weight: 400;
}

到此這篇關(guān)于微信小程序獲取驗(yàn)證碼60秒倒計(jì)時(shí)模板的文章就介紹到這了,更多相關(guān)微信小程序60秒倒計(jì)時(shí)內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論