refactor(ui): 将复制功能从 ChatDrawer 移动到 ChatDrawerResult 组件
Some checks failed
Build and Deploy / deploy (push) Has been cancelled

将复制到剪贴板的功能逻辑从 ChatDrawer 组件重构到 ChatDrawerResult 组件中,实现功能职责的合理分离。ChatDrawer 组件不再处理复制逻辑,相关的事件绑定和工具函数导入也已移除,使组件结构更加清晰。
This commit is contained in:
2026-03-23 23:02:21 +08:00
parent 345d407e3e
commit f9136b6d95
2 changed files with 11 additions and 13 deletions

View File

@@ -20,7 +20,6 @@ import {
AlertDialogTitle
} from '@/components/ui/alert-dialog'
import { sendChatStream } from '@/api/agent'
import { copyToClipboard } from '@/utils/clipboard'
import HistoryPanel from './HistoryPanel.vue'
import ChatDrawerHeader from './ChatDrawerHeader.vue'
import ChatDrawerEmpty from './ChatDrawerEmpty.vue'
@@ -90,15 +89,6 @@ const handleGenerate = async () => {
emit('send', { agentId: props.agent?.id, content: prompt, modelMode: modelMode.value })
}
const handleCopy = async () => {
const success = await copyToClipboard(generatedContent.value)
if (success) {
toast.success('已复制')
} else {
toast.error('复制失败')
}
}
const handleRegenerate = async () => {
if (!currentInput.value || isGenerating.value) return
generatedContent.value = ''
@@ -200,7 +190,6 @@ watch(() => props.visible, (val) => {
:generated-content="generatedContent"
:is-generating="isGenerating"
@reset="handleReset"
@copy="handleCopy"
@regenerate="handleRegenerate"
/>
</div>

View File

@@ -1,9 +1,11 @@
<script setup>
import { ref, nextTick } from 'vue'
import { Icon } from '@iconify/vue'
import { toast } from 'vue-sonner'
import { Button } from '@/components/ui/button'
import { ScrollArea } from '@/components/ui/scroll-area'
import Skeleton from '@/components/ui/skeleton/Skeleton.vue'
import { copyToClipboard } from '@/utils/clipboard'
const props = defineProps({
currentInput: { type: String, default: '' },
@@ -11,12 +13,19 @@ const props = defineProps({
isGenerating: { type: Boolean, default: false }
})
const emit = defineEmits(['reset', 'copy', 'regenerate'])
const emit = defineEmits(['reset', 'regenerate'])
const scrollAreaRef = ref(null)
const handleReset = () => emit('reset')
const handleCopy = () => emit('copy')
const handleCopy = async () => {
const success = await copyToClipboard(props.generatedContent)
if (success) {
toast.success('已复制')
} else {
toast.error('复制失败')
}
}
const handleRegenerate = () => emit('regenerate')
const scrollToBottom = () => {