App.vue 2.8 KB

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