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,3 +1,4 @@
VITE_API_URL=http://192.168.1.3:9528
VITE_TRADINGVIEW_LIBRARY_URL=http://192.168.1.5:6173
VITE_TRADINGVIEW_DATA_API_URL=https://demo-feed-data.tradingview.com
VITE_TRADINGVIEW_DATA_API_URL=https://demo-feed-data.tradingview.com
VITE_APP_VERSION=0.0.1

View File

@@ -1,3 +1,4 @@
VITE_API_URL=http://192.168.1.3:9527
VITE_TRADINGVIEW_LIBRARY_URL=http://192.168.1.5:6173
VITE_TRADINGVIEW_DATA_API_URL=https://demo-feed-data.tradingview.com
VITE_TRADINGVIEW_DATA_API_URL=https://demo-feed-data.tradingview.com
VITE_APP_VERSION=0.0.1

View File

@@ -7,6 +7,7 @@ const { locale, loadSavedLanguage } = useLanguage();
const { initializeWallet } = useWalletStore();
const { updateProfile } = useUserStore();
const platform = usePlatform();
const { checkAndPromptUpdate } = useAppUpdate();
onMounted(() => {
if (!isAuthenticated.value)
@@ -18,6 +19,9 @@ onMounted(() => {
userStore.updateProfile();
}
});
useTimeoutFn(() => {
checkAndPromptUpdate();
}, 3000);
});
onBeforeMount(() => {

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",
};

1
types/env.d.ts vendored
View File

@@ -12,6 +12,7 @@ interface ImportMetaEnv {
readonly VITE_API_URL: string;
readonly VITE_TRADINGVIEW_LIBRARY_URL: string;
readonly VITE_TRADINGVIEW_DATA_API_URL: string;
readonly VITE_APP_VERSION: string;
}
interface ImportMeta {

View File

@@ -35,6 +35,9 @@ export default defineConfig({
resolvers: [IonicResolver(), iconsResolver({ prefix: "i" })],
}),
],
define: {
APP_VERSION: JSON.stringify(process.env.VITE_APP_VERSION || "0.0.1"),
},
resolve: {
alias: {
"@": path.resolve(__dirname, "./src"),