|
@@ -162,7 +162,8 @@
|
|
user:null,
|
|
user:null,
|
|
checkTimer: null, // 轮询定时器 ID
|
|
checkTimer: null, // 轮询定时器 ID
|
|
maxRetryCount: 10, // 最大轮询次数(可选)
|
|
maxRetryCount: 10, // 最大轮询次数(可选)
|
|
- retryCount: 0 // 当前轮询次数(可选)
|
|
|
|
|
|
+ retryCount: 0 ,// 当前轮询次数(可选)
|
|
|
|
+ timeoutTimer:null//总轮询定时器
|
|
}
|
|
}
|
|
},
|
|
},
|
|
onLoad(option) {
|
|
onLoad(option) {
|
|
@@ -291,6 +292,7 @@
|
|
|
|
|
|
},
|
|
},
|
|
otherPayOrder(){
|
|
otherPayOrder(){
|
|
|
|
+
|
|
var that=this;
|
|
var that=this;
|
|
console.log(that.order.id)
|
|
console.log(that.order.id)
|
|
var sum=that.order.id
|
|
var sum=that.order.id
|
|
@@ -299,6 +301,7 @@
|
|
})
|
|
})
|
|
},
|
|
},
|
|
payOrder(){
|
|
payOrder(){
|
|
|
|
+
|
|
var data = {orderId:this.order.id,payType:this.order.payType};
|
|
var data = {orderId:this.order.id,payType:this.order.payType};
|
|
var that=this;
|
|
var that=this;
|
|
uni.showLoading();
|
|
uni.showLoading();
|
|
@@ -321,23 +324,40 @@
|
|
},
|
|
},
|
|
envVersion: 'release', // 开发版 develop,体验版 trial,正式环境传 release
|
|
envVersion: 'release', // 开发版 develop,体验版 trial,正式环境传 release
|
|
success(res) {
|
|
success(res) {
|
|
|
|
+
|
|
uni.showLoading({
|
|
uni.showLoading({
|
|
title:"查询支付结果中...",
|
|
title:"查询支付结果中...",
|
|
|
|
|
|
})
|
|
})
|
|
|
|
+ // 定义计时总变量
|
|
|
|
+ let timeoutFlag = false;
|
|
|
|
+ const timeoutTimer = setTimeout(() => {
|
|
|
|
+ timeoutFlag = true;
|
|
|
|
+ clearInterval(that.checkTimer);
|
|
|
|
+ uni.hideLoading();
|
|
|
|
+ uni.showToast({
|
|
|
|
+ title: '支付状态查询超时',
|
|
|
|
+ icon: 'none'
|
|
|
|
+ });
|
|
|
|
+ uni.redirectTo({
|
|
|
|
+ url: '/pages_user/user/storeOrderDetail?id=' + that.order.id
|
|
|
|
+ });
|
|
|
|
+ }, 10000); // 总时长10秒
|
|
// 启动定时器并保存 ID
|
|
// 启动定时器并保存 ID
|
|
that.checkTimer = setInterval(() => {
|
|
that.checkTimer = setInterval(() => {
|
|
const data = { orderId: that.order.id };
|
|
const data = { orderId: that.order.id };
|
|
checkpayment(data).then(res => {
|
|
checkpayment(data).then(res => {
|
|
|
|
+ if (timeoutFlag) return; // 如果已超时则不再处理
|
|
if (res.code == 200) {
|
|
if (res.code == 200) {
|
|
if (res.status == 1) {
|
|
if (res.status == 1) {
|
|
// 跳转前清除定时器
|
|
// 跳转前清除定时器
|
|
clearInterval(that.checkTimer);
|
|
clearInterval(that.checkTimer);
|
|
- uni.navigateTo({
|
|
|
|
|
|
+ clearTimeout(timeoutTimer);
|
|
|
|
+ uni.redirectTo({
|
|
url: '/pages_user/user/storeOrderDetail?id=' + that.order.id
|
|
url: '/pages_user/user/storeOrderDetail?id=' + that.order.id
|
|
});
|
|
});
|
|
}
|
|
}
|
|
- // else{
|
|
|
|
|
|
+ // else if{
|
|
// setTimeout(()=>{
|
|
// setTimeout(()=>{
|
|
// clearInterval(that.checkTimer);
|
|
// clearInterval(that.checkTimer);
|
|
// uni.navigateTo({
|
|
// uni.navigateTo({
|
|
@@ -345,18 +365,29 @@
|
|
// });
|
|
// });
|
|
// },10000)
|
|
// },10000)
|
|
// }
|
|
// }
|
|
|
|
+ }else{
|
|
|
|
+ // 接口异常时清除定时器
|
|
|
|
+ clearInterval(that.checkTimer);
|
|
|
|
+ clearTimeout(timeoutTimer);
|
|
|
|
+ uni.hideLoading();
|
|
|
|
+ uni.showToast({
|
|
|
|
+ title: '查询异常:' + res.msg,
|
|
|
|
+ icon: 'none'
|
|
|
|
+ });
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}, 4000);
|
|
}, 4000);
|
|
- // setTimeout(()=>{
|
|
|
|
- // that.otherPayOrder()
|
|
|
|
- // },4000)
|
|
|
|
|
|
+ // 页面卸载时清理定时器(重要!)
|
|
|
|
+ that.$once('hook:beforeDestroy', () => {
|
|
|
|
+ clearInterval(that.checkTimer);
|
|
|
|
+ clearTimeout(timeoutTimer);
|
|
|
|
+ });
|
|
console.log('结果结果',res)
|
|
console.log('结果结果',res)
|
|
-// 接口调用成功的回调函数
|
|
|
|
|
|
+ // 接口调用成功的回调函数
|
|
},
|
|
},
|
|
fail(res) {
|
|
fail(res) {
|
|
if (that.checkTimer) clearInterval(that.checkTimer);
|
|
if (that.checkTimer) clearInterval(that.checkTimer);
|
|
-// 接口调用失败的回调函数
|
|
|
|
|
|
+ // 接口调用失败的回调函数
|
|
}
|
|
}
|
|
})
|
|
})
|
|
// var result=JSON.parse(res.result);
|
|
// var result=JSON.parse(res.result);
|