feat: 页面优化2
This commit is contained in:
parent
93044a47c7
commit
b20417cb60
|
@ -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 }}
|
||||
<body>
|
||||
<!-- 页面内容 -->
|
||||
<div class="payment-info">
|
||||
<div class="payment-info" id="payment-info">
|
||||
<h2>订单支付</h2>
|
||||
<p>{{.desc}}</p>
|
||||
<p>交易号:{{ .id }}</p>
|
||||
|
@ -137,12 +136,12 @@
|
|||
<div id="pay"></div>
|
||||
<!-- 支付方式列表 -->
|
||||
<ul id="payment-list"></ul>
|
||||
|
||||
<!-- Loading状态 -->
|
||||
<div id="loading" class="loading-container" style="display: none;">
|
||||
<div class="loading-spinner"></div>
|
||||
<p class="loading-text">支付处理中,请稍候...</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Loading状态 -->
|
||||
<div id="loading" class="loading-container" style="display: none;">
|
||||
<div class="loading-spinner"></div>
|
||||
<p class="loading-text">支付处理中,请稍等...</p>
|
||||
</div>
|
||||
|
||||
</body>
|
||||
|
@ -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 = '<h3>支付环境异常,请检查</h3>';
|
||||
} 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 = '<h3>请选择支付方式</h3>';
|
||||
|
||||
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 {
|
||||
|
|
Loading…
Reference in New Issue