From 4c66fa998fe9e26dee7ec4652b9dd6a62e46edf4 Mon Sep 17 00:00:00 2001 From: teukkk Date: Wed, 25 Jun 2025 19:20:30 +0800 Subject: [PATCH] refactor: chat left menu avatar --- ui/src/api/chat/chat.ts | 14 +++++++++++++- ui/src/api/type/chat.ts | 10 +++++++++- ui/src/router/chat/index.ts | 1 + ui/src/stores/modules/chat-user.ts | 7 ++++++- ui/src/views/chat/pc/index.vue | 30 +++++++++++++++++++++--------- 5 files changed, 50 insertions(+), 12 deletions(-) diff --git a/ui/src/api/chat/chat.ts b/ui/src/api/chat/chat.ts index ae2357f0f..3baa31bdc 100644 --- a/ui/src/api/chat/chat.ts +++ b/ui/src/api/chat/chat.ts @@ -42,6 +42,10 @@ const open: (loading?: Ref) => Promise> = (loading) => { const chat: (chat_id: string, data: any) => Promise = (chat_id, data) => { return postStream(`/chat/api/chat_message/${chat_id}`, data) } + +/** + * 应用认证信息 + */ const chatProfile: (assessToken: string, loading?: Ref) => Promise> = ( assessToken, loading, @@ -219,6 +223,13 @@ const resetCurrentPassword: ( ) => Promise> = (request, loading) => { return post('/chat_user/current/reset_password', request, undefined, loading) } + +/** + * 获取当前用户信息 + */ +const getChatUserProfile: (loading?: Ref) => Promise> = (loading) => { + return get('/chat_user/profile', {}, loading) +} export default { open, chat, @@ -240,5 +251,6 @@ export default { pageChat, pageChatRecord, logout, - resetCurrentPassword + resetCurrentPassword, + getChatUserProfile } diff --git a/ui/src/api/type/chat.ts b/ui/src/api/type/chat.ts index 7b8f3a9b8..aac3b8faf 100644 --- a/ui/src/api/type/chat.ts +++ b/ui/src/api/type/chat.ts @@ -12,4 +12,12 @@ interface ChatProfile { // 登录类型 login_value?: Array } -export { type ChatProfile } + +interface ChatUserProfile { + email: string + id: string + nick_name: string + username: string + source: string +} +export { type ChatProfile, type ChatUserProfile } diff --git a/ui/src/router/chat/index.ts b/ui/src/router/chat/index.ts index c703c61d0..f9b97e30f 100644 --- a/ui/src/router/chat/index.ts +++ b/ui/src/router/chat/index.ts @@ -59,6 +59,7 @@ router.beforeEach( } else { try { await chatUser.applicationProfile() + await chatUser.getChatUserProfile() } catch (e: any) { if (e.response?.status === 401) { next({ diff --git a/ui/src/stores/modules/chat-user.ts b/ui/src/stores/modules/chat-user.ts index b04d1a5d8..a9b7cce29 100644 --- a/ui/src/stores/modules/chat-user.ts +++ b/ui/src/stores/modules/chat-user.ts @@ -1,6 +1,6 @@ import { defineStore } from 'pinia' import ChatAPI from '@/api/chat/chat' -import { type ChatProfile } from '@/api/type/chat' +import type { ChatProfile, ChatUserProfile } from '@/api/type/chat' import type { LoginRequest } from '@/api/type/user' import type { Ref } from 'vue' interface ChatUser { @@ -11,6 +11,7 @@ interface Application {} interface Chat { chat_profile?: ChatProfile application?: Application + chatUserProfile?: ChatUserProfile token?: string accessToken?: string } @@ -30,6 +31,10 @@ const useChatUserStore = defineStore('chat-user', { return this.chat_profile }) }, + async getChatUserProfile() { + const res = await ChatAPI.getChatUserProfile() + this.chatUserProfile = res.data + }, applicationProfile() { return ChatAPI.applicationProfile().then((ok) => { this.application = ok.data diff --git a/ui/src/views/chat/pc/index.vue b/ui/src/views/chat/pc/index.vue index bb6ac68e9..0ff0e2185 100644 --- a/ui/src/views/chat/pc/index.vue +++ b/ui/src/views/chat/pc/index.vue @@ -135,34 +135,38 @@ {{ $t('chat.noHistory') }} - + +
+ + + +
+