成功
This commit is contained in:
parent
f5a51ffa7c
commit
309760863a
@ -9,11 +9,54 @@
|
|||||||
import QRCode from 'qrcode';
|
import QRCode from 'qrcode';
|
||||||
import { ref } from 'vue';
|
import { ref } from 'vue';
|
||||||
import {authStore} from "~/stores/auth/index.js";
|
import {authStore} from "~/stores/auth/index.js";
|
||||||
|
import {orderQuery} from "~/api/goods/index.js";
|
||||||
const {payment}= authStore()
|
const {payment}= authStore()
|
||||||
definePageMeta({
|
definePageMeta({
|
||||||
i18n: 'payment.title'
|
i18n: 'payment.title'
|
||||||
})
|
})
|
||||||
|
const router=useRouter()
|
||||||
|
const resData=ref({})
|
||||||
|
let timer = null
|
||||||
|
const queryOrder = async () => {
|
||||||
|
try {
|
||||||
|
const res = await orderQuery({
|
||||||
|
orderNo: payment.value.payUid
|
||||||
|
})
|
||||||
|
|
||||||
|
if (res.status === 0) {
|
||||||
|
resData.value = res.data
|
||||||
|
|
||||||
|
// 只在支付成功时停止轮询
|
||||||
|
if (resData.value.status === 1) {
|
||||||
|
clearInterval(timer)
|
||||||
|
router.push({
|
||||||
|
path: '/payment/result',
|
||||||
|
query:{
|
||||||
|
orderNo:payment.value.payUid
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
clearInterval(timer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 立即执行一次
|
||||||
|
await queryOrder()
|
||||||
const qrCodeUrl=ref('')
|
const qrCodeUrl=ref('')
|
||||||
|
// 开始轮询
|
||||||
|
timer = setInterval(async () => {
|
||||||
|
await queryOrder()
|
||||||
|
}, 1000)
|
||||||
|
|
||||||
|
// 组件卸载时清除定时器
|
||||||
|
onUnmounted(() => {
|
||||||
|
if (timer) {
|
||||||
|
clearInterval(timer)
|
||||||
|
closeToast()
|
||||||
|
}
|
||||||
|
})
|
||||||
async function generateQRCodeURL(text) {
|
async function generateQRCodeURL(text) {
|
||||||
try {
|
try {
|
||||||
const url = await QRCode.toDataURL(text, {
|
const url = await QRCode.toDataURL(text, {
|
||||||
|
Loading…
Reference in New Issue
Block a user