lxr 1 неделя назад
Родитель
Сommit
a0d6a1ef28
1 измененных файлов с 147 добавлено и 72 удалено
  1. 147 72
      HBuilderProjects/shareAiConsult.html

+ 147 - 72
HBuilderProjects/shareAiConsult.html

@@ -35,7 +35,7 @@
       background: var(--bg);
       color: var(--text);
       min-height: 100vh;
-      padding-bottom: calc(88px + var(--safe-bottom));
+      padding-bottom: calc(92px + var(--safe-bottom));
     }
 
     .hero {
@@ -134,44 +134,58 @@
     }
 
     .footer__dock {
-      position: relative;
+      display: flex;
+      justify-content: center;
       width: 100%;
       pointer-events: auto;
     }
 
+    .footer__btn-slot {
+      width: 50%;
+      height: 48px;
+    }
+
     .continue-btn {
+      display: flex;
+      align-items: center;
+      justify-content: center;
       width: 100%;
-      height: 44px;
+      height: 48px;
+      margin: 0;
+      padding: 0;
       border: none;
       border-radius: 999px;
-      background: linear-gradient(90deg, #ffb347 0%, #f47d1f 55%, #ff7849 100%);
-      box-shadow: 0 4px 12px rgba(244, 125, 31, 0.28);
-      color: #fff;
-      font-size: 16px;
-      font-weight: 600;
+      background: linear-gradient(90deg, #ffb84c 0%, #ff6b3e 100%);
+      box-shadow: 0 4px 16px rgba(255, 107, 62, 0.32);
       touch-action: manipulation;
+      -webkit-tap-highlight-color: transparent;
+    }
+
+    .continue-btn__label {
+      display: block;
+      height: 20px;
+      width: auto;
+      max-width: 90%;
+      pointer-events: none;
+      -webkit-user-drag: none;
     }
 
     #launch-btn {
       display: none;
-      position: absolute;
-      left: 0;
-      right: 0;
-      top: 0;
       width: 100%;
-      height: 44px;
-      min-height: 44px;
+      height: 48px;
+      min-height: 48px;
       border-radius: 999px;
       overflow: hidden;
     }
 
     body.is-wechat.wx-jssdk-ready #launch-btn {
       display: block;
+      pointer-events: auto;
     }
 
     body.is-wechat.wx-jssdk-ready #btnContinue {
-      visibility: hidden;
-      pointer-events: none;
+      display: none !important;
     }
 
     #openAppToast {
@@ -202,32 +216,43 @@
 
   <footer class="footer">
     <div class="footer__dock">
-      <button type="button" class="continue-btn" id="btnContinue">和U宝继续聊 →</button>
-      <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: 44px;
-              margin: 0;
-              padding: 0;
-              border: none;
-              border-radius: 999px;
-              background: linear-gradient(90deg, #ffb347 0%, #f47d1f 55%, #ff7849 100%);
-              box-shadow: 0 4px 12px rgba(244, 125, 31, 0.28);
-              color: #fff;
-              font-size: 16px;
-              font-weight: 600;
-              line-height: 44px;
-              text-align: center;
-              cursor: pointer;
-              -webkit-tap-highlight-color: transparent;
-            }
-          </style>
-          <button class="wx-open-app-btn">和U宝继续聊 →</button>
-        </script>
-      </wx-open-launch-app>
+      <div class="footer__btn-slot">
+        <button type="button" class="continue-btn" id="btnContinue" aria-label="和U宝继续聊">
+          <img class="continue-btn__label" src="images/uCharts.png" alt="和U宝继续聊" decoding="async">
+        </button>
+        <wx-open-launch-app id="launch-btn" appid="wxf5f1efe3a9f5012e" extinfo="">
+          <script type="text/wxtag-template">
+            <style>
+              .wx-open-app-btn {
+                display: flex;
+                align-items: center;
+                justify-content: center;
+                width: 100%;
+                height: 48px;
+                margin: 0;
+                padding: 0;
+                border: none;
+                border-radius: 999px;
+                background: linear-gradient(90deg, #ffb84c 0%, #ff6b3e 100%);
+                box-shadow: 0 4px 16px rgba(255, 107, 62, 0.32);
+                cursor: pointer;
+                -webkit-tap-highlight-color: transparent;
+                box-sizing: border-box;
+              }
+              .wx-open-app-btn__label {
+                display: block;
+                height: 20px;
+                width: auto;
+                max-width: 90%;
+                pointer-events: none;
+              }
+            </style>
+            <button class="wx-open-app-btn" aria-label="和U宝继续聊">
+              <img class="wx-open-app-btn__label" src="https://test.ailien.shop/h5/HBuilderProjects/images/uCharts.png" alt="和U宝继续聊" decoding="async">
+            </button>
+          </script>
+        </wx-open-launch-app>
+      </div>
     </div>
   </footer>
 
@@ -290,6 +315,52 @@
         }
       }
 
