App.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <template>
  2. <el-config-provider :size="getGlobalComponentSize" :locale="zhCn" :message="messageConfig" :button="buttonConfig">
  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. </el-config-provider>
  8. </template>
  9. <script lang="ts" name="app" setup>
  10. import { computed, ref, onBeforeMount, onMounted, onBeforeUnmount, nextTick, watch, reactive, defineAsyncComponent } from 'vue';
  11. import { useRoute } from 'vue-router';
  12. import zhCn from 'element-plus/es/locale/lang/zh-cn';
  13. import { storeToRefs } from 'pinia';
  14. import { useTagsViewRoutes } from '@/stores/tagsViewRoutes';
  15. import { useThemeConfig } from '@/stores/themeConfig';
  16. import other from '@/utils/other';
  17. import checkUpdate from '@/utils/checkUpdate';
  18. import mittBus from '@/utils/mitt';
  19. import { Session, Local } from '@/utils/storage';
  20. import setIntroduction from '@/utils/setIconfont';
  21. import { loginPageInfo } from '@/api/login';
  22. import { getImageUrl } from '@/utils/tools';
  23. import { useKeepALiveNames } from '@/stores/keepAliveNames';
  24. import { useFavicon,useDark } from '@vueuse/core';
  25. // 引入组件
  26. const LockScreen = defineAsyncComponent(() => import('@/layout/lockScreen/index.vue'));
  27. const SetTings = defineAsyncComponent(() => import('@/layout/navBars/breadcrumb/setings.vue'));
  28. const CloseFull = defineAsyncComponent(() => import('@/layout/navBars/breadcrumb/closeFull.vue'));
  29. const route = useRoute();
  30. const stores = useTagsViewRoutes();
  31. const storesThemeConfig = useThemeConfig();
  32. const { themeConfig } = storeToRefs(storesThemeConfig);
  33. const storesKeepALiveNames = useKeepALiveNames();
  34. const storesTagsViewRoutes = useTagsViewRoutes();
  35. const { tagsViewRoutes } = storeToRefs(storesTagsViewRoutes);
  36. // 设置锁屏时组件显示隐藏
  37. const setLockScreen = computed(() => {
  38. // 防止锁屏后,刷新出现不相关界面
  39. // https://gitee.com/lyt-top/vue-next-admin/issues/I6AF8P
  40. return !themeConfig.value.isLockScreen;
  41. });
  42. // 可同时显示的消息最大数量
  43. const messageConfig = reactive<any>({
  44. max: 3,
  45. });
  46. // 自动在两个中文字符之间插入空格
  47. const buttonConfig = reactive<any>({
  48. autoInsertSpace: false,
  49. });
  50. // 获取全局组件大小
  51. const getGlobalComponentSize = computed(() => {
  52. return other.globalComponentSize();
  53. });
  54. // 布局配置弹窗打开
  55. const setTingsRef = ref<RefType>();
  56. const openSetTingsDrawer = () => {
  57. setTingsRef.value.openDrawer();
  58. };
  59. // 设置初始化,防止刷新时恢复默认
  60. onBeforeMount(async () => {
  61. try{
  62. // 获取登录页的背景图和系统名称等
  63. const { result } = await loginPageInfo();
  64. const globalTitle = result.sysName ?? ''; // 标题名称
  65. const loginImage = result.loginImage ? result.loginImage : `${getImageUrl('default/login_bg.png')}`; // 登录页背景图
  66. const isLoginMessageCode = result.isLoginMessageCode; // 是否开启短信验证码
  67. const appScope = result.appScope ?? 'YiBin'; // 应用范围
  68. const callCenterType = result.callCenterType ?? 'TianRun'; // 呼叫中心类型
  69. const cityName = result.cityName ?? ''; // 城市名称
  70. const cityCode = result.cityCode ?? ''; // 城市编码
  71. const cityAbbr = result.cityAbbr ?? ''; // 城市简称
  72. const locationCenter = result.locationCenter ?? []; // 城市中心点
  73. const operate = result.operate ?? ''; // 管理运营 页脚
  74. const techSupport = result.techSupport ?? ''; // 技术支持 页脚
  75. const recordNumber = result.recordNumber ?? ''; // 备案号 页脚
  76. const faviconImage = result.faviconImage ?? ``; // favicon 浏览器标签图标
  77. const menuLogoImage = result.menuLogoImage ?? ``; // 菜单logo
  78. const menuLogoImageMini = result.menuLogoImageMini ?? ``; // 菜单logo-mini
  79. const changPwdImage = result.changPwdImage ?? ``; // 修改密码图片
  80. const callCenterSocketUrl = result.callCenterSocketUrl ?? ''; // 呼叫中心socket地址
  81. const recordPrefix = result.recordPrefix ?? ''; // 录音前缀
  82. const recordDownLoadPrefix = result.recordDownLoadPrefix ?? ''; // 录音下载前缀
  83. storesThemeConfig.setThemeConfig(
  84. Object.assign(themeConfig.value, {
  85. globalTitle,
  86. loginImage,
  87. isLoginMessageCode,
  88. appScope,
  89. callCenterType,
  90. cityName,
  91. cityCode,
  92. cityAbbr,
  93. locationCenter,
  94. operate,
  95. techSupport,
  96. recordNumber,
  97. faviconImage,
  98. menuLogoImage,
  99. menuLogoImageMini,
  100. changPwdImage,
  101. callCenterSocketUrl,
  102. recordPrefix,
  103. recordDownLoadPrefix,
  104. })
  105. );
  106. }catch (e){
  107. console.log(e)
  108. }
  109. // 设置批量第三方 icon 图标
  110. setIntroduction.cssCdn();
  111. // 设置批量第三方 js
  112. setIntroduction.jsCdn();
  113. });
  114. // 页面加载时
  115. onMounted(() => {
  116. nextTick(async () => {
  117. try {
  118. // 获取缓存中的布局配置
  119. if (Local.get('themeConfig')) {
  120. storesThemeConfig.setThemeConfig(Local.get('themeConfig'));
  121. document.documentElement.style.cssText = Local.get('themeConfigStyle');
  122. }
  123. // 开发环境不提示更新
  124. if (import.meta.env.VITE_MODE_NAME != 'development') {
  125. // 监听是否更新 半个小时检查一次
  126. await checkUpdate(1800);
  127. }
  128. // 监听布局配置弹窗点击打开
  129. mittBus.on('openSetTingsDrawer', () => {
  130. openSetTingsDrawer();
  131. });
  132. // 获取缓存中的全屏配置
  133. if (Session.get('isTagsViewCurrenFull')) {
  134. stores.setCurrenFullscreen(Session.get('isTagsViewCurrenFull'));
  135. }
  136. // 清除某个页面的缓存
  137. mittBus.on('clearCache', (view: any) => {
  138. clearCacheTagsView(view);
  139. });
  140. // 动态修改icon
  141. const icon = useFavicon();
  142. icon.value = themeConfig.value.faviconImage; // 更改当前左上角角标
  143. const isDark = useDark();
  144. isDark.value = themeConfig.value.isIsDark; // 更改暗黑模式
  145. // 解决火狐拖动打开新窗口
  146. document.body.ondrop = (event) => {
  147. event.preventDefault();
  148. event.stopPropagation();
  149. };
  150. /*mittBus.on('*', (index, data) => {
  151. console.log(index, data);
  152. });*/
  153. } catch (error) {
  154. console.log(error);
  155. }
  156. });
  157. });
  158. // 清除缓存 name
  159. const clearCacheTagsView = async (routeName: string) => {
  160. let item: EmptyObjectType | null | undefined;
  161. tagsViewRoutes.value.forEach((v: any) => {
  162. if (v.name === routeName) {
  163. item = v;
  164. }
  165. });
  166. if (!item) return false;
  167. await storesKeepALiveNames.delCachedView(item);
  168. if (item.meta?.isKeepAlive) await storesKeepALiveNames.addCachedView(item);
  169. };
  170. // 页面销毁时,关闭监听布局配置/i18n监听
  171. onBeforeUnmount(() => {
  172. mittBus.off('openSetTingsDrawer', () => {});
  173. mittBus.off('clearCache', () => {});
  174. });
  175. // 监听路由的变化,设置网站标题
  176. watch(
  177. () => route.path,
  178. () => {
  179. other.useTitle();
  180. },
  181. {
  182. deep: true,
  183. }
  184. );
  185. </script>