更新 front/templates/payPage.html

This commit is contained in:
zhangguoping 2025-07-21 17:17:59 +08:00
parent d20b0e99be
commit 6ebbd46ae4
1 changed files with 18 additions and 17 deletions

View File

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