App.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <template>
  2. <el-config-provider :size="getGlobalComponentSize" :locale="getGlobalI18n">
  3. <!-- v-show="themeConfig.lockScreenTime > 1" -->
  4. <router-view v-show="themeConfig.lockScreenTime > 1" />
  5. <LockScreen v-if="themeConfig.isLockScreen" />
  6. <Setings ref="setingsRef" v-show="themeConfig.lockScreenTime > 1" />
  7. <CloseFull v-if="!themeConfig.isLockScreen" />
  8. <Upgrade v-if="getVersion" />
  9. </el-config-provider>
  10. </template>
  11. <script setup lang="ts" name="app">
  12. import { defineAsyncComponent, computed, ref, onBeforeMount, onMounted, onUnmounted, nextTick, watch, onBeforeUnmount } from 'vue';
  13. import { useRoute } from 'vue-router';
  14. import { useI18n } from 'vue-i18n';
  15. import { storeToRefs } from 'pinia';
  16. import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
  17. import { useThemeConfig } from '/@/stores/themeConfig';
  18. import other from '/@/utils/other';
  19. import { Local, Session } from '/@/utils/storage';
  20. import mittBus from '/@/utils/mitt';
  21. import setIntroduction from '/@/utils/setIconfont';
  22. // 引入组件
  23. const LockScreen = defineAsyncComponent(() => import('/@/layout/lockScreen/index.vue'));
  24. const Setings = defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/setings.vue'));
  25. const CloseFull = defineAsyncComponent(() => import('/@/layout/navBars/breadcrumb/closeFull.vue'));
  26. const Upgrade = defineAsyncComponent(() => import('/@/layout/upgrade/index.vue'));
  27. // 定义变量内容
  28. const { messages, locale } = useI18n();
  29. const setingsRef = ref();
  30. const route = useRoute();
  31. const stores = useTagsViewRoutes();
  32. const storesThemeConfig = useThemeConfig();
  33. const { themeConfig } = storeToRefs(storesThemeConfig);
  34. import websocket from '/@/utils/websocket';
  35. import { ElNotification } from 'element-plus';
  36. // 获取版本号
  37. const getVersion = computed(() => {
  38. let isVersion = false;
  39. if (route.path !== '/login') {
  40. // @ts-ignore
  41. if ((Local.get('version') && Local.get('version') !== __VERSION__) || !Local.get('version')) isVersion = true;
  42. }
  43. return isVersion;
  44. });
  45. // 获取全局组件大小
  46. const getGlobalComponentSize = computed(() => {
  47. return other.globalComponentSize();
  48. });
  49. // 获取全局 i18n
  50. const getGlobalI18n = computed(() => {
  51. return messages.value[locale.value];
  52. });
  53. // 设置初始化,防止刷新时恢复默认
  54. onBeforeMount(() => {
  55. //localStorage.clear();
  56. // 设置批量第三方 icon 图标
  57. setIntroduction.cssCdn();
  58. // 设置批量第三方 js
  59. setIntroduction.jsCdn();
  60. //websockt 模块
  61. try {
  62. //websocket.init(wsReceive)
  63. } catch (e) {
  64. console.log('websocket错误');
  65. }
  66. });
  67. // 页面加载时
  68. onMounted(() => {
  69. nextTick(() => {
  70. // 监听布局配'置弹窗点击打开
  71. mittBus.on('openSetingsDrawer', () => {
  72. setingsRef.value.openDrawer();
  73. });
  74. // 获取缓存中的布局配置
  75. if (Local.get('themeConfig')) {
  76. storesThemeConfig.setThemeConfig({ themeConfig: Local.get('themeConfig') });
  77. document.documentElement.style.cssText = Local.get('themeConfigStyle');
  78. }
  79. // 获取缓存中的全屏配置
  80. if (Session.get('isTagsViewCurrenFull')) {
  81. stores.setCurrenFullscreen(Session.get('isTagsViewCurrenFull'));
  82. }
  83. });
  84. });
  85. // 页面销毁时,关闭监听布局配置/i18n监听
  86. onUnmounted(() => {
  87. mittBus.off('openSetingsDrawer', () => {});
  88. });
  89. // 监听路由的变化,设置网站标题
  90. watch(
  91. () => route.path,
  92. () => {
  93. other.useTitle();
  94. },
  95. {
  96. deep: true,
  97. }
  98. );
  99. // websocket相关代码
  100. import { messageCenterStore } from '/@/stores/messageCenter';
  101. const wsReceive = (message: any) => {
  102. const data = JSON.parse(message.data);
  103. const { unread } = data;
  104. const messageCenter = messageCenterStore();
  105. messageCenter.setUnread(unread);
  106. if (data.contentType === 'SYSTEM') {
  107. ElNotification({
  108. title: '系统消息',
  109. message: data.content,
  110. type: 'success',
  111. position: 'bottom-right',
  112. duration: 5000,
  113. });
  114. }
  115. };
  116. onBeforeUnmount(() => {
  117. // 关闭连接
  118. websocket.close();
  119. });
  120. </script>