zhuli пре 2 недеља
родитељ
комит
9b6ab3eba1
1 измењених фајлова са 60 додато и 142 уклоњено
  1. 60 142
      HBuilderProjects/shareIndex.html

+ 60 - 142
HBuilderProjects/shareIndex.html

@@ -469,48 +469,32 @@
 			pointer-events: none;
 			pointer-events: none;
 		}
 		}
 
 
-		#fabDock,
-		.fab-dock__slot,
-		#fabDock .fab,
-		.fab-wx-hit {
-			pointer-events: auto;
-		}
-
 		.fab-dock__slot {
 		.fab-dock__slot {
-			position: relative;
 			width: 100%;
 			width: 100%;
 			max-width: 320px;
 			max-width: 320px;
 			height: 48px;
 			height: 48px;
 			margin: 0 auto;
 			margin: 0 auto;
+			pointer-events: auto;
 		}
 		}
 
 
-		.fab-wx-hit {
-			display: none;
-			position: absolute;
-			left: 0;
-			right: 0;
-			top: 0;
-			height: 48px;
-			z-index: 3;
-		}
-
-		#fabDock.wx-open-enabled .fab-wx-hit {
-			display: block;
-		}
-
-		#fabDock.wx-open-enabled #openApp {
+		#openApp img {
 			pointer-events: none;
 			pointer-events: none;
 		}
 		}
 
 
+		/* 微信内:wx.config 成功后只显示开放标签按钮(官方用法) */
 		#launch-btn {
 		#launch-btn {
-			display: block;
+			display: none;
 			width: 100%;
 			width: 100%;
 			height: 48px;
 			height: 48px;
 			min-height: 48px;
 			min-height: 48px;
 		}
 		}
 
 
-		#openApp img {
-			pointer-events: none;
+		body.is-wechat.wx-jssdk-ready #launch-btn {
+			display: block;
+		}
+
+		body.is-wechat.wx-jssdk-ready #openApp {
+			display: none !important;
 		}
 		}
 
 
 		.fab {
 		.fab {
@@ -1036,35 +1020,36 @@
 	<div id="openAppToast" role="status" aria-live="polite"></div>
 	<div id="openAppToast" role="status" aria-live="polite"></div>
 	<div id="fabDock" class="fab-wrap">
 	<div id="fabDock" class="fab-wrap">
 		<div class="fab-dock__slot">
 		<div class="fab-dock__slot">
+			<!-- 非微信 / 微信 JSSDK 未就绪:scheme 唤起 -->
 			<button type="button" class="fab" id="openApp">
 			<button type="button" class="fab" id="openApp">
 				<img src="images/uBtn.png" alt="APP内打开" decoding="async">
 				<img src="images/uBtn.png" alt="APP内打开" decoding="async">
 			</button>
 			</button>
-			<div id="fabWxHit" class="fab-wx-hit" aria-hidden="true">
-				<wx-open-launch-app id="launch-btn" appid="wxf5f1efe3a9f5012e">
-					<script type="text/wxtag-template">
-						<style>
-							.wx-open-app-btn {
-								display: block;
-								width: 100%;
-								height: 48px;
-								margin: 0;
-								padding: 0;
-								border: none;
-								background: transparent;
-							}
-							.wx-open-app-btn img {
-								display: block;
-								width: 100%;
-								height: 48px;
-								object-fit: contain;
-							}
-						</style>
-						<button class="wx-open-app-btn" aria-label="APP内打开">
-							<img src="https://test.ailien.shop/h5/HBuilderProjects/images/uBtn.png" alt="APP内打开" />
-						</button>
-					</script>
-				</wx-open-launch-app>
-			</div>
+			<!-- 微信内 wx.config 成功后:仅此按钮可唤起 App(须用户直接点击) -->
+			<wx-open-launch-app id="launch-btn" appid="wxf5f1efe3a9f5012e" extinfo="">
+				<script type="text/wxtag-template">
+					<style>
+						.wx-open-app-btn {
+							display: block;
+							width: 100%;
+							height: 48px;
+							margin: 0;
+							padding: 0;
+							border: none;
+							background: transparent;
+							cursor: pointer;
+						}
+						.wx-open-app-btn img {
+							display: block;
+							width: 100%;
+							height: 48px;
+							object-fit: contain;
+						}
+					</style>
+					<button class="wx-open-app-btn" aria-label="APP内打开">
+						<img src="https://test.ailien.shop/h5/HBuilderProjects/images/uBtn.png" alt="APP内打开" />
+					</button>
+				</script>
+			</wx-open-launch-app>
 		</div>
 		</div>
 		<div class="home-indicator" aria-hidden="true"></div>
 		<div class="home-indicator" aria-hidden="true"></div>
 	</div>
 	</div>
@@ -1384,6 +1369,7 @@
 				});
 				});
 				wx.ready(function () {
 				wx.ready(function () {
 					weChatJssdkConfigured = true;
 					weChatJssdkConfigured = true;
+					document.body.classList.add('wx-jssdk-ready');
 					if (wxSignUrlFullBeforeStrip) {
 					if (wxSignUrlFullBeforeStrip) {
 						history.replaceState(
 						history.replaceState(
 							history.state,
 							history.state,
@@ -1392,13 +1378,13 @@
 						);
 						);
 						wxSignUrlFullBeforeStrip = '';
 						wxSignUrlFullBeforeStrip = '';
 					}
 					}
-					scheduleWxOpenTagRefresh();
+					refreshWxLaunchTagAttrs();
 					resolve(true);
 					resolve(true);
 				});
 				});
 				wx.error(function (err) {
 				wx.error(function (err) {
 					weChatJssdkConfigured = false;
 					weChatJssdkConfigured = false;
+					document.body.classList.remove('wx-jssdk-ready');
 					wxJssdkInitPromise = null;
 					wxJssdkInitPromise = null;
-					updateFabOpenLayer();
 					var errMsg = getWxErrMsg(err);
 					var errMsg = getWxErrMsg(err);
 					setWxInitError(formatWxConfigErrorTip(err, urlForWx));
 					setWxInitError(formatWxConfigErrorTip(err, urlForWx));
 					if (isWxDebugOn()) window.alert(wxInitLastError);
 					if (isWxDebugOn()) window.alert(wxInitLastError);
@@ -1440,38 +1426,10 @@
 			} catch (eA) {}
 			} catch (eA) {}
 		}
 		}
 
 
