1、添加防抖动

2、添加打开url
This commit is contained in:
ywyonui 2025-08-30 16:23:23 +08:00
parent e664978136
commit 4cd7abfc9c
2 changed files with 122 additions and 6 deletions

View File

@ -31,7 +31,9 @@
<view class="action-buttons">
<view class="cancel-btn" @click="cancelRegistration">取消报名</view>
<view class="pay-btn" @click="payNow">立即支付</view>
<view class="pay-btn" :class="{ 'pay-btn--disabled': isSubmitting }" @click="payNow">
{{ isSubmitting ? '支付中...' : '立即支付' }}
</view>
</view>
</view>
</view>
@ -68,6 +70,79 @@ const countdownTime = ref("1分20秒");
let timer: any = null;
let seconds = 1 * 60 + 20; // 120
//
const isSubmitting = ref(false);
//
const openPaymentPage = (payUrl: string) => {
console.log('开始打开支付页面:', payUrl);
try {
// 使 uni.openUrl (uni-app )
if (typeof uni.openUrl === 'function') {
console.log('使用 uni.openUrl 打开支付页面:', payUrl);
uni.openUrl({
url: payUrl,
fail: (err) => {
console.log('uni.openUrl 失败:', err);
// plus.runtime.openURL
if (typeof (window as any).plus !== 'undefined' && (window as any).plus.runtime && (window as any).plus.runtime.openURL) {
console.log('降级到 plus.runtime.openURL');
try {
(window as any).plus.runtime.openURL(payUrl);
} catch (plusError) {
console.log('plus.runtime.openURL 失败:', plusError);
// location.href
console.log('最终降级到 location.href');
window.location.href = payUrl;
}
} else {
// location.href
console.log('最终降级到 location.href');
window.location.href = payUrl;
}
}
});
}
// 使 plus.runtime.openURL (HTML5+ )
else if (typeof (window as any).plus !== 'undefined' && (window as any).plus.runtime && (window as any).plus.runtime.openURL) {
console.log('使用 plus.runtime.openURL 打开支付页面:', payUrl);
try {
(window as any).plus.runtime.openURL(payUrl);
} catch (plusError) {
console.log('plus.runtime.openURL 失败:', plusError);
// location.href
console.log('降级到 location.href');
window.location.href = payUrl;
}
}
// location.href
else {
console.log('使用 location.href 打开支付页面:', payUrl);
window.location.href = payUrl;
}
//
uni.showToast({
title: "正在跳转支付页面...",
icon: "none",
duration: 2000
});
} catch (error) {
console.log('支付页面跳转异常:', error);
// 使 location.href
window.location.href = payUrl;
//
uni.showToast({
title: "跳转失败,正在重试...",
icon: "none",
duration: 2000
});
}
};
//
const startCountdown = () => {
timer = setInterval(() => {
@ -125,7 +200,14 @@ const cancelRegistration = () => {
//
const payNow = async () => {
//
if (isSubmitting.value) {
return;
}
try {
isSubmitting.value = true;
const res = await jzXkFqJfjApi({
xsId: getData.xsId,
xkId: getData.xkId,
@ -136,7 +218,11 @@ const payNow = async () => {
openId: getUser.openId,
});
if (res.resultCode === 1 && res.result) {
window.open(res.result.cashierPayHtml, '_blank');
// 使 uni.openUrl plus.runtime.openUrl
const payUrl = res.result.cashierPayHtml;
openPaymentPage(payUrl);
/* setData({
...getData,
...res.result
@ -155,14 +241,24 @@ const payNow = async () => {
// uni.redirectTo({
// url: `/pages/base/xk/pay/wait?payUrl=${encodeURIComponent(url)}`
// });
} finally {
//
setTimeout(() => {
isSubmitting.value = false;
}, 2000);
}
};
onMounted(async() => {
const res = await jzGetQkExpiredTime({ xsId: getCurXs.id} );
console.log('获取倒计时', res);
seconds = res.result;
startCountdown();
try {
const res = await jzGetQkExpiredTime({ xsId: getCurXs.id} );
console.log('获取倒计时', res);
seconds = res.result;
startCountdown();
} catch (error) {
console.log(error);
goBack();
}
});
onUnmounted(() => {
@ -263,6 +359,13 @@ onUnmounted(() => {
.pay-btn {
background-color: #ff8c00;
color: #fff;
&.pay-btn--disabled {
background-color: #ccc;
color: #666;
cursor: not-allowed;
pointer-events: none;
}
}
}
}

View File

@ -7,6 +7,7 @@ import AutoStylePlugin from "./plugin/vite-plugin-autoStyle";
import {HOMEAGENT} from "./src/config";
export default defineConfig({
base: './', // 添加这行,确保使用相对路径
server: {
proxy: {
"/base": {
@ -16,6 +17,7 @@ export default defineConfig({
},
},
port: 5139,
host: true, // 允许外部访问
},
plugins: [
//c 为class 例如 class="wi-10"
@ -59,5 +61,16 @@ export default defineConfig({
'@': resolve(__dirname, './src'),
'#': resolve(__dirname, './types')
}
},
// 添加构建优化配置
build: {
rollupOptions: {
output: {
manualChunks: {
'vendor': ['vue', 'pinia'],
'uni': ['@dcloudio/uni-app', '@dcloudio/uni-h5']
}
}
}
}
});