From d252a2546e0824c28dd28fe943908db0ddf9e713 Mon Sep 17 00:00:00 2001 From: teukkk Date: Wed, 25 Jun 2025 16:49:17 +0800 Subject: [PATCH] feat: chat left menu avatar --- ui/src/api/chat/chat.ts | 20 +++ .../layout-header/avatar/ResetPassword.vue | 20 ++- ui/src/stores/modules/chat-user.ts | 8 + ui/src/views/chat/pc/index.vue | 140 +++++++++++++++--- 4 files changed, 160 insertions(+), 28 deletions(-) diff --git a/ui/src/api/chat/chat.ts b/ui/src/api/chat/chat.ts index 72467f9cb..ae2357f0f 100644 --- a/ui/src/api/chat/chat.ts +++ b/ui/src/api/chat/chat.ts @@ -11,6 +11,7 @@ import { } from '@/request/chat/index' import { type ChatProfile } from '@/api/type/chat' import { type Ref } from 'vue' +import type { ResetPasswordRequest } from "@/api/type/user.ts"; import useStore from '@/stores' import type { LoginRequest } from '@/api/type/user' @@ -201,6 +202,23 @@ const pageChatRecord: ( loading, ) } + +/** + * 登出 + */ +const logout: (loading?: Ref) => Promise> = (loading) => { + return post('/auth/logout', undefined, undefined, loading) +} + +/** + * 重置密码 + */ +const resetCurrentPassword: ( + request: ResetPasswordRequest, + loading?: Ref +) => Promise> = (request, loading) => { + return post('/chat_user/current/reset_password', request, undefined, loading) +} export default { open, chat, @@ -221,4 +239,6 @@ export default { vote, pageChat, pageChatRecord, + logout, + resetCurrentPassword } diff --git a/ui/src/layout/layout-header/avatar/ResetPassword.vue b/ui/src/layout/layout-header/avatar/ResetPassword.vue index 7c5138070..8645001f7 100644 --- a/ui/src/layout/layout-header/avatar/ResetPassword.vue +++ b/ui/src/layout/layout-header/avatar/ResetPassword.vue @@ -52,6 +52,14 @@ import useStore from '@/stores' import { useRouter } from 'vue-router' import { t } from '@/locales' +const props = defineProps<{ + emitConfirm?: boolean; // 在父级调接口 +}>() + +const emit = defineEmits<{ + (e: 'confirm', value: ResetCurrentUserPasswordRequest): void; +}>(); + const router = useRouter() const { login } = useStore() @@ -133,10 +141,14 @@ const open = () => { } const resetPassword = () => { resetPasswordFormRef1.value?.validate().then(() => { - return UserApi.resetCurrentPassword(resetPasswordForm.value).then(() => { - login.logout() - router.push({ name: 'login' }) - }) + if(props.emitConfirm) { + emit('confirm', resetPasswordForm.value) + } else { + return UserApi.resetCurrentPassword(resetPasswordForm.value).then(() => { + login.logout() + router.push({ name: 'login' }) + }) + } }) } const close = () => { diff --git a/ui/src/stores/modules/chat-user.ts b/ui/src/stores/modules/chat-user.ts index ea82cf760..b04d1a5d8 100644 --- a/ui/src/stores/modules/chat-user.ts +++ b/ui/src/stores/modules/chat-user.ts @@ -92,6 +92,14 @@ const useChatUserStore = defineStore('chat-user', { return this.token }) }, + logout() { + return ChatAPI.logout().then(() => { + sessionStorage.removeItem(`${this.accessToken}-accessToken`) + localStorage.removeItem(`${this.accessToken}-accessToken`) + this.token = undefined + return true + }) + }, }, }) diff --git a/ui/src/views/chat/pc/index.vue b/ui/src/views/chat/pc/index.vue index 14e4aa6f6..d34e524bf 100644 --- a/ui/src/views/chat/pc/index.vue +++ b/ui/src/views/chat/pc/index.vue @@ -20,28 +20,28 @@ :size="32" style="background: none" > - - - + + + + +

{{ applicationDetail?.name }}

-

{{ applicationDetail?.name }}

- - - - {{ $t('chat.createChat') }} - -

{{ $t('chat.history') }}

+ + + {{ $t('chat.createChat') }} + +

{{ $t('chat.history') }}

{{ $t('chat.noHistory') }}
+ + + + + + - + - +
@@ -200,6 +236,7 @@ + @@ -213,21 +250,43 @@ import useStore from '@/stores' import useResize from '@/layout/hooks/useResize' import { hexToRgba } from '@/utils/theme' import EditTitleDialog from './EditTitleDialog.vue' +import { useRouter } from 'vue-router' +import ResetPassword from '@/layout/layout-header/avatar/ResetPassword.vue' import { t } from '@/locales' +import type { ResetCurrentUserPasswordRequest } from '@/api/type/user' + useResize() -const { user, chatLog, common } = useStore() +const { user, chatLog, common, chatUser } = useStore() +const router = useRouter() const EditTitleDialogRef = ref() const isCollapse = ref(false) const isPcCollapse = ref(false) -watch(()=> common.device, () => { - if(common.isMobile()) { +watch(() => common.device, () => { + if (common.isMobile()) { isPcCollapse.value = false } }) +const logout = () => { + chatUser.logout().then(() => { + router.push({ name: 'login' }) + }) +} + +const resetPasswordRef = ref>() +const openResetPassword = () => { + resetPasswordRef.value?.open() +} + +const handleResetPassword = (param: ResetCurrentUserPasswordRequest) => { + chatAPI.resetCurrentPassword(param).then(() => { + logout() + }) +} + const customStyle = computed(() => { return { background: applicationDetail.value?.custom_theme?.theme_color, @@ -472,6 +531,8 @@ onMounted(() => { position: relative; .el-menu { + display: flex; + flex-direction: column; background: linear-gradient(187.61deg, rgba(235, 241, 255, 0.5) 39.6%, rgba(231, 249, 255, 0.5) 94.3%), #eef1f4; @@ -484,12 +545,31 @@ onMounted(() => { background: transparent; } + .el-dropdown { + margin-top: auto; + .user-info { + width: 100%; + cursor: pointer; + border-radius: 6px; + padding: 4px 8px; + margin: 16px; + box-sizing: border-box; + &:hover { + background-color: #1F23291A; + } + } + } + &.el-menu--collapse { - .el-menu-item,.el-menu-tooltip__trigger,.el-sub-menu__title { + + .el-menu-item, + .el-menu-tooltip__trigger, + .el-sub-menu__title { padding: 0; } - .el-menu-item .el-menu-tooltip__trigger,.el-sub-menu__title { + .el-menu-item .el-menu-tooltip__trigger, + .el-sub-menu__title { position: static; width: 40px; height: 40px; @@ -498,9 +578,15 @@ onMounted(() => { justify-content: center; margin: 0 auto; } - .el-menu-item:hover .el-menu-tooltip__trigger,.el-sub-menu__title:hover { + + .el-menu-item:hover .el-menu-tooltip__trigger, + .el-sub-menu__title:hover { background-color: #1F23291A; } + + .user-info { + margin: 16px 8px; + } } } @@ -509,7 +595,7 @@ onMounted(() => { } .left-height { - height: calc(100vh - 140px); + height: calc(100vh - 212px); } .pc-collapse { @@ -633,3 +719,9 @@ onMounted(() => { } } + + \ No newline at end of file