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