App.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <el-config-provider :locale="currentLocale">
  3. <router-view />
  4. </el-config-provider>
  5. </template>
  6. <script lang="ts">
  7. import { defineComponent, onMounted } from "vue";
  8. import { checkVersion } from "version-rocket";
  9. import { ElConfigProvider } from "element-plus";
  10. import en from "element-plus/es/locale/lang/en";
  11. import zhCn from "element-plus/es/locale/lang/zh-cn";
  12. import plusEn from "plus-pro-components/es/locale/lang/en";
  13. import plusZhCn from "plus-pro-components/es/locale/lang/zh-cn";
  14. import dictUtil from "@/utils/dict";
  15. import { getToken } from "@/utils/auth";
  16. export default defineComponent({
  17. name: "app",
  18. components: {
  19. [ElConfigProvider.name]: ElConfigProvider
  20. },
  21. computed: {
  22. currentLocale() {
  23. return this.$storage.locale?.locale === "zh"
  24. ? { ...zhCn, ...plusZhCn }
  25. : { ...en, ...plusEn };
  26. }
  27. },
  28. beforeCreate() {
  29. const { version, name: title } = __APP_INFO__.pkg;
  30. const { VITE_PUBLIC_PATH, MODE } = import.meta.env;
  31. // https://github.com/guMcrey/version-rocket/blob/main/README.zh-CN.md#api
  32. if (MODE === "production") {
  33. // 版本实时更新检测,只作用于线上环境
  34. checkVersion(
  35. // config
  36. {
  37. // 5分钟检测一次版本
  38. pollingTime: 300000,
  39. localPackageVersion: version,
  40. originVersionFileUrl: `${location.origin}${VITE_PUBLIC_PATH}version.json`
  41. },
  42. // options
  43. {
  44. title,
  45. description: "检测到新版本",
  46. buttonText: "立即更新"
  47. }
  48. );
  49. }
  50. },
  51. setup() {
  52. onMounted(() => {
  53. const token = getToken();
  54. if (token?.accessToken) {
  55. dictUtil.loadDicts();
  56. }
  57. });
  58. }
  59. });
  60. </script>