feat(success): 支付成功页面添加轮询逻辑

This commit is contained in:
woody 2025-07-03 13:24:47 +08:00
parent 492dd04657
commit a11f104adc
1 changed files with 17 additions and 24 deletions

View File

@ -41,7 +41,7 @@ import { mapGetters } from 'vuex'
import { payStatus, registerInfo } from '@/config/pay.js'
import successDialog from '@/components/successDialog.vue'
let interval = null
let setTimeoutFlag = null
export default {
name: 'PaySuccess',
components: {
@ -50,7 +50,6 @@ export default {
data() {
return {
orderCode: '',
sucPay: 0,
specialArea: null,
isRecharge: undefined,
}
@ -72,45 +71,39 @@ export default {
const extParam = JSON.parse(atob(options.extParam || '{}'))
this.specialArea = extParam.specialArea
this.isRecharge = extParam.source
const source = options.source || ''
if (source) {
this.orderCode = options.orderCode || ''
this.orderCode && this.checkPayStatus()
// this.goToOrderList()
return
}
this.orderCode = extParam.orderCode || ''
this.orderCode && this.pollingPayStatus(this.orderCode)
//
uni.setNavigationBarTitle({
title: '支付成功',
})
},
onUnload() {
clearInterval(interval)
clearTimeout(setTimeoutFlag)
},
methods: {
//
checkPayStatus(orderCode) {
//
interval = setInterval(() => {
if (this.sucPay == 1) {
pollingPayStatus(orderCode) {
payStatus({ businessCode: orderCode }).then(res => {
if (res.data == 1) {
//
clearInterval(interval)
if (
this.specialArea == 1 ||
this.specialArea == 7 ||
this.specialArea == 24
) {
clearTimeout(setTimeoutFlag)
if ([1, 7, 24].includes(Number(this.specialArea))) {
registerInfo(orderCode).then(res => {
this.$refs.successDialog.showSuccess(res.data)
})
}
} else {
payStatus({ businessCode: orderCode }).then(res => {
this.sucPay = res.data
if (res.data == 0) {
setTimeoutFlag = setTimeout(() => {
this.pollingPayStatus(orderCode)
}, 1000)
} else {
clearTimeout(setTimeoutFlag)
}
})
}
}, 2000)
})
},
//