diff --git a/src/pages/base/xk/pay/index.vue b/src/pages/base/xk/pay/index.vue index d873934..b957e6f 100644 --- a/src/pages/base/xk/pay/index.vue +++ b/src/pages/base/xk/pay/index.vue @@ -31,7 +31,9 @@ 取消报名 - 立即支付 + + {{ isSubmitting ? '支付中...' : '立即支付' }} + @@ -68,6 +70,79 @@ const countdownTime = ref("1分20秒"); let timer: any = null; 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 = () => { 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; + } } } } diff --git a/vite.config.ts b/vite.config.ts index b67c884..4f7d89c 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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'] + } + } + } } });