App.vue 1.4 KB

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