|
|
@@ -309,92 +309,6 @@
|
|
|
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>
|
|
|
@@ -404,29 +318,6 @@
|
|
|
|
|
|
<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="关闭">×</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 在上,避免挡住点击 -->
|
|
|
@@ -815,81 +706,9 @@
|
|
|
};
|
|
|
}
|
|
|
|
|
|
- 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, requestParams);
|
|
|
-
|
|
|
+ console.log("[conversation-api] GET", requestUrl);
|
|
|
return fetch(requestUrl, {
|
|
|
method: "GET",
|
|
|
mode: "cors",
|
|
|
@@ -897,54 +716,29 @@
|
|
|
headers: { Accept: "application/json" },
|
|
|
})
|
|
|
.then(function (r) {
|
|
|
+ if (r.ok) return r.json();
|
|
|
return r
|
|
|
.text()
|
|
|
.catch(function () {
|
|
|
return "";
|
|
|
})
|
|
|
.then(function (text) {
|
|
|
- var parsed = null;
|
|
|
+ var hint = "";
|
|
|
try {
|
|
|
- parsed = text ? JSON.parse(text) : null;
|
|
|
+ var j = JSON.parse(text);
|
|
|
+ hint = j.msg || j.message || "";
|
|
|
} catch (eP) {
|
|
|
- parsed = text || null;
|
|
|
- }
|
|
|
- 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;
|
|
|
+ if (text) hint = text.slice(0, 120);
|
|
|
}
|
|
|
- return parsed;
|
|
|
+ throw new Error("对话接口 HTTP " + r.status + (hint ? ":" + hint : ""));
|
|
|
});
|
|
|
})
|
|
|
.then(function (res) {
|
|
|
var data = normalizeConversationApiPayload(res);
|
|
|
if (!data) {
|
|
|
- var parseErr = new Error("对话接口返回数据为空或格式无法解析");
|
|
|
- parseErr._debugResponse = res;
|
|
|
- throw parseErr;
|
|
|
+ throw new Error("对话接口返回数据为空或格式无法解析");
|
|
|
}
|
|
|
- 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;
|
|
|
});
|
|
|
}
|
|
|
|
|
|
@@ -1796,7 +1590,6 @@
|
|
|
}
|
|
|
|
|
|
function boot() {
|
|
|
- bindApiDebugModalEvents();
|
|
|
var launchTag = document.getElementById("launch-btn");
|
|
|
if (launchTag) launchTag.setAttribute("appid", WECHAT_OPEN_APP_ID);
|
|
|
bindWeChatLaunchTagEvents();
|