sunshibo 4 dias atrás
pai
commit
6da247bda9
1 arquivos alterados com 70 adições e 27 exclusões
  1. 70 27
      HBuilderProjects/shareAiConsult.html

+ 70 - 27
HBuilderProjects/shareAiConsult.html

@@ -192,7 +192,6 @@
     }
 
     .fab-dock__slot {
-      position: relative;
       width: 100%;
       max-width: 198px;
       height: 48px;
@@ -230,10 +229,6 @@
 
     #launch-btn {
       display: none;
-      position: absolute;
-      left: 0;
-      top: 0;
-      z-index: 2;
       width: 100%;
       height: 48px;
       min-height: 48px;
@@ -242,14 +237,13 @@
       opacity: 1;
     }
 
-    /* 开放标签叠在 openApp 上;保留 openApp 作视觉兜底,避免标签未渲染时按钮消失 */
     body.is-wechat.wx-jssdk-ready #launch-btn {
       display: block;
       pointer-events: auto;
     }
 
     body.is-wechat.wx-jssdk-ready #openApp {
-      pointer-events: none;
+      display: none !important;
     }
 
     .fab-wrap .fab {
@@ -316,6 +310,7 @@
 
   <div class="fab-wrap">
     <div class="fab-dock__slot">
+      <!-- 与 secondShareGoods 相同顺序:openApp 在下,launch-btn 在上,避免挡住点击 -->
       <button type="button" class="fab" id="openApp" aria-label="APP内打开">
         <span class="fab__brand-clip" aria-hidden="true">
           <img class="fab__brand-img" src="images/uCharts.png" alt="" decoding="async">
@@ -373,7 +368,6 @@
         </script>
       </wx-open-launch-app>
     </div>
-    <div class="home-indicator" aria-hidden="true"></div>
   </div>
 
   <script src="https://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
@@ -724,7 +718,7 @@
         main.innerHTML = bodyHtml;
         refreshWxLaunchTagAttrs();
         if (weChatJssdkConfigured && isWeChatInAppBrowser()) {
-          activateWxLaunchTagUi();
+          scheduleWxLaunchTagUiSync();
         }
       }
 
@@ -791,6 +785,10 @@
         return q("wxForce") === "1";
       }
 
+      function isWxConfigOnClickDebug() {
+        return q("wxConfigOnClick") === "1";
+      }
+
       function isWxPcAutoDebugHost() {
         var h = (location.hostname || "").toLowerCase();
         if (h === "localhost" || h === "127.0.0.1") return true;
@@ -1004,22 +1002,27 @@
         if (!tag) return false;
         try {
           if (tag.shadowRoot) {
-            var innerBtn = tag.shadowRoot.querySelector("button, .wx-open-app-btn");
-            if (innerBtn) return true;
+            return !!tag.shadowRoot.querySelector("button, .wx-open-app-btn");
           }
         } catch (eShadow) {}
-        var rect = tag.getBoundingClientRect();
-        return rect.height >= 40 && rect.width >= 40;
+        return false;
       }
 
