App.vue 3.6 KB

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