Skip to content

Commit f470cd1

Browse files
authored
feat: Dialogue built-in user information function (#4188)
1 parent 622780e commit f470cd1

File tree

3 files changed

+20
-8
lines changed

3 files changed

+20
-8
lines changed

ui/env.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
declare module 'katex'
33
interface Window {
44
sendMessage: ?((message: string, other_params_data: any) => void)
5+
chatUserProfile: ?(() => any)
56
MaxKB: {
67
prefix: string
78
chatPrefix: string

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

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ import {
114114
onMounted,
115115
onBeforeUnmount,
116116
provide,
117+
onBeforeMount,
117118
} from 'vue'
118119
import { useRoute } from 'vue-router'
119120
import applicationApi from '@/api/application/application'
@@ -169,7 +170,7 @@ const emit = defineEmits([
169170
'openParagraph',
170171
'openParagraphDocument',
171172
])
172-
const { application, common } = useStore()
173+
const { application, common, chatUser } = useStore()
173174
const isMobile = computed(() => {
174175
return common.isMobile() || mode === 'embed' || mode === 'mobile'
175176
})
@@ -645,7 +646,16 @@ const handleScroll = () => {
645646
}
646647
}
647648
}
648-
649+
onBeforeMount(() => {
650+
window.chatUserProfile = () => {
651+
if (props.type === 'ai-chat') {
652+
if (chatUser.chat_profile?.authentication_type === 'login') {
653+
return chatUser.getChatUserProfile()
654+
}
655+
}
656+
return Promise.resolve(null)
657+
}
658+
})
649659
onMounted(() => {
650660
if (isUserInput.value && localStorage.getItem(`${accessToken}userForm`)) {
651661
const userFormData = JSON.parse(localStorage.getItem(`${accessToken}userForm`) || '{}')
@@ -668,6 +678,7 @@ onMounted(() => {
668678
669679
onBeforeUnmount(() => {
670680
window.sendMessage = null
681+
window.userProfile = null
671682
})
672683
673684
function setScrollBottom() {

ui/src/stores/modules/chat-user.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {defineStore} from 'pinia'
1+
import { defineStore } from 'pinia'
22
import ChatAPI from '@/api/chat/chat'
3-
import type {ChatProfile, ChatUserProfile} from '@/api/type/chat'
4-
import type {LoginRequest} from '@/api/type/user'
5-
import type {Ref} from 'vue'
6-
import {getBrowserLang} from '@/locales/index'
3+
import type { ChatProfile, ChatUserProfile } from '@/api/type/chat'
4+
import type { LoginRequest } from '@/api/type/user'
5+
import type { Ref } from 'vue'
6+
import { getBrowserLang } from '@/locales/index'
77

88
interface ChatUser {
99
// 用户id
@@ -41,6 +41,7 @@ const useChatUserStore = defineStore('chat-user', {
4141
async getChatUserProfile() {
4242
const res = await ChatAPI.getChatUserProfile()
4343
this.chatUserProfile = res.data
44+
return res.data
4445
},
4546
applicationProfile() {
4647
return ChatAPI.applicationProfile().then((ok) => {
@@ -148,7 +149,6 @@ const useChatUserStore = defineStore('chat-user', {
148149
return ok.data
149150
})
150151
},
151-
152152
},
153153
})
154154

0 commit comments

Comments
 (0)