diff --git a/ui/src/components/ai-chat/component/chat-input-operate/index.vue b/ui/src/components/ai-chat/component/chat-input-operate/index.vue index 7cbb0f404..acf3085ed 100644 --- a/ui/src/components/ai-chat/component/chat-input-operate/index.vue +++ b/ui/src/components/ai-chat/component/chat-input-operate/index.vue @@ -271,7 +271,7 @@ const props = withDefaults( showUserInput?: boolean sendMessage: (question: string, other_params_data?: any, chat?: chatType) => void openChatId: () => Promise - checkInputParam: () => boolean + validate: () => Promise }>(), { applicationDetails: () => ({}), @@ -649,24 +649,27 @@ const stopTimer = () => { } function autoSendMessage() { - props.sendMessage(inputValue.value, { - image_list: uploadImageList.value, - document_list: uploadDocumentList.value, - audio_list: uploadAudioList.value, - video_list: uploadVideoList.value - }) - if (!props.checkInputParam()) { - return - } else { - inputValue.value = '' - uploadImageList.value = [] - uploadDocumentList.value = [] - uploadAudioList.value = [] - uploadVideoList.value = [] - if (quickInputRef.value) { - quickInputRef.value.textareaStyle.height = '45px' - } - } + props + .validate() + .then(() => { + props.sendMessage(inputValue.value, { + image_list: uploadImageList.value, + document_list: uploadDocumentList.value, + audio_list: uploadAudioList.value, + video_list: uploadVideoList.value + }) + inputValue.value = '' + uploadImageList.value = [] + uploadDocumentList.value = [] + uploadAudioList.value = [] + uploadVideoList.value = [] + if (quickInputRef.value) { + quickInputRef.value.textareaStyle.height = '45px' + } + }) + .catch(() => { + emit('update:showUserInput', true) + }) } function sendChatHandle(event?: any) { diff --git a/ui/src/components/ai-chat/component/user-form/index.vue b/ui/src/components/ai-chat/component/user-form/index.vue index e5d1f987a..6579a71fd 100644 --- a/ui/src/components/ai-chat/component/user-form/index.vue +++ b/ui/src/components/ai-chat/component/user-form/index.vue @@ -308,22 +308,18 @@ const getRouteQueryValue = (field: string) => { } return null } -/** - * 校验参数 - */ -const checkInputParam = () => { - // 检查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 - } +const validate = () => { + const promise_list = [] + if (dynamicsFormRef.value) { + promise_list.push(dynamicsFormRef.value?.validate()) } + if (dynamicsFormRef2.value) { + promise_list.push(dynamicsFormRef2.value?.validate()) + } + promise_list.push(validate_query()) + return Promise.all(promise_list) +} +const validate_query = () => { // 浏览器query参数找到接口传参 let msg = [] for (let f of apiInputFieldList.value) { @@ -331,15 +327,15 @@ const checkInputParam = () => { msg.push(f.field) } } - if (msg.length > 0) { MsgWarning( `${t('chat.tip.inputParamMessage1')} ${msg.join('、')}${t('chat.tip.inputParamMessage2')}` ) - return false + return Promise.reject(false) } - return true + return Promise.resolve(false) } + const initRouteQueryValue = () => { for (let f of apiInputFieldList.value) { if (!api_form_data_context.value[f.field]) { @@ -356,6 +352,7 @@ const initRouteQueryValue = () => { } } } + const decodeQuery = (query: string) => { try { return decodeURIComponent(query) @@ -364,10 +361,10 @@ const decodeQuery = (query: string) => { } } const confirmHandle = () => { - if (checkInputParam()) { + validate().then((ok) => { localStorage.setItem(`${accessToken}userForm`, JSON.stringify(form_data_context.value)) emit('confirm') - } + }) } const cancelHandle = () => { emit('cancel') @@ -383,7 +380,7 @@ const renderDebugAiChat = (data: any) => { dynamicsFormRef2.value?.render(apiInputFieldList.value, data) } } -defineExpose({ checkInputParam, render, renderDebugAiChat }) +defineExpose({ validate, render, renderDebugAiChat }) onMounted(() => { firstMounted.value = true handleInputFieldList() diff --git a/ui/src/components/ai-chat/index.vue b/ui/src/components/ai-chat/index.vue index 2732af577..213e373a2 100644 --- a/ui/src/components/ai-chat/index.vue +++ b/ui/src/components/ai-chat/index.vue @@ -63,7 +63,7 @@ :type="type" :send-message="sendMessage" :open-chat-id="openChatId" - :check-input-param="checkInputParam" + :validate="validate" :chat-management="ChatManagement" v-model:chat-id="chartOpenId" v-model:loading="loading" @@ -216,30 +216,39 @@ function UserFormCancel() { userFormRef.value?.render(form_data.value) 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) { if (isUserInput.value) { - if (!userFormRef.value?.checkInputParam()) { - showUserInput.value = true - return - } else { - 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 + 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 + }) + } else { + 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) - } } const handleDebounceClick = debounce((val, other_params_data?: any, chat?: chatType) => { @@ -268,7 +277,6 @@ const openChatId: () => Promise = () => { }) } else { if (isWorkFlow(obj.type)) { - console.log(obj) const submitObj = { work_flow: obj.work_flow, user_id: obj.user diff --git a/ui/src/stores/modules/application.ts b/ui/src/stores/modules/application.ts index 193eed479..d3de13782 100644 --- a/ui/src/stores/modules/application.ts +++ b/ui/src/stores/modules/application.ts @@ -97,8 +97,8 @@ const useApplicationStore = defineStore({ applicationApi .postAppAuthentication(token, loading, authentication_value) .then((res) => { - localStorage.setItem(`${token}accessToken`, res.data) - sessionStorage.setItem(`${token}accessToken`, res.data) + localStorage.setItem(`${token}-accessToken`, res.data) + sessionStorage.setItem(`${token}-accessToken`, res.data) resolve(res) }) .catch((error) => { diff --git a/ui/src/stores/modules/user.ts b/ui/src/stores/modules/user.ts index 1f98d8045..b065d7596 100644 --- a/ui/src/stores/modules/user.ts +++ b/ui/src/stores/modules/user.ts @@ -61,11 +61,15 @@ const useUserStore = defineStore({ return this.userType === 1 ? localStorage.getItem('token') : this.getAccessToken() }, getAccessToken() { - const token = sessionStorage.getItem(`${this.userAccessToken}accessToken`) + const token = sessionStorage.getItem(`${this.userAccessToken}-accessToken`) if (token) { return token } - return localStorage.getItem(`${this.userAccessToken}accessToken`) + const local_token = localStorage.getItem(`${token}-accessToken`) + if (local_token) { + return local_token + } + return localStorage.getItem(`accessToken`) }, getPermissions() { diff --git a/ui/src/views/login/index.vue b/ui/src/views/login/index.vue index 4cacd7ee5..714c439c6 100644 --- a/ui/src/views/login/index.vue +++ b/ui/src/views/login/index.vue @@ -153,6 +153,14 @@ interface qrOption { const orgOptions = ref([]) +function uuidv4() { + return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { + const r = (Math.random() * 16) | 0 + const v = c === 'x' ? r : (r & 0x3) | 0x8 + return v.toString(16) + }) +} + function redirectAuth(authType: string) { if (authType === 'LDAP' || authType === '') { return @@ -191,7 +199,7 @@ function redirectAuth(authType: string) { if (authType === 'OAuth2') { url = `${config.authEndpoint}?client_id=${config.clientId}&response_type=code` + - `&redirect_uri=${redirectUrl}&state=${res.data.id}` + `&redirect_uri=${redirectUrl}&state=${uuidv4()}` if (config.scope) { url += `&scope=${config.scope}` }