UnisKB/ui/src/layout/components/top-bar/avatar/index.vue

40 lines
1.2 KiB
Vue
Raw Normal View History

2023-10-13 08:11:54 +00:00
<template>
<el-dropdown trigger="click" type="primary">
<el-avatar :size="30"> {{ firstUserName }} </el-avatar>
<template #dropdown>
<el-dropdown-menu>
<el-dropdown-item @click="openResetPassword">
<AppIcon iconName="Lock"></AppIcon><span style="margin-left: 5px">修改密码</span>
</el-dropdown-item>
<el-dropdown-item @click="logout">
<AppIcon iconName="app-exit"></AppIcon><span style="margin-left: 5px">退出</span>
</el-dropdown-item>
</el-dropdown-menu>
</template>
</el-dropdown>
<ResetPassword ref="resetPasswordRef"></ResetPassword>
2023-09-15 09:40:35 +00:00
</template>
<script setup lang="ts">
2023-10-13 08:11:54 +00:00
import { computed, ref } from 'vue'
import { useUserStore } from '@/stores/user'
import { useRouter } from 'vue-router'
2023-10-16 10:58:51 +00:00
import ResetPassword from './ResetPasssword.vue'
2023-09-15 09:40:35 +00:00
const userStore = useUserStore()
const router = useRouter()
const firstUserName = computed(() => {
2023-10-13 08:11:54 +00:00
return userStore.userInfo?.username?.substring(0, 1)
2023-09-15 09:40:35 +00:00
})
2023-10-13 08:11:54 +00:00
const resetPasswordRef = ref<InstanceType<typeof ResetPassword>>()
2023-09-15 09:40:35 +00:00
const openResetPassword = () => {
2023-10-13 08:11:54 +00:00
resetPasswordRef.value?.open()
2023-09-15 09:40:35 +00:00
}
const logout = () => {
2023-10-13 08:11:54 +00:00
userStore.logout().then(() => {
router.push({ name: 'login' })
})
2023-09-15 09:40:35 +00:00
}
</script>
2023-10-13 08:11:54 +00:00
<style lang="scss" scoped></style>