TabBarShell.uvue
3.61 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<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>