MainTabShellLandscape.uvue 3.21 KB
<template>
	<view class="main-tab-shell-root">
		<view class="main-tab-shell-body main-tab-shell-body-landscape">
			<HomeFrameTabbarLandscape :user-name="userName"
			                          :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"
			                          @scene-change="onSceneChange"
			                          @setting="onSetting"
			                          @choose-scene="onChooseScene"
			                          @jump-person-center="jumpPersonCenter" />
			<view class="main-tab-shell-slot main-tab-shell-slot-landscape">
				<slot :user-info="slotUserInfo"></slot>
			</view>
		</view>
	</view>
</template>

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

import HomeFrameTabbarLandscape from "./TabbarLandscape.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 userName = _tabbar.userName;
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 onSceneChange = _tabbar.onSceneChange;
const onSetting = _tabbar.onSetting;
const onChooseScene = _tabbar.onChooseScene;
const jumpPersonCenter = _tabbar.jumpPersonCenter;

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-landscape {
	flex: 1;
	display: flex;
	flex-direction: row;
	width: 100%;
	height: 100%;
	min-height: 0;
	min-width: 0;
	overflow: hidden;
}

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