lxr 1 час назад
Родитель
Сommit
5355457ac1
1 измененных файлов с 226 добавлено и 89 удалено
  1. 226 89
      HBuilderProjects/shareAiConsult.html

+ 226 - 89
HBuilderProjects/shareAiConsult.html

@@ -309,6 +309,92 @@
       pointer-events: none;
       word-break: break-all;
     }
+
+    #apiDebugModal {
+      display: none;
+      position: fixed;
+      inset: 0;
+      z-index: 10002;
+      background: rgba(0, 0, 0, 0.55);
+      padding: 16px;
+      align-items: center;
+      justify-content: center;
+    }
+
+    #apiDebugModal.is-open {
+      display: flex;
+    }
+
+    .api-debug-panel {
+      width: 100%;
+      max-width: 520px;
+      max-height: calc(100vh - 32px);
+      background: #fff;
+      border-radius: 12px;
+      overflow: hidden;
+      display: flex;
+      flex-direction: column;
+      box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
+    }
+
+    .api-debug-panel__header {
+      display: flex;
+      align-items: center;
+      justify-content: space-between;
+      padding: 14px 16px;
+      border-bottom: 1px solid rgba(170, 170, 170, 0.25);
+      flex-shrink: 0;
+    }
+
+    .api-debug-panel__title {
+      font-size: 16px;
+      font-weight: 600;
+    }
+
+    .api-debug-panel__close {
+      border: none;
+      background: transparent;
+      font-size: 22px;
+      line-height: 1;
+      color: var(--muted);
+      cursor: pointer;
+      padding: 0 4px;
+    }
+
+    .api-debug-panel__body {
+      padding: 12px 16px 16px;
+      overflow-y: auto;
+      -webkit-overflow-scrolling: touch;
+    }
+
+    .api-debug-section {
+      margin-bottom: 14px;
+    }
+
+    .api-debug-section:last-child {
+      margin-bottom: 0;
+    }
+
+    .api-debug-section__label {
+      font-size: 12px;
+      font-weight: 600;
+      color: var(--orange);
+      margin-bottom: 6px;
+    }
+
+    .api-debug-section__content {
+      font-size: 12px;
+      line-height: 1.55;
+      color: #333;
+      background: #f7f8fa;
+      border-radius: 8px;
+      padding: 10px 12px;
+      white-space: pre-wrap;
+      word-break: break-all;
+      font-family: Consolas, "Courier New", monospace;
+      max-height: 240px;
+      overflow-y: auto;
+    }
   </style>
 </head>
 <body>
@@ -318,6 +404,29 @@
 
   <div id="openAppToast" role="status" aria-live="polite"></div>
 
+  <div id="apiDebugModal" role="dialog" aria-modal="true" aria-labelledby="apiDebugTitle">
+    <div class="api-debug-panel">
+      <div class="api-debug-panel__header">
+        <span class="api-debug-panel__title" id="apiDebugTitle">对话记录接口调试</span>
+        <button type="button" class="api-debug-panel__close" id="apiDebugClose" aria-label="关闭">&times;</button>
+      </div>
+      <div class="api-debug-panel__body">
+        <div class="api-debug-section">
+          <div class="api-debug-section__label">完整链接</div>
+          <div class="api-debug-section__content" id="apiDebugUrl"></div>
+        </div>
+        <div class="api-debug-section">
+          <div class="api-debug-section__label">请求参数</div>
+          <div class="api-debug-section__content" id="apiDebugParams"></div>
+        </div>
+        <div class="api-debug-section">
+          <div class="api-debug-section__label">接口返回</div>
+          <div class="api-debug-section__content" id="apiDebugResponse"></div>
+        </div>
+      </div>
+    </div>
+  </div>
+
   <div class="fab-wrap">
     <div class="fab-dock__slot">
       <!-- 与 secondShareGoods 相同顺序:openApp 在下,launch-btn 在上,避免挡住点击 -->
