| New file |
| | |
| | | <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> |