bugfix: 切换对话的图片生成
This commit is contained in:
@@ -21,7 +21,16 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, reactive, computed, onUnmounted, onMounted, nextTick, watch } from 'vue'
|
||||
import {
|
||||
ref,
|
||||
reactive,
|
||||
computed,
|
||||
onUnmounted,
|
||||
onMounted,
|
||||
nextTick,
|
||||
watch,
|
||||
onActivated
|
||||
} from 'vue'
|
||||
import List from './List.vue'
|
||||
import Input from '../../components/Input.vue'
|
||||
import { chatUrl } from '@/api/agent'
|
||||
@@ -29,8 +38,10 @@
|
||||
import { useUserInfoStore, useProjectStore, useAgentStore } from '@/stores'
|
||||
import MyEvent from '@/utils/myEvent'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useRoute } from 'vue-router'
|
||||
|
||||
const { t } = useI18n()
|
||||
const route = useRoute()
|
||||
|
||||
const userStore = useUserInfoStore()
|
||||
const agentStore = useAgentStore()
|
||||
@@ -56,7 +67,7 @@
|
||||
const isGenerating = ref(false)
|
||||
const isPaused = ref(false) // 标记是否为主动暂停
|
||||
const params = reactive<AgentParamsType>({
|
||||
projectID: null,
|
||||
projectID: route.params.id as string,
|
||||
message: '',
|
||||
token: userStore.state.token,
|
||||
versionID: '',
|
||||
@@ -116,7 +127,6 @@
|
||||
onMounted(() => {
|
||||
MyEvent.add('resetAgent', handleReset)
|
||||
// 检查 store 中是否有初始项目数据
|
||||
// projectStore.setId('1') // 临时设置项目ID为1,实际应用中应根据上下文动态设置
|
||||
const initialData = agentStore.getInitialProjectData
|
||||
if (initialData) {
|
||||
// 等待页面渲染完成后自动发送初始消息
|
||||
@@ -142,6 +152,27 @@
|
||||
}
|
||||
})
|
||||
|
||||
// 用于存储不在页面显示但是仍进行中的对话信息
|
||||
const newQueue = ref<{
|
||||
nodeId?: string
|
||||
name?: string
|
||||
}>({})
|
||||
onActivated(() => {
|
||||
if (newQueue.value.nodeId) {
|
||||
projectStore.setProject({ nodeId: newQueue.value.nodeId })
|
||||
}
|
||||
if (newQueue.value.name) {
|
||||
MyEvent.emit('newTitle', {
|
||||
title: newQueue.value.name,
|
||||
id: params.projectID
|
||||
})
|
||||
}
|
||||
if (newQueue.value.newSketch) {
|
||||
mergeUniqueKeys(sketchList.value, newQueue.value.newSketch)
|
||||
}
|
||||
newQueue.value = {}
|
||||
})
|
||||
|
||||
const handleSendMessage = async (
|
||||
message: {
|
||||
text: string
|
||||
@@ -176,7 +207,7 @@
|
||||
id: messageList.value.length + 1,
|
||||
text: '',
|
||||
isUser: false,
|
||||
sessionId: projectStore.state.id,
|
||||
sessionId: route.params.id as string,
|
||||
loading: true,
|
||||
thinking: false,
|
||||
thinkingText: '',
|
||||
@@ -188,7 +219,7 @@
|
||||
const abortController = createAbortController()
|
||||
|
||||
// console.log('token---', params.token, '参数---', params)
|
||||
params.projectID = projectStore.state.id
|
||||
params.projectID = route.params.id as string
|
||||
try {
|
||||
const urlParams = new URLSearchParams<AgentParamsType>({
|
||||
...params,
|
||||
@@ -301,7 +332,7 @@
|
||||
) {
|
||||
isGeneratingReport.value = false
|
||||
sessionStorage.setItem(
|
||||
'reportsContent_' + projectStore.state.id,
|
||||
'reportsContent_' + params.projectID,
|
||||
reportsContent.value
|
||||
)
|
||||
}
|
||||
@@ -339,7 +370,11 @@
|
||||
.filter((line) => line.startsWith('data:'))
|
||||
.map((line) => line.replace(/^data:\s*/, ''))[0]
|
||||
params.versionID = versionID
|
||||
projectStore.setProject({ nodeId: versionID })
|
||||
if (aiMessage.sessionId === projectStore.state.id) {
|
||||
projectStore.setProject({ nodeId: versionID })
|
||||
} else {
|
||||
newQueue.value.nodeId = versionID
|
||||
}
|
||||
}
|
||||
|
||||
if (eventName === 'tool') {
|
||||
@@ -357,11 +392,12 @@
|
||||
contentBody += `<slot slot-name="url"></slot>`
|
||||
}
|
||||
if (jsonData.title) {
|
||||
emits('setTitle', jsonData.title)
|
||||
console.log('发送title', {
|
||||
title: jsonData.title,
|
||||
id: params.projectID
|
||||
})
|
||||
if (aiMessage.sessionId === projectStore.state.id) {
|
||||
emits('setTitle', jsonData.title)
|
||||
} else {
|
||||
newQueue.value.name = jsonData.title
|
||||
}
|
||||
|
||||
MyEvent.emit('newTitle', {
|
||||
title: jsonData.title,
|
||||
id: params.projectID
|
||||
@@ -370,15 +406,14 @@
|
||||
|
||||
if (hasSketch) {
|
||||
hasSketchEvent = true
|
||||
|
||||
Object.keys(jsonData).forEach((key) => {
|
||||
if (!sketchList.value.some((item) => item[key])) {
|
||||
sketchList.value.push({
|
||||
[key]: jsonData[key]
|
||||
})
|
||||
}
|
||||
})
|
||||
MyEvent.emit('OpenSketch')
|
||||
let tempArr = []
|
||||
if (params.projectID === projectStore.state.id) {
|
||||
mergeUniqueKeys(sketchList.value, jsonData)
|
||||
MyEvent.emit('OpenSketch', params.projectID)
|
||||
} else {
|
||||
mergeUniqueKeys(tempArr, jsonData)
|
||||
newQueue.value.newSketch = tempArr
|
||||
}
|
||||
}
|
||||
if (eventName === 'reportName' || eventName === 'reportTitle') {
|
||||
aiMessage.reportName = jsonData.reportName || jsonData.reportTitle
|
||||
@@ -633,6 +668,18 @@
|
||||
})
|
||||
}
|
||||
|
||||
const mergeUniqueKeys = (targetArr, newData) => {
|
||||
// 提取现有数组中所有的 key,存入 Set 以实现 O(1) 查询
|
||||
const existingKeys = new Set(targetArr.flatMap((item) => Object.keys(item)))
|
||||
|
||||
Object.entries(newData).forEach(([key, value]) => {
|
||||
if (!existingKeys.has(key)) {
|
||||
targetArr.push({ [key]: value })
|
||||
existingKeys.add(key) // 防止 newData 内部有重复 key 时重复插入
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
setChatInfo
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user