App.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <template>
  2. <el-config-provider :size="getGlobalComponentSize" :locale="getGlobalI18n">
  3. <router-view v-show="setLockScreen" />
  4. <LockScreen v-if="themeConfig.isLockScreen" />
  5. <Settings ref="settingsRef" v-show="setLockScreen" />
  6. <CloseFull v-if="!themeConfig.isLockScreen" />
  7. <!-- <Upgrade v-if="needUpdate" /> -->
  8. <!-- <Sponsors /> -->
  9. </el-config-provider>
  10. </template>
  11. <script setup lang="ts" name="app">
  12. import { defineAsyncComponent, computed, ref, onBeforeMount, onMounted, onUnmounted, nextTick, watch } 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. // import Watermark from '/@/utils/watermark';
  23. import { SysConfigApi } from '/@/api-services';
  24. import { getAPI } from '/@/utils/axios-utils';
  25. // 引入组件
  26. const LockScreen = defineAsyncComponent(() => import('/@/layout/lockScreen/index.vue'));
  27. const Settings = defineAsyncComponent(() => import('/@/layout/navBars/topBar/settings.vue'));
  28. const CloseFull = defineAsyncComponent(() => import('/@/layout/navBars/topBar/closeFull.vue'));
  29. // const Upgrade = defineAsyncComponent(() => import('/@/layout/upgrade/index.vue'));
  30. // const Sponsors = defineAsyncComponent(() => import('/@/layout/sponsors/index.vue'));
  31. // 定义变量内容
  32. const { messages, locale } = useI18n();
  33. const settingsRef = ref();
  34. const route = useRoute();
  35. const stores = useTagsViewRoutes();
  36. const storesThemeConfig = useThemeConfig();
  37. const { themeConfig } = storeToRefs(storesThemeConfig);
  38. const needUpdate = ref(false);
  39. // 设置锁屏时组件显示隐藏
  40. const setLockScreen = computed(() => {
  41. // 防止锁屏后,刷新出现不相关界面
  42. // https://gitee.com/lyt-top/vue-next-admin/issues/I6AF8P
  43. return themeConfig.value.isLockScreen ? themeConfig.value.lockScreenTime > 1 : themeConfig.value.lockScreenTime >= 0;
  44. });
  45. // // 获取版本号
  46. // const getVersion = computed(() => {
  47. // let isVersion = false;
  48. // if (route.path !== '/login') {
  49. // // @ts-ignore
  50. // if ((Local.get('version') && Local.get('version') !== __NEXT_VERSION__) || !Local.get('version')) isVersion = true;
  51. // }
  52. // return isVersion;
  53. // });
  54. // checkUpdate(() => {
  55. // needUpdate.value = true;
  56. // }, 60000);
  57. // 获取全局组件大小
  58. const getGlobalComponentSize = computed(() => {
  59. return other.globalComponentSize();
  60. });
  61. // 获取全局 i18n
  62. const getGlobalI18n = computed(() => {
  63. return messages.value[locale.value];
  64. });
  65. // 设置初始化,防止刷新时恢复默认
  66. onBeforeMount(() => {
  67. // 设置批量第三方 icon 图标
  68. setIntroduction.cssCdn();
  69. // 设置批量第三方 js
  70. setIntroduction.jsCdn();
  71. });
  72. // 页面加载时
  73. onMounted(() => {
  74. nextTick(() => {
  75. // 监听布局配'置弹窗点击打开
  76. mittBus.on('openSettingsDrawer', () => {
  77. settingsRef.value.openDrawer();
  78. });
  79. // 获取缓存中的布局配置
  80. if (Local.get('themeConfig')) {
  81. storesThemeConfig.setThemeConfig({ themeConfig: Local.get('themeConfig') });
  82. document.documentElement.style.cssText = Local.get('themeConfigStyle');
  83. }
  84. // 获取缓存中的全屏配置
  85. if (Session.get('isTagsViewCurrenFull')) {
  86. stores.setCurrenFullscreen(Session.get('isTagsViewCurrenFull'));
  87. }
  88. });
  89. });
  90. // 页面销毁时,关闭监听布局配置/i18n监听
  91. onUnmounted(() => {
  92. mittBus.off('openSettingsDrawer', () => {});
  93. });
  94. // 监听路由的变化,设置网站标题
  95. watch(
  96. () => route.path,
  97. () => {
  98. other.useTitle();
  99. },
  100. {
  101. deep: true,
  102. }
  103. );
  104. // 加载系统信息
  105. const loadSysInfo = () => {
  106. getAPI(SysConfigApi)
  107. .apiSysConfigSysInfoGet()
  108. .then((res) => {
  109. if (res.data.type != 'success') return;
  110. const data = res.data.result;
  111. // 系统logo
  112. themeConfig.value.logoUrl = data.sysLogo;
  113. // 主标题
  114. themeConfig.value.globalTitle = data.sysTitle;
  115. // 副标题
  116. themeConfig.value.globalViceTitle = data.sysViceTitle;
  117. // 系统说明
  118. themeConfig.value.globalViceTitleMsg = data.sysViceDesc;
  119. // Icp备案信息
  120. themeConfig.value.icp = data.sysIcp;
  121. themeConfig.value.icpUrl = data.sysIcpUrl;
  122. // 水印
  123. themeConfig.value.isWatermark = data.sysWatermark != null;
  124. themeConfig.value.watermarkText = data.sysWatermark;
  125. // 版权说明
  126. themeConfig.value.copyright = data.sysCopyright;
  127. // 更新 favicon
  128. updateFavicon(data.sysLogo);
  129. // 保存配置
  130. Local.remove('themeConfig');
  131. Local.set('themeConfig', storesThemeConfig.themeConfig);
  132. })
  133. .catch(() => {
  134. // 置空 logo 地址
  135. themeConfig.value.logoUrl = '';
  136. // 保存配置
  137. Local.remove('themeConfig');
  138. Local.set('themeConfig', storesThemeConfig.themeConfig);
  139. return;
  140. });
  141. };
  142. // 更新 favicon
  143. const updateFavicon = (url: string): void => {
  144. const favicon = document.getElementById('favicon') as HTMLAnchorElement;
  145. favicon!.href = url ? url : 'data:;base64,=';
  146. };
  147. // 加载系统信息
  148. loadSysInfo();
  149. </script>
  150. <style lang="scss">
  151. .el-form--inline {
  152. .el-form-item {
  153. .el-select {
  154. width: 171px !important;
  155. }
  156. .el-select__wrapper {
  157. line-height: 22px !important;
  158. }
  159. .el-date-editor {
  160. --el-date-editor-width: 171px !important;
  161. }
  162. .el-input {
  163. width: 171px !important;
  164. }
  165. }
  166. }
  167. </style>