Commit 07c9557e by 岑成威

fix: 改造tabbar

1 parent d3f276a6
......@@ -2,6 +2,7 @@
"version" : "1.0",
"configurations" : [
{
"customPlaygroundType" : "local",
"playground" : "custom",
"type" : "uni-app:app-android"
}
......
<template>
<view class="home-frame-container"
:key="adapterClass"
:class="[modeClass, resolutionClass, adapterClass]">
<view class="home-content">
<HomeFrameTabbar :adapter-class="adapterClass"
:tab-index="activeTabIndex"
:user-info="userInfo" />
<view class="right-side">
<slot :user-info="userInfo"></slot>
</view>
<HomeFrameLeftSide :adapter-class="adapterClass"
:tab-index="activeTabIndex"
:user-info="userInfo" />
</view>
</view>
</template>
......@@ -21,7 +20,7 @@ import { layoutService } from "@/services/LayoutService.uts";
import { requestRecordPermission } from "@/utils/permission.uts";
import { storage } from "@/utils/storage.uts";
import HomeFrameLeftSide from "./LeftSide.uvue";
import HomeFrameTabbar from "./Tabbar.uvue";
type SceneShellSlotProps = {
userInfo: UTSJSONObject
......
<template>
<!-- 横屏 / Pad:左侧竖向导航(头像 + 场景切换 + 设置) -->
<!-- 横屏 / Pad:左侧竖向导航(头像 + un-tabbar + 设置) -->
<view v-if="!isPortraitMode"
:key="adapterClassName"
class="left-side left-side-pad"
class="home-tabbar home-tabbar-landscape"
:class="[adapterClassName]">
<image class="left-side-bg-img"
<image class="home-tabbar-bg-img"
mode="aspectFill"
src="/static/images/home/left-bg.png" />
<view class="user-box user-box-clickable" @click="jumpPersonCenter">
......@@ -13,48 +12,63 @@
<text class="user-name-text">{{ userName }}</text>
</view>
</view>
<view class="left-tabs">
<view v-for="(item, index) in tabs"
:key="index"
class="tab-item"
:class="[currentTabIndex === index ? 'tabActive' : '']"
@click="onChangeTab(index)">
<view class="icon-box">
<view class="icon-placeholder" :class="[currentTabIndex === index ? 'icon-active' : '']"></view>
</view>
<text class="tab-label">{{ item.label }}</text>
</view>
<view class="landscape-tabbar-wrap">
<un-tabbar :model-value="currentTabIndex"
class="landscape-un-tabbar"
:custom-style="landscapeTabbarRootStyle"
:fixed="false"
:placeholder="false"
:safe-area-inset-bottom="false"
active-color="#3773f8"
inactive-color="#8a98b5"
bg-color="transparent"
:height="landscapeTabbarInnerHeight"
@change="onTabChange(($event as string | number))">
<un-tabbar-item v-for="(item, index) in tabs"
:key="index"
:name="index"
:text="item.label"
:icon-size="landscapeTabbarIconSize">
<template #icon="{ active }">
<image v-if="active === true"
class="tabbar-icon-img"
mode="aspectFit"
:src="getTabIconSrc(item.icon, true)" />
<image v-else
class="tabbar-icon-img"
mode="aspectFit"
:src="getTabIconSrc(item.icon, false)" />
</template>
</un-tabbar-item>
</un-tabbar>
</view>
<view class="left-footer flex-col">
<view class="home-tabbar-footer flex-col">
<view class="btn-placeholder" @tap="onSceneChange"></view>
<view class="btn-placeholder" @tap="onSetting"></view>
</view>
<!-- 切换场景弹窗:用 visible 受控,避免 UTS 下 ref+expose 的强转问题 -->
<CenterPopup :list="sceneTypeList"
title="选择场景"
:visible="showScenePopup"
@choose="onChooseScene"
@update:visible="onScenePopupVisible" />
<!-- 设置弹窗 -->
<SettingBox :visible="showSetting"
@update:visible="onSettingVisible" />
</view>
<!-- 竖屏手机:uView 底部 TabBar,图标沿用 static/images/tabbar -->
<!-- 竖屏手机:底部 TabBar -->
<view v-else
:key="adapterClassName"
class="left-side left-side-portrait"
:class="[adapterClassName, isPadPortraitMode ? 'left-side-portrait-pad' : '']">
class="home-tabbar home-tabbar-portrait"
:class="[adapterClassName, isPadPortraitMode ? 'home-tabbar-portrait-pad' : '']">
<un-tabbar :model-value="currentTabIndex"
class="portrait-un-tabbar"
:fixed="false"
:fixed="true"
:placeholder="false"
:safe-area-inset-bottom="true"
active-color="#3773f8"
inactive-color="#8a98b5"
bg-color="#ffffff"
:height="tabbarHeight"
@change="onPortraitTabChange(($event as string | number))">
@change="onTabChange(($event as string | number))">
<un-tabbar-item v-for="(item, index) in tabs"
:key="index"
:name="index"
......@@ -85,7 +99,6 @@ import { storage } from "@/utils/storage.uts";
import SettingBox from "@/pages/person/SettingBox.uvue";
// 导入样式变量
import { getLandscapeConfig } from "./styles/landscape.uts";
import { getPortraitConfig, PORTRAIT_COMMON } from "./styles/portrait.uts";
......@@ -113,36 +126,54 @@ const isPadPortraitMode = computed((): boolean => {
return cls.indexOf("layout-portrait-768x1174") >= 0;
});
// TabBar 高度 - 根据分辨率动态设置
const tabbarHeight = computed((): number => {
// 使用 cssClassRef.value 确保响应式
const adapterCls = cssClassRef.value;
// 竖屏配置
const portraitConfig = getPortraitConfig(adapterCls);
if (portraitConfig != null) {
return portraitConfig.tabbarHeight as number;
}
// 默认值
return PORTRAIT_COMMON.tabbarHeight as number;
});
// TabBar 图标尺寸 - 根据分辨率动态设置
const tabbarIconSize = computed((): number => {
// 使用 cssClassRef.value 确保响应式
const adapterCls = cssClassRef.value;
// 竖屏配置
const portraitConfig = getPortraitConfig(adapterCls);
if (portraitConfig != null) {
return portraitConfig.tabbarIconSize as number;
}
// 默认值
return PORTRAIT_COMMON.tabbarIconSize as number;
});
/** 横屏:un-tabbar 根节点纵向排布,高度与分辨率配置对齐 */
const landscapeTabbarRootStyle = computed((): string => {
const adapterCls = cssClassRef.value;
const lc = getLandscapeConfig(adapterCls);
const h = lc != null ? lc.leftTabsHeight : "540px";
const padLeft = lc != null ? lc.leftTabsPaddingLeft : "16px";
return `display:flex;flex-direction:column;align-items:center;justify-content:center;width:100%;height:${h};padding-left:${padLeft};padding-top:8px;padding-bottom:8px;box-sizing:border-box;`;
});
/** 横屏单项行高(un-tabbar 内部横向条高度,竖向排列时每行占位) */
const landscapeTabbarInnerHeight = computed((): number => {
const adapterCls = cssClassRef.value;
const lc = getLandscapeConfig(adapterCls);
if (lc != null && adapterCls.indexOf("1920") >= 0) {
return 64;
}
if (lc != null) {
return 58;
}
return 56;
});
const landscapeTabbarIconSize = computed((): number => {
const adapterCls = cssClassRef.value;
if (adapterCls.indexOf("1920") >= 0) {
return 32;
}
return 28;
});
const currentTabIndex = computed((): number => {
const idx = props.tabIndex as null | number;
return idx != null ? idx : 0;
......@@ -220,8 +251,6 @@ const tabs: TabItem[] = [
{ label: "首页", icon: "home", name: "HomeSlot" },
{ label: "接待中心", icon: "record", name: "ReceptionCenter" },
{ label: "我的", icon: "my", name: "MyCenter" },
// { label: "场景集市", icon: "scene", name: "SceneMarket" },
// { label: "活动中心", icon: "activity", name: "ActivityCenter" }
];
function getTabIconSrc(icon: string, active: boolean): string {
......@@ -246,8 +275,6 @@ const userName = computed((): string => {
return "";
}
const obj = info as UTSJSONObject;
// 与旧项目一致优先用 name;接口可能返回 staffName;无则用 merchantName
// App 端 storage 可能解析出 number,统一转 string 保证 text 能显示
const raw = obj.name ?? obj.staffName ?? obj.merchantName;
if (raw == null) {
return "";
......@@ -274,7 +301,6 @@ function resolveMainHomeUrl(): string {
return url;
}
/** 与 pages.json 的 path 一致(不含前导 /);失败时再试无前导 /,兼容部分运行时装载表差异 */
function reLaunchPage(pagesJsonPath: string): void {
const trimmed = pagesJsonPath.startsWith("/") ? pagesJsonPath.substring(1) : pagesJsonPath;
const withSlash = "/" + trimmed;
......@@ -296,7 +322,6 @@ function navigateToTab(index: number): void {
return;
}
if (index == 1) {
// 放在 pages 根目录短路径,避免深层目录在部分构建里未进路由表(reLaunch errCode 4)
reLaunchPage("pages/receptionShell");
return;
}
......@@ -306,11 +331,7 @@ function navigateToTab(index: number): void {
}
}
function onChangeTab(index: number): void {
navigateToTab(index);
}
function onPortraitTabChange(name: string | number): void {
function onTabChange(name: string | number): void {
const idx = name as number;
navigateToTab(idx);
}
......@@ -362,4 +383,19 @@ function jumpPersonCenter(): void {
<style scoped lang="scss">
@import "./styles/common.scss";
/* un-tabbar 为加密包,横屏需自上而下:穿透内部承载 tab 项的横向 flex 容器 */
.home-tabbar-landscape .landscape-un-tabbar > :deep(view) {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
}
.home-tabbar-landscape .landscape-un-tabbar > :deep(view) > :deep(view) {
display: flex;
flex-direction: column;
align-items: center;
width: 100%;
}
</style>
<template>
<view class="home-frame-container"
:key="adapterClass"
:class="[modeClass, resolutionClass, adapterClass]">
<!-- 首页内容区:横竖方向由容器 modeClass + common.scss 控制 .home-content -->
<view class="home-content">
<!-- Tabbar 在前:横屏 row 时自然在屏幕左侧;竖屏仍靠 order 把主内容置上 -->
<HomeFrameTabbar :adapter-class="adapterClass"
:tab-index="0"
:user-info="userInfo" />
<view class="right-side">
<!-- 仅「场景首页」:接待中心 / 我的 为独立路由页(见 LeftSide 导航) -->
<!-- 仅「场景首页」:接待中心 / 我的 为独立路由页(见 HomeFrameTabbar) -->
<!-- 三卡片布局:轻改 / 权益等使用 swiperCustom -->
<view v-if="useCardLayout" class="app-content-box right-content show-content-box">
<view v-if="resolvedShowStartReception"
......@@ -64,10 +67,6 @@
</view>
</view>
</view>
<HomeFrameLeftSide :adapter-class="adapterClass"
:tab-index="0"
:user-info="userInfo" />
</view>
</view>
</template>
......@@ -83,7 +82,7 @@ import { layoutService } from "@/services/LayoutService.uts";
import { requestRecordPermission } from "@/utils/permission.uts";
import { storage } from "@/utils/storage.uts";
import HomeFrameLeftSide from "./LeftSide.uvue";
import HomeFrameTabbar from "./Tabbar.uvue";
import HomeFrameMessageIndex from "./MessageIndex.uvue";
import ProductIntroSwiper from "./ProductIntroSwiper.uvue";
......
......@@ -30,6 +30,8 @@
.mode-landscape .home-content {
flex-direction: row;
/* 避免系统 RTL 下「第一个子节点」跑到视觉右侧,侧栏需始终在物理左侧 */
direction: ltr;
}
.right-side {
......@@ -43,12 +45,15 @@
order: 1;
}
.mode-portrait .left-side-portrait {
.mode-portrait .home-tabbar-portrait {
order: 2;
}
/* 横屏:Tabbar 在 DOM 中已先于 right-side,侧栏在物理左侧 */
// ===== 应用内容区 =====
.app-content-box {
/* 横屏:与左侧 Tabbar 用户区视觉对齐;竖屏见下方 .mode-portrait 覆盖 */
margin-top: 40px;
flex: 1;
display: flex;
......@@ -56,6 +61,10 @@
overflow: hidden;
}
.mode-portrait .app-content-box {
margin-top: 0;
}
.right-content {
padding: 0 var(--l-spacing-xl) 0 var(--l-spacing-md);
}
......@@ -344,8 +353,8 @@
background: linear-gradient(to right, #eeeeee, rgba(216, 216, 216, 0));
}
// ===== LeftSide 横屏导航基础样式 =====
.left-side {
// ===== HomeFrame Tabbar(横屏左侧 / 竖屏底部)=====
.home-tabbar {
display: flex;
flex-direction: column;
position: relative;
......@@ -353,7 +362,7 @@
flex-shrink: 0;
background-image: linear-gradient(to bottom, #e8f0fe, #e8ecf5);
.left-side-bg-img {
.home-tabbar-bg-img {
position: absolute;
left: 0;
top: 0;
......@@ -364,17 +373,18 @@
}
.user-box,
.left-tabs,
.left-footer {
.landscape-tabbar-wrap,
.home-tabbar-footer {
position: relative;
z-index: 1;
}
}
.left-side-pad {
.home-tabbar-landscape {
min-height: 0;
}
.left-side-portrait {
.home-tabbar-portrait {
width: 100%;
flex-shrink: 0;
flex-direction: column;
......@@ -397,7 +407,7 @@
height: 30px;
}
.left-side-portrait-pad {
.home-tabbar-portrait-pad {
padding-bottom: 6px;
}
......@@ -468,62 +478,24 @@
text-align: center;
}
// LeftSide 横屏导航基础样式
.left-tabs {
// 横屏:中间区域放 un-tabbar(组件根节点通过 custom-style 纵向排列)
.landscape-tabbar-wrap {
flex: 1;
min-height: 0;
width: 100%;
height: 540px;
display: flex;
flex-direction: column;
justify-content: center;
position: absolute;
left: 0;
padding: 8px 0;
padding-left: 16px;
}
.tab-item {
width: 80px;
display: flex;
flex-direction: column;
align-items: center;
margin-bottom: 12.5px;
}
.icon-box {
width: 52px;
height: 52px;
display: flex;
flex-direction: row;
justify-content: center;
align-items: center;
border-radius: 26px;
}
.icon-placeholder {
width: 32px;
height: 32px;
background-color: #8a98b5;
border-radius: 8px;
}
.icon-active {
background-color: #3773f8;
}
.tab-label {
font-size: 13px;
color: #8a98b5;
margin-top: 6px;
text-align: center;
}
.tabActive {
.tab-label {
color: #3773f8;
}
.landscape-un-tabbar {
width: 100%;
flex: 1;
min-height: 0;
}
.left-footer {
.home-tabbar-footer {
margin-top: auto;
padding-bottom: 40px;
}
......
......@@ -12,7 +12,7 @@ export type LandscapeConfig = {
toolBoxHeight: string
toolBoxContentPaddingBottom?: string
// LeftSide 导航
// HomeFrame Tabbar(横屏)
leftTabsHeight: string
leftTabsPaddingLeft: string
iconBoxSize: string
......@@ -30,7 +30,7 @@ export const LANDSCAPE_1174x768: LandscapeConfig = {
toolBoxHeight: '152px',
toolBoxContentPaddingBottom: '14px',
// LeftSide 导航
// HomeFrame Tabbar(横屏)
leftTabsHeight: '560px',
leftTabsPaddingLeft: '18px',
iconBoxSize: '56px',
......@@ -46,7 +46,7 @@ export const LANDSCAPE_1920x1080: LandscapeConfig = {
moduleBoxHeight: '320px',
toolBoxHeight: '480px',
// LeftSide 导航
// HomeFrame Tabbar(横屏)
leftTabsHeight: '620px',
leftTabsPaddingLeft: '22px',
iconBoxSize: '64px',
......
......@@ -15,7 +15,7 @@ export type PortraitConfig = {
toolBoxMarginBottom?: string
toolBoxHeight?: string
// LeftSide TabBar
// HomeFrame Tabbar(竖屏)
leftSidePortraitPaddingBottom?: string
tabbarHeight: number
tabbarIconSize: number
......@@ -34,7 +34,7 @@ export const PORTRAIT_768x1174: PortraitConfig = {
toolBoxHeight: '552px',
toolBoxMarginBottom: '60px',
// LeftSide TabBar
// HomeFrame Tabbar(竖屏)
leftSidePortraitPaddingBottom: '8px',
tabbarHeight: 106,
tabbarIconSize: 60
......@@ -44,7 +44,7 @@ export const PORTRAIT_768x1174: PortraitConfig = {
* 其他竖屏分辨率(默认)
*/
export const PORTRAIT_COMMON: PortraitConfig = {
// LeftSide TabBar
// HomeFrame Tabbar(竖屏)
tabbarHeight: 56,
tabbarIconSize: 24
};
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!