更新 front/templates/payPage.html

This commit is contained in:
zhangguoping 2025-07-21 17:00:56 +08:00
parent 707c1d20c1
commit 394d68624d
1 changed files with 11 additions and 13 deletions

View File

@ -164,7 +164,7 @@
function showLoading() { function showLoading() {
document.getElementById('payment-info').style.display = 'none'; document.getElementById('payment-info').style.display = 'none';
document.getElementById('pay-container').style.display = 'none'; document.getElementById('pay-container').style.display = 'none';
document.getElementById('loading').style.display = 'flex'; document.getElementById('loading').style.display = 'block';
} }
// 关闭Loading效果 // 关闭Loading效果
@ -177,11 +177,8 @@
// 处理支付回调 // 处理支付回调
function handlePaymentCallback() { function handlePaymentCallback() {
const id = getQueryParam('no'); const id = getQueryParam('no');
alert(id, 'id')
if (!id) return; if (!id) return;
showLoading(); // 显示加载状态
// 查询订单状态 // 查询订单状态
fetch(`/pay/front/api/v1/payPage/query?no=${id}`, { fetch(`/pay/front/api/v1/payPage/query?no=${id}`, {
method: 'POST', method: 'POST',
@ -193,7 +190,7 @@
.then(data => { .then(data => {
switch(data.status) { switch(data.status) {
case 2: // 处理中 case 2: // 处理中
setTimeout(handlePaymentCallback, 1000); // 1秒后重查 handlePaymentCallback(); // 重查状态
break; break;
case 3: // 支付成功 case 3: // 支付成功
if (data.return_url) { if (data.return_url) {
@ -201,6 +198,7 @@
} }
break; break;
default: // 其他状态(待支付/失败/关闭) default: // 其他状态(待支付/失败/关闭)
alert('其他状态:待支付/失败/关闭');
closeLoading(); closeLoading();
// window.location.reload(); // window.location.reload();
} }
@ -215,7 +213,7 @@
// 获取支付方式列表 // 获取支付方式列表
function fetchPaymentMethods() { function fetchPaymentMethods() {
const id = getQueryParam('no'); const id = getQueryParam('no');
console.log('Order no:', id); alert(`订单id${id}`);
if (id) { if (id) {
fetch(`/pay/front/api/v1/payPage/list?id=${id}`, { fetch(`/pay/front/api/v1/payPage/list?id=${id}`, {
method: 'POST', method: 'POST',
@ -239,25 +237,27 @@
const pay = document.getElementById('pay'); const pay = document.getElementById('pay');
pay.innerHTML = '<h3>支付环境异常,请检查</h3>'; pay.innerHTML = '<h3>支付环境异常,请检查</h3>';
} else if (data.data.length === 1) { } else if (data.data.length === 1) {
// 只有一种支付方式显示loading效果 alert('只有一种支付方式');
showLoading();
if(localStorage.getItem('auto-redirect')){ if(localStorage.getItem('auto-redirect')){
alert(`只有一种支付方式,有自动跳转标记:${localStorage.getItem('auto-redirect')}`);
// 如果有自动跳转标记,展示支付界面 // 如果有自动跳转标记,展示支付界面
renderPaymentMethods(data.data); renderPaymentMethods(data.data);
}else{ }else{
alert(`只有一种支付方式,没有自动跳转标记`);
// 否则设置自动跳转标记,并跳转 // 否则设置自动跳转标记,并跳转
localStorage.setItem('auto-redirect', "true"); localStorage.setItem('auto-redirect', "true");
window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${data.data[0].pay_channel_id}&no=${id}`; window.location.href = `/pay/front/api/v1/payPage/submit?pay_channel_id=${data.data[0].pay_channel_id}&no=${id}`;
} }
} else { } else {
alert(`多种支付方式`);
// 多种支付方式,展示支付界面 // 多种支付方式,展示支付界面
renderPaymentMethods(data.data); renderPaymentMethods(data.data);
} }
}) })
.catch(error => { .catch(error => {
console.error('获取支付方式失败:', error); console.error('获取支付方式失败:', error);
document.getElementById('loading').style.display = 'none'; closeLoading();
const pay = document.getElementById('pay'); const pay = document.getElementById('pay');
pay.innerHTML = '<h3 style="color: red;">获取支付方式失败,请刷新重试</h3>'; pay.innerHTML = '<h3 style="color: red;">获取支付方式失败,请刷新重试</h3>';
}); });
@ -345,13 +345,11 @@
// 页面加载时执行 // 页面加载时执行
window.onload = function() { window.onload = function() {
showLoading()
alert(1, 'zgp')
if (getQueryParam('return') == 'true' && !localStorage.getItem('auto-redirect')) { if (getQueryParam('return') == 'true' && !localStorage.getItem('auto-redirect')) {
alert(2, 'zgp') alert('支付回调且不是自动跳转');
handlePaymentCallback(); // 如果是支付回调且不是自动跳转,处理支付结果 handlePaymentCallback(); // 如果是支付回调且不是自动跳转,处理支付结果
} else { } else {
alert(3, 'zgp') alert('首次加载');
localStorage.removeItem('auto-redirect'); // 清除可能的auto-redirect标记 localStorage.removeItem('auto-redirect'); // 清除可能的auto-redirect标记
fetchPaymentMethods(); // 获取支付方式 fetchPaymentMethods(); // 获取支付方式
} }