diff --git a/auto-imports.d.ts b/auto-imports.d.ts index f5718a5..edb50a1 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -235,6 +235,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 @@ -574,6 +575,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 1aa521f..f7b0c5a 100644 --- a/src/App.vue +++ b/src/App.vue @@ -4,6 +4,7 @@ import { App as CapacitorApp } from "@capacitor/app"; const userStore = useUserStore(); const { isAuthenticated } = storeToRefs(userStore); const { loadSavedLanguage } = useLanguage(); +const platform = usePlatform(); onBeforeMount(() => { loadSavedLanguage(); @@ -24,7 +25,7 @@ onMounted(() => { 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"; +}