支付增加轮询,store/common判断是否展示红包代码修改

This commit is contained in:
2025-01-15 15:24:06 +08:00
parent c2bbfc2342
commit c276c9431b
2 changed files with 42 additions and 14 deletions

View File

@@ -17,6 +17,7 @@
const state = reactive({
orderId: '',
timer: null,
timer1: null,
maxAjaxNum: 5,
ajaxNum: 0,
url: null, //要打开的外部链接
@@ -31,6 +32,8 @@
getOrderInfo({
orderId: state.orderId
}).then(res => {
state.ajaxNum+=1
console.log(res);
if (res == 1) {
uni.hideLoading()
@@ -50,31 +53,56 @@
title: '支付成功',
icon: 'none'
})
state.timer = setTimeout(() => {
clearTimeout(state.timer)
state.timer1 = setTimeout(() => {
cleartimer()
uni.navigateBack()
}, 500)
}
} else {
// #ifdef APP
uni.showLoading({
title: '支付中'
})
// #endif
}
if(state.ajaxNum>=state.maxAjaxNum){
uni.navigateBack()
cleartimer()
}
});
}
function cleartimer(){
console.log('cleartimer');
uni.hideLoading()
clearInterval(state.timer)
clearTimeout(state.timer1)
state.timer=null
state.timer1=null
state.ajaxNum=0
}
onShow(() => {
// #ifdef APP
uni.showLoading({
title: '支付中'
})
// #endif
state.ajaxNum=0;
getOrder()
clearInterval(state.timer)
state.timer=setInterval(()=>{
getOrder()
},2000)
})
onHide(() => {
console.log('onHide');
cleartimer()
uni.hideLoading()
})
onUnload(() => {
console.log('onUnload');
cleartimer()
uni.hideLoading()
uni.hideLoading()
})
onLoad((option) => {
console.log(option);
state.url = option.url
state.orderId = option.orderId
})