index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. <template>
  2. <div class="app-header">
  3. <div class="app-header__left">
  4. <slot name="left"></slot>
  5. <span>{{ t('app.name') }}</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.unreadCount > 0">
  11. <app-icon icon="g-icon-notice" @click="openComponent('notice')" />
  12. </el-badge>
  13. <app-icon icon="Tickets" @click="openComponent('report')" />
  14. <app-icon icon="Setting" @click="openComponent('setting')" />
  15. <!-- <app-icon icon="g-icon-minimize" @click="exitFullSreen" v-if="fullScreen" />
  16. <app-icon icon="g-icon-maximize" @click="setFullSreen" v-else /> -->
  17. </div>
  18. <el-dropdown class="user-dropdown" effect="dark" trigger="click">
  19. <span class="user-dropdown__link">
  20. <img class="g-image--avatar" :title="userStore.customerName" :src="userAvatar" />
  21. <span v-if="!globalStore.isMobile">{{ userStore.customerName }}</span>
  22. <app-icon class="el-icon--right" icon="ArrowDown" />
  23. </span>
  24. <template #dropdown>
  25. <el-dropdown-menu>
  26. <el-dropdown-item :icon="Avatar" @click="openComponent('avater')">{{ t('operation.modifyavatar') }}</el-dropdown-item>
  27. <el-dropdown-item :icon="Unlock" @click="openComponent('modify')">{{ t('routes.modifypwd') }}</el-dropdown-item>
  28. <!-- <el-dropdown-item :icon="Delete" @click="openComponent('cancel')">注销账户</el-dropdown-item> -->
  29. <el-dropdown-item :icon="SwitchButton"
  30. @click="eventBus.$emit('LogoutNotify')">{{ t('common.logout') }}</el-dropdown-item>
  31. </el-dropdown-menu>
  32. </template>
  33. </el-dropdown>
  34. </div>
  35. <component ref="componentRef" :is="componentMap.get(componentId)" @closed="closeComponent" v-if="componentId" />
  36. </div>
  37. </template>
  38. <script lang="ts" setup>
  39. import { ref, onMounted, computed, defineAsyncComponent } from 'vue'
  40. import { SwitchButton, Unlock, Avatar } from '@element-plus/icons-vue'
  41. import { getFileUrl, diffDays } from '@/filters'
  42. import { useComponent } from '@/hooks/component'
  43. import { useLoginStore, useUserStore, useGlobalStore, useNoticeStore, i18n } from '@/stores'
  44. import { localData } from '@/stores/storage'
  45. // import enUS from 'vant/es/locale/lang/en-US'
  46. import eventBus from '@/services/bus'
  47. import AppIcon from '@pc/components/base/icon/index.vue'
  48. import { ElMessageBox } from 'element-plus'
  49. const componentMap = new Map<string, unknown>([
  50. ['notice', defineAsyncComponent(() => import('./components/notice/index.vue'))],
  51. ['modify', defineAsyncComponent(() => import('./components/modify/index.vue'))],
  52. // ['cancel', defineAsyncComponent(() => import('./components/cancel/index.vue'))],
  53. ['avater', defineAsyncComponent(() => import('./components/avater/index.vue'))],
  54. ['report', defineAsyncComponent(() => import('./components/report/index.vue'))],
  55. ['setting', defineAsyncComponent(() => import('./components/setting/index.vue'))],
  56. ])
  57. const { componentId, openComponent, closeComponent } = useComponent()
  58. const loginStore = useLoginStore()
  59. const globalStore = useGlobalStore()
  60. const userStore = useUserStore()
  61. const noticeStore = useNoticeStore()
  62. const fullScreen = ref(false)
  63. const { t } = i18n.global
  64. // 用户头像
  65. const userAvatar = computed(() => {
  66. const file = userStore.userInfo?.headurl
  67. return file ? getFileUrl(file) : ''
  68. })
  69. // 全屏
  70. // const setFullSreen = () => {
  71. // document.documentElement.requestFullscreen();
  72. // }
  73. // 退出全屏
  74. // const exitFullSreen = () => {
  75. // document.exitFullscreen();
  76. // }
  77. onMounted(() => {
  78. const reportAgree = localData.getValue('reportAgree')
  79. const userReportAgree = reportAgree.find((e) => e.loginId === loginStore.loginId)
  80. /// 如果未同意 或者跨天
  81. if (!userReportAgree || diffDays(userReportAgree.agreedTime) > 0) {
  82. if (userReportAgree) {
  83. userReportAgree.isAgree = false
  84. localData.setValue('reportAgree', reportAgree)
  85. }
  86. openComponent('report')
  87. }
  88. // 监听全屏变化
  89. window.addEventListener('fullscreenchange', () => {
  90. if (document.fullscreenElement) {
  91. fullScreen.value = true;
  92. } else {
  93. fullScreen.value = false;
  94. }
  95. })
  96. // 是否需要弹出提示信息
  97. // const showLoginAlert = globalStore.getSystemInfo('showLoginAlert')
  98. // if (showLoginAlert) {
  99. // ElMessageBox.confirm(
  100. // t('user.login.tips7'),
  101. // t('common.tips'),
  102. // {
  103. // showCancelButton: false
  104. // }
  105. // )
  106. // }
  107. })
  108. </script>
  109. <style lang="less" scoped>
  110. @import './index.less';
  111. </style>