mirror of
https://github.com/pure-admin/vue-pure-admin.git
synced 2025-11-09 13:53:38 +08:00
feat: 添加项目版本实时更新检测功能
This commit is contained in:
27
src/App.vue
27
src/App.vue
@@ -7,10 +7,12 @@
|
||||
|
||||
<script lang="ts">
|
||||
import { defineComponent } from "vue";
|
||||
import { checkVersion } from "version-rocket";
|
||||
import { ElConfigProvider } from "element-plus";
|
||||
import zhCn from "element-plus/lib/locale/lang/zh-cn";
|
||||
import en from "element-plus/lib/locale/lang/en";
|
||||
import { ReDialog } from "@/components/ReDialog";
|
||||
import zhCn from "element-plus/lib/locale/lang/zh-cn";
|
||||
|
||||
export default defineComponent({
|
||||
name: "app",
|
||||
components: {
|
||||
@@ -21,6 +23,29 @@ export default defineComponent({
|
||||
currentLocale() {
|
||||
return this.$storage.locale?.locale === "zh" ? zhCn : en;
|
||||
}
|
||||
},
|
||||
beforeCreate() {
|
||||
const { version, name: title } = __APP_INFO__.pkg;
|
||||
const { VITE_PUBLIC_PATH, MODE } = import.meta.env;
|
||||
// https://github.com/guMcrey/version-rocket/blob/main/README.zh-CN.md#api
|
||||
if (MODE === "production") {
|
||||
// 版本实时更新检测,只作用于线上环境
|
||||
checkVersion(
|
||||
// config
|
||||
{
|
||||
// 5分钟检测一次版本
|
||||
pollingTime: 300000,
|
||||
localPackageVersion: version,
|
||||
originVersionFileUrl: `${location.origin}${VITE_PUBLIC_PATH}version.json`
|
||||
},
|
||||
// options
|
||||
{
|
||||
title,
|
||||
description: "检测到新版本",
|
||||
buttonText: "立即更新"
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user