feat: 添加应用版本检查与更新提示功能;更新环境变量以支持版本管理
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
VITE_API_URL=http://192.168.1.3:9528
|
VITE_API_URL=http://192.168.1.3:9528
|
||||||
VITE_TRADINGVIEW_LIBRARY_URL=http://192.168.1.5:6173
|
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
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
VITE_API_URL=http://192.168.1.3:9527
|
VITE_API_URL=http://192.168.1.3:9527
|
||||||
VITE_TRADINGVIEW_LIBRARY_URL=http://192.168.1.5:6173
|
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
|
||||||
@@ -7,6 +7,7 @@ const { locale, loadSavedLanguage } = useLanguage();
|
|||||||
const { initializeWallet } = useWalletStore();
|
const { initializeWallet } = useWalletStore();
|
||||||
const { updateProfile } = useUserStore();
|
const { updateProfile } = useUserStore();
|
||||||
const platform = usePlatform();
|
const platform = usePlatform();
|
||||||
|
const { checkAndPromptUpdate } = useAppUpdate();
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
if (!isAuthenticated.value)
|
if (!isAuthenticated.value)
|
||||||
@@ -18,6 +19,9 @@ onMounted(() => {
|
|||||||
userStore.updateProfile();
|
userStore.updateProfile();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
useTimeoutFn(() => {
|
||||||
|
checkAndPromptUpdate();
|
||||||
|
}, 3000);
|
||||||
});
|
});
|
||||||
|
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import type { VersionInfo } from "@/api/types";
|
import type { VersionInfo } from "@/api/types";
|
||||||
import { App } from "@capacitor/app";
|
import { App } from "@capacitor/app";
|
||||||
import { alertController, modalController } from "@ionic/vue";
|
import { alertController } from "@ionic/vue";
|
||||||
import { client } from "@/api";
|
import { client } from "@/api";
|
||||||
import { i18n } from "@/locales";
|
import { i18n } from "@/locales";
|
||||||
|
|
||||||
@@ -28,8 +28,14 @@ function compareVersion(version1: string, version2: string): number {
|
|||||||
return 0;
|
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() {
|
export function useAppUpdate() {
|
||||||
const isChecking = ref(false);
|
const isChecking = ref(false);
|
||||||
@@ -53,7 +59,7 @@ export function useAppUpdate() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Web 平台从环境变量或 package.json 获取
|
// Web 平台从环境变量或 package.json 获取
|
||||||
return import.meta.env.VITE_APP_VERSION || "0.0.1";
|
return import.meta.env.VITE_APP_VERSION;
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error("获取当前版本失败:", error);
|
console.error("获取当前版本失败:", error);
|
||||||
@@ -93,11 +99,7 @@ export function useAppUpdate() {
|
|||||||
version: "0.0.2", // 模拟有新版本
|
version: "0.0.2", // 模拟有新版本
|
||||||
forceUpdate: false,
|
forceUpdate: false,
|
||||||
updateMessage: "修复了一些问题并优化了性能",
|
updateMessage: "修复了一些问题并优化了性能",
|
||||||
updateUrl: platform === "ios"
|
updateUrl: updateUrls[platform] || "",
|
||||||
? "https://apps.apple.com/app/id123456789"
|
|
||||||
: platform === "android"
|
|
||||||
? "https://play.google.com/store/apps/details?id=riwa.ionic.app"
|
|
||||||
: "",
|
|
||||||
minSupportVersion: "0.0.1",
|
minSupportVersion: "0.0.1",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
1
types/env.d.ts
vendored
1
types/env.d.ts
vendored
@@ -12,6 +12,7 @@ interface ImportMetaEnv {
|
|||||||
readonly VITE_API_URL: string;
|
readonly VITE_API_URL: string;
|
||||||
readonly VITE_TRADINGVIEW_LIBRARY_URL: string;
|
readonly VITE_TRADINGVIEW_LIBRARY_URL: string;
|
||||||
readonly VITE_TRADINGVIEW_DATA_API_URL: string;
|
readonly VITE_TRADINGVIEW_DATA_API_URL: string;
|
||||||
|
readonly VITE_APP_VERSION: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface ImportMeta {
|
interface ImportMeta {
|
||||||
|
|||||||
@@ -35,6 +35,9 @@ export default defineConfig({
|
|||||||
resolvers: [IonicResolver(), iconsResolver({ prefix: "i" })],
|
resolvers: [IonicResolver(), iconsResolver({ prefix: "i" })],
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
|
define: {
|
||||||
|
APP_VERSION: JSON.stringify(process.env.VITE_APP_VERSION || "0.0.1"),
|
||||||
|
},
|
||||||
resolve: {
|
resolve: {
|
||||||
alias: {
|
alias: {
|
||||||
"@": path.resolve(__dirname, "./src"),
|
"@": path.resolve(__dirname, "./src"),
|
||||||
|
|||||||
Reference in New Issue
Block a user