diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/App.vue b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/App.vue index 5b1c69b1b..5b7e1d0b0 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/App.vue +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/App.vue @@ -5,6 +5,8 @@ // 考虑到用户刷新网页时会丢失全局数据、页面栈、页面数据等,因此直接跳回首页即可 async onLaunch(param) { + // 在App.vue文件中获取到页面到URL (微信调取扫一扫会用到) + window.localStorage.setItem('scanUrl',location.href.split('#')[0]) //应用的生命周期 应用启动后触发 // #ifdef H5 || APP-VUE // H5 刷新时获取当前页面路径 diff --git a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/scanCode.vue b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/scanCode.vue index 1df50df26..7f1daeb33 100644 --- a/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/scanCode.vue +++ b/Learun.Framework.Ultimate V7/LearunApp-2.2.0/components/scanCode.vue @@ -8,7 +8,7 @@ props:{}, data() { return { - scanCodeReady:false, + wxObject:null, }; }, mounted() { @@ -17,12 +17,15 @@ methods: { setConfig() { const promise = new Promise((resolve, reject) => { - this.HTTP_GET("weixinapi/getweixinwebaccess_token?url=" + encodeURIComponent(window.location.href)).then((success)=>{ + // let url = window.location.href + let url = /(Android)/i.test(navigator.userAgent) ? location.href.split('#')[0] : window.localStorage.getItem('scanUrl') + this.HTTP_GET("weixinapi/getweixinwebaccess_token?url=" + encodeURIComponent(url)).then((success)=>{ if(!success){ resolve(false) return } - wx.config({ + this.wxObject = wx + this.wxObject.config({ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: success.appid, // 必填,公众号的唯一标识 timestamp: success.timestamp, // 必填,生成签名的时间戳 @@ -30,8 +33,11 @@ signature: success.certificate, // 必填,签名 jsApiList: ["scanQRCode"] // 必填,需要使用的JS接口列表 }); - wx.ready(() => { - this.scanCodeReady = true + this.wxObject.ready(() => { + this.TOAST("扫码初始化成功") + }) + this.wxObject.error(() => { + this.TOAST("扫码初始化失败") }) }) }) @@ -39,19 +45,23 @@ }, scanCode(){ return new Promise((resolve)=>{ - if(!this.scanCodeReady){ + if(!this.wxObject||!this.wxObject.scanQRCode){ + this.TOAST("无效方法") resolve(false) + }else{ + this.TOAST("正在调用扫码...") } - wx.scanQRCode({ + this.wxObject.scanQRCode({ needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果, scanType: ["qrCode", "barCode"], // 可以指定扫二维码还是一维码,默认二者都有 - success: function (res) { + success: (res) => { + this.TOAST("方法调用成功") var result = res.resultStr; // 当 needResult 为 1 时,扫码返回的结果 var resultArr = result.split(','); // 扫描结果以逗号分割数组 var codeContent = resultArr[resultArr.length - 1]; // 获取数组最后一个元素,也就是最终的内容 resolve({result:codeContent}) }, - fail: function (res) { + fail: (res) =>{ this.TOAST("调用扫码失败") resolve(false) }