App.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <template>
  2. <el-config-provider :size="getGlobalComponentSize" :locale="locale">
  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 { storeToRefs } from 'pinia';
  15. import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
  16. import { useThemeConfig } from '/@/stores/themeConfig';
  17. import other from '/@/utils/other';
  18. import { Local, Session } from '/@/utils/storage';
  19. import mittBus from '/@/utils/mitt';
  20. import setIntroduction from '/@/utils/setIconfont';
  21. // import Watermark from '/@/utils/watermark';
  22. import { SysConfigApi } from '/@/api-services';
  23. import { getAPI } from '/@/utils/axios-utils';
  24. import { useLangStore } from '/@/stores/useLangStore';
  25. import localeMap from '../lang/elementLocales'
  26. const currentLang = Local.get('themeConfig')?.globalI18n || 'zh-cn'
  27. const locale = computed(() => localeMap[currentLang] || localeMap['zh-cn'])
  28. // 引入组件
  29. const LockScreen = defineAsyncComponent(() => import('/@/layout/lockScreen/index.vue'));
  30. const Settings = defineAsyncComponent(() => import('/@/layout/navBars/topBar/settings.vue'));
  31. const CloseFull = defineAsyncComponent(() => import('/@/layout/navBars/topBar/closeFull.vue'));
  32. // const Upgrade = defineAsyncComponent(() => import('/@/layout/upgrade/index.vue'));
  33. // const Sponsors = defineAsyncComponent(() => import('/@/layout/sponsors/index.vue'));
  34. // 定义变量内容
  35. const settingsRef = ref();
  36. const route = useRoute();
  37. const stores = useTagsViewRoutes();
  38. const storesThemeConfig = useThemeConfig();
  39. const { themeConfig } = storeToRefs(storesThemeConfig);
  40. const needUpdate = ref(false);
  41. // 设置锁屏时组件显示隐藏
  42. const setLockScreen = computed(() => {
  43. // 防止锁屏后,刷新出现不相关界面
  44. // https://gitee.com/lyt-top/vue-next-admin/issues/I6AF8P
  45. return themeConfig.value.isLockScreen ? themeConfig.value.lockScreenTime > 1 : themeConfig.value.lockScreenTime >= 0;
  46. });
  47. // // 获取版本号
  48. // const getVersion = computed(() => {
  49. // let isVersion = false;
  50. // if (route.path !== '/login') {
  51. // // @ts-ignore
  52. // if ((Local.get('version') && Local.get('version') !== __NEXT_VERSION__) || !Local.get('version')) isVersion = true;
  53. // }
  54. // return isVersion;
  55. // });
  56. // checkUpdate(() => {
  57. // needUpdate.value = true;
  58. // }, 60000);
  59. // 获取全局组件大小,直接响应 themeConfig
  60. const getGlobalComponentSize = computed(() => {
  61. return themeConfig.value.globalComponentSize;
  62. });
  63. // 获取全局 i18n
  64. // const getGlobalI18n = computed(() => {
  65. //return messages.value[locale.value];
  66. // });
  67. // 设置初始化,防止刷新时恢复默认
  68. onBeforeMount(() => {
  69. // 设置批量第三方 icon 图标
  70. setIntroduction.cssCdn();
  71. // 设置批量第三方 js
  72. setIntroduction.jsCdn();
  73. });
  74. // 页面加载时
  75. onMounted(() => {
  76. nextTick(() => {
  77. // 监听布局配'置弹窗点击打开
  78. mittBus.on('openSettingsDrawer', () => {
  79. settingsRef.value.openDrawer();
  80. });
  81. // 获取缓存中的布局配置
  82. if (Local.get('themeConfig')) {
  83. storesThemeConfig.setThemeConfig({ themeConfig: Local.get('themeConfig') });
  84. document.documentElement.style.cssText = Local.get('themeConfigStyle');
  85. }
  86. // 获取缓存中的全屏配置
  87. if (Session.get('isTagsViewCurrenFull')) {
  88. stores.setCurrenFullscreen(Session.get('isTagsViewCurrenFull'));
  89. }
  90. });
  91. });
  92. // 页面销毁时,关闭监听布局配置/i18n监听
  93. onUnmounted(() => {
  94. mittBus.off('openSettingsDrawer', () => { });
  95. });
  96. // 监听路由的变化,设置网站标题
  97. watch(
  98. () => route.path,
  99. () => {
  100. other.useTitle();
  101. },
  102. {
  103. deep: true,
  104. }
  105. );
  106. // 加载系统信息
  107. const loadSysInfo = () => {
  108. getAPI(SysConfigApi)
  109. .apiSysConfigSysInfoGet()
  110. .then((res) => {
  111. if (res.data.type != 'success') return;
  112. const data = res.data.result;
  113. // 系统logo
  114. themeConfig.value.logoUrl = data.logo;
  115. // 主标题
  116. themeConfig.value.globalTitle = data.title;
  117. // 副标题
  118. themeConfig.value.globalViceTitle = data.viceTitle;
  119. // 系统说明
  120. themeConfig.value.globalViceTitleMsg = data.viceDesc;
  121. // Icp备案信息
  122. themeConfig.value.icp = data.icp;
  123. themeConfig.value.icpUrl = data.icpUrl;
  124. // 水印
  125. themeConfig.value.isWatermark = data.watermark != null;
  126. themeConfig.value.watermarkText = data.watermark;
  127. // 版权说明
  128. themeConfig.value.copyright = data.copyright;
  129. // 登录验证
  130. themeConfig.value.secondVer = data.secondVer == 1;
  131. themeConfig.value.captcha = data.captcha == 1;
  132. // 登陆时隐藏租户
  133. themeConfig.value.hideTenantForLogin = data.hideTenantForLogin;
  134. // 注册功能
  135. themeConfig.value.registration = data.enableReg == 1;
  136. // 登录页预填:平台参数
  137. themeConfig.value.loginDefaultAccount = (data as any).defaultLoginAccount ?? '';
  138. themeConfig.value.loginDefaultPassword = (data as any).defaultPassword ?? '';
  139. // 更新配置加载状态
  140. themeConfig.value.isLoaded = true;
  141. // 更新 favicon
  142. updateFavicon(data.logo);
  143. // 保存配置
  144. Local.remove('themeConfig');
  145. Local.set('themeConfig', storesThemeConfig.themeConfig);
  146. })
  147. .catch(() => {
  148. // 置空 logo 地址
  149. themeConfig.value.logoUrl = '';
  150. // 保存配置
  151. Local.remove('themeConfig');
  152. Local.set('themeConfig', storesThemeConfig.themeConfig);
  153. return;
  154. });
  155. };
  156. // 更新 favicon
  157. const updateFavicon = (url: string): void => {
  158. const favicon = document.getElementById('favicon') as HTMLAnchorElement;
  159. favicon!.href = url ? url : 'data:;base64,=';
  160. };
  161. // 加载系统信息
  162. loadSysInfo();
  163. const langStore = useLangStore();
  164. langStore.loadLanguages();
  165. // 阻止火狐浏览器在拖动时打开新窗口
  166. document.body.ondrop = function (event) {
  167. event.preventDefault();
  168. event.stopPropagation();
  169. };
  170. </script>