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;
tooltip?: string;
};
app?: {
minVersion?: string;
minVersionTip?: string;
};
};
}
@ -107,6 +111,10 @@ export const useSettingStore = defineStore({
price: 399,
price3: 899,
},
app: {
minVersion: "",
minVersionTip: "",
},
},
}),
getters: {

View File

@ -156,32 +156,48 @@ import * as api from "./api";
import { useI18n } from "/src/locales";
const { t } = useI18n();
import { usePluginStore } from "/@/store/plugin";
import { notification } from "ant-design-vue";
defineOptions({
name: "DashboardUser",
});
const version = ref(import.meta.env.VITE_APP_VERSION);
const latestVersion = ref("");
const hasNewVersion = computed(() => {
if (!latestVersion.value) {
function isNewVersion(version: string, latestVersion: string) {
if (!latestVersion) {
return false;
}
if (latestVersion.value === version.value) {
if (latestVersion === version) {
return false;
}
//
const current = version.value.split(".");
const latest = latestVersion.value.split(".");
const current = version.split(".");
const latest = latestVersion.split(".");
for (let i = 0; i < current.length; i++) {
if (parseInt(latest[i]) < parseInt(current[i])) {
return false;
if (parseInt(latest[i]) > parseInt(current[i])) {
return true;
}
}
return true;
return false;
}
const hasNewVersion = computed(() => {
return isNewVersion(version.value, latestVersion.value);
});
async function loadLatestVersion() {
latestVersion.value = await api.GetLatestVersion();
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 siteInfo: Ref<SiteInfo> = computed(() => {