index.vue 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <div class="app-header">
  3. <div class="app-header__left">
  4. <slot name="left"></slot>
  5. <span>多元世纪</span>
  6. </div>
  7. <div class="app-header__right">
  8. <slot name="right"></slot>
  9. <div class="iconbar">
  10. <el-badge type="danger" :is-dot="noticeStore.unreadList.length > 0">
  11. <app-icon icon="g-icon--notice" @click="openComponent('notice')" />
  12. </el-badge>
  13. <span class="g-icon--minimize" @click="exitFullSreen" v-if="fullScreen"></span>
  14. <span class="g-icon--maximize" @click="setFullSreen" v-else></span>
  15. </div>
  16. <el-dropdown class="user-dropdown" trigger="click">
  17. <span class="user-dropdown__link">
  18. <img class="g-image--avatar" :title="userStore.accountName" :src="userAvatar" />
  19. <span v-if="!globalStore.isMobile">{{ userStore.accountName }}</span>
  20. <app-icon class="el-icon--right" icon="ArrowDown" />
  21. </span>
  22. <template #dropdown>
  23. <el-dropdown-menu>
  24. <el-dropdown-item :icon="Unlock"
  25. @click="openComponent('modify')">修改密码</el-dropdown-item>
  26. <el-dropdown-item :icon="SwitchButton"
  27. @click="eventBus.$emit('LogoutNotify')">退出登录</el-dropdown-item>
  28. </el-dropdown-menu>
  29. </template>
  30. </el-dropdown>
  31. </div>
  32. <component :is="componentMap.get(componentId)" @closed="closeComponent" v-if="componentId" />
  33. </div>
  34. </template>
  35. <script lang="ts" setup>
  36. import { ref, onMounted, computed, defineAsyncComponent } from 'vue'
  37. import { SwitchButton, Unlock } from '@element-plus/icons-vue'
  38. import { getFileUrl } from '@/filters'
  39. import { useComponent } from '@/hooks/component'
  40. import { useUserStore, useGlobalStore, useNoticeStore } from '@/stores'
  41. import eventBus from '@/services/bus'
  42. import AppIcon from '@pc/components/base/icon/index.vue'
  43. const componentMap = new Map<string, unknown>([
  44. ['notice', defineAsyncComponent(() => import('./components/notice/index.vue'))],
  45. ['modify', defineAsyncComponent(() => import('./components/modify/index.vue'))],
  46. ])
  47. const { componentId, openComponent, closeComponent } = useComponent()
  48. const globalStore = useGlobalStore()
  49. const userStore = useUserStore()
  50. const noticeStore = useNoticeStore()
  51. const fullScreen = ref(false)
  52. // 用户头像
  53. const userAvatar = computed(() => {
  54. const file = userStore.userInfo?.headurl
  55. return file ? getFileUrl(file) : ''
  56. })
  57. // 全屏
  58. const setFullSreen = () => {
  59. document.documentElement.requestFullscreen();
  60. }
  61. // 退出全屏
  62. const exitFullSreen = () => {
  63. document.exitFullscreen();
  64. }
  65. onMounted(() => {
  66. // 监听全屏变化
  67. window.addEventListener('fullscreenchange', () => {
  68. if (document.fullscreenElement) {
  69. fullScreen.value = true;
  70. } else {
  71. fullScreen.value = false;
  72. }
  73. })
  74. })
  75. </script>
  76. <style lang="less" scoped>
  77. @import './index.less';
  78. </style>