+      function stripPayloadQueryFromUrl() {
+        try {
+          if (!location.search || location.search.indexOf("payload=") < 0) return;
+          var u = new URL(location.href);
+          u.searchParams.delete("payload");
+          var next = u.pathname + (u.search || "") + (u.hash || "");
+          history.replaceState(null, document.title, next);
+        } catch (eStrip) {}
+      }
+
+      function formatNavTitle(question) {
+        var titled = formatDiscussionTitle(question);
+        var maxLen = 14;
+        var short = titled.length > maxLen ? titled.slice(0, maxLen) + "..." : titled;
+        return short + "-U宝";
+      }
+
+      function parseContentToMessages(content) {
+        var text = String(content || "").trim();
+        if (!text) return [];
+        var messages = [];
+        var blocks = text.split(/\n\n+/);
+        for (var i = 0; i < blocks.length; i++) {
+          var block = String(blocks[i] || "").trim();
+          if (!block) continue;
+          var userMatch = block.match(/^我[::]\s*([\s\S]*)$/);
+          if (userMatch) {
+            var userText = String(userMatch[1] || "").trim();
+            if (userText) messages.push({ role: "user", content: userText });
+            continue;
+          }
+          var aiMatch = block.match(/^UBAO[::]\s*([\s\S]*)$/i);
+          if (aiMatch) {
+            var aiText = String(aiMatch[1] || "").trim();
+            if (aiText) messages.push({ role: "ai", content: aiText });
+          }
+        }
+        return messages;
+      }
+
+      function resolveShareMessages(data) {
+        var messages = Array.isArray(data && data.messages) ? data.messages : [];
+        if (messages.length) return messages;
+        return parseContentToMessages(data && data.content);
+      }
+
       function getFirstUserQuestion(messages) {
         var list = Array.isArray(messages) ? messages : [];
         for (var i = 0; i < list.length; i++) {
@@ -381,13 +452,19 @@
           return;
         }
 
-        var messages = data.messages || [];
+        var messages = resolveShareMessages(data);
         var firstQuestion =
-          String(data.firstQuestion || "").trim() || getFirstUserQuestion(messages);
+          String(data.firstQuestion || "").trim() ||
+          getFirstUserQuestion(messages) ||
+          (function () {
+            var text = String(data.content || "").trim();
+            var m = text.match(/^我[::]([\s\S]+?)(?:\n\n|$)/);
+            return m ? String(m[1] || "").trim() : "";
+          })();
         var pageTitle = formatDiscussionTitle(firstQuestion);
         var dateText = formatDate(data.shareTime);
 
-        document.title = pageTitle;
+        document.title = formatNavTitle(firstQuestion);
 
         var bodyHtml =
           '<section class="hero">' +
@@ -403,11 +480,6 @@
         var convHtml = renderMessages(messages);
         if (convHtml) {
           bodyHtml += '<section class="conversation">' + convHtml + "</section>";
-        } else if (data.content) {
-          bodyHtml +=
-            '<section class="fallback-card"><div class="ai-card__text">' +
-            escHtml(data.content) +
-            "</div></section>";
         } else {
           bodyHtml += '<div class="empty">暂无对话内容</div>';
         }
@@ -416,24 +488,14 @@
         refreshWxLaunchTagAttrs();
       }
 
