App.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <template>
  2. <el-config-provider :size="getGlobalComponentSize" :locale="getGlobalI18n">
  3. <router-view v-show="getLockScreen" />
  4. <LockScreen v-if="themeConfig.isLockScreen" />
  5. <Setings ref="setingsRef" v-show="getLockScreen" />
  6. <CloseFull v-if="!themeConfig.isLockScreen" />
  7. <Upgrade v-if="getVersion" />
  8. </el-config-provider>
  9. </template>
  10. <script setup lang="ts" name="app">
  11. import { defineAsyncComponent, computed, ref, onBeforeMount, onMounted, onUnmounted, nextTick, watch } from 'vue'
  12. import { useRoute } from 'vue-router'
  13. import { useI18n } from 'vue-i18n'
  14. import { storeToRefs } from 'pinia'
  15. import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes'
  16. import { useThemeConfig } from '/@/stores/themeConfig'
  17. import other from '/@/utils/other'
  18. import { Local, Session } from '/@/utils/storage'
  19. import mittBus from '/@/utils/mitt'
  20. import setIntroduction from '/@/utils/setIconfont'
  21. // 引入组件
  22. const LockScreen = defineAsyncComponent(() => import('/@/layout/lockScreen/index.vue'))
  23. const Setings = defineAsyncComponent(() => import('/@/layout/navBars/topBar/setings.vue'))
  24. const CloseFull = defineAsyncComponent(() => import('/@/layout/navBars/topBar/closeFull.vue'))
  25. const Upgrade = defineAsyncComponent(() => import('/@/layout/upgrade/index.vue'))
  26. // 定义变量内容
  27. const { messages, locale } = useI18n()
  28. const setingsRef = ref()
  29. const route = useRoute()
  30. const stores = useTagsViewRoutes()
  31. const storesThemeConfig = useThemeConfig()
  32. const { themeConfig } = storeToRefs(storesThemeConfig)
  33. // 设置锁屏时组件显示隐藏
  34. const getLockScreen = computed(() => {
  35. // 防止锁屏后,刷新出现不相关界面
  36. return themeConfig.value.isLockScreen ? themeConfig.value.lockScreenTime > 1 : themeConfig.value.lockScreenTime >= 0
  37. })
  38. // 获取版本号
  39. const getVersion = computed(() => {
  40. let isVersion = false
  41. if (route.path !== '/login') {
  42. // @ts-ignore
  43. const currentVersion = __NEXT_VERSION__
  44. const lastVersion = Local.get('version')
  45. if (!lastVersion) {
  46. Local.set('version', currentVersion)
  47. } else if (lastVersion !== currentVersion) {
  48. isVersion = true
  49. }
  50. }
  51. return isVersion
  52. })
  53. // 获取全局组件大小
  54. const getGlobalComponentSize = computed(() => {
  55. return other.globalComponentSize()
  56. })
  57. // 获取全局 i18n
  58. const getGlobalI18n = computed(() => {
  59. return messages.value[locale.value]
  60. })
  61. // 设置初始化,防止刷新时恢复默认
  62. onBeforeMount(() => {
  63. // 设置批量第三方 icon 图标
  64. setIntroduction.cssCdn()
  65. // 设置批量第三方 js
  66. setIntroduction.jsCdn()
  67. })
  68. // 页面加载时
  69. onMounted(() => {
  70. nextTick(() => {
  71. // 监听布局配'置弹窗点击打开
  72. mittBus.on('openSetingsDrawer', () => {
  73. setingsRef.value.openDrawer()
  74. })
  75. // 获取缓存中的布局配置
  76. if (Local.get('themeConfig')) {
  77. storesThemeConfig.setThemeConfig({ themeConfig: Local.get('themeConfig') })
  78. document.documentElement.style.cssText = Local.get('themeConfigStyle')
  79. }
  80. // 获取缓存中的全屏配置
  81. if (Session.get('isTagsViewCurrenFull')) {
  82. stores.setCurrenFullscreen(Session.get('isTagsViewCurrenFull'))
  83. }
  84. })
  85. })
  86. // 页面销毁时,关闭监听布局配置/i18n监听
  87. onUnmounted(() => {
  88. mittBus.off('openSetingsDrawer', () => {})
  89. })
  90. // 监听路由的变化,设置网站标题
  91. watch(
  92. () => route.path,
  93. () => {
  94. other.useTitle()
  95. },
  96. {
  97. deep: true,
  98. }
  99. )
  100. </script>