perf: 优化打开chatId代码

This commit is contained in:
shaohuzhang1 2024-11-14 18:26:34 +08:00 committed by shaohuzhang1
parent 359dc9f3ee
commit 8b707272ca

View File

@ -139,56 +139,49 @@ const handleDebounceClick = debounce((val, other_params_data?: any, chat?: chatT
}, 200) }, 200)
/** /**
* 对话 * 打开对话id
*/ */
function getChartOpenId(chat?: any) { const openChatId: () => Promise<string> = () => {
loading.value = true
const obj = props.applicationDetails const obj = props.applicationDetails
if (props.appId) { if (props.appId) {
return applicationApi return applicationApi
.getChatOpen(props.appId) .getChatOpen(props.appId)
.then((res) => { .then((res) => {
chartOpenId.value = res.data chartOpenId.value = res.data
chatMessage(chat) return res.data
}) })
.catch((res) => { .catch((res) => {
if (res.response.status === 403) { if (res.response.status === 403) {
application.asyncAppAuthentication(accessToken).then(() => { return application.asyncAppAuthentication(accessToken).then(() => {
getChartOpenId(chat) return openChatId()
}) })
} else {
loading.value = false
return Promise.reject(res)
} }
return Promise.reject(res)
}) })
} else { } else {
if (isWorkFlow(obj.type)) { if (isWorkFlow(obj.type)) {
const submitObj = { const submitObj = {
work_flow: obj.work_flow work_flow: obj.work_flow
} }
return applicationApi return applicationApi.postWorkflowChatOpen(submitObj).then((res) => {
.postWorkflowChatOpen(submitObj)
.then((res) => {
chartOpenId.value = res.data chartOpenId.value = res.data
chatMessage(chat) return res.data
})
.catch((res) => {
loading.value = false
return Promise.reject(res)
}) })
} else { } else {
return applicationApi return applicationApi.postChatOpen(obj).then((res) => {
.postChatOpen(obj)
.then((res) => {
chartOpenId.value = res.data chartOpenId.value = res.data
return res.data
})
}
}
}
/**
* 对话
*/
function getChartOpenId(chat?: any) {
return openChatId().then(() => {
chatMessage(chat) chatMessage(chat)
}) })
.catch((res) => {
loading.value = false
return Promise.reject(res)
})
}
}
} }
/** /**