App.vue 1.6 KB

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