lxr 1 週間 前
コミット
96096126bc
1 ファイル変更166 行追加54 行削除
  1. 166 54
      HBuilderProjects/shareAiConsult.html

+ 166 - 54
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,61 @@
     }
 
     .footer__dock {
-      position: relative;
+      display: flex;
+      justify-content: center;
       width: 100%;
       pointer-events: auto;
     }
 
+    .footer__btn-slot {
+      position: relative;
+      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;
+      position: relative;
+      z-index: 1;
+    }
+
+    .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: 100%;
+      min-height: 48px;
       border-radius: 999px;
       overflow: hidden;
+      z-index: 2;
     }
 
     body.is-wechat.wx-jssdk-ready #launch-btn {
       display: block;
-    }
-
-    body.is-wechat.wx-jssdk-ready #btnContinue {
-      visibility: hidden;
-      pointer-events: none;
+      pointer-events: auto;
     }
 
     #openAppToast {
@@ -202,32 +219,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 +318,81 @@
         }
       }
 
+      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 [];
+
+        function pushParsed(list, role, body) {
+          var t = String(body || "").trim();
+          if (t) list.push({ role: role, content: t });
+        }
+
+        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) {
+            pushParsed(messages, "user", userMatch[1]);
+            continue;
+          }
+          var aiMatch = block.match(/^UBAO[::]\s*([\s\S]*)$/i);
+          if (aiMatch) {
+            pushParsed(messages, "ai", aiMatch[1]);
+          }
+        }
+        if (messages.length) return messages;
+
+        var current = null;
+        var lines = text.split(/\n/);
+        for (var j = 0; j < lines.length; j++) {
+          var line = String(lines[j] || "");
+          var userLine = line.match(/^我[::]\s*(.*)$/);
+          var aiLine = line.match(/^UBAO[::]\s*(.*)$/i);
+          if (userLine) {
+            if (current) messages.push(current);
+            current = { role: "user", content: String(userLine[1] || "").trim() };
+            continue;
+          }
+          if (aiLine) {
+            if (current) messages.push(current);
+            current = { role: "ai", content: String(aiLine[1] || "").trim() };
+            continue;
+          }
+          if (current && line.trim()) {
+            current.content = (current.content ? current.content + "\n" : "") + line.trim();
+          }
+        }
+        if (current && String(current.content || "").trim()) {
+          messages.push(current);
+        }
+        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 +484,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 +512,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>';
         }
@@ -500,8 +604,7 @@
       }
 
       function getWxConfigSignUrl() {
-        if (String(q("wxSignBaseOnly") || "") === "1") return getWxHtmlUrlBase();
-        return getWxSignPageUrlForApi();
+        return getWxHtmlUrlBase();
       }
 
       function getWxGetConfigApiUrl() {
@@ -909,10 +1012,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>