feat: 添加应用版本检查与更新提示功能;更新环境变量以支持版本管理

This commit is contained in:
2025-12-30 18:18:02 +07:00
parent e7e2b1bd85
commit 5b1ebac9c4
6 changed files with 22 additions and 10 deletions

View File

@@ -1,6 +1,6 @@
import type { VersionInfo } from "@/api/types";
import { App } from "@capacitor/app";
import { alertController, modalController } from "@ionic/vue";
import { alertController } from "@ionic/vue";
import { client } from "@/api";
import { i18n } from "@/locales";
@@ -28,8 +28,14 @@ function compareVersion(version1: string, version2: string): number {
return 0;
}
const updateUrls = {
ios: "https://apps.apple.com/app/id123456789",
android: "https://play.google.com/store/apps/details?id=riwa.ionic.app",
browser: "",
} as const;
/**
* 应用更新检查组合式函数
* 应用更新检查
*/
export function useAppUpdate() {
const isChecking = ref(false);
@@ -53,7 +59,7 @@ export function useAppUpdate() {
}
// Web 平台从环境变量或 package.json 获取
return import.meta.env.VITE_APP_VERSION || "0.0.1";
return import.meta.env.VITE_APP_VERSION;
}
catch (error) {
console.error("获取当前版本失败:", error);
@@ -93,11 +99,7 @@ export function useAppUpdate() {
version: "0.0.2", // 模拟有新版本
forceUpdate: false,
updateMessage: "修复了一些问题并优化了性能",
updateUrl: platform === "ios"
? "https://apps.apple.com/app/id123456789"
: platform === "android"
? "https://play.google.com/store/apps/details?id=riwa.ionic.app"
: "",
updateUrl: updateUrls[platform] || "",
minSupportVersion: "0.0.1",
};