fix: HTTP环境下复制功能修复
This commit is contained in:
31
www/app.js
31
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('复制失败,请手动复制');
|
||||
}
|
||||
}
|
||||
|
||||
// 清空当前对话
|
||||
|
||||
Reference in New Issue
Block a user