Skip to content

Commit 0861eb4

Browse files
authored
fix: Invalid verification of dialogue user form (#2839)
1 parent d78c145 commit 0861eb4

File tree

3 files changed

+64
-61
lines changed

3 files changed

+64
-61
lines changed

ui/src/components/ai-chat/component/chat-input-operate/index.vue

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ const props = withDefaults(
271271
showUserInput?: boolean
272272
sendMessage: (question: string, other_params_data?: any, chat?: chatType) => void
273273
openChatId: () => Promise<string>
274-
checkInputParam: () => boolean
274+
validate: () => Promise<boolean | string>
275275
}>(),
276276
{
277277
applicationDetails: () => ({}),
@@ -649,24 +649,27 @@ const stopTimer = () => {
649649
}
650650
651651
function autoSendMessage() {
652-
props.sendMessage(inputValue.value, {
653-
image_list: uploadImageList.value,
654-
document_list: uploadDocumentList.value,
655-
audio_list: uploadAudioList.value,
656-
video_list: uploadVideoList.value
657-
})
658-
if (!props.checkInputParam()) {
659-
return
660-
} else {
661-
inputValue.value = ''
662-
uploadImageList.value = []
663-
uploadDocumentList.value = []
664-
uploadAudioList.value = []
665-
uploadVideoList.value = []
666-
if (quickInputRef.value) {
667-
quickInputRef.value.textareaStyle.height = '45px'
668-
}
669-
}
652+
props
653+
.validate()
654+
.then(() => {
655+
props.sendMessage(inputValue.value, {
656+
image_list: uploadImageList.value,
657+
document_list: uploadDocumentList.value,
658+
audio_list: uploadAudioList.value,
659+
video_list: uploadVideoList.value
660+
})
661+
inputValue.value = ''
662+
uploadImageList.value = []
663+
uploadDocumentList.value = []
664+
uploadAudioList.value = []
665+
uploadVideoList.value = []
666+
if (quickInputRef.value) {
667+
quickInputRef.value.textareaStyle.height = '45px'
668+
}
669+
})
670+
.catch(() => {
671+
emit('update:showUserInput', true)
672+
})
670673
}
671674
672675
function sendChatHandle(event?: any) {

ui/src/components/ai-chat/component/user-form/index.vue

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -308,38 +308,34 @@ const getRouteQueryValue = (field: string) => {
308308
}
309309
return null
310310
}
311-
/**
312-
* 校验参数
313-
*/
314-
const checkInputParam = () => {
315-
// 检查inputFieldList是否有未填写的字段
316-
for (let i = 0; i < inputFieldList.value.length; i++) {
317-
if (
318-
inputFieldList.value[i].required &&
319-
(form_data_context.value[inputFieldList.value[i].field] === null ||
320-
form_data_context.value[inputFieldList.value[i].field] === undefined ||
321-
form_data_context.value[inputFieldList.value[i].field] === '')
322-
) {
323-
MsgWarning(t('chat.tip.requiredMessage'))
324-
return false
325-
}
311+
const validate = () => {
312+
const promise_list = []
313+
if (dynamicsFormRef.value) {
314+
promise_list.push(dynamicsFormRef.value?.validate())
326315
}
316+
if (dynamicsFormRef2.value) {
317+
promise_list.push(dynamicsFormRef2.value?.validate())
318+
}
319+
promise_list.push(validate_query())
320+
return Promise.all(promise_list)
321+
}
322+
const validate_query = () => {
327323
// 浏览器query参数找到接口传参
328324
let msg = []
329325
for (let f of apiInputFieldList.value) {
330326
if (f.required && !api_form_data_context.value[f.field]) {
331327
msg.push(f.field)
332328
}
333329
}
334-
335330
if (msg.length > 0) {
336331
MsgWarning(
337332
`${t('chat.tip.inputParamMessage1')} ${msg.join('')}${t('chat.tip.inputParamMessage2')}`
338333
)
339-
return false
334+
return Promise.reject(false)
340335
}
341-
return true
336+
return Promise.resolve(false)
342337
}
338+
343339
const initRouteQueryValue = () => {
344340
for (let f of apiInputFieldList.value) {
345341
if (!api_form_data_context.value[f.field]) {
@@ -356,6 +352,7 @@ const initRouteQueryValue = () => {
356352
}
357353
}
358354
}
355+
359356
const decodeQuery = (query: string) => {
360357
try {
361358
return decodeURIComponent(query)
@@ -364,10 +361,10 @@ const decodeQuery = (query: string) => {
364361
}
365362
}
366363
const confirmHandle = () => {
367-
if (checkInputParam()) {
364+
validate().then((ok) => {
368365
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(form_data_context.value))
369366
emit('confirm')
370-
}
367+
})
371368
}
372369
const cancelHandle = () => {
373370
emit('cancel')
@@ -383,7 +380,7 @@ const renderDebugAiChat = (data: any) => {
383380
dynamicsFormRef2.value?.render(apiInputFieldList.value, data)
384381
}
385382
}
386-
defineExpose({ checkInputParam, render, renderDebugAiChat })
383+
defineExpose({ validate, render, renderDebugAiChat })
387384
onMounted(() => {
388385
firstMounted.value = true
389386
handleInputFieldList()

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

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
:type="type"
6464
:send-message="sendMessage"
6565
:open-chat-id="openChatId"
66-
:check-input-param="checkInputParam"
66+
:validate="validate"
6767
:chat-management="ChatManagement"
6868
v-model:chat-id="chartOpenId"
6969
v-model:loading="loading"
@@ -216,29 +216,33 @@ function UserFormCancel() {
216216
userFormRef.value?.render(form_data.value)
217217
showUserInput.value = false
218218
}
219-
const checkInputParam = () => {
220-
return userFormRef.value?.checkInputParam() || false
219+
220+
const validate = () => {
221+
return userFormRef.value?.validate() || Promise.reject(false)
221222
}
222223
223224
function sendMessage(val: string, other_params_data?: any, chat?: chatType) {
224225
if (isUserInput.value) {
225-
if (!userFormRef.value?.checkInputParam()) {
226-
showUserInput.value = true
227-
return
228-
} else {
229-
let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
230-
const newData = Object.keys(form_data.value).reduce((result: any, key: string) => {
231-
result[key] = Object.prototype.hasOwnProperty.call(userFormData, key)
232-
? userFormData[key]
233-
: form_data.value[key]
234-
return result
235-
}, {})
236-
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData))
237-
showUserInput.value = false
238-
}
239-
}
240-
if (!loading.value && props.applicationDetails?.name) {
241-
handleDebounceClick(val, other_params_data, chat)
226+
userFormRef.value
227+
?.validate()
228+
.then((ok) => {
229+
let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
230+
const newData = Object.keys(form_data.value).reduce((result: any, key: string) => {
231+
result[key] = Object.prototype.hasOwnProperty.call(userFormData, key)
232+
? userFormData[key]
233+
: form_data.value[key]
234+
return result
235+
}, {})
236+
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData))
237+
showUserInput.value = false
238+
if (!loading.value && props.applicationDetails?.name) {
239+
handleDebounceClick(val, other_params_data, chat)
240+
}
241+
})
242+
.catch((e) => {
243+
showUserInput.value = true
244+
return
245+
})
242246
}
243247
}
244248
@@ -268,7 +272,6 @@ const openChatId: () => Promise<string> = () => {
268272
})
269273
} else {
270274
if (isWorkFlow(obj.type)) {
271-
console.log(obj)
272275
const submitObj = {
273276
work_flow: obj.work_flow,
274277
user_id: obj.user

0 commit comments

Comments
 (0)