1、添加防抖动
2、添加打开url
This commit is contained in:
parent
e664978136
commit
4cd7abfc9c
@ -31,7 +31,9 @@
|
|||||||
|
|
||||||
<view class="action-buttons">
|
<view class="action-buttons">
|
||||||
<view class="cancel-btn" @click="cancelRegistration">取消报名</view>
|
<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>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@ -68,6 +70,79 @@ const countdownTime = ref("1分20秒");
|
|||||||
let timer: any = null;
|
let timer: any = null;
|
||||||
let seconds = 1 * 60 + 20; // 1分20秒
|
let seconds = 1 * 60 + 20; // 1分20秒
|
||||||
|
|
||||||
|
// 防止重复提交状态
|
||||||
|
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 = () => {
|
const startCountdown = () => {
|
||||||
timer = setInterval(() => {
|
timer = setInterval(() => {
|
||||||
@ -125,7 +200,14 @@ const cancelRegistration = () => {
|
|||||||
|
|
||||||
// 立即支付
|
// 立即支付
|
||||||
const payNow = async () => {
|
const payNow = async () => {
|
||||||
|
// 防止重复点击
|
||||||
|
if (isSubmitting.value) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
isSubmitting.value = true;
|
||||||
|
|
||||||
const res = await jzXkFqJfjApi({
|
const res = await jzXkFqJfjApi({
|
||||||
xsId: getData.xsId,
|
xsId: getData.xsId,
|
||||||
xkId: getData.xkId,
|
xkId: getData.xkId,
|
||||||
@ -136,7 +218,11 @@ const payNow = async () => {
|
|||||||
openId: getUser.openId,
|
openId: getUser.openId,
|
||||||
});
|
});
|
||||||
if (res.resultCode === 1 && res.result) {
|
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({
|
/* setData({
|
||||||
...getData,
|
...getData,
|
||||||
...res.result
|
...res.result
|
||||||
@ -155,14 +241,24 @@ const payNow = async () => {
|
|||||||
// uni.redirectTo({
|
// uni.redirectTo({
|
||||||
// url: `/pages/base/xk/pay/wait?payUrl=${encodeURIComponent(url)}`
|
// url: `/pages/base/xk/pay/wait?payUrl=${encodeURIComponent(url)}`
|
||||||
// });
|
// });
|
||||||
|
} finally {
|
||||||
|
// 延迟重置状态,避免快速重复点击
|
||||||
|
setTimeout(() => {
|
||||||
|
isSubmitting.value = false;
|
||||||
|
}, 2000);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onMounted(async() => {
|
onMounted(async() => {
|
||||||
const res = await jzGetQkExpiredTime({ xsId: getCurXs.id} );
|
try {
|
||||||
console.log('获取倒计时', res);
|
const res = await jzGetQkExpiredTime({ xsId: getCurXs.id} );
|
||||||
seconds = res.result;
|
console.log('获取倒计时', res);
|
||||||
startCountdown();
|
seconds = res.result;
|
||||||
|
startCountdown();
|
||||||
|
} catch (error) {
|
||||||
|
console.log(error);
|
||||||
|
goBack();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
@ -263,6 +359,13 @@ onUnmounted(() => {
|
|||||||
.pay-btn {
|
.pay-btn {
|
||||||
background-color: #ff8c00;
|
background-color: #ff8c00;
|
||||||
color: #fff;
|
color: #fff;
|
||||||
|
|
||||||
|
&.pay-btn--disabled {
|
||||||
|
background-color: #ccc;
|
||||||
|
color: #666;
|
||||||
|
cursor: not-allowed;
|
||||||
|
pointer-events: none;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,7 @@ import AutoStylePlugin from "./plugin/vite-plugin-autoStyle";
|
|||||||
import {HOMEAGENT} from "./src/config";
|
import {HOMEAGENT} from "./src/config";
|
||||||
|
|
||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
|
base: './', // 添加这行,确保使用相对路径
|
||||||
server: {
|
server: {
|
||||||
proxy: {
|
proxy: {
|
||||||
"/base": {
|
"/base": {
|
||||||
@ -16,6 +17,7 @@ export default defineConfig({
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
port: 5139,
|
port: 5139,
|
||||||
|
host: true, // 允许外部访问
|
||||||
},
|
},
|
||||||
plugins: [
|
plugins: [
|
||||||
//c 为class 例如 class="wi-10"
|
//c 为class 例如 class="wi-10"
|
||||||
@ -59,5 +61,16 @@ export default defineConfig({
|
|||||||
'@': resolve(__dirname, './src'),
|
'@': resolve(__dirname, './src'),
|
||||||
'#': resolve(__dirname, './types')
|
'#': resolve(__dirname, './types')
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
// 添加构建优化配置
|
||||||
|
build: {
|
||||||
|
rollupOptions: {
|
||||||
|
output: {
|
||||||
|
manualChunks: {
|
||||||
|
'vendor': ['vue', 'pinia'],
|
||||||
|
'uni': ['@dcloudio/uni-app', '@dcloudio/uni-h5']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user