fix: collection form function cannot be used normally and will be stuck in the answer #2857 (#2952)

This commit is contained in:
shaohuzhang1 2025-04-22 16:24:39 +08:00 committed by GitHub
parent f646102262
commit 6fe001fcf8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 34 additions and 25 deletions

View File

@ -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<boolean>
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)
}

View File

@ -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<boolean> {
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)
}
}