From 6fe001fcf8d1b3e9343002d56e336b4b48b9c087 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 <80892890+shaohuzhang1@users.noreply.github.com> Date: Tue, 22 Apr 2025 16:24:39 +0800 Subject: [PATCH] fix: collection form function cannot be used normally and will be stuck in the answer #2857 (#2952) --- .../component/answer-content/index.vue | 9 ++-- ui/src/components/ai-chat/index.vue | 50 +++++++++++-------- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/ui/src/components/ai-chat/component/answer-content/index.vue b/ui/src/components/ai-chat/component/answer-content/index.vue index 7f09fa04c..26cd8a0d0 100644 --- a/ui/src/components/ai-chat/component/answer-content/index.vue +++ b/ui/src/components/ai-chat/component/answer-content/index.vue @@ -80,7 +80,7 @@ const props = defineProps<{ chatRecord: chatType application: any loading: boolean - sendMessage: (question: string, other_params_data?: any, chat?: chatType) => void + sendMessage: (question: string, other_params_data?: any, chat?: chatType) => Promise chatManagement: any type: 'log' | 'ai-chat' | 'debug-ai-chat' }>() @@ -98,9 +98,10 @@ const showUserAvatar = computed(() => { const chatMessage = (question: string, type: 'old' | 'new', other_params_data?: any) => { if (type === 'old') { add_answer_text_list(props.chatRecord.answer_text_list) - props.sendMessage(question, other_params_data, props.chatRecord) - props.chatManagement.open(props.chatRecord.id) - props.chatManagement.write(props.chatRecord.id) + props.sendMessage(question, other_params_data, props.chatRecord).then(() => { + props.chatManagement.open(props.chatRecord.id) + props.chatManagement.write(props.chatRecord.id) + }) } else { props.sendMessage(question, other_params_data) } diff --git a/ui/src/components/ai-chat/index.vue b/ui/src/components/ai-chat/index.vue index 7ec6ae2a6..78563ba85 100644 --- a/ui/src/components/ai-chat/index.vue +++ b/ui/src/components/ai-chat/index.vue @@ -224,33 +224,41 @@ const validate = () => { return userFormRef.value?.validate() || Promise.reject(false) } -function sendMessage(val: string, other_params_data?: any, chat?: chatType) { +function sendMessage(val: string, other_params_data?: any, chat?: chatType): Promise { if (isUserInput.value) { - userFormRef.value - ?.validate() - .then((ok) => { - let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}') - const newData = Object.keys(form_data.value).reduce((result: any, key: string) => { - result[key] = Object.prototype.hasOwnProperty.call(userFormData, key) - ? userFormData[key] - : form_data.value[key] - return result - }, {}) - localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData)) - showUserInput.value = false - if (!loading.value && props.applicationDetails?.name) { - handleDebounceClick(val, other_params_data, chat) - } - }) - .catch((e) => { - showUserInput.value = true - return - }) + if (userFormRef.value) { + return userFormRef.value + ?.validate() + .then((ok) => { + let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}') + const newData = Object.keys(form_data.value).reduce((result: any, key: string) => { + result[key] = Object.prototype.hasOwnProperty.call(userFormData, key) + ? userFormData[key] + : form_data.value[key] + return result + }, {}) + localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData)) + showUserInput.value = false + if (!loading.value && props.applicationDetails?.name) { + handleDebounceClick(val, other_params_data, chat) + return true + } + throw 'err: no send' + }) + .catch((e) => { + showUserInput.value = true + return false + }) + } else { + return Promise.reject(false) + } } else { showUserInput.value = false if (!loading.value && props.applicationDetails?.name) { handleDebounceClick(val, other_params_data, chat) + return Promise.resolve(true) } + return Promise.reject(false) } }