From b97abb0fc6f9672bf1d080709a5d0c62201a8014 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Sun, 26 Apr 2026 11:18:27 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20HTTP=E7=8E=AF=E5=A2=83=E4=B8=8B=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E5=8A=9F=E8=83=BD=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- www/app.js | 31 ++++++++++++++++++++++++------- www/index.html | 6 +++--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/www/app.js b/www/app.js index 92943ad..395d19c 100644 --- a/www/app.js +++ b/www/app.js @@ -469,21 +469,38 @@ function deleteMessage(index) { function copyMessage(index) { if (!currentConversation) return; - const content = currentConversation.messages[index].content; + const msg = currentConversation.messages[index]; + // 如果是图片消息,复制图片描述或提示 + let content = msg.content; + if (msg.image && content === '[图片]') { + content = '[图片: ' + (msg.imageName || '未命名') + ']'; + } - navigator.clipboard.writeText(content).then(() => { - showToast('已复制到剪贴板'); - }).catch(err => { + // HTTP 环境下 navigator.clipboard 不工作,优先使用 fallback + try { const textarea = document.createElement('textarea'); textarea.value = content; textarea.style.position = 'fixed'; + textarea.style.top = '0'; + textarea.style.left = '0'; textarea.style.opacity = '0'; + textarea.style.pointerEvents = 'none'; document.body.appendChild(textarea); + textarea.focus(); textarea.select(); - document.execCommand('copy'); + + const success = document.execCommand('copy'); document.body.removeChild(textarea); - showToast('已复制到剪贴板'); - }); + + if (success) { + showToast('已复制到剪贴板'); + } else { + showToast('复制失败,请手动复制'); + } + } catch (err) { + console.error('复制失败:', err); + showToast('复制失败,请手动复制'); + } } // 清空当前对话 diff --git a/www/index.html b/www/index.html index b313289..ec0bab9 100644 --- a/www/index.html +++ b/www/index.html @@ -8,12 +8,12 @@