index.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!--
  2. * @FilePath: index.vue
  3. * @Author: 旭颖
  4. * @Date: 2022-10-31 14:56:49
  5. * @LastEditors: Please set LastEditors
  6. * @LastEditTime: 2023-06-30 18:18:35
  7. -->
  8. <script lang="ts" setup>
  9. import { useUserStore } from '@/store/modules/user'
  10. import { toLoginRoute } from '@/utils/routes'
  11. import { VabRoute } from '/#/router'
  12. const route: VabRoute = useRoute()
  13. const router = useRouter()
  14. const userStore = useUserStore()
  15. const { username } = storeToRefs(userStore)
  16. const { logout } = userStore
  17. const active = ref(false)
  18. const handleVisibleChange = (val: boolean) => {
  19. active.value = val
  20. }
  21. const handleCommand = async (command: string) => {
  22. switch (command) {
  23. case 'logout':
  24. await logout()
  25. await router.push(toLoginRoute(route.fullPath))
  26. break
  27. case 'personalCenter':
  28. await router.push('/setting/personalCenter')
  29. break
  30. }
  31. }
  32. </script>
  33. <template>
  34. <el-dropdown @command="handleCommand" @visible-change="handleVisibleChange">
  35. <span class="avatar-dropdown">
  36. <!-- <el-avatar class="user-avatar" :src="avatar" /> -->
  37. <div class="user-name">
  38. <span class="hidden-xs-only" :title="username">{{ username }}</span>
  39. <vab-icon
  40. class="vab-dropdown"
  41. :class="{ 'vab-dropdown-active': active }"
  42. icon="arrow-down-s-line"
  43. />
  44. </div>
  45. </span>
  46. <template #dropdown>
  47. <el-dropdown-menu>
  48. <el-dropdown-item command="personalCenter">
  49. <vab-icon icon="user-line" />
  50. <span>修改密码</span>
  51. </el-dropdown-item>
  52. <el-dropdown-item command="logout">
  53. <vab-icon icon="logout-circle-r-line" />
  54. <span>退出登录</span>
  55. </el-dropdown-item>
  56. </el-dropdown-menu>
  57. </template>
  58. </el-dropdown>
  59. </template>
  60. <style lang="scss" scoped>
  61. .avatar-dropdown {
  62. display: flex;
  63. align-content: center;
  64. align-items: center;
  65. justify-content: center;
  66. justify-items: center;
  67. .user-avatar {
  68. flex-shrink: 0;
  69. width: 40px;
  70. height: 40px;
  71. margin-left: 15px;
  72. cursor: pointer;
  73. border-radius: 50%;
  74. }
  75. .user-name {
  76. position: relative;
  77. display: flex;
  78. flex-shrink: 0;
  79. align-content: center;
  80. align-items: center;
  81. height: 40px;
  82. margin-left: 6px;
  83. line-height: 40px;
  84. cursor: pointer;
  85. span {
  86. max-width: 100px;
  87. overflow: hidden;
  88. text-overflow: ellipsis;
  89. white-space: nowrap;
  90. }
  91. [class*='ri-'] {
  92. margin-left: 3px !important;
  93. }
  94. }
  95. }
  96. </style>