zhuli пре 2 недеља
родитељ
комит
18c2fe648d
1 измењених фајлова са 72 додато и 77 уклоњено
  1. 72 77
      HBuilderProjects/shareIndex.html

+ 72 - 77
HBuilderProjects/shareIndex.html

@@ -497,16 +497,22 @@
 
 		.fab-wx-hit {
 			display: none;
-			position: absolute;
-			left: 0;
-			right: 0;
-			top: 0;
+			width: 100%;
 			height: 48px;
-			z-index: 3;
+		}
+
+		/* wx.config 成功后:隐藏普通按钮,只显示开放标签(真机必须直接点开放标签) */
+		#fabDock.wx-open-enabled #openApp {
+			display: none !important;
 		}
 
 		#fabDock.wx-open-enabled .fab-wx-hit {
 			display: block;
+			position: relative;
+			left: auto;
+			right: auto;
+			top: auto;
+			z-index: 3;
 		}
 
 		#launch-btn {
@@ -514,6 +520,7 @@
 			width: 100%;
 			height: 48px;
 			min-height: 48px;
+			line-height: 48px;
 		}
 
 		#openAppToast {
@@ -1511,15 +1518,8 @@
 						history.replaceState(history.state, document.title, restore);
 						wxSignUrlFullBeforeStrip = '';
 					}
-					var tag = document.getElementById('launch-btn');
-					if (tag) {
-						try {
-							tag.setAttribute('extinfo', buildWeChatLaunchExtinfo());
-						} catch (eReady) {}
-					}
-					updateFabOpenLayer();
-					setTimeout(updateFabOpenLayer, 300);
-					setTimeout(updateFabOpenLayer, 1000);
+					scheduleWxOpenTagRefresh();
+					showFabToast('请点击底部 APP内打开(微信开放标签)');
 					resolve(true);
 				});
 				wx.error(function (err) {
@@ -1569,54 +1569,54 @@
 			});
 		}
 
