App.vue 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. import api from '/@/api/system';
  20. export default defineComponent({
  21. name: 'app',
  22. components: { LockScreen, Setings, CloseFull },
  23. created() {
  24. api.sysinfo().then((res: any) => {
  25. localStorage.setItem('sysinfo', JSON.stringify(res));
  26. });
  27. },
  28. setup() {
  29. const { proxy } = <any>getCurrentInstance();
  30. const setingsRef = ref();
  31. const route = useRoute();
  32. const store = useStore();
  33. const state = reactive({
  34. i18nLocale: null,
  35. });
  36. // 获取布局配置信息
  37. const getThemeConfig = computed(() => {
  38. return store.state.themeConfig.themeConfig;
  39. });
  40. // 获取全局组件大小
  41. const getGlobalComponentSize = computed(() => {
  42. return other.globalComponentSize;
  43. });
  44. // 布局配置弹窗打开
  45. const openSetingsDrawer = () => {
  46. setingsRef.value.openDrawer();
  47. };
  48. // 设置初始化,防止刷新时恢复默认
  49. onBeforeMount(() => {
  50. // 设置批量第三方 icon 图标
  51. setIntroduction.cssCdn();
  52. // 设置批量第三方 js
  53. setIntroduction.jsCdn();
  54. });
  55. // 页面加载时
  56. onMounted(() => {
  57. nextTick(() => {
  58. // 监听布局配置弹窗点击打开
  59. proxy.mittBus.on('openSetingsDrawer', () => {
  60. openSetingsDrawer();
  61. });
  62. // 设置 i18n,App.vue 中的 el-config-provider
  63. proxy.mittBus.on('getI18nConfig', (locale: string) => {
  64. (state.i18nLocale as string | null) = locale;
  65. });
  66. // 获取缓存中的布局配置
  67. if (Local.get('themeConfig')) {
  68. store.dispatch('themeConfig/setThemeConfig', Local.get('themeConfig'));
  69. document.documentElement.style.cssText = Local.get('themeConfigStyle');
  70. }
  71. // 获取缓存中的全屏配置
  72. if (Session.get('isTagsViewCurrenFull')) {
  73. store.dispatch('tagsViewRoutes/setCurrenFullscreen', Session.get('isTagsViewCurrenFull'));
  74. }
  75. });
  76. });
  77. // 页面销毁时,关闭监听布局配置/i18n监听
  78. onUnmounted(() => {
  79. proxy.mittBus.off('openSetingsDrawer', () => {});
  80. proxy.mittBus.off('getI18nConfig', () => {});
  81. });
  82. // 监听路由的变化,设置网站标题
  83. watch(
  84. () => route.path,
  85. () => {
  86. other.useTitle();
  87. }
  88. );
  89. return {
  90. setingsRef,
  91. getThemeConfig,
  92. getGlobalComponentSize,
  93. ...toRefs(state),
  94. };
  95. },
  96. });
  97. </script>