TabbarLandscape.uvue 5.82 KB
<template>
	<view class="home-tabbar home-tabbar-landscape">
		<!-- <image class="home-tabbar-bg-img"
		       mode="aspectFill"
		       src="/static/images/home/left-bg.png" /> -->
		<view class="hf-landscape-column">
			<view class="user-box user-box-clickable hf-landscape-user"
			      @click="emit('jumpPersonCenter')">
				<view class="hf-landscape-profile">
					<un-avatar :text="avatarText"
					           shape="circle"
					           size="42"
					           bgColor="#2f6af7"
					           color="#ffffff"
					           fontSize="20" />
					<text class="hf-landscape-name">{{ userName }}</text>
				</view>
			</view>
		</view>
		<view class="landscape-tabbar-wrap">
			<view class="landscape-un-tabbar landscape-vertical-tabs">
				<view v-for="(item, index) in tabs"
				      :key="index"
				      class="landscape-vertical-tabs__item"
				      :class="index === currentTabIndex ? 'landscape-vertical-tabs__item--active' : ''"
				      @click="onTabItemClick(index)">
					<view class="landscape-vertical-tabs__inner">
						<image class="landscape-vertical-tabs__icon"
						       mode="aspectFit"
						       :src="index === currentTabIndex ? item.iconSrcActive : item.iconSrcInactive" />
						<text class="landscape-vertical-tabs__label">{{ item.label }}</text>
					</view>
				</view>
			</view>
		</view>
		<view class="home-tabbar-footer flex-col hf-landscape-footer">
			<view class="hf-landscape-footer-btn"
			      @tap="emit('sceneChange')">
				<image class="hf-landscape-footer-icon"
				       mode="aspectFit"
				       src="/static/images/home/scene-change.png" />
			</view>
			<view class="hf-landscape-footer-btn hf-landscape-footer-btn--after"
			      @tap="emit('setting')">
				<image class="hf-landscape-footer-icon"
				       mode="aspectFit"
				       src="/static/images/home/setting.png" />
			</view>
		</view>
		<CenterPopup :list="sceneTypeList"
		             title="选择场景"
		             :visible="showScenePopup"
		             @choose="emit('chooseScene', $event)"
		             @update:visible="emit('scenePopupVisible', $event)" />
		<SettingBox :visible="showSetting"
		            @update:visible="emit('settingVisible', $event)" />
	</view>
</template>

<script setup lang="uts">
import { computed } from "vue";

import CenterPopup from "@/components/CenterPopup.uvue";
import SettingBox from "@/pages/person/SettingBox.uvue";

import { HOME_FRAME_TABS } from "./tabbarShared.uts";

const props = defineProps<{
  userName: string
  currentTabIndex: number
  sceneTypeList: UTSJSONObject[]
  showScenePopup: boolean
  showSetting: boolean
}>();

const emit = defineEmits<{
  tabChange: [name: string | number]
  scenePopupVisible: [v: boolean]
  settingVisible: [v: boolean]
  sceneChange: []
  setting: []
  chooseScene: [index: number]
  jumpPersonCenter: []
}>();

const tabs = HOME_FRAME_TABS;

/** 与 MyCenterMain 一致:姓名首字,空则「我」 */
const avatarText = computed((): string => {
	const n = props.userName;
	if (n == null || n === "") {
		return "我";
	}
	const s = n as string;
	if (s.length <= 0) {
		return "我";
	}
	return s.substring(0, 1);
});

function onTabItemClick(index: number): void {
	emit("tabChange", index);
}
</script>

<style scoped lang="scss">
@import "./styles/common.scss";

/* 顶部用户区:仅内容高度,不把中间 Tab 区挤没 */
.hf-landscape-column {
	flex-shrink: 0;
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	box-sizing: border-box;
	padding: 14px 10px 0;
	position: relative;
	z-index: 1;
}

/* 横屏侧栏:用户区 / Tab / 底按钮同一竖直中轴 */
.hf-landscape-user {
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	box-sizing: border-box;
	padding-top: 0;
	flex-shrink: 0;
}

.hf-landscape-profile {
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
}

/* 与 MyCenterMain .name 一致;与 Tab 文案同宽便于视觉对齐 */
.hf-landscape-name {
	margin-top: 10px;
	font-size: 14px;
	font-weight: 600;
	color: #1a2433;
	line-height: 24px;
	text-align: center;
	width: 100%;
	max-width: 104px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.hf-landscape-footer {
	width: 100%;
	display: flex;
	flex-direction: column;
	align-items: center;
	box-sizing: border-box;
	flex-shrink: 0;
	padding-left: 10px;
	padding-right: 10px;
}

.hf-landscape-footer-btn {
	width: 44px;
	height: 44px;
	display: flex;
	flex-direction: row;
	align-items: center;
	justify-content: center;
}

.hf-landscape-footer-btn--after {
	margin-top: 12px;
}

.hf-landscape-footer-icon {
	width: 40px;
	height: 40px;
	flex-shrink: 0;
}

/* 横屏侧栏 Tab:占满中间 landscape-tabbar-wrap,条目在剩余高度内垂直居中 */
.landscape-vertical-tabs {
	flex: 1;
	min-height: 0;
	width: 100%;
	padding-left: var(--tabbar-padding, 16px);
	padding-right: var(--tabbar-padding, 16px);
	padding-top: 8px;
	padding-bottom: 8px;
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
	box-sizing: border-box;
}

.landscape-vertical-tabs__item {
	width: 100%;
	display: flex;
	flex-direction: row;
	justify-content: center;
	align-items: center;
	padding: 18px 0;
	box-sizing: border-box;
}

.landscape-vertical-tabs__item + .landscape-vertical-tabs__item {
	margin-top: 10px;
}

.landscape-vertical-tabs__inner {
	display: flex;
	flex-direction: column;
	align-items: center;
	justify-content: center;
}

.landscape-vertical-tabs__icon {
	width: var(--tabbar-icon-size, 28px);
	height: var(--tabbar-icon-size, 28px);
	flex-shrink: 0;
}

.landscape-vertical-tabs__label {
	margin-top: 6px;
	font-size: 12px;
	color: #8a98b5;
	text-align: center;
	width: 100%;
	max-width: 104px;
	overflow: hidden;
	text-overflow: ellipsis;
	white-space: nowrap;
}

.landscape-vertical-tabs__item--active .landscape-vertical-tabs__label {
	color: #3773f8;
	font-weight: 500;
}
</style>