SceneShell.uvue
2.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
<template>
<!-- 物理 tab 三页共用:横/竖两套壳 + 默认槽;方向由 updateOrientation + useOrientation 驱动 -->
<MainTabShellPortrait v-if="shellIsPortrait"
:active-tab-index="props.activeTabIndex">
<template #default="{ userInfo: u }">
<slot :user-info="u"></slot>
</template>
</MainTabShellPortrait>
<MainTabShellLandscape v-else
:active-tab-index="props.activeTabIndex">
<template #default="{ userInfo: u }">
<slot :user-info="u"></slot>
</template>
</MainTabShellLandscape>
</template>
<script setup lang="uts">
import { computed, defineExpose, onMounted, onResize, provide, ref, type Ref } from "vue";
import { updateOrientation, useOrientation } from "@/services/adapter/hooks/index.uts";
import { requestRecordPermission } from "@/utils/permission.uts";
import { storage } from "@/utils/storage.uts";
import { hideNativeTabBar } from "@/utils/tabBarShell.uts";
import MainTabShellLandscape from "./MainTabShellLandscape.uvue";
import MainTabShellPortrait from "./MainTabShellPortrait.uvue";
import { SCENE_SHELL_USER_INFO_INJECT_KEY } from "./tabbarShared.uts";
type SceneShellSlotProps = {
userInfo: UTSJSONObject
};
type SceneShellSlots = {
default(props: SceneShellSlotProps): any
};
defineSlots<SceneShellSlots>();
const props = defineProps<{
/** 当前 tab 页下标:0 首页、1 接待、2 我的(与 un-tabbar 高亮一致) */
activeTabIndex: number
}>();
updateOrientation();
const orientationHook = useOrientation();
const shellIsPortrait = computed((): boolean => {
const ip = orientationHook.isPortrait as Ref<boolean>;
return ip.value == true;
});
onMounted((): void => {
// await requestRecordPermission();
hideNativeTabBar();
updateOrientation();
});
onResize((_res: any): void => {
updateOrientation();
});
const userInfo = ref<UTSJSONObject>({});
provide(SCENE_SHELL_USER_INFO_INJECT_KEY, userInfo);
function updateApp(): void {
const info = storage.get("userInfo");
if (info != null) {
userInfo.value = info as UTSJSONObject;
}
}
onShow(() => {
hideNativeTabBar();
});
defineExpose({
updateApp
});
</script>