App.vue 3.8 KB

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