Commit 07c9557e by 岑成威

fix: 改造tabbar

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