-		function isFabWxOpenLayerActive() {
-			var dock = document.getElementById('fabDock');
-			return !!(dock && dock.classList.contains('wx-open-enabled'));
-		}
-
-		function updateFabOpenLayer() {
-			var dock = document.getElementById('fabDock');
-			var hit = document.getElementById('fabWxHit');
-			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();
-			[200, 600, 1500].forEach(function (ms) {
-				setTimeout(function () {
-					if (!weChatJssdkConfigured) return;
-					refreshWxLaunchTagAttrs();
-					updateFabOpenLayer();
-				}, ms);
-			});
-		}
-
 		function bindWeChatLaunchTagEvents() {
 		function bindWeChatLaunchTagEvents() {
 			var tag = document.getElementById('launch-btn');
 			var tag = document.getElementById('launch-btn');
-			if (!tag) return;
+			if (!tag || tag._wxLaunchBound) return;
+			tag._wxLaunchBound = true;
 			refreshWxLaunchTagAttrs();
 			refreshWxLaunchTagAttrs();
 			tag.addEventListener('launch', function () {
 			tag.addEventListener('launch', function () {
 				console.log('[wx-open-launch-app] launch ok');
 				console.log('[wx-open-launch-app] launch ok');
@@ -1572,31 +1530,6 @@
 			console.log('[openApp]', tip);
 			console.log('[openApp]', tip);
 		}
 		}
 
 
-		function ensureWeChatJssdkReadyOnClick() {
-			showFabToast('正在获取微信签名…');
-			var timedOut = false;
-			var timer = window.setTimeout(function () {
-				timedOut = true;
-				showAppOpenFailTip('getWxConfig 请求超时,请检查网络或后端接口');
-			}, 15000);
-			wxJssdkInitPromise = null;
-			return initWeChatOpenLaunchApp().then(function (ok) {
-				window.clearTimeout(timer);
-				if (timedOut) return false;
-				if (ok) {
-					scheduleWxOpenTagRefresh();
-					showFabToast('签名完成,请再点一次底部 APP内打开');
-					return true;
-				}
-				showAppOpenFailTip(
-					wxInitLastError
-						? 'JSSDK 未就绪:' + wxInitLastError
-						: 'JSSDK 未就绪:未请求到 getWxConfig'
-				);
-				return false;
-			});
-		}
-
 		function showAppOpenFailTip(msg) {
 		function showAppOpenFailTip(msg) {
 			var tip = msg || '未能打开 App,请确认已安装最新版「U店在哪」。';
 			var tip = msg || '未能打开 App,请确认已安装最新版「U店在哪」。';
 			if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
 			if (typeof uni !== 'undefined' && typeof uni.showToast === 'function') {
@@ -1629,23 +1562,8 @@
 		 * 系统浏览器:唤起 scheme;微信内常拦截 scheme,需「在浏览器打开」。
 		 * 系统浏览器:唤起 scheme;微信内常拦截 scheme,需「在浏览器打开」。
 		 */
 		 */
 		function tryOpenHBuilderApp() {
 		function tryOpenHBuilderApp() {
-			var inWx = isWeChatInAppBrowser();
-
-			/* JSSDK 已就绪:必须由用户手指点击 wx-open-launch-app,JS 模拟 click 无效 */
-			if (inWx && weChatJssdkConfigured && isFabWxOpenLayerActive()) {
-				return;
-			}
-			if (inWx && weChatJssdkConfigured) {
-				showAppOpenFailTip(
-					'开放标签未显示。请刷新页面;若仍失败请检查开放平台是否绑定移动应用 ' +
-						WECHAT_OPEN_APP_ID
-				);
-				return;
-			}
-			if (inWx && !weChatJssdkConfigured) {
-				ensureWeChatJssdkReadyOnClick();
-				return;
-			}
+			/* 微信内须直接点击 wx-open-launch-app,scheme 会被拦截 */
+			if (isWeChatInAppBrowser()) return;
 
 
 			showFabToast('正在打开 U店在哪…');
 			showFabToast('正在打开 U店在哪…');
 			var deepLink = buildAppDeepLink();
 			var deepLink = buildAppDeepLink();
@@ -2850,24 +2768,24 @@
 		function boot() {
 		function boot() {
 			var launchTag = document.getElementById('launch-btn');
 			var launchTag = document.getElementById('launch-btn');
 			if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
 			if (launchTag) launchTag.setAttribute('appid', WECHAT_OPEN_APP_ID);
-			var openAppClickLock = 0;
-			function onOpenAppActivate(e) {
-				if (isWeChatInAppBrowser() && weChatJssdkConfigured && isFabWxOpenLayerActive()) {
-					return;
+			bindWeChatLaunchTagEvents();
+			if (isWeChatInAppBrowser()) {
+				document.body.classList.add('is-wechat');
+				scheduleWeChatJssdkBootstrap();
+				var openBtnWx = document.getElementById('openApp');
+				if (openBtnWx) {
+					openBtnWx.addEventListener('click', function () {
+						if (!weChatJssdkConfigured) {
+							showFabToast(
+								wxInitLastError || '微信 SDK 初始化中,请稍候再点底部按钮'
+							);
+						}
+					});
 				}
 				}
-				if (e && e.cancelable) e.preventDefault();
-				var now = Date.now();
-				if (now - openAppClickLock < 400) return;
-				openAppClickLock = now;
-				tryOpenHBuilderApp();
-			}
-			var openBtn = document.getElementById('openApp');
-			if (openBtn) {
-				openBtn.addEventListener('click', onOpenAppActivate);
-				openBtn.addEventListener('touchend', onOpenAppActivate);
+			} else {
+				var openBtn = document.getElementById('openApp');
+				if (openBtn) openBtn.addEventListener('click', tryOpenHBuilderApp);
 			}
 			}
-			/* 先于 run(),避免误以为没调 getWxConfig */
-			scheduleWeChatJssdkBootstrap();
 			run();
 			run();
 			bindMarketingMore();
 			bindMarketingMore();
 			bindStaffSection();
 			bindStaffSection();