From 1669ac78a9489d4aa3b29fd0314be96084e80a7c Mon Sep 17 00:00:00 2001 From: zhangyahui Date: Mon, 2 Mar 2026 16:40:40 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E5=88=87=E6=8D=A2=E5=AF=B9=E8=AF=9D?= =?UTF-8?q?=E6=97=B6=E5=85=88=E6=B8=85=E7=A9=BA=E5=BD=93=E5=89=8D=E5=88=97?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/home/agent/components/Agent.vue | 31 ++++++++++++++++------- src/views/home/agent/index.vue | 3 +-- src/views/home/components/Input.vue | 21 ++++++++------- 3 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/views/home/agent/components/Agent.vue b/src/views/home/agent/components/Agent.vue index 0663160..7e687cb 100644 --- a/src/views/home/agent/components/Agent.vue +++ b/src/views/home/agent/components/Agent.vue @@ -113,7 +113,7 @@ const handleSendMessage = async ( message: { text: string - images: Array<{ url: string; name: string }>, + images: Array<{ url: string; name: string }> tempImages: any[] }, skipUserMessage = false @@ -129,7 +129,7 @@ id: messageList.value.length + 1, text: message.text, isUser: true, - imageUrls:message.tempImages + imageUrls: message.tempImages }) } @@ -360,8 +360,20 @@ ) } - const setChatInfo = (data) => { - // messageList.value = list + const setChatInfo = (info) => { + // 先清空列表 + const data = info.conversation + const project = info.project + messageList.value = [] + params.versionID = '' + sketchList.value = [] + params.configParams.type = project.type + params.configParams.region = project.area + params.configParams.style = project.style + params.configParams.temperature = project.temperature + // 如果没有数据,直接返回 + if (!data) return + const { ancestors, current } = data const imgList = [] const ancestorsList = [] @@ -395,11 +407,12 @@ } }) || [] - messageList.value = [...ancestorsList, ...currentList] - params.versionID = current.id - sketchList.value = imgList - // console.log('messagelist:', messageList.value) - // debugger + // 延迟设置新数据,确保 UI 有时间响应清空操作 + nextTick(() => { + messageList.value = [...ancestorsList, ...currentList] + params.versionID = current?.id + sketchList.value = imgList + }) } defineExpose({ diff --git a/src/views/home/agent/index.vue b/src/views/home/agent/index.vue index e3c36b3..cadc269 100644 --- a/src/views/home/agent/index.vue +++ b/src/views/home/agent/index.vue @@ -54,7 +54,6 @@ ) } const handleSelectNode = () => { - console.log('handleSelectNode') getNodeAncestors({ projectId: projectStore.state.id, id: projectStore.state.nodeId }).then( (res) => { console.log('res', res) @@ -65,7 +64,7 @@ const handleGetProjectInfoAndHistory = () => { getProjectInfo({ id: route.params.id }).then((res) => { - if (res?.conversation) agentRef.value.setChatInfo(res.conversation) + if (res) agentRef.value.setChatInfo(res) let data = res?.project || res if (data?.latestNodeId) data.nodeId = data.latestNodeId projectStore.setProject({ diff --git a/src/views/home/components/Input.vue b/src/views/home/components/Input.vue index 62e92f4..975b8aa 100644 --- a/src/views/home/components/Input.vue +++ b/src/views/home/components/Input.vue @@ -232,15 +232,15 @@ formData.append('file', file) uploadImage(formData).then((res) => { - const reader = new FileReader() - reader.onload = (e) => { - uploadedImages.value.push({ - url: e.target?.result as string, - name: file.name, - path: res - }) - } - reader.readAsDataURL(file) + const reader = new FileReader() + reader.onload = (e) => { + uploadedImages.value.push({ + url: e.target?.result as string, + name: file.name, + path: res + }) + } + reader.readAsDataURL(file) }) } }) @@ -565,6 +565,9 @@ const handleCreateProject = async () => { // 这里可以添加创建项目的逻辑 + if (!inputValue.value.trim()) { + return + } const params = { type: typeValue.value, area: areaValue.value,