diff --git a/auto-imports.d.ts b/auto-imports.d.ts index b13f401..cd777b1 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -248,6 +248,7 @@ declare global { const useParentElement: typeof import('@vueuse/core').useParentElement const usePerformanceObserver: typeof import('@vueuse/core').usePerformanceObserver const usePermission: typeof import('@vueuse/core').usePermission + const usePlatform: typeof import('./src/composables/usePlatform').usePlatform const usePointer: typeof import('@vueuse/core').usePointer const usePointerLock: typeof import('@vueuse/core').usePointerLock const usePointerSwipe: typeof import('@vueuse/core').usePointerSwipe @@ -610,6 +611,7 @@ declare module 'vue' { readonly useParentElement: UnwrapRef readonly usePerformanceObserver: UnwrapRef readonly usePermission: UnwrapRef + readonly usePlatform: UnwrapRef readonly usePointer: UnwrapRef readonly usePointerLock: UnwrapRef readonly usePointerSwipe: UnwrapRef diff --git a/src/App.vue b/src/App.vue index 11553a7..894aff4 100644 --- a/src/App.vue +++ b/src/App.vue @@ -6,6 +6,7 @@ const { isAuthenticated } = storeToRefs(userStore); const { locale, loadSavedLanguage } = useLanguage(); const { initializeWallet } = useWalletStore(); const { updateProfile } = useUserStore(); +const platform = usePlatform(); onMounted(() => { if (!isAuthenticated.value) @@ -31,7 +32,7 @@ watch(locale, (newLocale) => { diff --git a/src/composables/usePlatform.ts b/src/composables/usePlatform.ts new file mode 100644 index 0000000..3350bbb --- /dev/null +++ b/src/composables/usePlatform.ts @@ -0,0 +1,24 @@ +import { Capacitor } from "@capacitor/core"; +import { getPlatforms } from "@ionic/vue"; + +export function usePlatform() { + const platforms = getPlatforms(); + + // 优先检测浏览器环境 + if (platforms.includes("desktop") || platforms.includes("mobileweb")) { + return "browser"; + } + + // 检测原生环境 + if (Capacitor.isNativePlatform()) { + if (platforms.includes("ios")) { + return "ios"; + } + + if (platforms.includes("android")) { + return "android"; + } + } + + return "browser"; +}