diff --git a/src/views/cashier/index.vue b/src/views/cashier/index.vue index e5cb813..d000339 100644 --- a/src/views/cashier/index.vue +++ b/src/views/cashier/index.vue @@ -75,9 +75,10 @@ this.fromAppurl1 =fromAppurl; this.token = token; this.rechargeAmount = rechargeAmount; - this.ready(); - this.getCurrentLocation(); - this.detail(trainingOrderId,token,type); + this.ready( this.getCurrentLocation()); + this.ready(this.detail(trainingOrderId,token,type)); + //this.getCurrentLocation(); + //this.detail(trainingOrderId,token,type); } @@ -213,10 +214,15 @@ } }, goToApp() { - AlipayJSBridge.call('openInBrowser', { - url: decodeURIComponent(this.fromAppurl1) - }); - AlipayJSBridge.call('closeWebview'); + if (window.AlipayJSBridge) { + AlipayJSBridge.call('openInBrowser', { + url: decodeURIComponent(this.fromAppurl1) + }); + AlipayJSBridge.call('closeWebview'); + }else{ + // 如果没有注入则监听注入的事件 + document.addEventListener('AlipayJSBridgeReady', this.goToApp(), false); + } // window.location.href=decodeURIComponent(this.fromAppurl1); }, diff --git a/src/views/cashier/result.vue b/src/views/cashier/result.vue index 3c8fe02..7478d52 100644 --- a/src/views/cashier/result.vue +++ b/src/views/cashier/result.vue @@ -35,32 +35,29 @@ export default { } this.price=price; this.fromAppurl=fromAppurl; - this.ready(); }, methods: { - ready(callback) { - // 如果jsbridge已经注入则直接调用 - if (window.AlipayJSBridge) { - callback && callback(); - } else { - // 如果没有注入则监听注入的事件 - document.addEventListener('AlipayJSBridgeReady', callback, false); - } - }, goToApp() { + if (window.AlipayJSBridge) { AlipayJSBridge.call('openInBrowser', { url: decodeURIComponent(this.fromAppurl) }); AlipayJSBridge.call('closeWebview'); + }else{ + // 如果没有注入则监听注入的事件 + document.addEventListener('AlipayJSBridgeReady', this.goToApp(), false); + } }, }, created() { + if (!window.AlipayJSBridge) { // 注入支付宝jsapi const s = document.createElement("script"); s.type = "text/javascript"; s.src ="https://gw.alipayobjects.com/as/g/h5-lib/alipayjsapi/3.1.1/alipayjsapi.min.js"; document.body.appendChild(s); + } }, }; diff --git a/src/views/index/index.vue b/src/views/index/index.vue index 750ba67..6fbd9a3 100644 --- a/src/views/index/index.vue +++ b/src/views/index/index.vue @@ -21,8 +21,8 @@ export default { }, methods: { pay(){ - //window.location.href = 'alipays://platformapi/startapp?saId=10000007&qrcode='+encodeURIComponent('http://192.168.1.39:9103/alipay/auth?trainingOrderId=506e9ae34e544f89abb220f0cec0c442&token=amlhcGVpMTY5NDU5MTE3NjIyMzA1NDc1&fromAppurl=paymoney://car:8888/carstep')//拉起支付宝扫一扫 - window.location.href="alipays://platformapi/startapp?appId=20000042&publicBizType=LIFE_APP&publicId=2021004116616163&url="+encodeURIComponent('http://192.168.1.39:9103/alipay/auth?trainingOrderId=506e9ae34e544f89abb220f0cec0c442&token=amlhcGVpMTY5NDU5MTE3NjIyMzA1NDc1&fromAppurl=paymoney://car:8888/carstep')//拉起生活号 + window.location.href = 'alipays://platformapi/startapp?saId=10000007&qrcode='+encodeURIComponent('http://192.168.1.39:9103/alipay/auth?trainingOrderId=506e9ae34e544f89abb220f0cec0c442&token=amlhcGVpMTY5NDU5MTE3NjIyMzA1NDc1&fromAppurl=paymoney://car:8888/carstep')//拉起支付宝扫一扫 + // window.location.href="alipays://platformapi/startapp?appId=20000042&publicBizType=LIFE_APP&publicId=2021004116616163&url="+encodeURIComponent('http://192.168.1.39:9103/alipay/auth?trainingOrderId=506e9ae34e544f89abb220f0cec0c442&token=amlhcGVpMTY5NDU5MTE3NjIyMzA1NDc1&fromAppurl=paymoney://car:8888/carstep')//拉起生活号 //window.location.href ='alipayqr://platformapi/startapp?saId=10000007&qrcode='+encodeURI('http://192.168.1.39:9103/alipay/auth?type=111&trainingOrderId=111&fromAppurl=111&token=111')//另一种拉起支付宝扫一扫 } },