Skip to content

Commit 825cd3b

Browse files
committed
perf: 优化打开chatId代码
1 parent a0cfcb7 commit 825cd3b

File tree

1 file changed

+22
-29
lines changed

1 file changed

+22
-29
lines changed

ui/src/components/ai-chat/index.vue

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -139,57 +139,50 @@ const handleDebounceClick = debounce((val, other_params_data?: any, chat?: chatT
139139
}, 200)
140140
141141
/**
142-
* 对话
142+
* 打开对话id
143143
*/
144-
function getChartOpenId(chat?: any) {
145-
loading.value = true
144+
const openChatId: () => Promise<string> = () => {
146145
const obj = props.applicationDetails
147146
if (props.appId) {
148147
return applicationApi
149148
.getChatOpen(props.appId)
150149
.then((res) => {
151150
chartOpenId.value = res.data
152-
chatMessage(chat)
151+
return res.data
153152
})
154153
.catch((res) => {
155154
if (res.response.status === 403) {
156-
application.asyncAppAuthentication(accessToken).then(() => {
157-
getChartOpenId(chat)
155+
return application.asyncAppAuthentication(accessToken).then(() => {
156+
return openChatId()
158157
})
159-
} else {
160-
loading.value = false
161-
return Promise.reject(res)
162158
}
159+
return Promise.reject(res)
163160
})
164161
} else {
165162
if (isWorkFlow(obj.type)) {
166163
const submitObj = {
167164
work_flow: obj.work_flow
168165
}
169-
return applicationApi
170-
.postWorkflowChatOpen(submitObj)
171-
.then((res) => {
172-
chartOpenId.value = res.data
173-
chatMessage(chat)
174-
})
175-
.catch((res) => {
176-
loading.value = false
177-
return Promise.reject(res)
178-
})
166+
return applicationApi.postWorkflowChatOpen(submitObj).then((res) => {
167+
chartOpenId.value = res.data
168+
return res.data
169+
})
179170
} else {
180-
return applicationApi
181-
.postChatOpen(obj)
182-
.then((res) => {
183-
chartOpenId.value = res.data
184-
chatMessage(chat)
185-
})
186-
.catch((res) => {
187-
loading.value = false
188-
return Promise.reject(res)
189-
})
171+
return applicationApi.postChatOpen(obj).then((res) => {
172+
chartOpenId.value = res.data
173+
return res.data
174+
})
190175
}
191176
}
192177
}
178+
/**
179+
* 对话
180+
*/
181+
function getChartOpenId(chat?: any) {
182+
return openChatId().then(() => {
183+
chatMessage(chat)
184+
})
185+
}
193186
194187
/**
195188
* 获取一个递归函数,处理流式数据

0 commit comments

Comments
 (0)