【无标题】

index.wxml文件

    <view class="cod-box">
        <view class="input-name-code">
            <input type="text" class="input-code" placeholder="输入验证码" placeholder-style="color: #C0C4CC;" bindinput="codeInput"/>
        </view>
        <view class="code-img" bindtap="refreshCode">
            <image src="{{codeUrl}}" class="input-code-img" />
        </view>
    </view>

index.wxss文件




    randomString(e) {
        e = e || 32;
        let t = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz1234567890",
            a = t.length,
            n = "";
        for (let i = 0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));
        return n
    },



  async refreshCode() {
        if(this.data.lock){
           return
        }   
        console.log(this.data.lock)
        let randomStr = this.randomString()
        let that = this
        wx.request({
            url: `${base_api_url}/ocular/wx/code` + '?randomStr=' + randomStr, //获取图片的URL
            method: "get",
            responseType: 'arraybuffer', //ArrayBuffer涉及面比较广,我的理解是ArrayBuffer代表内存之中的一段二进制数据,一旦生成不能再改。可以通过视图(TypedArray和DataView)进行操作。
            success(res) {
                console.log(res,'验证码')
                let url = 'data:image/png;base64,' + wx.arrayBufferToBase64(res.data)
                that.setData({
                    codeUrl: url, //设置data里面的图片url
                    randomStr: randomStr
                })
            },
            fail(res) {
               console.log(res)
            }
        })
        this.setData({
            lock:true
        });
        console.log(this.data.lock)
        setTimeout(() => {
            this.setData({
             lock:false
            });
          }, 500);
    },

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值