App.vue 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <el-config-provider :size="getGlobalComponentSize" :locale="i18nLocale">
  3. <router-view v-show="getThemeConfig.lockScreenTime !== 0" />
  4. <LockScreen v-if="getThemeConfig.isLockScreen" />
  5. <Setings ref="setingsRef" v-show="getThemeConfig.lockScreenTime !== 0" />
  6. <CloseFull />
  7. </el-config-provider>
  8. </template>
  9. <script lang="ts">
  10. import { computed, ref, getCurrentInstance, onBeforeMount, onMounted, onUnmounted, nextTick, defineComponent, watch, reactive, toRefs } from 'vue';
  11. import { useRoute } from 'vue-router';
  12. import { useStore } from '/@/store/index';
  13. import other from '/@/utils/other';
  14. import { Local, Session } from '/@/utils/storage';
  15. import setIntroduction from '/@/utils/setIconfont';
  16. import LockScreen from '/@/layout/lockScreen/index.vue';
  17. import Setings from '/@/layout/navBars/breadcrumb/setings.vue';
  18. import CloseFull from '/@/layout/navBars/breadcrumb/closeFull.vue';
  19. export default defineComponent({
  20. name: 'app',
  21. components: { LockScreen, Setings, CloseFull },
  22. setup() {
  23. const { proxy } = <any>getCurrentInstance();
  24. const setingsRef = ref();
  25. const route = useRoute();
  26. const store = useStore();
  27. const state = reactive({
  28. i18nLocale: null,
  29. });
  30. // 获取布局配置信息
  31. const getThemeConfig = computed(() => {
  32. return store.state.themeConfig.themeConfig;
  33. });
  34. // 获取全局组件大小
  35. const getGlobalComponentSize = computed(() => {
  36. return other.globalComponentSize;
  37. });
  38. // 布局配置弹窗打开
  39. const openSetingsDrawer = () => {
  40. setingsRef.value.openDrawer();
  41. };
  42. // 设置初始化,防止刷新时恢复默认
  43. onBeforeMount(() => {
  44. // 设置批量第三方 icon 图标
  45. setIntroduction.cssCdn();
  46. // 设置批量第三方 js
  47. setIntroduction.jsCdn();
  48. });
  49. // 页面加载时
  50. onMounted(() => {
  51. nextTick(() => {
  52. // 监听布局配置弹窗点击打开
  53. proxy.mittBus.on('openSetingsDrawer', () => {
  54. openSetingsDrawer();
  55. });
  56. // 设置 i18n,App.vue 中的 el-config-provider
  57. proxy.mittBus.on('getI18nConfig', (locale: string) => {
  58. (state.i18nLocale as string | null) = locale;
  59. });
  60. // 获取缓存中的布局配置
  61. if (Local.get('themeConfig')) {
  62. store.dispatch('themeConfig/setThemeConfig', Local.get('themeConfig'));
  63. document.documentElement.style.cssText = Local.get('themeConfigStyle');
  64. }
  65. // 获取缓存中的全屏配置
  66. if (Session.get('isTagsViewCurrenFull')) {
  67. store.dispatch('tagsViewRoutes/setCurrenFullscreen', Session.get('isTagsViewCurrenFull'));
  68. }
  69. });
  70. });
  71. // 页面销毁时,关闭监听布局配置/i18n监听
  72. onUnmounted(() => {
  73. proxy.mittBus.off('openSetingsDrawer', () => {});
  74. proxy.mittBus.off('getI18nConfig', () => {});
  75. });
  76. // 监听路由的变化,设置网站标题
  77. watch(
  78. () => route.path,
  79. () => {
  80. other.useTitle();
  81. }
  82. );
  83. return {
  84. setingsRef,
  85. getThemeConfig,
  86. getGlobalComponentSize,
  87. ...toRefs(state),
  88. };
  89. },
  90. });
  91. </script>