@@ -392,8 +501,6 @@
         "https://prod.ailien.shop/ai/life-manager/api/v1/legal-consultation/history/conversation";
       var AI_UBAO_CONVERSATION_API =
         "https://prod.ailien.shop/ai/life-manager/api/v1/ubao-conversation/history/conversation";
-      var AI_CS_CONVERSATION_API =
-        "https://prod.ailien.shop/ai/life-manager/api/v1/udian-cs-conversation/history/conversation";
 
       var sharePayloadCache = null;
       var weChatJssdkConfigured = false;
@@ -565,65 +672,17 @@
         });
       }
 
-      function getShareClientType() {
-        return String(q("client_type") || q("clientType") || "").trim();
-      }
-
-      /** 品牌/接口分流:client_type=0 为 AI 客服;否则看 type(1=U宝,2=法律U宝) */
-      function getSharePageType() {
-        if (getShareClientType() === "0") return "0";
-        var type = String(q("type") || "").trim();
-        return type || "1";
-      }
-
-      /** type=1 U宝;type=0 AI客服;其它(如 2)法律U宝 */
-      function getShareBrandByType(type) {
-        var t = String(type || "").trim();
-        if (t === "0") {
-          return {
-            ogTitle: "和AI客服的对话",
-            ogDescription: "点击查看对话内容",
-            appPath: "pages/aiKfChat/index",
-            pageType: "",
-            fabLabel: "和AI客服继续聊",
-          };
-        }
-        if (t === "2") {
-          return {
-            ogTitle: "和法律U宝的对话",
-            ogDescription: "点击查看对话内容",
-            appPath: "pages/lawyer/index",
-            pageType: "",
-            fabLabel: "和法律U宝继续聊",
-          };
-        }
-        return {
-          ogTitle: "和U宝的对话",
-          ogDescription: "点击查看对话内容",
-          appPath: "pages/aiSearchResult/index",
-          pageType: "home",
-          fabLabel: "和U宝继续聊",
-        };
-      }
-
       function getConversationApiBase(type) {
-        var t = String(type || "").trim();
-        if (t === "1") return AI_UBAO_CONVERSATION_API;
-        if (t === "0") return AI_CS_CONVERSATION_API;
-        return AI_LEGAL_CONVERSATION_API;
+        return String(type || "").trim() === "1"
+          ? AI_UBAO_CONVERSATION_API
+          : AI_LEGAL_CONVERSATION_API;
       }
 
       function buildConversationApiUrl(sessionId, userId, type) {
         var params = new URLSearchParams();
         params.set("session_id", sessionId);
         params.set("user_id", userId);
-        var clientType = getShareClientType();
-        var pageType = String(type || "").trim();
-        if (clientType === "0" || pageType === "0") {
-          params.set("client_type", "0");
-          return AI_CS_CONVERSATION_API + "?" + params.toString();
-        }
-        return getConversationApiBase(pageType || "1") + "?" + params.toString();
+        return getConversationApiBase(type) + "?" + params.toString();
       }
 
       function normalizeConversationRole(raw) {
@@ -756,9 +815,81 @@
         };
       }
 
