MainTabShellPortrait.uvue 2.82 KB
<template>
	<view class="main-tab-shell-root">
		<view class="main-tab-shell-body main-tab-shell-body-portrait">
			<view class="main-tab-shell-slot main-tab-shell-slot-portrait">
				<slot :user-info="slotUserInfo"></slot>
			</view>
			<HomeFrameTabbarPortrait :current-tab-index="currentTabIndex"
			                         :scene-type-list="sceneTypeList"
			                         :show-scene-popup="showScenePopup"
			                         :show-setting="showSetting"
			                         @tab-change="onTabChange"
			                         @scene-popup-visible="onScenePopupVisible"
			                         @setting-visible="onSettingVisible"
			                         @choose-scene="onChooseScene" />
		</view>
	</view>
</template>

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

import HomeFrameTabbarPortrait from "./TabbarPortrait.uvue";
import type { HomeFrameTabbarSource } from "./tabbarShared.uts";
import { SCENE_SHELL_USER_INFO_INJECT_KEY, useHomeFrameTabbar } from "./tabbarShared.uts";
import { storage } from "@/utils/storage.uts";

type MainTabShellSlotProps = {
	userInfo: UTSJSONObject
};

type MainTabShellSlots = {
	default(props: MainTabShellSlotProps): any
};

defineSlots<MainTabShellSlots>();

const props = defineProps<{
  activeTabIndex: number
}>();

const shellUserInfoRef = inject(SCENE_SHELL_USER_INFO_INJECT_KEY, null) as Ref<UTSJSONObject> | null;

const tabbarSource: HomeFrameTabbarSource = {
	getTabIndex: (): number => props.activeTabIndex,
	getUserInfo: (): null | UTSJSONObject => {
		const r = shellUserInfoRef;
		if (r != null) {
			return r.value as UTSJSONObject;
		}
		return storage.get("userInfo") as null | UTSJSONObject;
	}
};

const _tabbar = useHomeFrameTabbar(tabbarSource);
const currentTabIndex = _tabbar.currentTabIndex;
const sceneTypeList = _tabbar.sceneTypeList;
const showScenePopup = _tabbar.showScenePopup;
const showSetting = _tabbar.showSetting;
const onTabChange = _tabbar.onTabChange;
const onScenePopupVisible = _tabbar.onScenePopupVisible;
const onSettingVisible = _tabbar.onSettingVisible;
const onChooseScene = _tabbar.onChooseScene;

const slotUserInfo = computed((): UTSJSONObject => {
	const r = shellUserInfoRef;
	if (r != null) {
		return r.value as UTSJSONObject;
	}
	const raw = storage.get("userInfo");
	return raw != null ? raw as UTSJSONObject : ({} as UTSJSONObject);
});
</script>

<style scoped lang="scss">
.main-tab-shell-root {
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;
	min-height: 0;
	min-width: 0;
}

.main-tab-shell-body-portrait {
	flex: 1;
	display: flex;
	flex-direction: column;
	width: 100%;
	height: 100%;
	min-height: 0;
	min-width: 0;
	overflow: hidden;
}

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