index.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <template>
  2. <div class="app-header">
  3. <div class="app-header__left">
  4. <slot name="left"></slot>
  5. <el-breadcrumb separator-icon="ArrowRight" v-show="!state.isMobile">
  6. <template v-for="(item, index) in $route.matched" :key="index">
  7. <el-breadcrumb-item :to="{ path: item.path }">
  8. <!--<i :class="item.meta.icon" v-if="item.meta.icon"></i>-->
  9. <span>{{ item.meta.title ?? 'item.name' }}</span>
  10. </el-breadcrumb-item>
  11. </template>
  12. </el-breadcrumb>
  13. </div>
  14. <div class="app-header__right">
  15. <slot name="right"></slot>
  16. <div class="iconbar">
  17. <el-badge type="danger" :is-dot="unreadList.length > 0">
  18. <app-icon icon="g-icon--notice" @click="openComponent('notice')" />
  19. </el-badge>
  20. <app-icon icon="ChatDotRound" @click="routerTo('bargain_buy')" />
  21. <app-icon icon="SetUp" @click="openComponent('calculator')" />
  22. <app-icon icon="Collection" @click="openComponent('certificate')" />
  23. <app-icon icon="g-icon--minimize" @click="exitFullSreen" v-if="fullScreen" />
  24. <app-icon icon="g-icon--maximize" @click="setFullSreen" v-else />
  25. </div>
  26. <el-dropdown class="user-dropdown" trigger="click">
  27. <span class="user-dropdown__link">
  28. <img class="g-image--avatar" :title="getAccountName()" />
  29. <span v-if="!state.isMobile">{{ getAccountName() }}</span>
  30. <app-icon class="el-icon--right" icon="ArrowDown" />
  31. </span>
  32. <template #dropdown>
  33. <el-dropdown-menu>
  34. <!-- <el-dropdown-item icon="Key">修改密码</el-dropdown-item> -->
  35. <el-dropdown-item icon="SwitchButton" @click="signOut()">退出登录</el-dropdown-item>
  36. </el-dropdown-menu>
  37. </template>
  38. </el-dropdown>
  39. </div>
  40. <component :is="componentMap.get(componentId)" v-bind="{ dataList }" @closed="closeComponent"
  41. v-if="componentId" />
  42. </div>
  43. </template>
  44. <script lang="ts" setup>
  45. import { ref, onMounted, defineAsyncComponent } from 'vue'
  46. import { useRouter } from 'vue-router'
  47. import client from '@/utils/client'
  48. import { useUserStore } from '@/stores'
  49. import { useSign } from '@/business/sign'
  50. import { useComponent } from '@/hooks/component'
  51. import { useNotice } from '@/business/notice'
  52. import AppIcon from '@pc/components/base/icon/index.vue'
  53. const componentMap = new Map<string, unknown>([
  54. ['notice', defineAsyncComponent(() => import('./components/notice/index.vue'))],
  55. ['calculator', defineAsyncComponent(() => import('./components/calculator/index.vue'))],
  56. ['certificate', defineAsyncComponent(() => import('./components/certificate/index.vue'))],
  57. ])
  58. const { componentId, openComponent, closeComponent } = useComponent()
  59. const { dataList, unreadList, getNoticeList } = useNotice()
  60. const { state } = client
  61. const { signOut } = useSign()
  62. const { getAccountName } = useUserStore()
  63. const router = useRouter()
  64. const fullScreen = ref(false)
  65. // 全屏
  66. const setFullSreen = () => {
  67. document.documentElement.requestFullscreen()
  68. }
  69. // 退出全屏
  70. const exitFullSreen = () => {
  71. document.exitFullscreen()
  72. }
  73. // 路由跳转
  74. const routerTo = (name: string) => {
  75. router.push({ name })
  76. }
  77. getNoticeList()
  78. onMounted(() => {
  79. // 监听全屏变化
  80. window.addEventListener('fullscreenchange', () => {
  81. if (document.fullscreenElement) {
  82. fullScreen.value = true
  83. } else {
  84. fullScreen.value = false
  85. }
  86. })
  87. })
  88. </script>
  89. <style lang="less" scoped>
  90. @import './index.less';
  91. </style>