From b20417cb60550346d00c58106eb12be83aa29e14 Mon Sep 17 00:00:00 2001 From: wolter <11@gmail> Date: Fri, 18 Jul 2025 15:27:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E9=A1=B5=E9=9D=A2=E4=BC=98=E5=8C=962?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/templates/payPage.html | 129 ++++++++--------------------------- 1 file changed, 28 insertions(+), 101 deletions(-) diff --git a/front/templates/payPage.html b/front/templates/payPage.html index 8faa222..5a3af89 100644 --- a/front/templates/payPage.html +++ b/front/templates/payPage.html @@ -113,8 +113,7 @@ .payment-option input[type="radio"] { margin-right: 15px; } - - /* 选中状态样式 */ + .payment-option.selected { border-color: #007BFF; background-color: #f0f7ff; @@ -125,7 +124,7 @@ {{if eq .code 200 }} -
+

订单支付

{{.desc}}

交易号:{{ .id }}

@@ -137,12 +136,12 @@
- - - +
+ + + @@ -161,94 +160,30 @@ return null; } - // 检查是否是支付回调 - function isPaymentCallback() { - return getQueryParam('callback') === 'true'; - } - - // 获取预设的支付方式 - function getPresetPaymentMethod() { - return getQueryParam('preset_method') || null; - } - - // 检查订单状态 - function checkOrderStatus(orderNo) { - return fetch(`/pay/front/api/v1/payPage/status?no=${orderNo}`, { - method: 'GET', - }) - .then(response => { - if (!response.ok) { - throw new Error('网络响应不正常'); - } - return response.json(); - }) - .then(data => { - if (data.code !== 200) { - throw new Error(data.message || '获取订单状态失败'); - } - return data; - }); - } - // 显示Loading状态 function showLoading() { + document.getElementById('payment-info').style.display = 'none'; document.getElementById('pay-container').style.display = 'none'; document.getElementById('loading').style.display = 'flex'; } - // 隐藏Loading状态 - function hideLoading() { - document.getElementById('pay-container').style.display = 'block'; - document.getElementById('loading').style.display = 'none'; - } - // 处理支付回调 function handlePaymentCallback() { - const orderNo = getQueryParam('no'); - if (!orderNo) { - console.error('订单号不存在'); - return; - } - showLoading(); + const loadingText = document.querySelector('.loading-text'); + loadingText.textContent = `支付处理中,请稍等...`; - // 检查订单状态 - checkOrderStatus(orderNo) - .then(data => { - if (data.data.status === 'SUCCESS') { - // 支付成功,跳转到指定链接 - if (data.data.redirectUrl) { - setTimeout(() => { - window.location.href = data.data.redirectUrl; - }, 1000); - } else { - hideLoading(); - alert('支付成功!'); - } - } else if (data.data.status === 'PENDING') { - // 支付处理中,1秒后再次检查 - setTimeout(() => { - handlePaymentCallback(); - }, 1000); - } else { - // 支付失败或其他状态 - hideLoading(); - alert('支付未完成: ' + (data.data.message || '未知错误')); - } - }) - .catch(error => { - hideLoading(); - console.error('检查订单状态失败:', error); - alert('检查订单状态失败: ' + error.message); - }); + // 1秒后刷新页面 + setTimeout(() => { + clearInterval(dotInterval); + window.location.reload(); + }, 1000); } // 获取支付方式列表 function fetchPaymentMethods() { const id = getQueryParam('no'); - const presetMethod = getPresetPaymentMethod(); - console.log('Order no:', id, 'Preset method:', presetMethod); - + console.log('Order no:', id); if (id) { fetch(`/pay/front/api/v1/payPage/list?id=${id}`, { method: 'POST', @@ -272,11 +207,11 @@ const pay = document.getElementById('pay'); pay.innerHTML = '

支付环境异常,请检查

'; } else if (data.data.length === 1) { - // 只有一个支付方式时,显示支付中状态并直接跳转 + // 只有一个支付方式时,显示空白页并直接跳转 showLoading(); window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${data.data[0].pay_channel_id}&no=${id}`; } else { - renderPaymentMethods(data.data, presetMethod); + renderPaymentMethods(data.data); } }) .catch(error => { @@ -290,14 +225,15 @@ } // 渲染支付方式列表 - function renderPaymentMethods(paymentMethods, presetMethod) { + function renderPaymentMethods(paymentMethods) { const pay = document.getElementById('pay'); pay.innerHTML = '

请选择支付方式

'; const paymentList = document.getElementById('payment-list'); paymentList.innerHTML = ''; - - let hasPresetMethod = false; + + // 标记是否是第一个支付方式 + let isFirstMethod = true; paymentMethods.forEach(method => { const listItem = document.createElement('li'); @@ -308,12 +244,12 @@ radioInput.name = 'paymentMethod'; radioInput.value = method.pay_channel_id; radioInput.id = `method-${method.pay_channel_id}`; - - // 检查是否是预设的支付方式 - if (presetMethod && (method.pay_channel_id === presetMethod || method.pay_name.includes(presetMethod))) { + + // 如果是第一个支付方式,默认选中 + if(isFirstMethod) { radioInput.checked = true; listItem.classList.add('selected'); - hasPresetMethod = true; + isFirstMethod = false; } const label = document.createElement('label'); @@ -344,15 +280,6 @@ }); }); - // 如果没有匹配的预设支付方式,默认选中第一个 - if (!hasPresetMethod && paymentMethods.length > 0) { - const firstItem = document.querySelector('.payment-option'); - if (firstItem) { - firstItem.classList.add('selected'); - firstItem.querySelector('input[type="radio"]').checked = true; - } - } - // 添加提交按钮 const submitButton = document.createElement('button'); submitButton.type = 'button'; @@ -377,7 +304,7 @@ // 页面加载时执行 window.onload = function() { - if (isPaymentCallback()) { + if (getQueryParam('return')) { // 如果是支付回调,处理支付结果 handlePaymentCallback(); } else {