App.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <script lang="ts">
  2. import "@/assets/css/app.less";
  3. import "@/assets/theme/index.less";
  4. import "@/assets/theme/mobile.less";
  5. import FullscreenLayout from "@/layout/fullscreen-layout.vue";
  6. import Layout from "@/layout/index.vue";
  7. import { ElConfigProvider } from "element-plus";
  8. import { defineComponent, onMounted, reactive, watch } from "vue";
  9. import { useI18n } from "vue-i18n";
  10. import { useRoute } from "vue-router";
  11. import { useAppStore } from "@/store";
  12. import app from "./constants/app";
  13. import { EPageLayoutEnum, EThemeColor, EThemeSetting } from "./constants/enum";
  14. import { getLocaleLang, supportLangs } from "./i18n";
  15. import { IObject } from "./types/interface";
  16. import { getThemeConfigCache, setThemeColor, updateTheme } from "./utils/theme";
  17. export default defineComponent({
  18. name: "App",
  19. components: { Layout, FullscreenLayout, [ElConfigProvider.name]: ElConfigProvider },
  20. setup() {
  21. const store = useAppStore();
  22. const route = useRoute();
  23. const { t, locale } = useI18n();
  24. const state = reactive({
  25. layout: location.href.includes("pop=true") ? EPageLayoutEnum.fullscreen : EPageLayoutEnum.page
  26. });
  27. const onInitLang = (vl: string, oldVl?: string) => {
  28. window.document.querySelector("html")?.setAttribute("lang", vl);
  29. document.title = t("ui.app.productName");
  30. if (oldVl && route.path !== "/login") {
  31. store.updateState({ appIsReady: false });
  32. location.reload();
  33. }
  34. };
  35. onMounted(() => {
  36. //读取主题色缓存
  37. const themeCache = getThemeConfigCache();
  38. const themeColor = themeCache[EThemeSetting.ThemeColor];
  39. setThemeColor(EThemeColor.ThemeColor, themeColor);
  40. updateTheme(themeColor);
  41. onInitLang(getLocaleLang());
  42. });
  43. watch(() => locale.value, onInitLang);
  44. watch(
  45. () => [route.path, route.query, route.fullPath],
  46. ([path, query, fullPath]) => {
  47. store.updateState({ activeTabName: fullPath });
  48. state.layout = app.fullscreenPages.includes(path as string) || (query as IObject)["pop"] ? EPageLayoutEnum.fullscreen : EPageLayoutEnum.page;
  49. }
  50. );
  51. return {
  52. store,
  53. state,
  54. pageTag: EPageLayoutEnum.page,
  55. locale: supportLangs[locale.value].el
  56. };
  57. }
  58. });
  59. </script>
  60. <template>
  61. <el-config-provider :locale="locale">
  62. <div v-if="!store.state.appIsRender" v-loading="true" :element-loading-fullscreen="true" :element-loading-lock="true" style="width: 100vw; height: 100vh; position: absolute; top: 0; left: 0; z-index: 99999; background: #fff"></div>
  63. <template v-if="store.state.appIsReady">
  64. <layout v-if="state.layout === pageTag"> </layout>
  65. <fullscreen-layout v-else></fullscreen-layout>
  66. </template>
  67. </el-config-provider>
  68. </template>