|
|
@@ -73,11 +73,12 @@
|
|
|
opacity: 1;
|
|
|
}
|
|
|
|
|
|
- body.is-wechat.wx-jssdk-ready #launch-btn {
|
|
|
+ /* 仅「分享卡片」等受支持场景展示开放标签;复制链接进入见 .wx-copy-link-entry */
|
|
|
+ body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #launch-btn {
|
|
|
display: block;
|
|
|
}
|
|
|
|
|
|
- body.is-wechat.wx-jssdk-ready #openApp {
|
|
|
+ body.is-wechat.wx-jssdk-ready.wx-open-tag-scene #openApp {
|
|
|
display: none !important;
|
|
|
}
|
|
|
|
|
|
@@ -796,6 +797,51 @@
|
|
|
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(当前场景不支持)。
|
|
|
+ */
|
|
|
+ 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() {
|
|
|
+ if (!isWeChatInAppBrowser()) return;
|
|
|
+ var ok = isWxOpenLaunchAppSceneSupported();
|
|
|
+ document.body.classList.toggle('wx-open-tag-scene', ok);
|
|
|
+ document.body.classList.toggle('wx-copy-link-entry', !ok);
|
|
|
+ }
|
|
|
+
|
|
|
+ function logWxEntryDiagnostics() {
|
|
|
+ if (!isWeChatInAppBrowser()) return;
|
|
|
+ console.log('[wx-entry]', {
|
|
|
+ entryFrom: getWxShareEntryFrom() || '(无,多为复制链接进入)',
|
|
|
+ openLaunchTagScene: isWxOpenLaunchAppSceneSupported(),
|
|
|
+ signUrl: getWxConfigSignUrl()
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ function showWxCopyLinkEntryTip() {
|
|
|
+ showFabToast(
|
|
|
+ '当前为复制链接进入,微信不支持直接打开 App。请使用 App「分享到微信」发送卡片后,从卡片进入。'
|
|
|
+ );
|
|
|
+ }
|
|
|
+
|
|
|
function readQueryParam(name) {
|
|
|
return q(name);
|
|
|
}
|
|
|
@@ -1041,7 +1087,10 @@
|
|
|
wx.ready(function () {
|
|
|
weChatJssdkConfigured = true;
|
|
|
document.body.classList.add('wx-jssdk-ready');
|
|
|
- refreshWxLaunchTagAttrs();
|
|
|
+ applyWxOpenLaunchSceneBodyClass();
|
|
|
+ if (isWxOpenLaunchAppSceneSupported()) {
|
|
|
+ refreshWxLaunchTagAttrs();
|
|
|
+ }
|
|
|
console.log('[wx.config] ready, htmlUrl=', htmlUrl);
|
|
|
resolve(true);
|
|
|
});
|
|
|
@@ -1097,6 +1146,10 @@
|
|
|
? String(detail.errmsg)
|
|
|
: '';
|
|
|
console.warn('[wx-open-launch-app]', detail);
|
|
|
+ if (/launch:fail/i.test(errMsg) && !isWxOpenLaunchAppSceneSupported()) {
|
|
|
+ showWxCopyLinkEntryTip();
|
|
|
+ return;
|
|
|
+ }
|
|
|
showAppOpenFailTip(
|
|
|
errMsg
|
|
|
? '未能唤起 App:' + errMsg
|
|
|
@@ -1957,13 +2010,22 @@
|
|
|
if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
|
|
|
bindWeChatLaunchTagEvents();
|
|
|
if (shouldInitWeChatJssdkOnLoad()) {
|
|
|
- if (isWeChatInAppBrowser()) document.body.classList.add('is-wechat');
|
|
|
+ if (isWeChatInAppBrowser()) {
|
|
|
+ document.body.classList.add('is-wechat');
|
|
|
+ applyWxOpenLaunchSceneBodyClass();
|
|
|
+ logWxEntryDiagnostics();
|
|
|
+ }
|
|
|
if (isWxPcBrowser() && (isWxForceDebug() || isWxPcAutoDebugHost())) {
|
|
|
document.body.classList.add('wx-pc-debug');
|
|
|
}
|
|
|
scheduleWeChatJssdkBootstrap();
|
|
|
}
|
|
|
|
|
|
+ document.addEventListener('WeixinOpenTagsError', function (e) {
|
|
|
+ console.warn('[WeixinOpenTagsError]', e && e.detail);
|
|
|
+ applyWxOpenLaunchSceneBodyClass();
|
|
|
+ });
|
|
|
+
|
|
|
if (isWeChatInAppBrowser()) {
|
|
|
var openBtnWx = document.getElementById('openApp');
|
|
|
if (openBtnWx) {
|
|
|
@@ -1972,6 +2034,10 @@
|
|
|
showFabToast(
|
|
|
wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
|
|
|
);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (!isWxOpenLaunchAppSceneSupported()) {
|
|
|
+ showWxCopyLinkEntryTip();
|
|
|
}
|
|
|
});
|
|
|
}
|