From a596066968e625bd39a79f4d15635e50659512cd Mon Sep 17 00:00:00 2001
From: yfx <1249361928@.com>
Date: Wed, 01 Apr 2026 11:43:24 +0800
Subject: [PATCH] lx
---
pages/web/polling.vue | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 112 insertions(+), 0 deletions(-)
diff --git a/pages/web/polling.vue b/pages/web/polling.vue
new file mode 100644
index 0000000..add7582
--- /dev/null
+++ b/pages/web/polling.vue
@@ -0,0 +1,112 @@
+<script>
+export default {
+ name: "index",
+
+ data() {
+ return {
+ src: '',
+ bindCardId: "",
+ timer: null,
+ show: false,
+ download: false,
+ loading: false // 🔥 防并发
+ }
+ },
+
+ onLoad(pro) {
+ uni.showLoading({
+ title: '请稍等...',
+ })
+
+ setTimeout(() => {
+ if (pro.url) {
+ this.src = decodeURIComponent(pro.url)
+ }
+
+ if (pro.download) {
+ this.download = true
+ }
+
+ if (pro.bindCardId) {
+ this.bindCardId = pro.bindCardId
+ }
+
+ this.show = true
+ uni.hideLoading()
+
+ // 🔥 初始化完成后再开始轮询
+ this.startPolling()
+
+ }, 1000)
+ },
+
+ onShow() {
+ // 防止返回页面重复开启
+ if (!this.timer && this.bindCardId) {
+ this.startPolling()
+ }
+ },
+
+ onUnload() {
+ this.clearPolling()
+ },
+
+ methods: {
+ startPolling() {
+ this.clearPolling()
+
+ this.timer = setInterval(() => {
+ this.checkStatus()
+ }, 3000)
+ },
+
+ clearPolling() {
+ if (this.timer) {
+ clearInterval(this.timer)
+ this.timer = null
+ }
+ },
+
+ checkStatus() {
+ if (!this.bindCardId || this.loading) return
+
+ this.loading = true
+
+ uni.request({
+ url: this.$webHost + `/api/v2/pay/queryMultiBindcardStatus/${this.bindCardId}`,
+
+ success: (res) => {
+ if (res.data.code === 200 && res.data.data) {
+ this.clearPolling()
+
+ uni.reLaunch({
+ url: '/pages/index/index'
+ })
+ }
+ },
+
+ fail: (err) => {
+ console.error('请求失败', err)
+ },
+
+ complete: () => {
+ this.loading = false
+ }
+ })
+ }
+ }
+}
+</script>
+
+<template>
+ <view style="width: 100vw;height: calc(100vh - 88rpx);">
+ <view v-if="show">
+ <web-view ref="web" :src="src" style="width: 100vw;"/>
+ </view>
+
+ </view>
+</template>
+
+<style scoped lang="scss">
+
+</style>
--
Gitblit v1.9.3