-      function buildAiConsultOpenParams() {
-        var params = new URLSearchParams();
-        params.set("pageType", "home");
-        params.set("fromShareAiConsult", "1");
-        return params;
-      }
-
       function buildAppDeepLink() {
-        var path = APP_UNI_AI_PATH;
-        var qs = buildAiConsultOpenParams().toString();
+        var path = String(APP_UNI_AI_PATH || "pages/aiSearchResult/index").replace(/^\//, "");
         var root = APP_IOS_URL_SCHEME.replace(/\/$/, "");
-        return root + "/" + path + (qs ? "?" + qs : "");
+        return root + "/" + path;
       }
 
       function buildWeChatLaunchExtinfo() {
-        var qs = buildAiConsultOpenParams().toString();
-        var uniPage = qs ? APP_UNI_AI_PATH + "?" + qs : APP_UNI_AI_PATH;
-        return uniPage.length <= 1024 ? uniPage : APP_UNI_AI_PATH + "?pageType=home&fromShareAiConsult=1";
+        return String(APP_UNI_AI_PATH || "pages/aiSearchResult/index").replace(/^\//, "");
       }
 
       function isWeChatInAppBrowser() {
@@ -500,8 +562,7 @@
       }
 
       function getWxConfigSignUrl() {
-        if (String(q("wxSignBaseOnly") || "") === "1") return getWxHtmlUrlBase();
-        return getWxSignPageUrlForApi();
+        return getWxHtmlUrlBase();
       }
 
       function getWxGetConfigApiUrl() {
@@ -727,7 +788,13 @@
               : detail && detail.errmsg
                 ? String(detail.errmsg)
                 : "";
-          console.warn("[wx-open-launch-app]", detail);
+          console.warn("[wx-open-launch-app]", detail, "extinfo=", tag.getAttribute("extinfo"));
+          if (/launch:fail/i.test(errMsg)) {
+            showAppOpenFailTip(
+              "未能打开 App,请确认已安装最新版「U店在哪」"
+            );
+            return;
+          }
           showAppOpenFailTip(
             errMsg
               ? "未能打开 App:" + errMsg
@@ -814,11 +881,9 @@
       function showAppOpenFailTip(msg) {
         var tip = msg || "未能打开 App,请确认已安装最新版「U店在哪」。";
         if (typeof uni !== "undefined" && typeof uni.showToast === "function") {
-          uni.showToast({ title: msg, icon: "none", duration: 2800 });
-        } else if (isWeChatInAppBrowser()) {
-          window.alert(tip);
+          uni.showToast({ title: tip, icon: "none", duration: 2800 });
         } else {
-          showFabToast(tip);
+          showFabToast(tip, 3200);
         }
       }
 
@@ -894,6 +959,7 @@
       function tryOpenApp() {
         if (isWeChatInAppBrowser()) {
           if (!weChatJssdkConfigured) {
+            showFabToast("微信 SDK 初始化中,请稍候再点");
             initWeChatOpenLaunchApp(true).then(function (ok) {
               if (!ok) {
                 showAppOpenFailTip(wxInitLastError || "微信唤起 App 初始化失败");
@@ -909,10 +975,19 @@
         document.body.classList.add("is-wechat");
       }
 
+      document.addEventListener("WeixinOpenTagsError", function (e) {
+        console.warn("[WeixinOpenTagsError]", e && e.detail);
+        document.body.classList.remove("wx-jssdk-ready");
+        showFabToast("微信开放标签加载失败,请稍候再试");
+      });
+
+      var sharePayload = parsePayload();
+      stripPayloadQueryFromUrl();
+
       bindWeChatLaunchTagEvents();
-      scheduleWeChatJssdkBootstrap();
       document.getElementById("btnContinue").addEventListener("click", tryOpenApp);
-      render(parsePayload());
+      render(sharePayload);
+      scheduleWeChatJssdkBootstrap();
     })();
   </script>
 </body>