From 398d8b3f195e85d3f42246a8c5315c3af9448a5b Mon Sep 17 00:00:00 2001 From: CaptainB Date: Fri, 13 Sep 2024 16:15:20 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E8=B0=83=E8=AF=95=E6=97=B6?= =?UTF-8?q?=E5=B1=95=E7=A4=BA=E6=89=80=E6=9C=89=E7=9A=84=E5=8F=82=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E5=B5=8C=E5=85=A5=E5=90=8E=E4=BB=85=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E8=BE=93=E5=85=A5=EF=BC=8C=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E9=9C=80=E8=A6=81=E5=86=99=E5=9C=A8url?= =?UTF-8?q?=E4=B8=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ui/src/components/ai-chat/index.vue | 66 +++++++++++++-------- ui/src/views/application-workflow/index.vue | 2 +- ui/src/views/chat/pc/index.vue | 1 + 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/ui/src/components/ai-chat/index.vue b/ui/src/components/ai-chat/index.vue index 5d1755e1e..1cb1a74ae 100644 --- a/ui/src/components/ai-chat/index.vue +++ b/ui/src/components/ai-chat/index.vue @@ -35,7 +35,7 @@ -
+
@@ -51,8 +51,9 @@ ref="dynamicsFormRef" /> ([]) const inputFieldList = ref([]) const apiInputFieldList = ref([]) const form_data = ref({}) +const api_form_data = ref({}) const isDisabledChart = computed( () => !(inputValue.value.trim() && (props.appId || props.data?.name)) @@ -431,12 +437,8 @@ function showSource(row: any) { } function quickProblemHandle(val: string) { - // 检查inputFieldList是否有未填写的字段 - for (let i = 0; i < inputFieldList.value.length; i++) { - if (inputFieldList.value[i].required && !form_data.value[inputFieldList.value[i].field]) { - MsgWarning('请填写所有必填字段') - return - } + if (!checkInputParam()) { + return } if (!loading.value && props.data?.name) { handleDebounceClick(val) @@ -447,14 +449,40 @@ const handleDebounceClick = debounce((val) => { chatMessage(null, val) }, 200) -function sendChatHandle(event: any) { +function checkInputParam() { // 检查inputFieldList是否有未填写的字段 for (let i = 0; i < inputFieldList.value.length; i++) { if (inputFieldList.value[i].required && !form_data.value[inputFieldList.value[i].field]) { MsgWarning('请填写所有必填字段') - return + return false } } + // 浏览器query参数找到接口传参 + let msg = [] + for (let f of apiInputFieldList.value) { + if (!props.debug) { + if (f.required && !route.query[f.field]) { + msg.push(f.field) + } + api_form_data.value[f.field] = route.query[f.field] + } else { + if (f.required && !api_form_data.value[f.field]) { + MsgWarning('请填写所有必填字段') + return false + } + } + } + if (msg.length > 0) { + MsgWarning(`请在URL中填写参数 ${msg.join('、')}的值`) + return false + } + return true +} + +function sendChatHandle(event: any) { + if (!checkInputParam()) { + return + } if (!event.ctrlKey) { // 如果没有按下组合键ctrl,则会阻止默认事件 event.preventDefault() @@ -616,18 +644,6 @@ const errorWrite = (chat: any, message?: string) => { } function chatMessage(chat?: any, problem?: string, re_chat?: boolean) { - // 浏览器query参数找到接口传参 - let msg = [] - for (let f of apiInputFieldList.value) { - if (f.required && !route.query[f.field]) { - msg.push(f.field) - } - form_data.value[f.field] = route.query[f.field] - } - if (msg.length > 0) { - MsgWarning(`请在URL中填写参数 ${msg.join('、')}的值`) - return - } loading.value = true if (!chat) { chat = reactive({ @@ -658,7 +674,7 @@ function chatMessage(chat?: any, problem?: string, re_chat?: boolean) { const obj = { message: chat.problem_text, re_chat: re_chat || false, - form_data: form_data.value + form_data: {...form_data.value, ...api_form_data.value} } // 对话 applicationApi diff --git a/ui/src/views/application-workflow/index.vue b/ui/src/views/application-workflow/index.vue index c3f3f6377..f9ba4a4cc 100644 --- a/ui/src/views/application-workflow/index.vue +++ b/ui/src/views/application-workflow/index.vue @@ -138,7 +138,7 @@
- +
diff --git a/ui/src/views/chat/pc/index.vue b/ui/src/views/chat/pc/index.vue index 3ed0c7a30..701cbfdae 100644 --- a/ui/src/views/chat/pc/index.vue +++ b/ui/src/views/chat/pc/index.vue @@ -108,6 +108,7 @@ :appId="applicationDetail?.id" :record="currentRecordList" :chatId="currentChatId" + :debug="true" @refresh="refresh" @scroll="handleScroll" >