Skip to content

Commit 4c66fa9

Browse files
committed
refactor: chat left menu avatar
1 parent bdba507 commit 4c66fa9

File tree

5 files changed

+50
-12
lines changed

5 files changed

+50
-12
lines changed

ui/src/api/chat/chat.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ const open: (loading?: Ref<boolean>) => Promise<Result<string>> = (loading) => {
4242
const chat: (chat_id: string, data: any) => Promise<any> = (chat_id, data) => {
4343
return postStream(`/chat/api/chat_message/${chat_id}`, data)
4444
}
45+
46+
/**
47+
* 应用认证信息
48+
*/
4549
const chatProfile: (assessToken: string, loading?: Ref<boolean>) => Promise<Result<ChatProfile>> = (
4650
assessToken,
4751
loading,
@@ -219,6 +223,13 @@ const resetCurrentPassword: (
219223
) => Promise<Result<boolean>> = (request, loading) => {
220224
return post('/chat_user/current/reset_password', request, undefined, loading)
221225
}
226+
227+
/**
228+
* 获取当前用户信息
229+
*/
230+
const getChatUserProfile: (loading?: Ref<boolean>) => Promise<Result<any>> = (loading) => {
231+
return get('/chat_user/profile', {}, loading)
232+
}
222233
export default {
223234
open,
224235
chat,
@@ -240,5 +251,6 @@ export default {
240251
pageChat,
241252
pageChatRecord,
242253
logout,
243-
resetCurrentPassword
254+
resetCurrentPassword,
255+
getChatUserProfile
244256
}

ui/src/api/type/chat.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,12 @@ interface ChatProfile {
1212
// 登录类型
1313
login_value?: Array<string>
1414
}
15-
export { type ChatProfile }
15+
16+
interface ChatUserProfile {
17+
email: string
18+
id: string
19+
nick_name: string
20+
username: string
21+
source: string
22+
}
23+
export { type ChatProfile, type ChatUserProfile }

ui/src/router/chat/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ router.beforeEach(
5959
} else {
6060
try {
6161
await chatUser.applicationProfile()
62+
await chatUser.getChatUserProfile()
6263
} catch (e: any) {
6364
if (e.response?.status === 401) {
6465
next({

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { defineStore } from 'pinia'
22
import ChatAPI from '@/api/chat/chat'
3-
import { type ChatProfile } from '@/api/type/chat'
3+
import type { ChatProfile, ChatUserProfile } from '@/api/type/chat'
44
import type { LoginRequest } from '@/api/type/user'
55
import type { Ref } from 'vue'
66
interface ChatUser {
@@ -11,6 +11,7 @@ interface Application {}
1111
interface Chat {
1212
chat_profile?: ChatProfile
1313
application?: Application
14+
chatUserProfile?: ChatUserProfile
1415
token?: string
1516
accessToken?: string
1617
}
@@ -30,6 +31,10 @@ const useChatUserStore = defineStore('chat-user', {
3031
return this.chat_profile
3132
})
3233
},
34+
async getChatUserProfile() {
35+
const res = await ChatAPI.getChatUserProfile()
36+
this.chatUserProfile = res.data
37+
},
3338
applicationProfile() {
3439
return ChatAPI.applicationProfile().then((ok) => {
3540
this.application = ok.data

ui/src/views/chat/pc/index.vue

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -135,34 +135,38 @@
135135
<el-text type="info">{{ $t('chat.noHistory') }}</el-text>
136136
</div>
137137
</el-sub-menu>
138-
<el-dropdown trigger="click" type="primary" class="w-full">
138+
139+
<div v-if="!chatUser.chat_profile?.authentication" class="no-auth-avatar">
140+
<el-avatar :size="32">
141+
<img src="@/assets/user-icon.svg" style="width: 54%" alt="" />
142+
</el-avatar>
143+
</div>
144+
<el-dropdown v-else trigger="click" type="primary" class="w-full">
139145
<div class="flex align-center user-info">
140146
<el-avatar :size="32">
141147
<img src="@/assets/user-icon.svg" style="width: 54%" alt="" />
142148
</el-avatar>
143-
<!-- TODO -->
144-
<span v-show="!isPcCollapse" class="ml-8 color-text-primary">{{ 222 }}</span>
149+
<span v-show="!isPcCollapse" class="ml-8 color-text-primary">{{ chatUser.chatUserProfile?.nick_name }}</span>
145150
</div>
146151

147152
<template #dropdown>
148153
<el-dropdown-menu class="avatar-dropdown">
149-
<div class="flex align-center" style="padding: 12px;">
154+
<div class="flex align-center" style="padding: 8px 12px;">
150155
<div class="mr-8 flex align-center">
151156
<el-avatar :size="40">
152157
<img src="@/assets/user-icon.svg" style="width: 54%" alt="" />
153158
</el-avatar>
154159
</div>
155160
<div>
156-
<!-- TODO -->
157-
<h4 class="medium mb-4">{{ 111 }}</h4>
158-
<div class="color-secondary">{{ `${t('common.username')}: 222` }}</div>
161+
<h4 class="medium mb-4">{{ chatUser.chatUserProfile?.nick_name }}</h4>
162+
<div class="color-secondary">{{ `${t('common.username')}: ${chatUser.chatUserProfile?.username}` }}</div>
159163
</div>
160164
</div>
161-
<el-dropdown-item class="border-t" style="padding-top: 8px; padding-bottom: 8px;" @click="openResetPassword">
165+
<el-dropdown-item v-if="chatUser.chatUserProfile?.source === 'LOCAL'" class="border-t" style="padding-top: 8px; padding-bottom: 8px;" @click="openResetPassword">
162166
<AppIcon iconName="app-export" />
163167
{{ $t('views.login.resetPassword') }}
164168
</el-dropdown-item>
165-
<el-dropdown-item class="border-t" @click="logout">
169+
<el-dropdown-item v-if="chatUser.chatUserProfile?.source === 'LOCAL'" class="border-t" style="padding-top: 8px; padding-bottom: 8px;" @click="logout">
166170
<AppIcon iconName="app-export" />
167171
{{ $t('layout.logout') }}
168172
</el-dropdown-item>
@@ -545,6 +549,14 @@ onMounted(() => {
545549
background: transparent;
546550
}
547551
552+
.no-auth-avatar {
553+
margin-top: auto;
554+
padding: 16px;
555+
.el-avatar {
556+
cursor: default;
557+
}
558+
}
559+
548560
.el-dropdown {
549561
margin-top: auto;
550562
.user-info {

0 commit comments

Comments
 (0)