lxr před 1 týdnem
rodič
revize
7dd9f470eb
1 změnil soubory, kde provedl 85 přidání a 215 odebrání
  1. 85 215
      HBuilderProjects/shareAiConsult.html

+ 85 - 215
HBuilderProjects/shareAiConsult.html

@@ -35,7 +35,7 @@
       background: var(--bg);
       background: var(--bg);
       color: var(--text);
       color: var(--text);
       min-height: 100vh;
       min-height: 100vh;
-      padding-bottom: calc(92px + var(--safe-bottom));
+      padding-bottom: calc(88px + var(--safe-bottom));
     }
     }
 
 
     .hero {
     .hero {
@@ -64,12 +64,10 @@
 
 
     .conversation {
     .conversation {
       padding: 14px 15px 0;
       padding: 14px 15px 0;
-      box-sizing: border-box;
     }
     }
 
 
     .row {
     .row {
       display: flex;
       display: flex;
-      width: 100%;
       margin-bottom: 12px;
       margin-bottom: 12px;
     }
     }
 
 
@@ -82,67 +80,39 @@
     }
     }
 
 
     .user-bubble {
     .user-bubble {
-      position: relative;
       max-width: 78%;
       max-width: 78%;
       padding: 10px 12px;
       padding: 10px 12px;
-      background: #f47d1f;
+      background: var(--orange);
       border-radius: 6px;
       border-radius: 6px;
-      box-sizing: border-box;
-    }
-
-    .user-bubble::after {
-      content: "";
-      position: absolute;
-      right: -5px;
-      bottom: 10px;
-      width: 0;
-      height: 0;
-      border-style: solid;
-      border-width: 5px 0 5px 6px;
-      border-color: transparent transparent transparent #f47d1f;
-    }
-
-    .user-bubble__text {
+      color: #fff;
       font-size: 15px;
       font-size: 15px;
       font-weight: 500;
       font-weight: 500;
-      color: #ffffff;
-      line-height: 22px;
-      word-break: break-word;
+      line-height: 1.5;
       white-space: pre-wrap;
       white-space: pre-wrap;
+      word-break: break-word;
     }
     }
 
 
     .ai-card {
     .ai-card {
       width: 100%;
       width: 100%;
       padding: 14px 13px;
       padding: 14px 13px;
-      background: #ffffff;
+      background: #fff;
       border-radius: 8px;
       border-radius: 8px;
-      box-sizing: border-box;
       box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
       box-shadow: 0 1px 6px rgba(0, 0, 0, 0.04);
     }
     }
 
 
     .ai-card__text {
     .ai-card__text {
       font-size: 14px;
       font-size: 14px;
-      color: #151515;
-      line-height: 23px;
-      word-break: break-word;
+      line-height: 1.65;
       white-space: pre-wrap;
       white-space: pre-wrap;
+      word-break: break-word;
       text-align: left;
       text-align: left;
     }
     }
 
 
     .fallback-card {
     .fallback-card {
       margin: 14px 15px 0;
       margin: 14px 15px 0;
       padding: 14px 13px;
       padding: 14px 13px;
-      background: #ffffff;
+      background: #fff;
       border-radius: 8px;
       border-radius: 8px;
-      box-sizing: border-box;
-    }
-
-    .fallback-card__text {
-      font-size: 14px;
-      color: #151515;
-      line-height: 23px;
-      white-space: pre-wrap;
-      word-break: break-word;
     }
     }
 
 
     .empty {
     .empty {
@@ -157,66 +127,51 @@
       left: 0;
       left: 0;
       right: 0;
       right: 0;
       bottom: 0;
       bottom: 0;
-      z-index: 200;
+      z-index: 20;
       padding: 10px 15px calc(10px + var(--safe-bottom));
       padding: 10px 15px calc(10px + var(--safe-bottom));
       background: linear-gradient(180deg, rgba(244, 246, 251, 0) 0%, #f4f6fb 36%);
       background: linear-gradient(180deg, rgba(244, 246, 251, 0) 0%, #f4f6fb 36%);
       pointer-events: none;
       pointer-events: none;
     }
     }
 
 
     .footer__dock {
     .footer__dock {
-      display: flex;
-      justify-content: center;
+      position: relative;
       width: 100%;
       width: 100%;
       pointer-events: auto;
       pointer-events: auto;
     }
     }
 
 
-    .footer__btn-slot {
-      width: 50%;
-      height: 48px;
-      margin: 0 auto;
-    }
-
     .continue-btn {
     .continue-btn {
-      display: flex;
-      align-items: center;
-      justify-content: center;
       width: 100%;
       width: 100%;
-      height: 48px;
-      margin: 0;
-      padding: 0;
+      height: 44px;
       border: none;
       border: none;
       border-radius: 999px;
       border-radius: 999px;
-      background: linear-gradient(90deg, #ffb84c 0%, #ff6b3e 100%);
-      box-shadow: 0 4px 16px rgba(255, 107, 62, 0.32);
+      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;
       touch-action: manipulation;
       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 {
     #launch-btn {
       display: none;
       display: none;
+      position: absolute;
+      left: 0;
+      right: 0;
+      top: 0;
       width: 100%;
       width: 100%;
-      height: 48px;
-      min-height: 48px;
+      height: 44px;
+      min-height: 44px;
       border-radius: 999px;
       border-radius: 999px;
       overflow: hidden;
       overflow: hidden;
     }
     }
 
 
     body.is-wechat.wx-jssdk-ready #launch-btn {
     body.is-wechat.wx-jssdk-ready #launch-btn {
       display: block;
       display: block;
-      pointer-events: auto;
     }
     }
 
 
     body.is-wechat.wx-jssdk-ready #btnContinue {
     body.is-wechat.wx-jssdk-ready #btnContinue {
-      display: none !important;
+      visibility: hidden;
+      pointer-events: none;
     }
     }
 
 
     #openAppToast {
     #openAppToast {
