18c9354095
- 注入数据库、运行时配置、统一响应、文件存储和平台 AI 能力,补充业务读写工具与客户快捷操作契约。 - 移除模块内重复的组织、客户、工单、标签、技能、旧工作流、MCP 和迁移实现,将身份权限与业务主体交由宿主管理。 - 使用 libSQL 重构向量存储,并完善图片消息、访客身份、排队调度、企业微信和支持聊天页面。 - 统一 HTTP、DTO 与 WebSocket 的 snake_case 协议,补齐模块初始化、业务动作和公共载荷等回归测试。
60 lines
2.4 KiB
JavaScript
60 lines
2.4 KiB
JavaScript
(() => {
|
|
"use strict";
|
|
|
|
const params = new URLSearchParams(window.location.search);
|
|
const channel_id = (params.get("channel_id") || "").trim();
|
|
const external_id = (params.get("external_id") || `demo_${channel_id.slice(0, 12)}`).trim();
|
|
const external_name = (params.get("external_name") || "测试访客").trim();
|
|
const launcher = document.getElementById("widget-launcher");
|
|
const shell = document.getElementById("widget-frame-shell");
|
|
const frame = document.getElementById("widget-frame");
|
|
const status = document.getElementById("widget-status");
|
|
const hint = document.getElementById("action-hint");
|
|
let frameLoaded = false;
|
|
|
|
document.getElementById("channel-value").textContent = channel_id || "—";
|
|
document.getElementById("external-value").textContent = external_id || "—";
|
|
document.getElementById("name-value").textContent = external_name || "—";
|
|
|
|
if (!channel_id) {
|
|
launcher.disabled = true;
|
|
status.classList.add("error");
|
|
status.querySelector("span").textContent = "缺少 channel_id";
|
|
hint.lastChild.textContent = "缺少 channel_id,请从客服渠道编辑页重新打开测试页。";
|
|
return;
|
|
}
|
|
|
|
function chatUrl() {
|
|
const marker = "/support/demo";
|
|
const index = window.location.pathname.indexOf(marker);
|
|
const prefix = index >= 0 ? window.location.pathname.slice(0, index) : "";
|
|
const url = new URL(`${window.location.origin}${prefix}/support/chat/`);
|
|
url.searchParams.set("channel_id", channel_id);
|
|
url.searchParams.set("external_id", external_id);
|
|
url.searchParams.set("external_name", external_name);
|
|
return url.toString();
|
|
}
|
|
|
|
function setOpen(open) {
|
|
shell.hidden = !open;
|
|
launcher.setAttribute("aria-expanded", String(open));
|
|
launcher.setAttribute("aria-label", open ? "收起在线客服" : "打开在线客服");
|
|
if (open) {
|
|
if (!frameLoaded) {
|
|
frame.src = chatUrl();
|
|
frameLoaded = true;
|
|
} else {
|
|
frame.contentWindow?.postMessage({ type: "agent-desk:open" }, "*");
|
|
}
|
|
} else if (frameLoaded) {
|
|
frame.contentWindow?.postMessage({ type: "agent-desk:minimize" }, "*");
|
|
}
|
|
}
|
|
|
|
launcher.addEventListener("click", () => setOpen(shell.hidden));
|
|
window.addEventListener("message", (event) => {
|
|
if (event.source !== frame.contentWindow) return;
|
|
if (event.data?.type === "agent-desk:request-close") setOpen(false);
|
|
});
|
|
})();
|