|
|
@@ -474,7 +474,8 @@
|
|
|
position: absolute;
|
|
|
left: 24px;
|
|
|
right: 24px;
|
|
|
- bottom: calc(12px + var(--safe-bottom));
|
|
|
+ top: 12px;
|
|
|
+ height: 48px;
|
|
|
z-index: 3;
|
|
|
max-width: 320px;
|
|
|
margin: 0 auto;
|
|
|
@@ -489,6 +490,12 @@
|
|
|
.fab-wx-launch-host wx-open-launch-app {
|
|
|
display: block;
|
|
|
width: 100%;
|
|
|
+ height: 48px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .fab.fab--wx-pending {
|
|
|
+ opacity: 0.65;
|
|
|
+ pointer-events: none;
|
|
|
}
|
|
|
|
|
|
.fab {
|
|
|
@@ -1128,9 +1135,48 @@
|
|
|
|
|
|
var wxJssdkLoadPromise = null;
|
|
|
var wxConfigReady = false;
|
|
|
+ var wxTagReady = false;
|
|
|
var wxLaunchAppIdCache = '';
|
|
|
var wxLaunchMounted = false;
|
|
|
var wxPreparePromise = null;
|
|
|
+ var wxTagReadyWaiters = [];
|
|
|
+
|
|
|
+ function notifyWxTagReady() {
|
|
|
+ wxTagReady = true;
|
|
|
+ var list = wxTagReadyWaiters.slice();
|
|
|
+ wxTagReadyWaiters = [];
|
|
|
+ list.forEach(function (fn) {
|
|
|
+ try {
|
|
|
+ fn();
|
|
|
+ } catch (e) {}
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function waitForWxTagReady(timeoutMs) {
|
|
|
+ if (wxTagReady) return Promise.resolve();
|
|
|
+ return new Promise(function (resolve, reject) {
|
|
|
+ var done = false;
|
|
|
+ function finish(ok) {
|
|
|
+ if (done) return;
|
|
|
+ done = true;
|
|
|
+ if (ok) resolve();
|
|
|
+ else reject(new Error('微信开放标签初始化超时'));
|
|
|
+ }
|
|
|
+ wxTagReadyWaiters.push(function () {
|
|
|
+ finish(true);
|
|
|
+ });
|
|
|
+ window.setTimeout(function () {
|
|
|
+ finish(wxTagReady);
|
|
|
+ }, timeoutMs || 8000);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function setOpenAppWeChatPending(pending) {
|
|
|
+ var btn = document.getElementById('openApp');
|
|
|
+ if (!btn) return;
|
|
|
+ if (pending) btn.classList.add('fab--wx-pending');
|
|
|
+ else btn.classList.remove('fab--wx-pending');
|
|
|
+ }
|
|
|
|
|
|
function getWxSignPageUrl() {
|
|
|
return String(location.href || '').split('#')[0];
|
|
|
@@ -1260,6 +1306,7 @@
|
|
|
if (!host || !btn) return false;
|
|
|
if (wxLaunchMounted && host.querySelector('wx-open-launch-app')) return true;
|
|
|
|
|
|
+ wxTagReady = false;
|
|
|
var extinfo = escapeHtmlAttr(buildAppExtInfo());
|
|
|
var appid = escapeHtmlAttr(launchAppId);
|
|
|
host.innerHTML =
|
|
|
@@ -1277,21 +1324,34 @@
|
|
|
|
|
|
var tag = host.querySelector('wx-open-launch-app');
|
|
|
if (tag) {
|
|
|
+ tag.addEventListener('ready', function () {
|
|
|
+ notifyWxTagReady();
|
|
|
+ });
|
|
|
tag.addEventListener('launch', function () {
|
|
|
console.log('[wx-open-launch-app] launch');
|
|
|
});
|
|
|
tag.addEventListener('error', function (e) {
|
|
|
console.warn('[wx-open-launch-app]', e && e.detail);
|
|
|
- showWxLaunchTip('无法跳转 App,请确认已安装应用且公众号已关联该应用');
|
|
|
+ var detail = e && e.detail ? e.detail.errMsg || e.detail.errmsg || '' : '';
|
|
|
+ showWxLaunchTip(
|
|
|
+ detail
|
|
|
+ ? '无法打开 App:' + detail
|
|
|
+ : '无法跳转 App,请确认已安装应用且公众号已关联该应用'
|
|
|
+ );
|
|
|
});
|
|
|
}
|
|
|
|
|
|
host.classList.add('fab-wx-launch-host--active');
|
|
|
host.setAttribute('aria-hidden', 'false');
|
|
|
btn.setAttribute('aria-hidden', 'true');
|
|
|
+ btn.classList.add('fab--wx-pending');
|
|
|
btn.style.visibility = 'hidden';
|
|
|
btn.style.pointerEvents = 'none';
|
|
|
wxLaunchMounted = true;
|
|
|
+ /* 部分机型 ready 事件不稳定,超时后仍允许点击 */
|
|
|
+ window.setTimeout(function () {
|
|
|
+ if (!wxTagReady) notifyWxTagReady();
|
|
|
+ }, 1500);
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
@@ -1301,7 +1361,10 @@
|
|
|
if (forceRefresh) {
|
|
|
wxPreparePromise = null;
|
|
|
wxConfigReady = false;
|
|
|
+ wxTagReady = false;
|
|
|
+ wxLaunchMounted = false;
|
|
|
}
|
|
|
+ setOpenAppWeChatPending(true);
|
|
|
wxPreparePromise = loadWxJssdk()
|
|
|
.then(function () {
|
|
|
return fetchWxConfig();
|
|
|
@@ -1322,23 +1385,26 @@
|
|
|
if (!mountWxOpenLaunchApp(launchId)) {
|
|
|
throw new Error('微信开放标签挂载失败');
|
|
|
}
|
|
|
+ return waitForWxTagReady(8000).then(function () {
|
|
|
+ return cfg;
|
|
|
+ });
|
|
|
+ })
|
|
|
+ .then(function (cfg) {
|
|
|
+ setOpenAppWeChatPending(false);
|
|
|
return cfg;
|
|
|
+ })
|
|
|
+ .catch(function (e) {
|
|
|
+ setOpenAppWeChatPending(false);
|
|
|
+ throw e;
|
|
|
});
|
|
|
return wxPreparePromise;
|
|
|
}
|
|
|
|
|
|
function openAppViaWeChat() {
|
|
|
- if (wxLaunchMounted && wxConfigReady) {
|
|
|
+ if (wxLaunchMounted && wxConfigReady && wxTagReady) {
|
|
|
return;
|
|
|
}
|
|
|
- prepareWeChatAppLaunch(true)
|
|
|
- .then(function () {
|
|
|
- if (wxLaunchMounted) {
|
|
|
- showWxLaunchTip('请再次点击「APP内打开」');
|
|
|
- } else {
|
|
|
- showWxLaunchTip('微信唤起组件未就绪,请稍后重试');
|
|
|
- }
|
|
|
- })
|
|
|
+ prepareWeChatAppLaunch(false)
|
|
|
.catch(function (e) {
|
|
|
console.warn('[微信唤起App]', e, {
|
|
|
signUrl: getWxSignPageUrl(),
|
|
|
@@ -2651,11 +2717,24 @@
|
|
|
if (isWeChatInAppBrowser()) {
|
|
|
prepareWeChatAppLaunch(false).catch(function (e) {
|
|
|
console.warn('[微信预加载 getWxConfig]', e);
|
|
|
+ setOpenAppWeChatPending(false);
|
|
|
});
|
|
|
}
|
|
|
var openBtn = document.getElementById('openApp');
|
|
|
if (openBtn) {
|
|
|
openBtn.addEventListener('click', function () {
|
|
|
+ if (isWeChatInAppBrowser()) {
|
|
|
+ if (wxLaunchMounted && wxConfigReady && wxTagReady) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (wxPreparePromise) {
|
|
|
+ wxPreparePromise.catch(function () {});
|
|
|
+ showWxLaunchTip('正在准备打开 App,请稍候再点');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ openAppViaWeChat();
|
|
|
+ return;
|
|
|
+ }
|
|
|
tryOpenHBuilderApp();
|
|
|
});
|
|
|
}
|