From a11f104adcafae4d8cc1d9a682e60ae9632e55e9 Mon Sep 17 00:00:00 2001 From: woody Date: Thu, 3 Jul 2025 13:24:47 +0800 Subject: [PATCH] =?UTF-8?q?feat(success):=20=E6=94=AF=E4=BB=98=E6=88=90?= =?UTF-8?q?=E5=8A=9F=E9=A1=B5=E9=9D=A2=E6=B7=BB=E5=8A=A0=E8=BD=AE=E8=AF=A2?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/pay/success.vue | 41 +++++++++++++++++------------------------ 1 file changed, 17 insertions(+), 24 deletions(-) diff --git a/pages/pay/success.vue b/pages/pay/success.vue index 535a6cc..5d612a3 100644 --- a/pages/pay/success.vue +++ b/pages/pay/success.vue @@ -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) + }) }, // 跳转到订单列表