Remember the pitfalls of QR code sharing

Prerequisites:

expected outcome:

I added a code scanning function inside the project. The QR code rules will also be configured outside the project. You can jump to the inside of the mini program and jump to the corresponding result page after scanning the code.

actual results:

I scanned into the mini program from WeChat and jumped to the results page for the first time. Then the QR code scanning function was turned on inside the applet, but the QR code scanning operation was not performed. The QR code scanning tool was only opened. When returning, you will enter the last scan result page again.

reason:

App scene value 1001 is the scene value of scanning the QR code. The scene values ​​of both internal and external code scanning are both 1011. The value in e.query that I monitored is still the original value, that is, there is no update or delete operation. WeChat officials do not differentiate between the scene values ​​of internal code scanning and external code scanning.

solution:

Use getApp().globalData.isScanFail=true to define a global variable, add the global variable in the complete or fail of the internal scanCode, and then add a judgment when app.vue is listening. If there is this value, it will not happen again. Go to the results page.

Internal code scanning scanCode.vue:

      uni.scanCode({
        onlyFromCamera: false,
        success: function (res) {
          console.log('条码类型:' + res.scanType);
          console.log('条码内容:' + res.result);
          base.joinscan(res.result);
        },
        complete: function (res) {
          uni.showLoading({
            title: '识别中...',
          });
          setTimeout(function () {
            uni.hideLoading();
          }, 2000);
        },
        fail: function (res) {
        //添加扫码失败监听全局变量
          getApp().globalData.isScanFail = true;
          setTimeout(function () {
            uni.hideLoading();
          }, 2000);
        },
      });

 

External code scanning and monitoring app.vue

        console.log('跳到扫码失败页面', res.message);
          // 获取当前路由,已经处于扫码失败页面,跳过此处判断
          let datat = {
            message: res.message,
          };
            //判断全局变量,扫码失败监听结果判断
          if(this.globalData.isScanFail) {
            this.flagtarget('pages/home/home', {});
          } else {
          this.flagtarget('pages/scanFaceTag/scanFail', datat);
          }

Remember to define global variables in app.vue, which are at the same level as onload and method!


  globalData: {
    isScanFail: false,
  },
//和method同级

 


 

If it helps you, can you give me a little heart~

Guess you like

Origin blog.csdn.net/weixin_38791717/article/details/110224695