header.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <a-layout-header class="header-layout">
  3. <div class="content-layout">
  4. <h2><img :src="logoPng" /></h2>
  5. <a-dropdown placement="bottomRight">
  6. <template #overlay>
  7. <a-menu style="width: 100px" @click="handlerMenuClick">
  8. <a-menu-item v-for="menu in menus" :key="menu.key">
  9. {{ menu.label }}
  10. </a-menu-item>
  11. </a-menu>
  12. </template>
  13. <div class="avatar">
  14. <a-avatar :size="32">
  15. <template #icon>
  16. <img :src="userStore.current.avatar" />
  17. </template>
  18. </a-avatar>
  19. <span>
  20. {{ userStore.current.nickname }}
  21. <DownOutlined />
  22. </span>
  23. </div>
  24. </a-dropdown>
  25. </div>
  26. </a-layout-header>
  27. </template>
  28. <script lang="ts" setup>
  29. import { MenuProps } from 'ant-design-vue'
  30. import { useUserStore } from '@/store'
  31. import { postLogout } from '@/api'
  32. import { mainURL } from '@/env'
  33. import logoPng from '@/assets/images/logo.png'
  34. defineOptions({ name: 'LayoutHeader' })
  35. const userStore = useUserStore()
  36. userStore.fetch()
  37. const menus = [
  38. { label: '个人中心', key: 'user' },
  39. { label: '退出', key: 'logout' }
  40. ]
  41. const handlerMenuClick: MenuProps['onClick'] = async e => {
  42. if (e.key === 'logout') {
  43. await postLogout()
  44. location.replace(mainURL)
  45. } else {
  46. location.href = `${mainURL}/#/information`
  47. }
  48. }
  49. </script>
  50. <style lang="scss" scoped>
  51. .header-layout {
  52. background-color: #fff;
  53. display: flex;
  54. padding: 0;
  55. h2 {
  56. margin: 0;
  57. img {
  58. width: 130px;
  59. }
  60. }
  61. }
  62. .content-layout {
  63. display: flex;
  64. justify-content: space-between;
  65. align-items: center;
  66. }
  67. .avatar {
  68. display: flex;
  69. align-items: center;
  70. cursor: pointer;
  71. > span {
  72. margin-left: 8px;
  73. }
  74. }
  75. </style>