index.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. <!--
  2. * @FilePath: index.vue
  3. * @Author: 旭颖
  4. * @Date: 2022-10-31 14:56:49
  5. * @LastEditors: Please set LastEditors
  6. * @LastEditTime: 2023-03-16 11:51:51
  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 { avatar, 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. localStorage.removeItem('dictsSetting')
  26. localStorage.removeItem('factory')
  27. localStorage.removeItem('factory_list')
  28. await router.push(toLoginRoute(route.fullPath))
  29. break
  30. case 'personalCenter':
  31. await router.push('/setting/personalCenter')
  32. break
  33. }
  34. }
  35. </script>
  36. <template>
  37. <el-dropdown @command="handleCommand" @visible-change="handleVisibleChange">
  38. <span class="avatar-dropdown">
  39. <!-- <el-avatar class="user-avatar" :src="avatar" /> -->
  40. <div class="user-name">
  41. <span class="hidden-xs-only" :title="username">{{ username }}</span>
  42. <vab-icon
  43. class="vab-dropdown"
  44. :class="{ 'vab-dropdown-active': active }"
  45. icon="arrow-down-s-line"
  46. />
  47. </div>
  48. </span>
  49. <template #dropdown>
  50. <el-dropdown-menu>
  51. <!-- <el-dropdown-item command="personalCenter">
  52. <vab-icon icon="user-line" />
  53. <span>{{ translate('个人中心') }}</span>
  54. </el-dropdown-item> -->
  55. <el-dropdown-item command="logout">
  56. <vab-icon icon="logout-circle-r-line" />
  57. <span>退出登录</span>
  58. </el-dropdown-item>
  59. </el-dropdown-menu>
  60. </template>
  61. </el-dropdown>
  62. </template>
  63. <style lang="scss" scoped>
  64. .avatar-dropdown {
  65. display: flex;
  66. align-content: center;
  67. align-items: center;
  68. justify-content: center;
  69. justify-items: center;
  70. .user-avatar {
  71. flex-shrink: 0;
  72. width: 40px;
  73. height: 40px;
  74. margin-left: 15px;
  75. cursor: pointer;
  76. border-radius: 50%;
  77. }
  78. .user-name {
  79. position: relative;
  80. display: flex;
  81. flex-shrink: 0;
  82. align-content: center;
  83. align-items: center;
  84. height: 40px;
  85. margin-left: 6px;
  86. line-height: 40px;
  87. cursor: pointer;
  88. span {
  89. max-width: 100px;
  90. overflow: hidden;
  91. text-overflow: ellipsis;
  92. white-space: nowrap;
  93. }
  94. [class*='ri-'] {
  95. margin-left: 3px !important;
  96. }
  97. }
  98. }
  99. </style>