feat: 添加 usePlatform 组合函数并在 App 组件中使用,优化路由动画效果
This commit is contained in:
2
auto-imports.d.ts
vendored
2
auto-imports.d.ts
vendored
@@ -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<typeof import('@vueuse/core')['useParentElement']>
|
||||
readonly usePerformanceObserver: UnwrapRef<typeof import('@vueuse/core')['usePerformanceObserver']>
|
||||
readonly usePermission: UnwrapRef<typeof import('@vueuse/core')['usePermission']>
|
||||
readonly usePlatform: UnwrapRef<typeof import('./src/composables/usePlatform')['usePlatform']>
|
||||
readonly usePointer: UnwrapRef<typeof import('@vueuse/core')['usePointer']>
|
||||
readonly usePointerLock: UnwrapRef<typeof import('@vueuse/core')['usePointerLock']>
|
||||
readonly usePointerSwipe: UnwrapRef<typeof import('@vueuse/core')['usePointerSwipe']>
|
||||
|
||||
@@ -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(() => {
|
||||
<template>
|
||||
<IonApp>
|
||||
<Suspense>
|
||||
<IonRouterOutlet />
|
||||
<IonRouterOutlet :animated="platform !== 'browser'" />
|
||||
</Suspense>
|
||||
</IonApp>
|
||||
</template>
|
||||
|
||||
24
src/composables/usePlatform.ts
Normal file
24
src/composables/usePlatform.ts
Normal file
@@ -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";
|
||||
}
|
||||
Reference in New Issue
Block a user