diff --git a/demo/web/static/index.html b/demo/web/static/index.html index 4acf1a4..fc27338 100644 --- a/demo/web/static/index.html +++ b/demo/web/static/index.html @@ -1287,7 +1287,7 @@ function renderMarkdown(md) { liContent = liContent.replace(/^销售话术<\/strong>[::]?\s*/, ''); const scriptId = 'script-' + Math.random().toString(36).slice(2, 9); html += `
  • -
    +
    @@ -1305,7 +1305,7 @@ function renderMarkdown(md) { // 预期回应:灰色信息块 liContent = liContent.replace(/^预期回应<\/strong>[::]?\s*/, ''); html += `
  • -
    +
    预期回应 @@ -1317,7 +1317,7 @@ function renderMarkdown(md) { // 技巧提示:黄色提示块 liContent = liContent.replace(/^技巧提示<\/strong>[::]?\s*/, ''); html += `
  • -
    +
    技巧提示 @@ -1356,30 +1356,39 @@ function inlineMd(text) { } /** 复制销售话术到剪贴板,并显示 toast 提示 */ +/** 降级复制方案:使用临时 textarea + execCommand */ +function fallbackCopy(text) { + const textarea = document.createElement('textarea'); + textarea.value = text; + textarea.style.position = 'fixed'; + textarea.style.opacity = '0'; + document.body.appendChild(textarea); + textarea.select(); + try { + document.execCommand('copy'); + showToast('话术已复制', 'success'); + } catch (e) { + showToast('复制失败,请手动选择文本', 'error'); + } + document.body.removeChild(textarea); +} + function copyScript(scriptId) { const el = document.getElementById(scriptId); if (!el) return; const contentEl = el.querySelector('.script-content'); if (!contentEl) return; const text = contentEl.innerText.trim(); - navigator.clipboard.writeText(text).then(() => { - showToast('话术已复制', 'success'); - }).catch(() => { - // 降级方案:使用临时 textarea - const textarea = document.createElement('textarea'); - textarea.value = text; - textarea.style.position = 'fixed'; - textarea.style.opacity = '0'; - document.body.appendChild(textarea); - textarea.select(); - try { - document.execCommand('copy'); + // HTTP 环境下 navigator.clipboard 为 undefined,优先使用 execCommand 降级方案 + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(text).then(() => { showToast('话术已复制', 'success'); - } catch (e) { - showToast('复制失败,请手动选择文本', 'error'); - } - document.body.removeChild(textarea); - }); + }).catch(() => { + fallbackCopy(text); + }); + } else { + fallbackCopy(text); + } } /** 轻量 toast 提示 */