|
|
@@ -73,12 +73,11 @@
|
|
|
opacity: 1;
|
|
|
}
|
|
|
|
|
|
- /* 仅「分享卡片」等受支持场景展示开放标签;复制链接进入见 .wx-copy-link-entry */
|
|
|
- body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
|
|
|
+ body.is-wechat.wx-jssdk-ready #launch-btn {
|
|
|
display: block;
|
|
|
}
|
|
|
|
|
|
- body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
|
|
|
+ body.is-wechat.wx-jssdk-ready #openApp {
|
|
|
display: none !important;
|
|
|
}
|
|
|
|
|
|
@@ -797,51 +796,39 @@
|
|
|
return /MicroMessenger/i.test(navigator.userAgent || '');
|
|
|
}
|
|
|
|
|
|
- /** 微信打开 H5 时的场景来源(分享卡片会带 from,复制链接通常没有) */
|
|
|
- function getWxShareEntryFrom() {
|
|
|
- var from = q('from');
|
|
|
- return from ? String(from).trim().toLowerCase() : '';
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
- * wx-open-launch-app 仅在部分微信场景可用(App/好友分享卡片、朋友圈卡片等)。
|
|
|
- * 复制链接粘贴打开一般无 from=,微信会报 launch:fail(当前场景不支持)。
|
|
|
+ * 复制链接进入常无 from=;与点击分享卡片对齐,在拉 getWxConfig 前补 from=singlemessage(不刷新页面)。
|
|
|
*/
|
|
|
- function isWxOpenLaunchAppSceneSupported() {
|
|
|
- if (!isWeChatInAppBrowser()) return false;
|
|
|
- if (readQueryParam('wxOpenTag') === '1' || readQueryParam('wxForceOpenTag') === '1') {
|
|
|
- return true;
|
|
|
- }
|
|
|
- var from = getWxShareEntryFrom();
|
|
|
- return (
|
|
|
- from === 'singlemessage' ||
|
|
|
- from === 'groupmessage' ||
|
|
|
- from === 'timeline'
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
- function applyWxOpenLaunchSceneBodyClass() {
|
|
|
+ function ensureWxShareFromQueryBeforeConfig() {
|
|
|
if (!isWeChatInAppBrowser()) return;
|
|
|
- var ok = isWxOpenLaunchAppSceneSupported();
|
|
|
- document.body.classList.toggle('wx-open-tag-scene', ok);
|
|
|
- document.body.classList.toggle('wx-copy-link-entry', !ok);
|
|
|
+ var from = String(q('from') || '').trim();
|
|
|
+ if (from) return;
|
|
|
+ try {
|
|
|
+ var u = new URL(location.href);
|
|
|
+ u.searchParams.set('from', 'singlemessage');
|
|
|
+ history.replaceState(null, '', u.pathname + u.search + (location.hash || ''));
|
|
|
+ } catch (eFrom) {
|
|
|
+ var sep = location.search && location.search.length > 1 ? '&' : '?';
|
|
|
+ history.replaceState(
|
|
|
+ null,
|
|
|
+ '',
|
|
|
+ location.pathname +
|
|
|
+ (location.search || '') +
|
|
|
+ sep +
|
|
|
+ 'from=singlemessage' +
|
|
|
+ (location.hash || '')
|
|
|
+ );
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
function logWxEntryDiagnostics() {
|
|
|
if (!isWeChatInAppBrowser()) return;
|
|
|
console.log('[wx-entry]', {
|
|
|
- entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
|
|
|
- openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
|
|
|
+ entryFrom: q('from') || '(无)',
|
|
|
signUrl: getWxConfigSignUrl()
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- function showWxCopyLinkEntryTip() {
|
|
|
- showFabToast(
|
|
|
- '当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,从卡片进入。'
|
|
|
- );
|
|
|
- }
|
|
|
-
|
|
|
function readQueryParam(name) {
|
|
|
return q(name);
|
|
|
}
|
|
|
@@ -1087,10 +1074,7 @@
|
|
|
wx.ready(function () {
|
|
|
weChatJssdkConfigured = true;
|
|
|
document.body.classList.add('wx-jssdk-ready');
|
|
|
- applyWxOpenLaunchSceneBodyClass();
|
|
|
- if (isWxOpenLaunchAppSceneSupported()) {
|
|
|
- refreshWxLaunchTagAttrs();
|
|
|
- }
|
|
|
+ refreshWxLaunchTagAttrs();
|
|
|
console.log('[wx.config] ready, htmlUrl=', htmlUrl);
|
|
|
resolve(true);
|
|
|
});
|
|
|
@@ -1146,10 +1130,6 @@
|
|
|
? String(detail.errmsg)
|
|
|
: '';
|
|
|
console.warn('[wx-open-launch-app]', detail);
|
|
|
- if (/launch:fail/i.test(errMsg) && !isWxOpenLaunchAppSceneSupported()) {
|
|
|
- showWxCopyLinkEntryTip();
|
|
|
- return;
|
|
|
- }
|
|
|
showAppOpenFailTip(
|
|
|
errMsg
|
|
|
? '未能唤起 App:' + errMsg
|
|
|
@@ -1162,6 +1142,7 @@
|
|
|
if (!shouldFetchWxConfig(!!fromUserClick)) {
|
|
|
return Promise.resolve(false);
|
|
|
}
|
|
|
+ ensureWxShareFromQueryBeforeConfig();
|
|
|
if (wxJssdkInitPromise && !fromUserClick) return wxJssdkInitPromise;
|
|
|
wxConfigSignRetriedBaseUrl = false;
|
|
|
wxInitLastError = '';
|
|
|
@@ -2009,12 +1990,12 @@
|
|
|
var launchTag = document.getElementById('launch-btn');
|
|
|
if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
|
|
|
bindWeChatLaunchTagEvents();
|
|
|
+ if (isWeChatInAppBrowser()) {
|
|
|
+ document.body.classList.add('is-wechat');
|
|
|
+ ensureWxShareFromQueryBeforeConfig();
|
|
|
+ logWxEntryDiagnostics();
|
|
|
+ }
|
|
|
if (shouldInitWeChatJssdkOnLoad()) {
|
|
|
- if (isWeChatInAppBrowser()) {
|
|
|
- document.body.classList.add('is-wechat');
|
|
|
- applyWxOpenLaunchSceneBodyClass();
|
|
|
- logWxEntryDiagnostics();
|
|
|
- }
|
|
|
if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
|
|
|
document.body.classList.add('wx-pc-debug');
|
|
|
}
|
|
|
@@ -2023,7 +2004,6 @@
|
|
|
|
|
|
document.addEventListener('WeixinOpenTagsError', function (e) {
|
|
|
console.warn('[WeixinOpenTagsError]', e && e.detail);
|
|
|
- applyWxOpenLaunchSceneBodyClass();
|
|
|
});
|
|
|
|
|
|
if (isWeChatInAppBrowser()) {
|
|
|
@@ -2034,10 +2014,6 @@
|
|
|
showFabToast(
|
|
|
wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
|
|
|
);
|
|
|
- return;
|
|
|
- }
|
|
|
- if (!isWxOpenLaunchAppSceneSupported()) {
|
|
|
- showWxCopyLinkEntryTip();
|
|
|
}
|
|
|
});
|
|
|
}
|