data: { scanExecuted: false,//扫描 isScanning: false }, //点击开场的时候自动加载onLoad onLoad: function () { this.scan(); }, // 扫描 onTabItemTap(item) { this.setData({ scanExecuted: false }); this.scan(); }, scan: function () { if (this.data.scanExecuted || this.data.isScanning) { return; } let that = this; that.setData({ isScanning: true }); wx.getSystemInfo({ success: function (res) { if (res.platform === 'android') { wx.authorize({ scope: 'scope.camera', success: function () { that.startScan(); }, fail: function () { console.log('用户拒绝授权相机权限'); that.setData({ isScanning: false }); } }); } else if (res.platform === 'ios') { that.startScan(); } } }); }, startScan: function () { let that = this; wx.scanCode({ success: function (res) { console.log(res); that.setData({ scanExecuted: true }); }, fail: function (err) { console.log(err); }, complete: function () { that.setData({ isScanning: false }); } }); } { "pagePath": "pages/codes/codes", "text": "开场", "iconPath": "/picture/saoma.png", "selectedIconPath": "/picture/saomaactive.png" }