@@ -247,43 +202,32 @@
 
 
   <footer class="footer">
   <footer class="footer">
     <div class="footer__dock">
     <div class="footer__dock">
-      <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>
+      <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>
     </div>
   </footer>
   </footer>
 
 
@@ -346,17 +290,6 @@
         }
         }
       }
       }
 
 
-      /** 对话 payload 在 query 中会导致 URL 过长,微信 JSSDK / 开放标签易 launch:fail;读完后清掉 query */
-      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 getFirstUserQuestion(messages) {
       function getFirstUserQuestion(messages) {
         var list = Array.isArray(messages) ? messages : [];
         var list = Array.isArray(messages) ? messages : [];
         for (var i = 0; i < list.length; i++) {
         for (var i = 0; i < list.length; i++) {
@@ -376,50 +309,6 @@
         return qText + "的讨论";
         return qText + "的讨论";
       }
       }
 
 
-      function formatNavTitle(question) {
-        var titled = formatDiscussionTitle(question);
-        var maxLen = 14;
-        var short = titled.length > maxLen ? titled.slice(0, maxLen) + "..." : titled;
-        return short + "-U宝";
-      }
-
-      function extractFirstQuestionFromContent(content) {
-        var text = String(content || "").trim();
-        if (!text) return "";
-        var match = text.match(/^我[::]([\s\S]+?)(?:\n\n|$)/);
-        if (match) return String(match[1] || "").trim();
-        return "";
-      }
-
-      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 formatDate(ts) {
       function formatDate(ts) {
         var d = ts ? new Date(Number(ts)) : new Date();
         var d = ts ? new Date(Number(ts)) : new Date();
         if (isNaN(d.getTime())) d = new Date();
         if (isNaN(d.getTime())) d = new Date();
@@ -436,9 +325,9 @@
             var userText = msg.isImage ? "[图片]" : String(msg.content || "").trim();
             var userText = msg.isImage ? "[图片]" : String(msg.content || "").trim();
             if (!userText) continue;
             if (!userText) continue;
             html +=
             html +=
-              '<div class="row row--user"><div class="user-bubble"><div class="user-bubble__text">' +
+              '<div class="row row--user"><div class="user-bubble">' +
               escHtml(userText) +
               escHtml(userText) +
-              "</div></div></div>";
+              "</div></div>";
             continue;
             continue;
           }
           }
           if (msg.role === "ai") {
           if (msg.role === "ai") {
@@ -487,22 +376,18 @@
         sharePayloadCache = data || null;
         sharePayloadCache = data || null;
         var main = document.getElementById("main");
         var main = document.getElementById("main");
         if (!data) {
         if (!data) {
-          document.title = "与AI助手-U宝";
           main.innerHTML = '<div class="empty">对话内容不存在或链接已失效</div>';
           main.innerHTML = '<div class="empty">对话内容不存在或链接已失效</div>';
           refreshWxLaunchTagAttrs();
           refreshWxLaunchTagAttrs();
           return;
           return;
         }
         }
 
 
-        var messages = resolveShareMessages(data);
+        var messages = data.messages || [];
         var firstQuestion =
         var firstQuestion =
-          String(data.firstQuestion || "").trim() ||
-          getFirstUserQuestion(messages) ||
-          extractFirstQuestionFromContent(data.content);
+          String(data.firstQuestion || "").trim() || getFirstUserQuestion(messages);
         var pageTitle = formatDiscussionTitle(firstQuestion);
         var pageTitle = formatDiscussionTitle(firstQuestion);
-        var navTitleText = formatNavTitle(firstQuestion);
         var dateText = formatDate(data.shareTime);
         var dateText = formatDate(data.shareTime);
 
 
-        document.title = navTitleText;
+        document.title = pageTitle;
 
 
         var bodyHtml =
         var bodyHtml =
           '<section class="hero">' +
           '<section class="hero">' +
@@ -518,6 +403,11 @@
         var convHtml = renderMessages(messages);
         var convHtml = renderMessages(messages);
         if (convHtml) {
         if (convHtml) {
           bodyHtml += '<section class="conversation">' + convHtml + "</section>";
           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 {
         } else {
           bodyHtml += '<div class="empty">暂无对话内容</div>';
           bodyHtml += '<div class="empty">暂无对话内容</div>';
         }
         }
@@ -526,14 +416,24 @@
         refreshWxLaunchTagAttrs();
         refreshWxLaunchTagAttrs();
       }
       }
 
 
+      function buildAiConsultOpenParams() {
+        var params = new URLSearchParams();
+        params.set("pageType", "home");
+        params.set("fromShareAiConsult", "1");
+        return params;
+      }
+
       function buildAppDeepLink() {
       function buildAppDeepLink() {
-        var path = String(APP_UNI_AI_PATH || "pages/aiSearchResult/index").replace(/^\//, "");
+        var path = APP_UNI_AI_PATH;
+        var qs = buildAiConsultOpenParams().toString();
         var root = APP_IOS_URL_SCHEME.replace(/\/$/, "");
         var root = APP_IOS_URL_SCHEME.replace(/\/$/, "");
-        return root + "/" + path;
+        return root + "/" + path + (qs ? "?" + qs : "");
       }
       }
 
 
       function buildWeChatLaunchExtinfo() {
       function buildWeChatLaunchExtinfo() {
-        return String(APP_UNI_AI_PATH || "pages/aiSearchResult/index").replace(/^\//, "");
+        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";
       }
       }
 
 
       function isWeChatInAppBrowser() {
       function isWeChatInAppBrowser() {
@@ -600,7 +500,8 @@
       }
       }
 
 
       function getWxConfigSignUrl() {
       function getWxConfigSignUrl() {
-        return getWxHtmlUrlBase();
+        if (String(q("wxSignBaseOnly") || "") === "1") return getWxHtmlUrlBase();
+        return getWxSignPageUrlForApi();
       }
       }
 
 
       function getWxGetConfigApiUrl() {
       function getWxGetConfigApiUrl() {
@@ -826,22 +727,7 @@
               : detail && detail.errmsg
               : detail && detail.errmsg
                 ? String(detail.errmsg)
                 ? String(detail.errmsg)
                 : "";
                 : "";
-          console.warn("[wx-open-launch-app]", detail, "extinfo=", tag.getAttribute("extinfo"));
-          if (/launch:fail_check/i.test(errMsg)) {
-            document.body.classList.remove("wx-jssdk-ready");
-            showAppOpenFailTip(
-              "微信唤起 App 校验失败,请确认开放标签域名与 App 关联配置正确"
-            );
-            return;
-          }
-          if (/launch:fail/i.test(errMsg)) {
-            document.body.classList.remove("wx-jssdk-ready");
-            showAppOpenFailTip(
-              "未能打开 App,请确认已安装最新版「U店在哪」,或从 App 内分享到微信后再打开"
-            );
-            return;
-          }
-          document.body.classList.remove("wx-jssdk-ready");
+          console.warn("[wx-open-launch-app]", detail);
           showAppOpenFailTip(
           showAppOpenFailTip(
             errMsg
             errMsg
               ? "未能打开 App:" + errMsg
               ? "未能打开 App:" + errMsg
@@ -928,9 +814,11 @@
       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") {
-          uni.showToast({ title: tip, icon: "none", duration: 2800 });
+          uni.showToast({ title: msg, icon: "none", duration: 2800 });
+        } else if (isWeChatInAppBrowser()) {
+          window.alert(tip);
         } else {
         } else {
-          showFabToast(tip, 3200);
+          showFabToast(tip);
         }
         }
       }
       }
 
 
@@ -1005,22 +893,13 @@
 
 
       function tryOpenApp() {
       function tryOpenApp() {
         if (isWeChatInAppBrowser()) {
         if (isWeChatInAppBrowser()) {
-          if (weChatJssdkConfigured && document.body.classList.contains("wx-jssdk-ready")) {
-            return;
-          }
           if (!weChatJssdkConfigured) {
           if (!weChatJssdkConfigured) {
-            showFabToast("正在初始化,请稍候…");
             initWeChatOpenLaunchApp(true).then(function (ok) {
             initWeChatOpenLaunchApp(true).then(function (ok) {
-              if (ok) {
-                document.body.classList.add("wx-jssdk-ready");
-                showFabToast("请再次点击打开 App");
-              } else {
-                showAppOpenFailTip(wxInitLastError || "微信初始化失败");
+              if (!ok) {
+                showAppOpenFailTip(wxInitLastError || "微信唤起 App 初始化失败");
               }
               }
             });
             });
-            return;
           }
           }
-          document.body.classList.add("wx-jssdk-ready");
           return;
           return;
         }
         }
         tryOpenHBuilderAppViaScheme();
         tryOpenHBuilderAppViaScheme();
@@ -1030,19 +909,10 @@
         document.body.classList.add("is-wechat");
         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();
       bindWeChatLaunchTagEvents();
-      document.getElementById("btnContinue").addEventListener("click", tryOpenApp);
-      render(sharePayload);
       scheduleWeChatJssdkBootstrap();
       scheduleWeChatJssdkBootstrap();
+      document.getElementById("btnContinue").addEventListener("click", tryOpenApp);
+      render(parsePayload());
     })();
     })();
   </script>
   </script>
 </body>
 </body>