From 6bc9b2c0d7df91c83965b6a0ab1b8daec3df308d Mon Sep 17 00:00:00 2001 From: jacobxu666 Date: Mon, 28 Sep 2026 14:26:14 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BA=91=E9=97=AA=E4=BB=98=E6=8E=A7?= =?UTF-8?q?=E4=BB=B6=E5=94=A4=E4=B8=8D=E8=B5=B7=E4=BF=AE=E5=A4=8D=E2=80=94?= =?UTF-8?q?=E2=80=94upsdk.js=20=E6=94=B9=E4=B8=BA=20main.js=20=E6=8C=82?= =?UTF-8?q?=E8=BD=BD=E5=89=8D=20document-start=20=E9=A2=84=E7=83=AD?= =?UTF-8?q?=E6=B3=A8=E5=85=A5=EF=BC=88HBuilderX=20=E6=9E=84=E5=BB=BA?= =?UTF-8?q?=E4=B8=8D=E5=90=83=E6=A0=B9=20index.html=20=E9=9D=99=E6=80=81?= =?UTF-8?q?=E6=A0=87=E7=AD=BE=EF=BC=89=EF=BC=8C=E7=A1=AE=E8=AE=A4=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=E9=A1=B5=E8=BD=AE=E8=AF=A2=E5=A4=8D=E7=94=A8=E9=A2=84?= =?UTF-8?q?=E7=83=AD=E6=A0=87=E7=AD=BE=E9=98=B2=E9=87=8D=E5=A4=8D=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Fable 5 --- common/petrolVoucher.js | 13 +++++++++++++ main.js | 5 +++++ pages/petrol/orderConfirm.vue | 10 ++++++++++ 3 files changed, 28 insertions(+) diff --git a/common/petrolVoucher.js b/common/petrolVoucher.js index 33f267c..d6a5418 100644 --- a/common/petrolVoucher.js +++ b/common/petrolVoucher.js @@ -22,6 +22,19 @@ export const VOUCHER_USE_FLOW = [ '支付差额可选:油卡 / 现金等' ] +// xuchao: 云闪付 SDK 前置预热注入。HBuilderX 的 H5 构建不吃项目根 index.html(静态标签会被丢), +// 只能在 main.js 最早期(document-start、App 挂载前)动态注入,逼近 xghmall 的 head 静态加载时机, +// 让云闪付原生控件桥在首屏就注册,避免到确认订单页才注入导致 upsdk.pay 唤不起。 +// 与 orderConfirm 页的 loadUpSdk 共用同一 script[data-upsdk] 标记,全局只注入一次。 +export function injectUpSdk() { + if (typeof document === 'undefined' || typeof window === 'undefined') return + if (window.upsdk || 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: 云闪付容器判定只看 UA——不能掺 window.upsdk 是否已加载(SDK 是异步注入的, // 首屏点击时可能还没 load 完,会把云闪付内首点误判为站外)。UA 关键字真机实测后定稿。 export function isUnionPayApp() { diff --git a/main.js b/main.js index bde1deb..b8308bb 100644 --- a/main.js +++ b/main.js @@ -1,4 +1,9 @@ import App from './App' +import { injectUpSdk } from '@/common/petrolVoucher.js' + +// xuchao: 云闪付控件 SDK 预热——HBuilderX 构建不吃根 index.html,静态标签无效, +// 在 App 挂载前(document-start 最早 JS 点)注入,逼近静态 head 加载时机(石油券支付修复) +injectUpSdk() // #ifndef VUE3 import Vue from 'vue' diff --git a/pages/petrol/orderConfirm.vue b/pages/petrol/orderConfirm.vue index 9741d61..6f952e0 100644 --- a/pages/petrol/orderConfirm.vue +++ b/pages/petrol/orderConfirm.vue @@ -95,6 +95,16 @@ export default { const loading = new Promise(resolve => { let done = false const finish = v => { if (!done) { done = true; resolve(v) } } + const exists = document.querySelector('script[data-upsdk]') + if (exists) { + // main.js 已预热注入:轮询等 window.upsdk 出现(避免重复插标签) + const t0 = Date.now() + const timer = setInterval(() => { + if (window.upsdk) { clearInterval(timer); finish(true) } + else if (Date.now() - t0 > timeout) { clearInterval(timer); finish(false) } + }, 200) + return + } const s = document.createElement('script') s.src = 'https://open.95516.com/s/open/js/upsdk.js' s.setAttribute('data-upsdk', '1')