navBar.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <div>
  3. <v-toolbar class="banner font-size-14 pl-0" density="compact" style="height: 50px;">
  4. <div class="innerBox d-flex justify-space-between">
  5. <div class="nav-logo" style="cursor: pointer;" @click="handleLogoClick">
  6. <v-img src="../../assets/logo.png" aspect-ratio="16/9" contain :width="97" style="height: 40px"></v-img>
  7. </div>
  8. <div class="d-flex user-nav align-center">
  9. <!-- 头像用户名 -->
  10. <div class="d-flex align-center" v-if="showBall">
  11. <v-menu open-on-hover>
  12. <template v-slot:activator="{ props }">
  13. <div class="d-flex ml-3 pl-2 align-center cursor-pointer" v-bind="props">
  14. <v-avatar>
  15. <v-img alt="" :src="getUserAvatar(schoolInfo?.avatar, schoolInfo?.sex)"></v-img>
  16. </v-avatar>
  17. <div class="ml-2 commonHover">
  18. {{ formatName(schoolInfo?.school?.name) + ' - ' + schoolInfo?.name ?? schoolInfo?.phone }}
  19. </div>
  20. </div>
  21. </template>
  22. <v-list>
  23. <v-list-item v-for="(item, index) in menuList" :key="index" @click="item.change">
  24. <template v-slot:prepend>
  25. <v-icon :icon="item.icon"></v-icon>
  26. </template>
  27. <v-list-item-title>{{ item.title }}</v-list-item-title>
  28. </v-list-item>
  29. </v-list>
  30. </v-menu>
  31. </div>
  32. </div>
  33. </div>
  34. </v-toolbar>
  35. </div>
  36. </template>
  37. <script setup>
  38. import { ref, onMounted } from 'vue'
  39. import { getToken } from '@/utils/auth'
  40. import { useUserStore } from '@/store/user'; const userStore = useUserStore()
  41. import { useRouter } from 'vue-router'; const router = useRouter()
  42. import { useI18n } from '@/hooks/web/useI18n'; const { t } = useI18n()
  43. import { getUserAvatar } from '@/utils/avatar'
  44. import { formatName } from '@/utils/getText';
  45. defineOptions({ name: 'teacher-navbar' })
  46. defineProps({
  47. sticky: {
  48. type: Boolean,
  49. default: true
  50. }
  51. })
  52. const showBall = ref(false)
  53. onMounted(() => {
  54. if (getToken()) {
  55. showBall.value = true
  56. }
  57. })
  58. const handleLogoClick = () => { window.open('/recruitHome') } // 点击logo
  59. // 退出登录
  60. const handleLogout = async () => {
  61. await userStore.userLogout(1)
  62. router.push({ path: '/flame' })
  63. }
  64. const menuList = ref([
  65. { title: t('setting.logOut'), icon: 'mdi-logout', change: handleLogout }
  66. ])
  67. // 学校信息
  68. let schoolInfo = ref(JSON.parse(localStorage.getItem('schoolInfo')) || {})
  69. userStore.$subscribe((mutation, state) => {
  70. if (Object.keys(state.schoolInfo).length) schoolInfo.value = state.schoolInfo
  71. })
  72. </script>
  73. <style lang="scss" scoped>
  74. .banner {
  75. width: 100%;
  76. height: 50px;
  77. z-index: var(--zIndex-nav) !important;
  78. color: #fff;
  79. background-color: var(--color-d5e6e8);
  80. padding-left: 0px;
  81. height: 50px;
  82. font-size: 15px;
  83. }
  84. .hover:hover {
  85. cursor: pointer;
  86. background: rgba(0, 0, 0, 0.03);
  87. }
  88. .innerBox {
  89. position: relative;
  90. width: 100%;
  91. align-items: center;
  92. padding: 0 30px;
  93. }
  94. .nav-logo {
  95. float: left;
  96. }
  97. .nav {
  98. font-size: 0;
  99. float: left;
  100. margin-left: 50px;
  101. height: 49px;
  102. line-height: 49px;
  103. }
  104. .user-nav {
  105. color: var(--color-333);
  106. font-size: 15px;
  107. }
  108. </style>