SceneShell.uvue 2.1 KB
<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>