This commit is contained in:
Mrx
2026-06-08 16:01:46 +08:00
parent 958139d149
commit c28f06411d

View File

@@ -1271,6 +1271,65 @@ const createReportPaymentOrder = async (paymentType) => {
}
}
const WECHAT_REPORT_POLL_INTERVAL_MS = 5000
const WECHAT_REPORT_MAX_POLL_COUNT = 36
const stopWechatPaymentPolling = () => {
if (wechatOrderPollTimer) {
clearInterval(wechatOrderPollTimer)
wechatOrderPollTimer = null
}
isCheckingWechatPayment.value = false
}
const startWechatPaymentPolling = (orderId) => {
if (!orderId) return
stopWechatPaymentPolling()
let pollCount = 0
const checkOnce = async () => {
pollCount++
if (pollCount > WECHAT_REPORT_MAX_POLL_COUNT) {
stopWechatPaymentPolling()
return
}
try {
isCheckingWechatPayment.value = true
const response = await productApi.checkComponentReportPaymentStatus(orderId)
const responseData = response.data?.data || response.data
const { payment_status, can_download } = responseData || {}
if (payment_status === 'success' && can_download) {
stopWechatPaymentPolling()
ElMessageBox.close()
canDownloadReport.value = true
reportPaymentStatus.value = 'success'
ElMessage.success('支付成功,正在下载示例报告...')
await downloadComponentReport()
} else if (payment_status === 'failed') {
stopWechatPaymentPolling()
ElMessageBox.close()
ElMessage.error('支付失败,请重试')
} else if (payment_status === 'cancelled') {
stopWechatPaymentPolling()
ElMessageBox.close()
ElMessage.info('支付已取消')
} else {
isCheckingWechatPayment.value = false
}
} catch (error) {
console.error('[startWechatPaymentPolling] 检查支付状态失败:', error)
isCheckingWechatPayment.value = false
}
}
checkOnce()
wechatOrderPollTimer = setInterval(checkOnce, WECHAT_REPORT_POLL_INTERVAL_MS)
}
// 显示微信支付二维码
const showWechatPaymentQRCode = (codeUrl, orderId) => {
// 验证二维码URL是否有效
@@ -1343,6 +1402,7 @@ const showWechatPaymentQRCode = (codeUrl, orderId) => {
closeOnClickModal: false,
closeOnPressEscape: false,
beforeClose: (action, instance, done) => {
stopWechatPaymentPolling()
if (action === 'confirm') {
// 用户点击了"我已支付"按钮,开始检查支付状态
startPaymentStatusCheck(orderId)
@@ -1353,7 +1413,7 @@ const showWechatPaymentQRCode = (codeUrl, orderId) => {
done()
}
}).catch(() => {
// 对话框被关闭(通过取消按钮或其他方式)
stopWechatPaymentPolling()
})
// 开始轮询微信支付状态