TabBarShell.uvue 3.61 KB
<template>
	<!-- TabBar 壳组件:横/竖两套布局 + 默认槽;方向由 useOrientation 驱动 -->
	<view v-if="shellIsPortrait" class="scene-shell-root-portrait">
		<view class="scene-shell-slot-portrait">
			<slot></slot>
		</view>
		<view class="scene-shell-tabbar-portrait">
			<Portrait :current-tab-index="props.activeTabIndex"
			                         @tab-change="onTabChange" />
		</view>
	</view>
	<view v-else class="scene-shell-root-landscape">
		<view class="scene-shell-body-landscape">
			<Landscape :user-name="userName"
			                          :current-tab-index="props.activeTabIndex"
			                          @tab-change="onTabChange"
			                          @setting="onSetting"
			                          @jump-person-center="jumpPersonCenter"
			                          @switch-store="onSwitchStore" />
			<view class="scene-shell-slot-landscape">
				<slot></slot>
			</view>
		</view>
	</view>
	<!-- ✅ 统一的设置弹窗(横竖屏共用) -->
	<SettingBox :visible="showSetting"
	            @update:visible="onSettingVisible" />
</template>

<script setup lang="uts">
import { computed, onMounted, onShow, type Ref } from "vue";

import SettingBox from "@/pages/person/SettingBox.uvue";
import { 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 Landscape from "./Landscape.uvue";
import Portrait from "./Portrait.uvue";
import type { HomeFrameTabbarSource } from "./tabbarShared.uts";
import { useHomeFrameTabbar } from "./tabbarShared.uts";

defineSlots();

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;
});

// ✅ Tabbar 逻辑(userInfo 从 storage 直接获取)
const tabbarSource: HomeFrameTabbarSource = {
	getTabIndex: (): number => props.activeTabIndex,
	getUserInfo: (): null | UTSJSONObject => {
		return storage.getUserInfo();
	}
};

const _tabbar = useHomeFrameTabbar(tabbarSource);
const userName = _tabbar.userName;
const showSetting = _tabbar.showSetting;
const onTabChange = _tabbar.onTabChange;
const onSettingVisible = _tabbar.onSettingVisible;
const onSetting = _tabbar.onSetting;
const jumpPersonCenter = _tabbar.jumpPersonCenter;
const onSwitchStore = _tabbar.onSwitchStore;

onMounted((): void => {
	requestRecordPermission();
	hideNativeTabBar();
});

onShow(() => {
	hideNativeTabBar();
});
</script>

<style scoped lang="scss">
/* ✅ 竖屏布局 */
.scene-shell-root-portrait {
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;
	min-height: 0;
	min-width: 0;
}

.scene-shell-slot-portrait {
	flex: 1;
	min-height: 0;
	min-width: 0;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}

.scene-shell-tabbar-portrait {
	height: var(--tabbar-height, 70px); /* ✅ 使用 CSS 变量控制 tabbar 高度 */
}

/* ✅ 横屏布局 */
.scene-shell-root-landscape {
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;
	min-height: 0;
	min-width: 0;
}

.scene-shell-body-landscape {
	flex: 1;
	display: flex;
	flex-direction: row;
	width: 100%;
	height: 100%;
	min-height: 0;
	min-width: 0;
	overflow: hidden;
}

.scene-shell-slot-landscape {
	flex: 1 1 0%;
	min-width: 0;
	min-height: 0;
	display: flex;
	flex-direction: column;
	overflow: hidden;
}
</style>