diff --git a/src/handlers/payment.rs b/src/handlers/payment.rs index c89e913..62e2e00 100644 --- a/src/handlers/payment.rs +++ b/src/handlers/payment.rs @@ -382,6 +382,8 @@ pub async fn payment_index() -> Result { const API_BASE = ''; // 同源 let currentShortCode = ''; let pollTimer = null; + let pollRetryCount = 0; + const POLL_MAX_RETRIES = 150; // 2s * 150 = 5min 超时 let jwt = ''; let isPaidActive = false; let paidExpiresAt = null; @@ -426,6 +428,15 @@ pub async fn payment_index() -> Result { async function pollLoginStatus() { if (!currentShortCode) return; + + pollRetryCount++; + if (pollRetryCount > POLL_MAX_RETRIES) { + clearInterval(pollTimer); + document.getElementById('scanStatus').textContent = '登录码已过期,请重新获取'; + document.getElementById('scanStatus').className = 'scan-status waiting'; + return; + } + try { const resp = await fetch(API_BASE + '/payment/login-status?code=' + encodeURIComponent(currentShortCode)); const data = await resp.json(); @@ -503,7 +514,12 @@ pub async fn payment_index() -> Result { showError('请先登录'); return; } - window.location.href = '/payment/page?package=' + selected + '&jwt=' + encodeURIComponent(jwt); + var btn = document.getElementById('payBtn'); + btn.disabled = true; + btn.textContent = '正在跳转...'; + setTimeout(function() { + window.location.href = '/payment/page?package=' + selected + '&jwt=' + encodeURIComponent(jwt); + }, 300); }