@@ -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' +
+ '