Skip to content

Commit aea3b57

Browse files
committed
fix: collection form function cannot be used normally and will be stuck in the answer
1 parent b97f4e1 commit aea3b57

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

ui/src/components/ai-chat/component/answer-content/index.vue

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ const props = defineProps<{
8080
chatRecord: chatType
8181
application: any
8282
loading: boolean
83-
sendMessage: (question: string, other_params_data?: any, chat?: chatType) => void
83+
sendMessage: (question: string, other_params_data?: any, chat?: chatType) => Promise<boolean>
8484
chatManagement: any
8585
type: 'log' | 'ai-chat' | 'debug-ai-chat'
8686
}>()
@@ -98,9 +98,10 @@ const showUserAvatar = computed(() => {
9898
const chatMessage = (question: string, type: 'old' | 'new', other_params_data?: any) => {
9999
if (type === 'old') {
100100
add_answer_text_list(props.chatRecord.answer_text_list)
101-
props.sendMessage(question, other_params_data, props.chatRecord)
102-
props.chatManagement.open(props.chatRecord.id)
103-
props.chatManagement.write(props.chatRecord.id)
101+
props.sendMessage(question, other_params_data, props.chatRecord).then(() => {
102+
props.chatManagement.open(props.chatRecord.id)
103+
props.chatManagement.write(props.chatRecord.id)
104+
})
104105
} else {
105106
props.sendMessage(question, other_params_data)
106107
}

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

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -224,33 +224,41 @@ const validate = () => {
224224
return userFormRef.value?.validate() || Promise.reject(false)
225225
}
226226
227-
function sendMessage(val: string, other_params_data?: any, chat?: chatType) {
227+
function sendMessage(val: string, other_params_data?: any, chat?: chatType): Promise<boolean> {
228228
if (isUserInput.value) {
229-
userFormRef.value
230-
?.validate()
231-
.then((ok) => {
232-
let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
233-
const newData = Object.keys(form_data.value).reduce((result: any, key: string) => {
234-
result[key] = Object.prototype.hasOwnProperty.call(userFormData, key)
235-
? userFormData[key]
236-
: form_data.value[key]
237-
return result
238-
}, {})
239-
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData))
240-
showUserInput.value = false
241-
if (!loading.value && props.applicationDetails?.name) {
242-
handleDebounceClick(val, other_params_data, chat)
243-
}
244-
})
245-
.catch((e) => {
246-
showUserInput.value = true
247-
return
248-
})
229+
if (userFormRef.value) {
230+
return userFormRef.value
231+
?.validate()
232+
.then((ok) => {
233+
let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
234+
const newData = Object.keys(form_data.value).reduce((result: any, key: string) => {
235+
result[key] = Object.prototype.hasOwnProperty.call(userFormData, key)
236+
? userFormData[key]
237+
: form_data.value[key]
238+
return result
239+
}, {})
240+
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData))
241+
showUserInput.value = false
242+
if (!loading.value && props.applicationDetails?.name) {
243+
handleDebounceClick(val, other_params_data, chat)
244+
return true
245+
}
246+
throw 'err: no send'
247+
})
248+
.catch((e) => {
249+
showUserInput.value = true
250+
return false
251+
})
252+
} else {
253+
return Promise.reject(false)
254+
}
249255
} else {
250256
showUserInput.value = false
251257
if (!loading.value && props.applicationDetails?.name) {
252258
handleDebounceClick(val, other_params_data, chat)
259+
return Promise.resolve(true)
253260
}
261+
return Promise.reject(false)
254262
}
255263
}
256264

0 commit comments

Comments
 (0)