App.vue 3.8 KB

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