bugfix: 复制对话内容

This commit is contained in:
2026-03-03 14:40:49 +08:00
parent 92e75d4d00
commit ef6f9c7371
5 changed files with 61 additions and 39 deletions

View File

@@ -135,24 +135,47 @@
const loading = ref(false)
const handleCopyText = () => {
navigator.clipboard
.writeText(props.content.text)
.then(() => {
// console.log('Text copied to clipboard');
ElMessage({
message: t('agent.copySuccess'),
type: 'success',
offset: 300
const text = props.content.text
if (navigator.clipboard) {
navigator.clipboard
.writeText(props.content.text)
.then(() => {
// console.log('Text copied to clipboard');
ElMessage({
message: t('agent.copySuccess'),
type: 'success',
offset: 300
})
})
})
.catch((err) => {
console.error('Could not copy text: ', err)
ElMessage({
message: t('agent.copyFailed'),
type: 'error',
offset: 300
.catch((err) => {
console.error('Could not copy text: ', err)
ElMessage({
message: t('agent.copyFailed'),
type: 'error',
offset: 300
})
})
} else {
var textarea = document.createElement('textarea')
document.body.appendChild(textarea)
// 隐藏此输入框
textarea.style.position = 'fixed'
textarea.style.clip = 'rect(0 0 0 0)'
textarea.style.top = '10px'
// 赋值
textarea.value = text
// 选中
textarea.select()
// 复制
document.execCommand('copy', true)
// 移除输入框
document.body.removeChild(textarea)
ElMessage({
message: t('agent.copySuccess'),
type: 'success',
offset: 300
})
}
}
const toggleThinkingCollapsed = () => {
@@ -252,6 +275,7 @@
<style lang="less">
.message-txt {
user-select: text;
ul {
list-style-position: inside;
}