App.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <el-config-provider :locale="locale" :size="assemblySize" :button="buttonConfig">
  3. <router-view></router-view>
  4. </el-config-provider>
  5. </template>
  6. <script setup lang="ts">
  7. import { onMounted, reactive, computed } from "vue";
  8. import { useI18n } from "vue-i18n";
  9. import { getBrowserLang } from "@/utils";
  10. import { useTheme } from "@/hooks/useTheme";
  11. import { ElConfigProvider } from "element-plus";
  12. import { LanguageType } from "./stores/interface";
  13. import { useGlobalStore } from "@/stores/modules/global";
  14. import en from "element-plus/es/locale/lang/en";
  15. import zhCn from "element-plus/es/locale/lang/zh-cn";
  16. const globalStore = useGlobalStore();
  17. // init theme
  18. const { initTheme } = useTheme();
  19. initTheme();
  20. // init language
  21. const i18n = useI18n();
  22. onMounted(() => {
  23. const language = globalStore.language ?? getBrowserLang();
  24. i18n.locale.value = language;
  25. globalStore.setGlobalState("language", language as LanguageType);
  26. });
  27. // element language
  28. const locale = computed(() => {
  29. if (globalStore.language == "zh") return zhCn;
  30. if (globalStore.language == "en") return en;
  31. return getBrowserLang() == "zh" ? zhCn : en;
  32. });
  33. // element assemblySize
  34. const assemblySize = computed(() => globalStore.assemblySize);
  35. // element button config
  36. const buttonConfig = reactive({ autoInsertSpace: false });
  37. </script>
  38. <style>
  39. body {
  40. font-family: 'PingFang-Medium', sans-serif;
  41. }
  42. </style>