feat: 用缓存处理对话中的项目切换问题
This commit is contained in:
@@ -80,7 +80,55 @@
|
||||
{ deep: true }
|
||||
)
|
||||
|
||||
const handleReset = () => {
|
||||
const saveSession = (projectId: string) => {
|
||||
if (!projectId) return
|
||||
agentStore.saveCacheConversation(projectId, {
|
||||
messageList: messageList.value,
|
||||
sketchList: sketchList.value,
|
||||
params: {
|
||||
...params,
|
||||
projectID: projectId
|
||||
},
|
||||
isGenerating: isGenerating.value,
|
||||
isPaused: isPaused.value
|
||||
})
|
||||
}
|
||||
|
||||
const restoreSession = (projectId: string) => {
|
||||
if (!projectId) return false
|
||||
const payload = agentStore.getCacheConversation(projectId)
|
||||
if (!payload) return false
|
||||
|
||||
messageList.value = payload.messageList || []
|
||||
sketchList.value = payload.sketchList || []
|
||||
if (payload.params) {
|
||||
params.projectID = payload.params.projectID || projectId
|
||||
params.message = payload.params.message || ''
|
||||
params.versionID = payload.params.versionID || ''
|
||||
params.configParams = payload.params.configParams || params.configParams
|
||||
params.needSuggestion = payload.params.needSuggestion || false
|
||||
params.useReport = payload.params.useReport || false
|
||||
params.imageUrlList = payload.params.imageUrlList || []
|
||||
params.quotaUrl = payload.params.quotaUrl || []
|
||||
}
|
||||
isGenerating.value = false
|
||||
isPaused.value = payload.isPaused || false
|
||||
return true
|
||||
}
|
||||
|
||||
const clearSession = (projectId: string) => {
|
||||
if (!projectId) return
|
||||
agentStore.removeCacheConversation(projectId)
|
||||
}
|
||||
|
||||
const handleReset = (force = false) => {
|
||||
if (!force && params.projectID) {
|
||||
saveSession(params.projectID)
|
||||
}
|
||||
if (force && params.projectID) {
|
||||
clearSession(params.projectID)
|
||||
}
|
||||
|
||||
messageList.value = []
|
||||
sketchList.value = []
|
||||
params.versionID = ''
|
||||
@@ -94,6 +142,7 @@
|
||||
style: ''
|
||||
}
|
||||
isGenerating.value = false
|
||||
isPaused.value = false
|
||||
}
|
||||
|
||||
// 每次请求时创建新的 AbortController
|
||||
@@ -109,6 +158,9 @@
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
if (params.projectID) {
|
||||
saveSession(params.projectID)
|
||||
}
|
||||
abort?.abort()
|
||||
MyEvent.remove('resetAgent', handleReset)
|
||||
})
|
||||
@@ -453,6 +505,9 @@
|
||||
isPaused.value = true
|
||||
isGenerating.value = false
|
||||
abort?.abort()
|
||||
if (params.projectID) {
|
||||
saveSession(params.projectID)
|
||||
}
|
||||
MyEvent.emit('stopChat')
|
||||
}
|
||||
|
||||
@@ -543,7 +598,7 @@
|
||||
thinkingText: combinedThinkingText,
|
||||
text: combinedContent,
|
||||
image_url: combinedImageUrl,
|
||||
webAddress: !!webAddress ? JSON.parse(webAddress) : null,
|
||||
webAddress: webAddress ? JSON.parse(webAddress) : null,
|
||||
isUser: false,
|
||||
id: result.length + 1,
|
||||
sessionId: sessionId
|
||||
@@ -627,7 +682,10 @@
|
||||
}
|
||||
|
||||
defineExpose({
|
||||
setChatInfo
|
||||
setChatInfo,
|
||||
saveSession,
|
||||
restoreSession,
|
||||
clearSession
|
||||
})
|
||||
</script>
|
||||
|
||||
|
||||
@@ -161,12 +161,14 @@
|
||||
const quotaList = props.content.image_url ?? []
|
||||
list.push(...quotaList)
|
||||
}
|
||||
console.log(imageUrls, '---imageUrls---')
|
||||
|
||||
if (!imageUrls || imageUrls.length === 0) return list
|
||||
imageUrls.forEach((item) => {
|
||||
imageUrls?.forEach((item) => {
|
||||
if (typeof item === 'string') {
|
||||
list.push(item)
|
||||
} else if (typeof item === 'object' && item.url) {
|
||||
list.push(item.url)
|
||||
} else if (typeof item === 'object' && item?.url) {
|
||||
list.push(item?.url)
|
||||
}
|
||||
})
|
||||
return list
|
||||
|
||||
Reference in New Issue
Block a user