From bf3bbaa5de134d27946af362be76c2577bf67984 Mon Sep 17 00:00:00 2001 From: jacobxu666 Date: Thu, 24 Sep 2026 12:38:49 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BA=91=E9=97=AA=E4=BB=98SDK=E6=94=B9?= =?UTF-8?q?=E4=B8=BA=E8=BF=90=E8=A1=8C=E6=97=B6=E6=B3=A8=E5=85=A5=E2=80=94?= =?UTF-8?q?=E2=80=94HBuilderX=E5=91=BD=E4=BB=A4=E8=A1=8C=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E4=B8=8D=E5=90=83=E6=A0=B9=E7=9B=AE=E5=BD=95index.html?= =?UTF-8?q?=E6=A8=A1=E6=9D=BF=EF=BC=88=E4=BC=9A=E4=B8=A2=E6=A0=87=E7=AD=BE?= =?UTF-8?q?=EF=BC=89=EF=BC=8C=E4=B8=8E=E4=BA=BA=E8=84=B8SDK=E5=90=8C?= =?UTF-8?q?=E6=AC=BE=E5=8A=A8=E6=80=81=E5=8A=A0=E8=BD=BD=E5=B9=B6=E5=B8=A6?= =?UTF-8?q?=E9=87=8D=E8=AF=95=E5=85=9C=E5=BA=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- pages/petrol/orderConfirm.vue | 55 +++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 19 deletions(-) diff --git a/pages/petrol/orderConfirm.vue b/pages/petrol/orderConfirm.vue index 7699cf7..fa992da 100644 --- a/pages/petrol/orderConfirm.vue +++ b/pages/petrol/orderConfirm.vue @@ -83,10 +83,22 @@ export default { uni.redirectTo({ url: '/pages/index/login?redirect=' + encodeURIComponent('/pages/venue/detail?id=851219003520709&type=2') }) return } + this.loadUpSdk() // xuchao: 运行时注入云闪付 SDK(构建模板不可靠,见 loadUpSdk 注释) if (options.orderNo) this.orderNo = options.orderNo this.initFromServer() }, methods: { + // xuchao: upsdk 运行时注入。不能依赖 index.html 静态标签——HBuilderX 命令行构建的 H5 模板 + // 不受项目根 index.html 控制(产物会丢标签),与人脸 SDK 同款动态加载兜底。 + loadUpSdk() { + if (typeof window !== 'undefined' && window.upsdk) return + if (typeof document === 'undefined') return + if (document.querySelector('script[data-upsdk]')) return + const s = document.createElement('script') + s.src = 'https://open.95516.com/s/open/js/upsdk.js' + s.setAttribute('data-upsdk', '1') + document.head.appendChild(s) + }, // xuchao: 价格展示以服务端 latest 为准(测试期 0.01);已有待支付单自动续用;已发券直接跳券详情 initFromServer() { this.$u.api.voucherLatest({ phone: this.phone }).then(res => { @@ -135,26 +147,31 @@ export default { }, // xuchao: 云闪付控件唤起,交互与湘工惠商城一致(xghmall ordersure.vue:195-229 同型) launchUnionPay(tn) { - if (typeof window === 'undefined' || !window.upsdk) { - this.submitting = false - uni.showToast({ title: '支付组件未就绪,请在云闪付内重进页面', icon: 'none' }) - return + this.loadUpSdk() + const tryPay = (retries) => { + if (typeof window !== 'undefined' && window.upsdk) { + window.upsdk.pluginReady(() => { + window.upsdk.pay({ + tn: tn, + success: () => { + uni.redirectTo({ url: '/pages/petrol/voucherDetail?orderNo=' + this.orderNo }) + }, + fail: () => { + this.submitting = false + uni.showToast({ title: '支付未完成,可在门店页继续支付', icon: 'none' }) + } + }) + }) + // 控件无异步结果时兜底:3 秒后恢复按钮(支付成功路径以回跳/轮询为准) + setTimeout(() => { this.submitting = false }, 3000) + } else if (retries > 0) { + setTimeout(() => tryPay(retries - 1), 500) + } else { + this.submitting = false + uni.showToast({ title: '支付组件加载失败,请在云闪付内重进页面', icon: 'none' }) + } } - const orderNo = this.orderNo - window.upsdk.pluginReady(() => { - window.upsdk.pay({ - tn: tn, - success: () => { - uni.redirectTo({ url: '/pages/petrol/voucherDetail?orderNo=' + orderNo }) - }, - fail: () => { - this.submitting = false - uni.showToast({ title: '支付未完成,可在门店页继续支付', icon: 'none' }) - } - }) - }) - // 控件无异步结果时兜底:3 秒后恢复按钮(支付成功路径以回跳/轮询为准) - setTimeout(() => { this.submitting = false }, 3000) + tryPay(8) // SDK 注入后最多等 4 秒 }, goBack() { const pages = getCurrentPages()