App.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <template>
  2. <el-config-provider :size="getGlobalComponentSize" :locale="getGlobalI18n">
  3. <router-view v-show="themeConfig.lockScreenTime > 1" />
  4. <LockScreen v-if="themeConfig.isLockScreen" />
  5. <Setings ref="setingsRef" v-show="themeConfig.lockScreenTime > 1" />
  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/breadcrumb/setings.vue'))
  24. const CloseFull = defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/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 getVersion = computed(() => {
  35. let isVersion = false
  36. if (route.path !== '/login') {
  37. // @ts-ignore
  38. if ((Local.get('version') && Local.get('version') !== __VERSION__) || !Local.get('version')) isVersion = true
  39. }
  40. return isVersion
  41. })
  42. // 获取全局组件大小
  43. const getGlobalComponentSize = computed(() => {
  44. return other.globalComponentSize()
  45. })
  46. // 获取全局 i18n
  47. const getGlobalI18n = computed(() => {
  48. return messages.value[locale.value]
  49. })
  50. // 设置初始化,防止刷新时恢复默认
  51. onBeforeMount(() => {
  52. // 设置批量第三方 icon 图标
  53. setIntroduction.cssCdn()
  54. // 设置批量第三方 js
  55. setIntroduction.jsCdn()
  56. })
  57. // 页面加载时
  58. onMounted(() => {
  59. nextTick(() => {
  60. // 监听布局配'置弹窗点击打开
  61. mittBus.on('openSetingsDrawer', () => {
  62. setingsRef.value.openDrawer()
  63. })
  64. // 获取缓存中的布局配置
  65. if (Local.get('themeConfig')) {
  66. storesThemeConfig.setThemeConfig({ themeConfig: Local.get('themeConfig') })
  67. document.documentElement.style.cssText = Local.get('themeConfigStyle')
  68. }
  69. // 获取缓存中的全屏配置
  70. if (Session.get('isTagsViewCurrenFull')) {
  71. stores.setCurrenFullscreen(Session.get('isTagsViewCurrenFull'))
  72. }
  73. })
  74. })
  75. // 页面销毁时,关闭监听布局配置/i18n监听
  76. onUnmounted(() => {
  77. mittBus.off('openSetingsDrawer', () => {})
  78. })
  79. // 监听路由的变化,设置网站标题
  80. watch(
  81. () => route.path,
  82. () => {
  83. other.useTitle()
  84. },
  85. {
  86. deep: true,
  87. }
  88. )
  89. </script>