微信公众号拉取扫码功能

点击扫码按钮拉取微信扫码

    // 扫码添加设备
    goAddEquipment() {
      const wx = window.wx
      let _this = this
      // wx.ready(function() {
        wx.checkJsApi({
          jsApiList: ['scanQRCode'], // 需要检测的JS接口列表,所有JS接口列表见附录2,
          success: function(res) {
            console.log(res)
          // 以键值对的形式返回,可用的api值true,不可用为false
          // 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
            wx.scanQRCode({
              needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
              scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有
              success: function(res) {
                console.log(res)
                var code = res.resultStr // 当needResult 为 1 时,扫码返回的结果
                // alert(code)
                _this._initDeviceStatus(code)
                // '设备重复绑定'
              },
              fail: function(res) {
                console.log(res)
                // _this._initWeixinAuth()
              }
            })
          }
        // })
      })
    },

不需要的可省略以下两步

    // 判断是否有设备
    _initDeviceStatus(code) {
      this.$http.get(`/device?device_code=${code}`).then(res => {
        if (res.errcode === 0 && res.data?.id) {
          return this.$http.post('/device/is_bind', {
            device_code: code
          })
          // this.confirm(code)
        } else {
          this.$toast('无效的设备二维码')
        }
      }).then(result => {
        if (result.errcode === 0 && !result.data) {
          this.confirm(code)
        } else {
          this.$toast('设备重复绑定')
        }
      })
    }
   confirm(code) {
      this.$store.commit("bindEquipment/INIT_STATE")
      this.$router.push({
        path: '/game',
        query: {
          dcode: code
        }
      })
    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LuckilyMyGirl

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值