perf: 增加版本过低提示

pull/469/head
xiaojunnuo 2025-07-23 00:10:15 +08:00
parent b382351c7b
commit d1ce36038c
2 changed files with 32 additions and 8 deletions

View File

@ -46,6 +46,10 @@ export interface SettingState {
price3: number; price3: number;
tooltip?: string; tooltip?: string;
}; };
app?: {
minVersion?: string;
minVersionTip?: string;
};
}; };
} }
@ -107,6 +111,10 @@ export const useSettingStore = defineStore({
price: 399, price: 399,
price3: 899, price3: 899,
}, },
app: {
minVersion: "",
minVersionTip: "",
},
}, },
}), }),
getters: { getters: {

View File

@ -156,32 +156,48 @@ import * as api from "./api";
import { useI18n } from "/src/locales"; import { useI18n } from "/src/locales";
const { t } = useI18n(); const { t } = useI18n();
import { usePluginStore } from "/@/store/plugin"; import { usePluginStore } from "/@/store/plugin";
import { notification } from "ant-design-vue";
defineOptions({ defineOptions({
name: "DashboardUser", name: "DashboardUser",
}); });
const version = ref(import.meta.env.VITE_APP_VERSION); const version = ref(import.meta.env.VITE_APP_VERSION);
const latestVersion = ref(""); const latestVersion = ref("");
const hasNewVersion = computed(() => {
if (!latestVersion.value) { function isNewVersion(version: string, latestVersion: string) {
if (!latestVersion) {
return false; return false;
} }
if (latestVersion.value === version.value) { if (latestVersion === version) {
return false; return false;
} }
// //
const current = version.value.split("."); const current = version.split(".");
const latest = latestVersion.value.split("."); const latest = latestVersion.split(".");
for (let i = 0; i < current.length; i++) { for (let i = 0; i < current.length; i++) {
if (parseInt(latest[i]) < parseInt(current[i])) { if (parseInt(latest[i]) > parseInt(current[i])) {
return false;
}
}
return true; return true;
}
}
return false;
}
const hasNewVersion = computed(() => {
return isNewVersion(version.value, latestVersion.value);
}); });
async function loadLatestVersion() { async function loadLatestVersion() {
latestVersion.value = await api.GetLatestVersion(); latestVersion.value = await api.GetLatestVersion();
console.log("latestVersion", latestVersion.value); console.log("latestVersion", latestVersion.value);
const minVersion = settingsStore.productInfo?.app?.minVersion;
if (minVersion) {
//
if (isNewVersion(version.value, minVersion)) {
notification.error({
message: settingsStore.productInfo?.app?.minVersionTip ?? "版本过低,为了您的数据安全,请尽快升级",
});
}
}
} }
const settingStore = useSettingStore(); const settingStore = useSettingStore();
const siteInfo: Ref<SiteInfo> = computed(() => { const siteInfo: Ref<SiteInfo> = computed(() => {