fix: 云闪付控件唤不起修复——upsdk.js 改为 main.js 挂载前 document-start 预热注入(HBuilderX 构建不吃根 index.html 静态标签),确认订单页轮询复用预热标签防重复加载

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
jacobxu666
2026-09-28 14:26:14 +08:00
co-authored by Claude Fable 5
parent 9f02144df7
commit 6bc9b2c0d7
3 changed files with 28 additions and 0 deletions
+13
View File
@@ -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 是异步注入的, // xuchao: 云闪付容器判定只看 UA——不能掺 window.upsdk 是否已加载(SDK 是异步注入的,
// 首屏点击时可能还没 load 完,会把云闪付内首点误判为站外)。UA 关键字真机实测后定稿。 // 首屏点击时可能还没 load 完,会把云闪付内首点误判为站外)。UA 关键字真机实测后定稿。
export function isUnionPayApp() { export function isUnionPayApp() {
+5
View File
@@ -1,4 +1,9 @@
import App from './App' import App from './App'
import { injectUpSdk } from '@/common/petrolVoucher.js'
// xuchao: 云闪付控件 SDK 预热——HBuilderX 构建不吃根 index.html,静态标签无效,
// 在 App 挂载前(document-start 最早 JS 点)注入,逼近静态 head 加载时机(石油券支付修复)
injectUpSdk()
// #ifndef VUE3 // #ifndef VUE3
import Vue from 'vue' import Vue from 'vue'
+10
View File
@@ -95,6 +95,16 @@ export default {
const loading = new Promise(resolve => { const loading = new Promise(resolve => {
let done = false let done = false
const finish = v => { if (!done) { done = true; resolve(v) } } 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') const s = document.createElement('script')
s.src = 'https://open.95516.com/s/open/js/upsdk.js' s.src = 'https://open.95516.com/s/open/js/upsdk.js'
s.setAttribute('data-upsdk', '1') s.setAttribute('data-upsdk', '1')