From b8ac4bf1f2035b8b9a6183a2f9632407ab67a13f Mon Sep 17 00:00:00 2001 From: Seven Date: Tue, 20 Jan 2026 16:02:21 +0700 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=20usePlatform=20?= =?UTF-8?q?=E7=BB=84=E5=90=88=E5=87=BD=E6=95=B0=E5=B9=B6=E5=9C=A8=20App=20?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E4=B8=AD=E4=BD=BF=E7=94=A8=EF=BC=8C=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E8=B7=AF=E7=94=B1=E5=8A=A8=E7=94=BB=E6=95=88=E6=9E=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- auto-imports.d.ts | 2 ++ src/App.vue | 3 ++- src/composables/usePlatform.ts | 24 ++++++++++++++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/composables/usePlatform.ts 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"; +}