-      function activateWxLaunchTagUi() {
-        document.body.classList.add("wx-jssdk-ready");
+      function syncWxLaunchTagUi() {
         if (!isWeChatInAppBrowser()) return;
-        window.setTimeout(function () {
-          if (isWxLaunchTagRendered()) return;
+        if (isWxLaunchTagRendered()) {
+          document.body.classList.add("wx-jssdk-ready");
+        } else {
           document.body.classList.remove("wx-jssdk-ready");
-          console.warn("[wx] launch tag not rendered, fallback to #openApp");
-        }, 500);
+        }
+      }
+
+      function scheduleWxLaunchTagUiSync() {
+        if (!isWeChatInAppBrowser()) return;
+        syncWxLaunchTagUi();
+        [200, 500, 1000, 1800].forEach(function (ms) {
+          window.setTimeout(syncWxLaunchTagUi, ms);
+        });
       }
 
       function applyWxConfigFromSign(sign, htmlUrl) {
@@ -1037,7 +1040,7 @@
           wx.ready(function () {
             weChatJssdkConfigured = true;
             refreshWxLaunchTagAttrs();
-            activateWxLaunchTagUi();
+            scheduleWxLaunchTagUiSync();
             console.log("[wx.config] ready, htmlUrl=", htmlUrl);
             resolve(true);
           });
@@ -1072,6 +1075,7 @@
         try {
           tag.setAttribute("appid", WECHAT_OPEN_APP_ID);
           tag.setAttribute("extinfo", buildWeChatLaunchExtinfo(!!useBarePathOnly));
+          console.log("[wx-open-launch-app] extinfo=", tag.getAttribute("extinfo"));
         } catch (eA) {}
       }
 
@@ -1112,7 +1116,7 @@
           ) {
             tag._wxLaunchBareRetried = true;
             refreshWxLaunchTagAttrs(true);
-            showFabToast("请再点一次「和U宝继续聊」");
+            showFabToast("请再点一次「APP内打开」");
             return;
           }
 
@@ -1246,13 +1250,15 @@
           } catch (e) {
             console.warn(e);
           }
+          if (installed === false) {
+            showDownloadTip();
+            return;
+          }
           try {
             plus.runtime.openURL(deepLink);
           } catch (e2) {
             console.warn(e2);
-            if (installed === false) {
-              showDownloadTip();
-            }
+            showDownloadTip();
           }
           return;
         }
@@ -1286,9 +1292,32 @@
         }, 3200);
       }
 
-      function tryOpenApp() {
+      function tryFetchWxConfigOnPcClick() {
+        if (!isWxPcBrowser()) return Promise.resolve(false);
+        showFabToast("正在请求 getWxConfig…");
+        wxJssdkInitPromise = null;
+        return initWeChatOpenLaunchApp(true).then(function (ok) {
+          if (ok) {
+            showFabToast(
+              weChatJssdkConfigured
+                ? "getWxConfig 成功,wx.config 已就绪"
+                : "getWxConfig 成功"
+            );
+          } else {
+            showFabToast(wxInitLastError || "getWxConfig 失败");
+          }
+          return ok;
+        });
+      }
+
+      function tryOpenHBuilderApp() {
         if (isWeChatInAppBrowser()) return;
-        tryOpenHBuilderAppViaScheme();
+        tryFetchWxConfigOnPcClick().then(function () {
+          if (isWxConfigOnClickDebug() && !isWxForceDebug() && !isWxPcAutoDebugHost()) {
+            return;
+          }
+          tryOpenHBuilderAppViaScheme();
+        });
       }
 
       function boot() {
@@ -1313,6 +1342,14 @@
           weChatJssdkConfigured = false;
           wxJssdkInitPromise = null;
           console.warn("[WeixinOpenTagsError]", e && e.detail);
+          var d = e && e.detail;
+          var em =
+            d && d.errMsg
+              ? String(d.errMsg)
+              : d && d.errmsg
+                ? String(d.errmsg)
+                : "";
+          showFabToast(em || "微信开放标签不可用,请升级微信后重试");
         });
 
         var openBtnWx = document.getElementById("openApp");
@@ -1324,10 +1361,16 @@
                   wxInitLastError || "微信 SDK 初始化中,请稍候再点底部按钮"
                 );
                 initWeChatOpenLaunchApp(true);
+                return;
+              }
+              if (!document.body.classList.contains("wx-jssdk-ready")) {
+                refreshWxLaunchTagAttrs();
+                scheduleWxLaunchTagUiSync();
+                showFabToast("开放标签加载中,请稍候再点");
               }
             });
           } else {
-            openBtnWx.addEventListener("click", tryOpenApp);
+            openBtnWx.addEventListener("click", tryOpenHBuilderApp);
           }
         }