feat: 页面优化1
This commit is contained in:
parent
162fe878b5
commit
0d77c47a60
|
@ -141,7 +141,7 @@
|
||||||
<!-- Loading状态 -->
|
<!-- Loading状态 -->
|
||||||
<div id="loading" class="loading-container" style="display: none;">
|
<div id="loading" class="loading-container" style="display: none;">
|
||||||
<div class="loading-spinner"></div>
|
<div class="loading-spinner"></div>
|
||||||
<p class="loading-text">支付处理中,请稍等...</p>
|
<p class="loading-text">支付处理中,请稍等...</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
@ -167,21 +167,21 @@
|
||||||
document.getElementById('loading').style.display = 'flex';
|
document.getElementById('loading').style.display = 'flex';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 关闭Loading效果
|
||||||
|
function closeLoading() {
|
||||||
|
document.getElementById('loading').style.display = 'none';
|
||||||
|
document.getElementById('payment-info').style.display = 'block';
|
||||||
|
document.getElementById('pay-container').style.display = 'block';
|
||||||
|
}
|
||||||
|
|
||||||
// 处理支付回调
|
// 处理支付回调
|
||||||
function handlePaymentCallback() {
|
function handlePaymentCallback() {
|
||||||
const id = getQueryParam('no');
|
const id = getQueryParam('no');
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
|
|
||||||
showLoading();
|
showLoading();
|
||||||
|
|
||||||
// 检查订单状态
|
// 检查订单状态
|
||||||
checkOrderStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 检查订单状态
|
|
||||||
function checkOrderStatus() {
|
|
||||||
const id = getQueryParam('no');
|
|
||||||
if (!id) return;
|
|
||||||
|
|
||||||
fetch(`/pay/front/api/v1/payPage/query?no=${id}`, {
|
fetch(`/pay/front/api/v1/payPage/query?no=${id}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
})
|
})
|
||||||
|
@ -193,47 +193,31 @@
|
||||||
throw new Error('请求失败');
|
throw new Error('请求失败');
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
const url = new URL(window.location.href);
|
||||||
switch(data.status) {
|
switch(data.status) {
|
||||||
case 3:
|
|
||||||
// 订单支付成功,刷新页面
|
|
||||||
window.location.reload();
|
|
||||||
break;
|
|
||||||
case 2:
|
case 2:
|
||||||
// 订单处理中,继续等待
|
// 订单处理中,1秒后再次检查
|
||||||
const loadingText = document.querySelector('.loading-text');
|
setTimeout(handlePaymentCallback, 1000);
|
||||||
loadingText.textContent = `支付处理中,请稍等...`;
|
|
||||||
|
|
||||||
// 1秒后再次检查
|
|
||||||
setTimeout(checkOrderStatus, 1000);
|
|
||||||
break;
|
break;
|
||||||
case 1: // 待支付
|
case 1: // 待支付
|
||||||
|
case 3: // 支付成功
|
||||||
case 4: // 支付失败
|
case 4: // 支付失败
|
||||||
case 5: // 订单关闭
|
case 5: // 订单关闭
|
||||||
default:
|
default:
|
||||||
// 这些状态都显示支付方式选择界面
|
// 移除return参数,刷新界面
|
||||||
fetchPaymentMethods(false);
|
url.searchParams.delete('return');
|
||||||
|
window.location.href = url.toString();
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
console.error('检查订单状态失败:', error);
|
console.error('检查订单状态失败:', error);
|
||||||
fetchPaymentMethods(false);
|
window.location.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// 显示支付页面
|
|
||||||
function showPaymentPage() {
|
|
||||||
document.getElementById('loading').style.display = 'none';
|
|
||||||
document.getElementById('payment-info').style.display = 'block';
|
|
||||||
document.getElementById('pay-container').style.display = 'block';
|
|
||||||
fetchPaymentMethods();
|
|
||||||
}
|
|
||||||
|
|
||||||
// 获取支付方式列表
|
// 获取支付方式列表
|
||||||
function fetchPaymentMethods(showLoading = true) {
|
function fetchPaymentMethods() {
|
||||||
if (showLoading) {
|
|
||||||
showLoading();
|
|
||||||
}
|
|
||||||
|
|
||||||
const id = getQueryParam('no');
|
const id = getQueryParam('no');
|
||||||
console.log('Order no:', id);
|
console.log('Order no:', id);
|
||||||
if (id) {
|
if (id) {
|
||||||
|
@ -254,20 +238,16 @@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
// 隐藏loading
|
|
||||||
document.getElementById('loading').style.display = 'none';
|
|
||||||
|
|
||||||
// 处理返回的数据,例如渲染支付方式列表
|
// 处理返回的数据,例如渲染支付方式列表
|
||||||
if (data === null || data.data.length === 0) {
|
if (data === null || data.data.length === 0) {
|
||||||
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效果,并跳转
|
||||||
|
showLoading();
|
||||||
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 {
|
||||||
// 多种支付方式,显示选择界面
|
// 多种支付方式,展示支付界面
|
||||||
document.getElementById('pay-container').style.display = 'block';
|
|
||||||
document.getElementById('payment-info').style.display = 'block';
|
|
||||||
renderPaymentMethods(data.data);
|
renderPaymentMethods(data.data);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -362,11 +342,11 @@
|
||||||
|
|
||||||
// 页面加载时执行
|
// 页面加载时执行
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
if (getQueryParam('return') === 'true') {
|
if (getQueryParam('return') == 'true') {
|
||||||
// 如果是支付回调,处理支付结果
|
// 如果是支付回调,处理支付结果
|
||||||
handlePaymentCallback();
|
handlePaymentCallback();
|
||||||
} else {
|
} else {
|
||||||
// 否则获取支付方式
|
// 获取支付方式
|
||||||
fetchPaymentMethods();
|
fetchPaymentMethods();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -379,7 +359,7 @@
|
||||||
<div class="payment-info" style="text-align: center;">
|
<div class="payment-info" style="text-align: center;">
|
||||||
<h2 style="color: #ff0000;">支付异常</h2>
|
<h2 style="color: #ff0000;">支付异常</h2>
|
||||||
<p>{{.message}}</p>
|
<p>{{.message}}</p>
|
||||||
<button onclick="window.location.href='/'">返回首页</button>
|
<button onclick="window.location.href='/'">返回</button>
|
||||||
</div>
|
</div>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue