App.vue 3.1 KB

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