index.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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="!globalStore.isMobile">
  6. <template v-for="(item, index) in $route.matched" :key="index">
  7. <el-breadcrumb-item>
  8. <!--<i :class="item.meta.icon" v-if="item.meta.icon"></i>-->
  9. <span>{{ t('routes.'+(item.name ?? item.meta.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>
  18. <span class="g-icon--notice"></span>
  19. </el-badge> -->
  20. <span class="g-icon--minimize" @click="exitFullSreen" v-if="fullScreen"></span>
  21. <span class="g-icon--maximize" @click="setFullSreen" v-else></span>
  22. </div>
  23. <el-dropdown class="user-dropdown" trigger="click">
  24. <span class="g-icon--language"></span>
  25. <template #dropdown>
  26. <el-dropdown-menu>
  27. <template v-for="item in getLanguageList()" :key="item.value">
  28. <el-dropdown-item @click="switchLanguage(item.value)">{{ item.label }}</el-dropdown-item>
  29. </template>
  30. </el-dropdown-menu>
  31. </template>
  32. </el-dropdown>
  33. <el-dropdown class="user-dropdown" trigger="click">
  34. <span class="user-dropdown__link">
  35. <span>{{ userStore.userInfo.username }}</span>
  36. <span>({{ userStore.userInfo.logincode }})</span>
  37. <el-icon class="el-icon--right">
  38. <arrow-down />
  39. </el-icon>
  40. </span>
  41. <template #dropdown>
  42. <el-dropdown-menu>
  43. <el-dropdown-item :icon="Key" @click="openComponent('Password')">{{ t('operation.modifypwd')
  44. }}</el-dropdown-item>
  45. <el-dropdown-item :icon="SwitchButton" @click="eventBus.$emit('Logout')">{{
  46. t('operation.loginout') }}</el-dropdown-item>
  47. </el-dropdown-menu>
  48. </template>
  49. </el-dropdown>
  50. </div>
  51. <component ref="componentRef" :is="componentMap.get(componentId)" @closed="closeComponent" v-if="componentId" />
  52. </div>
  53. </template>
  54. <script lang="ts" setup>
  55. import { ref, onMounted, defineAsyncComponent } from 'vue'
  56. import { ArrowRight, Key, SwitchButton, ArrowDown } from '@element-plus/icons-vue'
  57. import { useComponent } from '@/hooks/component'
  58. import { getLanguageList, Language } from '@/constants/language'
  59. import { useGlobalStore, useUserStore, i18n } from '@/stores'
  60. import { localData } from '@/stores/storage'
  61. import eventBus from '@/services/bus'
  62. const componentMap = new Map<string, unknown>([
  63. ['Password', defineAsyncComponent(() => import('@pc/views/auth/password/index.vue'))], // 修改密码
  64. ])
  65. const globalStore = useGlobalStore()
  66. const userStore = useUserStore()
  67. const fullScreen = ref(false)
  68. const { global: { t } } = i18n
  69. const { componentRef, componentId, openComponent, closeComponent } = useComponent()
  70. // 全屏
  71. const setFullSreen = () => {
  72. document.documentElement.requestFullscreen();
  73. }
  74. // 退出全屏
  75. const exitFullSreen = () => {
  76. document.exitFullscreen();
  77. }
  78. // 切换语言
  79. const switchLanguage = (lange: Language) => {
  80. i18n.global.locale = lange
  81. localData.setValue('appLanguage', lange)
  82. }
  83. onMounted(() => {
  84. // 监听全屏变化
  85. window.addEventListener('fullscreenchange', () => {
  86. if (document.fullscreenElement) {
  87. fullScreen.value = true;
  88. } else {
  89. fullScreen.value = false;
  90. }
  91. })
  92. })
  93. </script>
  94. <style lang="less" scoped>
  95. @import './index.less';
  96. </style>