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

This commit is contained in:
YeMingfei666 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({ const state = reactive({
orderId: '', orderId: '',
timer: null, timer: null,
timer1: null,
maxAjaxNum: 5, maxAjaxNum: 5,
ajaxNum: 0, ajaxNum: 0,
url: null, // url: null, //
@ -31,6 +32,8 @@
getOrderInfo({ getOrderInfo({
orderId: state.orderId orderId: state.orderId
}).then(res => { }).then(res => {
state.ajaxNum+=1
console.log(res); console.log(res);
if (res == 1) { if (res == 1) {
uni.hideLoading() uni.hideLoading()
@ -50,31 +53,56 @@
title: '支付成功', title: '支付成功',
icon: 'none' icon: 'none'
}) })
state.timer = setTimeout(() => { state.timer1 = setTimeout(() => {
clearTimeout(state.timer) cleartimer()
uni.navigateBack() uni.navigateBack()
}, 500) }, 500)
} }
} else { } else {
// #ifdef APP
uni.showLoading({ }
title: '支付中'
}) if(state.ajaxNum>=state.maxAjaxNum){
// #endif 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(() => { onShow(() => {
// #ifdef APP
uni.showLoading({
title: '支付中'
})
// #endif
state.ajaxNum=0;
getOrder() getOrder()
clearInterval(state.timer)
state.timer=setInterval(()=>{
getOrder()
},2000)
}) })
onHide(() => { onHide(() => {
console.log('onHide');
cleartimer()
uni.hideLoading() uni.hideLoading()
}) })
onUnload(() => { onUnload(() => {
console.log('onUnload');
cleartimer()
uni.hideLoading()
uni.hideLoading() uni.hideLoading()
}) })
onLoad((option) => { onLoad((option) => {
console.log(option);
state.url = option.url state.url = option.url
state.orderId = option.orderId state.orderId = option.orderId
}) })

View File

@ -46,12 +46,15 @@ export const useCommonStore = defineStore("common", {
return { return {
payTips: '付款完成后不要忘记抽红包哦', payTips: '付款完成后不要忘记抽红包哦',
goldBili: 0, goldBili: 0,
sysInfo:{} sysInfo:{},
isIos:false,
isExamine:1
}; };
}, },
actions: { actions: {
async init() { async init() {
this.sysInfo=uni.getSystemInfoSync() this.sysInfo=uni.getSystemInfoSync()
this.isIos=this.sysInfo.platform == 'ios'
const res = await getCommonConfig() const res = await getCommonConfig()
if (res) { if (res) {
for (let i in $map) { for (let i in $map) {
@ -64,13 +67,10 @@ export const useCommonStore = defineStore("common", {
} }
}, },
isIosExamine() { isIosExamine() {
const sysInfo = uni.getSystemInfoSync(); if (!this.isIos) {
let isIos = sysInfo.platform == 'ios'
if (!isIos) {
return true return true
} }
let isExamine = useCommonStore() if (this.isExamine == 1) {
if (isExamine.isExamine == 1) {
return false return false
} }
return true return true