From 3e9712f4eae05068db5039a0978e6a1155ac8fb2 Mon Sep 17 00:00:00 2001 From: wanghanlin <1533525126@qq.com> Date: Fri, 26 Jun 2026 17:27:07 +0800 Subject: [PATCH] =?UTF-8?q?=20ChatSDK=E6=B5=8B=E8=AF=95=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=E4=B8=AD=E5=AE=9E=E7=8E=B0=E6=8E=A5=E5=85=A5=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E7=94=9F=E6=88=90=E4=B8=8E=E5=A4=8D=E5=88=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/resources/static/sdk/test.html | 139 +++++++++++++++++++++++- 1 file changed, 138 insertions(+), 1 deletion(-) diff --git a/src/main/resources/static/sdk/test.html b/src/main/resources/static/sdk/test.html index 3015867..afde5ac 100644 --- a/src/main/resources/static/sdk/test.html +++ b/src/main/resources/static/sdk/test.html @@ -80,6 +80,10 @@ body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans S .code-section .st{color:#059669} /* 字符串 */ .code-section .nu{color:#2563EB} /* 数字 */ .code-section .bl{color:#DC2626} /* 必传高亮 */ +.code-tabs{display:flex;gap:4px} +.code-tab{padding:3px 10px;border:1px solid #E5E7EB;border-radius:4px;background:#fff;color:#6B7280;font-size:11px;cursor:pointer;transition:all .15s;font-family:inherit} +.code-tab--active{background:#4F46E5;color:#fff;border-color:#4F46E5} +.code-tab:hover:not(.code-tab--active){background:#F3F4F6} @@ -188,7 +192,13 @@ body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans S
📋 接入代码 - +
+
+ + +
+ +

@@ -284,6 +294,125 @@ body{font-family:-apple-system,BlinkMacSystemFont,"Segoe UI",Roboto,"Noto Sans S
   function assert(c,m){if(!c)throw new Error(m);}
   function assertExists(s,m){const el=document.getElementById(s)||document.querySelector(s);assert(!!el,m||s+' 不存在');return el;}
 
+  // ==================== 接入代码生成 ====================
+  // 当前代码展示 Tab:'snippet'(Script 片段)| 'fullpage'(完整 HTML 页面)
+  let codeTab = 'snippet';
+
+  // SDK 可选参数的默认值(与 config.ts parseConfig 严格对齐),用于判断是否需要在生成代码中输出
+  const SDK_DEFAULTS = {
+    title: 'AI 智能助手',
+    width: 380,
+    position: 'right-bottom',
+    primaryColor: '#4F46E5',
+    streaming: true,
+    locale: 'zh-CN',
+    showCategorySwitch: false,
+  };
+
+  // 生成 Script 片段代码(纯文本)
+  function buildCodeSnippet() {
+    const cfg = getCfg();
+    const domain = cfg.requestDomain;
+    // integrateId:纯数字输出为数字字面量,否则输出字符串
+    const iid = String(cfg.integrateId);
+    const iidLit = /^\d+$/.test(iid) ? iid : JSON.stringify(iid);
+    const params = [];
+    // 必传参数
+    params.push('  integrateId: ' + iidLit + ',  // 必传:客服角色 ID(对应后端 roleId)');
+    params.push('  requestDomain: ' + JSON.stringify(domain) + ',  // 必传:后端 API 域名');
+    // 可选参数:仅输出与默认值不同的项
+    if (cfg.userId) params.push('  userId: ' + JSON.stringify(cfg.userId) + ',  // 可选:客户账号 ID(对应后端 accountId)');
+    if (cfg.title !== SDK_DEFAULTS.title) params.push('  title: ' + JSON.stringify(cfg.title) + ',  // 弹窗标题');
+    if (cfg.primaryColor !== SDK_DEFAULTS.primaryColor) params.push('  primaryColor: ' + JSON.stringify(cfg.primaryColor) + ',  // 主色调');
+    if (cfg.position !== SDK_DEFAULTS.position) params.push('  position: ' + JSON.stringify(cfg.position) + ',  // 悬浮按钮位置');
+    if (cfg.width !== SDK_DEFAULTS.width) params.push('  width: ' + cfg.width + ',  // 弹窗宽度(px)');
+    if (cfg.streaming !== SDK_DEFAULTS.streaming) params.push('  streaming: ' + cfg.streaming + ',  // 是否启用流式输出');
+    if (cfg.locale !== SDK_DEFAULTS.locale) params.push('  locale: ' + JSON.stringify(cfg.locale) + ',  // 界面语言');
+    if (cfg.showCategorySwitch !== SDK_DEFAULTS.showCategorySwitch) params.push('  showCategorySwitch: ' + cfg.showCategorySwitch + ',  // 是否显示知识库切换');
+    // debug 强制 false(生产环境推荐),无论面板当前值
+    params.push('  debug: false  // 调试日志,生产环境建议关闭');
+    const initBlock = 'ChatbotSDK.init({\n' + params.join('\n') + '\n});';
+    return '\n' +
+           '