diff --git a/.env.development b/.env.development index a376891..3d63d7f 100644 --- a/.env.development +++ b/.env.development @@ -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 \ No newline at end of file +VITE_TRADINGVIEW_DATA_API_URL=https://demo-feed-data.tradingview.com +VITE_APP_VERSION=0.0.1 \ No newline at end of file diff --git a/.env.production b/.env.production index 28ba411..2c09e7e 100644 --- a/.env.production +++ b/.env.production @@ -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 \ No newline at end of file +VITE_TRADINGVIEW_DATA_API_URL=https://demo-feed-data.tradingview.com +VITE_APP_VERSION=0.0.1 \ No newline at end of file diff --git a/src/App.vue b/src/App.vue index 894aff4..5b20fc1 100644 --- a/src/App.vue +++ b/src/App.vue @@ -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(() => { diff --git a/src/composables/useAppUpdate.ts b/src/composables/useAppUpdate.ts index 93817b8..919816b 100644 --- a/src/composables/useAppUpdate.ts +++ b/src/composables/useAppUpdate.ts @@ -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", }; diff --git a/types/env.d.ts b/types/env.d.ts index d7590c3..31ee272 100644 --- a/types/env.d.ts +++ b/types/env.d.ts @@ -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 { diff --git a/vite.config.ts b/vite.config.ts index eafe448..e9cc781 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -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"),