feat: 添加项目版本实时更新检测功能

This commit is contained in:
xiaoxian521 2023-06-04 11:47:04 +08:00
parent 7f02418839
commit 34379b9530
3 changed files with 6170 additions and 2587 deletions

View File

@ -5,7 +5,7 @@
"scripts": {
"dev": "NODE_OPTIONS=--max-old-space-size=4096 vite",
"serve": "pnpm dev",
"build": "rimraf dist && NODE_OPTIONS=--max-old-space-size=8192 vite build",
"build": "rimraf dist && NODE_OPTIONS=--max-old-space-size=8192 vite build && generate-version-file",
"build:staging": "rimraf dist && vite build --mode staging",
"report": "rimraf dist && vite build",
"preview": "vite preview",
@ -66,6 +66,7 @@
"typeit": "^8.7.1",
"v-contextmenu": "3.0.0",
"v3-infinite-loading": "^1.2.2",
"version-rocket": "^1.6.2",
"vue": "^3.3.4",
"vue-i18n": "^9.2.2",
"vue-json-pretty": "^2.2.4",

8727
pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@ -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>