fix: Invalid verification of dialogue user form (#2839)

This commit is contained in:
shaohuzhang1 2025-04-09 18:11:50 +08:00 committed by GitHub
parent d78c1459b7
commit 0861eb4cdc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 64 additions and 61 deletions

View File

@ -271,7 +271,7 @@ const props = withDefaults(
showUserInput?: boolean showUserInput?: boolean
sendMessage: (question: string, other_params_data?: any, chat?: chatType) => void sendMessage: (question: string, other_params_data?: any, chat?: chatType) => void
openChatId: () => Promise<string> openChatId: () => Promise<string>
checkInputParam: () => boolean validate: () => Promise<boolean | string>
}>(), }>(),
{ {
applicationDetails: () => ({}), applicationDetails: () => ({}),
@ -649,24 +649,27 @@ const stopTimer = () => {
} }
function autoSendMessage() { function autoSendMessage() {
props.sendMessage(inputValue.value, { props
image_list: uploadImageList.value, .validate()
document_list: uploadDocumentList.value, .then(() => {
audio_list: uploadAudioList.value, props.sendMessage(inputValue.value, {
video_list: uploadVideoList.value image_list: uploadImageList.value,
}) document_list: uploadDocumentList.value,
if (!props.checkInputParam()) { audio_list: uploadAudioList.value,
return video_list: uploadVideoList.value
} else { })
inputValue.value = '' inputValue.value = ''
uploadImageList.value = [] uploadImageList.value = []
uploadDocumentList.value = [] uploadDocumentList.value = []
uploadAudioList.value = [] uploadAudioList.value = []
uploadVideoList.value = [] uploadVideoList.value = []
if (quickInputRef.value) { if (quickInputRef.value) {
quickInputRef.value.textareaStyle.height = '45px' quickInputRef.value.textareaStyle.height = '45px'
} }
} })
.catch(() => {
emit('update:showUserInput', true)
})
} }
function sendChatHandle(event?: any) { function sendChatHandle(event?: any) {

View File

@ -308,22 +308,18 @@ const getRouteQueryValue = (field: string) => {
} }
return null return null
} }
/** const validate = () => {
* 校验参数 const promise_list = []
*/ if (dynamicsFormRef.value) {
const checkInputParam = () => { promise_list.push(dynamicsFormRef.value?.validate())
// inputFieldList
for (let i = 0; i < inputFieldList.value.length; i++) {
if (
inputFieldList.value[i].required &&
(form_data_context.value[inputFieldList.value[i].field] === null ||
form_data_context.value[inputFieldList.value[i].field] === undefined ||
form_data_context.value[inputFieldList.value[i].field] === '')
) {
MsgWarning(t('chat.tip.requiredMessage'))
return false
}
} }
if (dynamicsFormRef2.value) {
promise_list.push(dynamicsFormRef2.value?.validate())
}
promise_list.push(validate_query())
return Promise.all(promise_list)
}
const validate_query = () => {
// query // query
let msg = [] let msg = []
for (let f of apiInputFieldList.value) { for (let f of apiInputFieldList.value) {
@ -331,15 +327,15 @@ const checkInputParam = () => {
msg.push(f.field) msg.push(f.field)
} }
} }
if (msg.length > 0) { if (msg.length > 0) {
MsgWarning( MsgWarning(
`${t('chat.tip.inputParamMessage1')} ${msg.join('、')}${t('chat.tip.inputParamMessage2')}` `${t('chat.tip.inputParamMessage1')} ${msg.join('、')}${t('chat.tip.inputParamMessage2')}`
) )
return false return Promise.reject(false)
} }
return true return Promise.resolve(false)
} }
const initRouteQueryValue = () => { const initRouteQueryValue = () => {
for (let f of apiInputFieldList.value) { for (let f of apiInputFieldList.value) {
if (!api_form_data_context.value[f.field]) { if (!api_form_data_context.value[f.field]) {
@ -356,6 +352,7 @@ const initRouteQueryValue = () => {
} }
} }
} }
const decodeQuery = (query: string) => { const decodeQuery = (query: string) => {
try { try {
return decodeURIComponent(query) return decodeURIComponent(query)
@ -364,10 +361,10 @@ const decodeQuery = (query: string) => {
} }
} }
const confirmHandle = () => { const confirmHandle = () => {
if (checkInputParam()) { validate().then((ok) => {
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(form_data_context.value)) localStorage.setItem(`${accessToken}userForm`, JSON.stringify(form_data_context.value))
emit('confirm') emit('confirm')
} })
} }
const cancelHandle = () => { const cancelHandle = () => {
emit('cancel') emit('cancel')
@ -383,7 +380,7 @@ const renderDebugAiChat = (data: any) => {
dynamicsFormRef2.value?.render(apiInputFieldList.value, data) dynamicsFormRef2.value?.render(apiInputFieldList.value, data)
} }
} }
defineExpose({ checkInputParam, render, renderDebugAiChat }) defineExpose({ validate, render, renderDebugAiChat })
onMounted(() => { onMounted(() => {
firstMounted.value = true firstMounted.value = true
handleInputFieldList() handleInputFieldList()

View File

@ -63,7 +63,7 @@
:type="type" :type="type"
:send-message="sendMessage" :send-message="sendMessage"
:open-chat-id="openChatId" :open-chat-id="openChatId"
:check-input-param="checkInputParam" :validate="validate"
:chat-management="ChatManagement" :chat-management="ChatManagement"
v-model:chat-id="chartOpenId" v-model:chat-id="chartOpenId"
v-model:loading="loading" v-model:loading="loading"
@ -216,29 +216,33 @@ function UserFormCancel() {
userFormRef.value?.render(form_data.value) userFormRef.value?.render(form_data.value)
showUserInput.value = false showUserInput.value = false
} }
const checkInputParam = () => {
return userFormRef.value?.checkInputParam() || false 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) {
if (isUserInput.value) { if (isUserInput.value) {
if (!userFormRef.value?.checkInputParam()) { userFormRef.value
showUserInput.value = true ?.validate()
return .then((ok) => {
} else { let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
let userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}') const newData = Object.keys(form_data.value).reduce((result: any, key: string) => {
const newData = Object.keys(form_data.value).reduce((result: any, key: string) => { result[key] = Object.prototype.hasOwnProperty.call(userFormData, key)
result[key] = Object.prototype.hasOwnProperty.call(userFormData, key) ? userFormData[key]
? userFormData[key] : form_data.value[key]
: form_data.value[key] return result
return result }, {})
}, {}) localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData))
localStorage.setItem(`${accessToken}userForm`, JSON.stringify(newData)) showUserInput.value = false
showUserInput.value = false if (!loading.value && props.applicationDetails?.name) {
} handleDebounceClick(val, other_params_data, chat)
} }
if (!loading.value && props.applicationDetails?.name) { })
handleDebounceClick(val, other_params_data, chat) .catch((e) => {
showUserInput.value = true
return
})
} }
} }
@ -268,7 +272,6 @@ const openChatId: () => Promise<string> = () => {
}) })
} else { } else {
if (isWorkFlow(obj.type)) { if (isWorkFlow(obj.type)) {
console.log(obj)
const submitObj = { const submitObj = {
work_flow: obj.work_flow, work_flow: obj.work_flow,
user_id: obj.user user_id: obj.user