diff --git a/ui/env.d.ts b/ui/env.d.ts index 97c603abd..9e940bf82 100644 --- a/ui/env.d.ts +++ b/ui/env.d.ts @@ -2,6 +2,7 @@ declare module 'katex' interface Window { sendMessage: ?((message: string, other_params_data: any) => void) + chatUserProfile: ?(() => any) MaxKB: { prefix: string chatPrefix: string diff --git a/ui/src/components/ai-chat/index.vue b/ui/src/components/ai-chat/index.vue index c7fd073b4..03700bac8 100644 --- a/ui/src/components/ai-chat/index.vue +++ b/ui/src/components/ai-chat/index.vue @@ -114,6 +114,7 @@ import { onMounted, onBeforeUnmount, provide, + onBeforeMount, } from 'vue' import { useRoute } from 'vue-router' import applicationApi from '@/api/application/application' @@ -169,7 +170,7 @@ const emit = defineEmits([ 'openParagraph', 'openParagraphDocument', ]) -const { application, common } = useStore() +const { application, common, chatUser } = useStore() const isMobile = computed(() => { return common.isMobile() || mode === 'embed' || mode === 'mobile' }) @@ -645,7 +646,16 @@ const handleScroll = () => { } } } - +onBeforeMount(() => { + window.chatUserProfile = () => { + if (props.type === 'ai-chat') { + if (chatUser.chat_profile?.authentication_type === 'login') { + return chatUser.getChatUserProfile() + } + } + return Promise.resolve(null) + } +}) onMounted(() => { if (isUserInput.value && localStorage.getItem(`${accessToken}userForm`)) { const userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}') @@ -668,6 +678,7 @@ onMounted(() => { onBeforeUnmount(() => { window.sendMessage = null + window.userProfile = null }) function setScrollBottom() { diff --git a/ui/src/stores/modules/chat-user.ts b/ui/src/stores/modules/chat-user.ts index 2d05affb9..a4efbda98 100644 --- a/ui/src/stores/modules/chat-user.ts +++ b/ui/src/stores/modules/chat-user.ts @@ -1,9 +1,9 @@ -import {defineStore} from 'pinia' +import { defineStore } from 'pinia' import ChatAPI from '@/api/chat/chat' -import type {ChatProfile, ChatUserProfile} from '@/api/type/chat' -import type {LoginRequest} from '@/api/type/user' -import type {Ref} from 'vue' -import {getBrowserLang} from '@/locales/index' +import type { ChatProfile, ChatUserProfile } from '@/api/type/chat' +import type { LoginRequest } from '@/api/type/user' +import type { Ref } from 'vue' +import { getBrowserLang } from '@/locales/index' interface ChatUser { // 用户id @@ -41,6 +41,7 @@ const useChatUserStore = defineStore('chat-user', { async getChatUserProfile() { const res = await ChatAPI.getChatUserProfile() this.chatUserProfile = res.data + return res.data }, applicationProfile() { return ChatAPI.applicationProfile().then((ok) => { @@ -148,7 +149,6 @@ const useChatUserStore = defineStore('chat-user', { return ok.data }) }, - }, })