lx
yfx
2026-04-01 a596066968e625bd39a79f4d15635e50659512cd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
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>