+      function formatDebugJson(obj) {
+        try {
+          return JSON.stringify(obj, null, 2);
+        } catch (e) {
+          return String(obj);
+        }
+      }
+
+      function showApiDebugModal(info) {
+        var modal = document.getElementById("apiDebugModal");
+        var urlEl = document.getElementById("apiDebugUrl");
+        var paramsEl = document.getElementById("apiDebugParams");
+        var responseEl = document.getElementById("apiDebugResponse");
+        if (!modal || !urlEl || !paramsEl || !responseEl) return;
+
+        var payload = info || {};
+        var responseText = "";
+        if (payload.error) {
+          responseText = "【错误】" + payload.error + "\n\n";
+        }
+        if (payload.response != null && payload.response !== "") {
+          responseText += formatDebugJson(payload.response);
+        } else if (!payload.error) {
+          responseText += "(无返回数据)";
+        }
+
+        urlEl.textContent = String(payload.url || "");
+        paramsEl.textContent = formatDebugJson(payload.params || {});
+        responseEl.textContent = responseText;
+
+        console.log("[conversation-api] 完整链接:", payload.url);
+        console.log("[conversation-api] 请求参数:", payload.params);
+        if (payload.response != null) {
+          console.log("[conversation-api] 接口返回:", payload.response);
+        }
+        if (payload.error) {
+          console.warn("[conversation-api] 错误:", payload.error);
+        }
+
+        modal.classList.add("is-open");
+      }
+
+      function bindApiDebugModalEvents() {
+        var modal = document.getElementById("apiDebugModal");
+        var closeBtn = document.getElementById("apiDebugClose");
+        if (!modal || modal._apiDebugBound) return;
+        modal._apiDebugBound = true;
+
+        function closeModal() {
+          modal.classList.remove("is-open");
+        }
+
+        if (closeBtn) {
+          closeBtn.addEventListener("click", closeModal);
+        }
+        modal.addEventListener("click", function (e) {
+          if (e.target === modal) closeModal();
+        });
+      }
+
+      function buildConversationRequestParams(sessionId, userId, type) {
+        return {
+          session_id: sessionId,
+          user_id: userId,
+          type: type || "",
+          apiBase: getConversationApiBase(type),
+          method: "GET",
+        };
+      }
+
       function fetchConversationHistory(sessionId, userId, type) {
+        var requestParams = buildConversationRequestParams(sessionId, userId, type);
         var requestUrl = buildConversationApiUrl(sessionId, userId, type);
-        console.log("[conversation-api] GET", requestUrl);
+        console.log("[conversation-api] GET", requestUrl, requestParams);
+
         return fetch(requestUrl, {
           method: "GET",
           mode: "cors",
@@ -766,29 +897,54 @@
           headers: { Accept: "application/json" },
         })
           .then(function (r) {
-            if (r.ok) return r.json();
             return r
               .text()
               .catch(function () {
                 return "";
               })
               .then(function (text) {
-                var hint = "";
+                var parsed = null;
                 try {
-                  var j = JSON.parse(text);
-                  hint = j.msg || j.message || "";
+                  parsed = text ? JSON.parse(text) : null;
                 } catch (eP) {
-                  if (text) hint = text.slice(0, 120);
+                  parsed = text || null;
                 }
-                throw new Error("对话接口 HTTP " + r.status + (hint ? ":" + hint : ""));
+                if (!r.ok) {
+                  var hint = "";
+                  if (parsed && typeof parsed === "object") {
+                    hint = parsed.msg || parsed.message || "";
+                  } else if (typeof parsed === "string") {
+                    hint = parsed.slice(0, 120);
+                  }
+                  var err = new Error("对话接口 HTTP " + r.status + (hint ? ":" + hint : ""));
+                  err._debugResponse = parsed;
+                  throw err;
+                }
+                return parsed;
               });
           })
           .then(function (res) {
             var data = normalizeConversationApiPayload(res);
             if (!data) {
-              throw new Error("对话接口返回数据为空或格式无法解析");
+              var parseErr = new Error("对话接口返回数据为空或格式无法解析");
+              parseErr._debugResponse = res;
+              throw parseErr;
             }
+            showApiDebugModal({
+              url: requestUrl,
+              params: requestParams,
+              response: res,
+            });
             return data;
+          })
+          .catch(function (e) {
+            showApiDebugModal({
+              url: requestUrl,
+              params: requestParams,
+              response: e && e._debugResponse != null ? e._debugResponse : null,
+              error: e && e.message ? e.message : "对话加载失败",
+            });
+            throw e;
           });
       }
 
@@ -801,9 +957,8 @@
         }
 
         var filterIds = parseMessageIdsFromQuery();
-        updateFabLabels(getShareBrandByType(getSharePageType()).fabLabel);
         main.innerHTML = '<div class="empty">对话内容加载中…</div>';