-		function isWxOpenLaunchTagReady() {
+		function refreshWxLaunchTagAttrs() {
 			var tag = document.getElementById('launch-btn');
-			if (!tag) return false;
-			if ((tag.offsetHeight || 0) >= 40 && (tag.offsetWidth || 0) >= 100) return true;
-			try {
-				if (tag.shadowRoot) {
-					var inner = tag.shadowRoot.querySelector('button');
-					if (inner && (inner.offsetHeight || 0) >= 40) return true;
-				}
-			} catch (eSh) {}
-			return false;
-		}
-
-		function tryTriggerWxOpenLaunchApp() {
-			var tag = document.getElementById('launch-btn');
-			if (!tag) return false;
+			if (!tag) return;
 			try {
-				if (tag.shadowRoot) {
-					var inner = tag.shadowRoot.querySelector('button');
-					if (inner && typeof inner.click === 'function') {
-						inner.click();
-						return true;
-					}
-				}
-				if (typeof tag.click === 'function') {
-					tag.click();
-					return true;
-				}
-			} catch (eWx) {
-				console.warn('[wx-open-launch-app] trigger', eWx);
+				if (WECHAT_OPEN_APP_ID) tag.setAttribute('appid', WECHAT_OPEN_APP_ID);
+				tag.setAttribute('extinfo', buildWeChatLaunchExtinfo());
+			} catch (eAttr) {
+				console.warn('[wx-open-launch-app] set attrs', eAttr);
 			}
-			return false;
 		}
 
-		/**
-		 * 仅当开放标签在真机已渲染出可点区域时,才用透明层盖住 #openApp;
-		 * 否则保持 #openApp 可点,避免「点了没反应」。
-		 */
+		/** wx.config 成功后即切换为开放标签按钮(不再依赖 offsetHeight 检测) */
 		function updateFabOpenLayer() {
 			var dock = document.getElementById('fabDock');
 			var hit = document.getElementById('fabWxHit');
-			var useWx =
-				isWeChatInAppBrowser() && weChatJssdkConfigured && isWxOpenLaunchTagReady();
+			var useWx = isWeChatInAppBrowser() && weChatJssdkConfigured;
 			if (dock) {
 				if (useWx) dock.classList.add('wx-open-enabled');
 				else dock.classList.remove('wx-open-enabled');
 			}
 			if (hit) hit.setAttribute('aria-hidden', useWx ? 'false' : 'true');
+			if (useWx) refreshWxLaunchTagAttrs();
+		}
+
+		function scheduleWxOpenTagRefresh() {
+			refreshWxLaunchTagAttrs();
+			updateFabOpenLayer();
+			var delays = [100, 400, 1000, 2000];
+			for (var i = 0; i < delays.length; i++) {
+				(function (ms) {
+					window.setTimeout(function () {
+						if (!weChatJssdkConfigured) return;
+						refreshWxLaunchTagAttrs();
+						updateFabOpenLayer();
+					}, ms);
+				})(delays[i]);
+			}
+			window.setTimeout(function () {
+				if (!weChatJssdkConfigured) return;
+				var tag = document.getElementById('launch-btn');
+				var h = tag ? tag.offsetHeight || 0 : 0;
+				if (h >= 20) return;
+				var dock = document.getElementById('fabDock');
+				if (dock) dock.classList.remove('wx-open-enabled');
+				showAppOpenFailTip(
+					'开放标签未渲染(高度为 0)。请检查:移动应用 AppID、开放平台绑定、测试号 JS 域名;链接加 wxDebug=1 查看 config。'
+				);
+			}, 2800);
 		}
 
 		var openAppFabClickLock = 0;
@@ -1624,37 +1624,33 @@
 			var now = Date.now();
 			if (now - openAppFabClickLock < 500) return;
 			openAppFabClickLock = now;
+			var dock = document.getElementById('fabDock');
+			if (
+				isWeChatInAppBrowser() &&
+				weChatJssdkConfigured &&
+				dock &&
+				dock.classList.contains('wx-open-enabled')
+			) {
+				showFabToast('请点 APP内打开 按钮(由微信开放标签唤起,非普通链接)');
+				return;
+			}
 			tryOpenHBuilderApp();
 		}
 
 		function bindOpenAppFabClick() {
-			var slot = document.querySelector('.fab-dock__slot');
 			var btn = document.getElementById('openApp');
-			function onFabActivate(e) {
-				if (e && e.cancelable) e.preventDefault();
-				handleOpenAppFabClick();
-			}
 			if (btn) {
-				btn.addEventListener('click', onFabActivate);
-			}
-			if (slot) {
-				slot.addEventListener(
-					'touchend',
-					function (e) {
-						if (e.cancelable) e.preventDefault();
-						onFabActivate(e);
-					},
-					false
-				);
+				btn.addEventListener('click', function (e) {
+					if (e && e.cancelable) e.preventDefault();
+					handleOpenAppFabClick();
+				});
 			}
 		}
 
 		function bindWeChatLaunchTagEvents() {
 			var tag = document.getElementById('launch-btn');
 			if (!tag) return;
-			try {
-				tag.setAttribute('extinfo', buildWeChatLaunchExtinfo());
-			} catch (eExt) {}
+			refreshWxLaunchTagAttrs();
 			tag.addEventListener('launch', function (e) {
 				console.log('[wx-open-launch-app] launch ok', e && e.detail);
 				reportWxDebug('wx-open-launch-app launch', e && e.detail ? e.detail : { errMsg: 'launch:ok' }, [
@@ -1673,8 +1669,6 @@
 								? String(detail.errmsg)
 								: '(无)')
 				]);
-				weChatJssdkConfigured = false;
-				updateFabOpenLayer();
 				var errMsg =
 					detail && detail.errMsg
 						? String(detail.errMsg)
@@ -1685,10 +1679,14 @@
 					showAppOpenFailTip(
 						'微信未能唤起 App(' +
 							errMsg +
-							')。请确认已安装 App,且移动应用已与公众号关联。'
+							')。请确认:①已安装 U店在哪;②开放标签 appid 为移动应用 ID;③开放平台已绑定域名与 App。'
 					);
 				} else {
-					showAppOpenFailTip();
+					showAppOpenFailTip(
+						errMsg
+							? '开放标签错误:' + errMsg
+							: '开放标签唤起失败,请用 wxDebug=1 查看详情。'
+					);
 				}
 			});
 		}
@@ -1787,11 +1785,8 @@
 			}
 
 			if (inWx && weChatJssdkConfigured) {
-				if (isWxOpenLaunchTagReady()) {
-					tryTriggerWxOpenLaunchApp();
-				} else {
-					showFabToast('开放标签未加载,正在尝试深链唤起…');
-				}
+				showFabToast('请使用底部 APP内打开 按钮(微信开放标签)');
+				return;
 			}
 
 			var deepLink = buildAppDeepLink();