App.vue 3.3 KB

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