-        fetchConversationHistory(params.sessionId, params.userId, getSharePageType())
+        fetchConversationHistory(params.sessionId, params.userId, params.type)
           .then(function (data) {
             if (filterIds && filterIds.length) {
               var filtered = filterConversationMessagesByIds(data.messages, filterIds);
@@ -908,7 +1063,6 @@
       }
 
       function applyWeixinShareMeta() {
-        var brand = getShareBrandByType(getSharePageType());
         var siteName = "U店在哪";
         var iconUrl =
           "https://alien-volume.oss-cn-beijing.aliyuncs.com/icon/ubao.png";
@@ -929,24 +1083,14 @@
         };
         setMeta("og:site_name", siteName);
         setMeta("application-name", siteName);
-        setMeta("og:title", brand.ogTitle);
-        setMeta("og:description", brand.ogDescription);
+        setMeta("og:title", "和U宝的对话");
+        setMeta("og:description", "点击查看对话内容");
         var links = document.querySelectorAll('link[rel="icon"], link[rel="apple-touch-icon"]');
         for (var i = 0; i < links.length; i++) {
           links[i].setAttribute("href", iconUrl);
         }
       }
 
-      function updateFabLabels(label) {
-        var text = String(label || "和U宝继续聊").trim() || "和U宝继续聊";
-        var openApp = document.getElementById("openApp");
-        if (openApp) {
-          openApp.setAttribute("aria-label", text);
-          var img = openApp.querySelector(".fab__brand-img");
-          if (img) img.setAttribute("alt", text);
-        }
-      }
-
       function countDisplayableMessages(messages) {
         var list = Array.isArray(messages) ? messages : [];
         var count = 0;
@@ -1025,9 +1169,7 @@
       }
 
       function render(data) {
-        var brand = getShareBrandByType(getSharePageType());
         applyWeixinShareMeta();
-        updateFabLabels(brand.fabLabel);
         sharePayloadCache = data || null;
         var main = document.getElementById("main");
         if (!data) {
@@ -1076,32 +1218,26 @@
       }
 
       function buildAiConsultOpenParams() {
-        var brand = getShareBrandByType(getSharePageType());
         var params = new URLSearchParams();
-        if (brand.pageType) params.set("pageType", brand.pageType);
+        params.set("pageType", "home");
         params.set("fromShareAiConsult", "1");
         return params;
       }
 
       function buildAppDeepLink() {
-        var brand = getShareBrandByType(getSharePageType());
-        var path = brand.appPath || APP_UNI_AI_PATH;
+        var path = APP_UNI_AI_PATH;
         var qs = buildAiConsultOpenParams().toString();
         var root = APP_IOS_URL_SCHEME.replace(/\/$/, "");
         return root + "/" + path + (qs ? "?" + qs : "");
       }
 
       function buildWeChatLaunchExtinfo(useBarePathOnly) {
-        var brand = getShareBrandByType(getSharePageType());
-        var path = (brand.appPath || APP_UNI_AI_PATH).replace(/^\//, "");
+        var path = APP_UNI_AI_PATH.replace(/^\//, "");
         if (useBarePathOnly) return path;
         var qs = buildAiConsultOpenParams().toString();
         var uniPage = qs ? path + "?" + qs : path;
         if (uniPage.length <= 1024) return uniPage;
-        if (brand.pageType) {
-          return path + "?pageType=" + encodeURIComponent(brand.pageType) + "&fromShareAiConsult=1";
-        }
-        return path + "?fromShareAiConsult=1";
+        return path + "?pageType=home&fromShareAiConsult=1";
       }
 
       function isWeChatInAppBrowser() {
@@ -1660,6 +1796,7 @@
       }
 
       function boot() {
+        bindApiDebugModalEvents();
         var launchTag = document.getElementById("launch-btn");
         if (launchTag) launchTag.setAttribute("appid", WECHAT_OPEN_APP_ID);
         bindWeChatLaunchTagEvents();