技巧提示
@@ -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 提示 */