fix: HTTP环境下复制功能修复

This commit is contained in:
2026-04-26 11:18:27 +08:00
parent b8e670978c
commit b97abb0fc6
2 changed files with 27 additions and 10 deletions

View File

@@ -469,21 +469,38 @@ function deleteMessage(index) {
function copyMessage(index) { function copyMessage(index) {
if (!currentConversation) return; 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(() => { // HTTP 环境下 navigator.clipboard 不工作,优先使用 fallback
showToast('已复制到剪贴板'); try {
}).catch(err => {
const textarea = document.createElement('textarea'); const textarea = document.createElement('textarea');
textarea.value = content; textarea.value = content;
textarea.style.position = 'fixed'; textarea.style.position = 'fixed';
textarea.style.top = '0';
textarea.style.left = '0';
textarea.style.opacity = '0'; textarea.style.opacity = '0';
textarea.style.pointerEvents = 'none';
document.body.appendChild(textarea); document.body.appendChild(textarea);
textarea.focus();
textarea.select(); textarea.select();
document.execCommand('copy');
const success = document.execCommand('copy');
document.body.removeChild(textarea); document.body.removeChild(textarea);
showToast('已复制到剪贴板');
}); if (success) {
showToast('已复制到剪贴板');
} else {
showToast('复制失败,请手动复制');
}
} catch (err) {
console.error('复制失败:', err);
showToast('复制失败,请手动复制');
}
} }
// 清空当前对话 // 清空当前对话

View File

@@ -8,12 +8,12 @@
<meta http-equiv="Pragma" content="no-cache"> <meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0"> <meta http-equiv="Expires" content="0">
<title>AI助手</title> <title>AI助手</title>
<link rel="stylesheet" href="style.css?v=2.1.1"> <link rel="stylesheet" href="style.css?v=2.1.2">
<link rel="manifest" href="manifest.json"> <link rel="manifest" href="manifest.json">
</head> </head>
<body> <body>
<div id="app"></div> <div id="app"></div>
<script src="marked.min.js?v=2.1.1"></script> <script src="marked.min.js?v=2.1.2"></script>
<script src="app.js?v=2.1.1"></script> <script src="app.js?v=2.1.2"></script>
</body> </body>
</html> </html>