/** * 家书 FamilyBook · 顶栏(鸿蒙端) * * 用户 2026-10-12 定的形态: * · **应用图标 + 「家书」标题**贴左上(下行小字显示当前模块); * · 顶栏底色**白色**(与下面的个人信息卡同色,连成一片); * · 顶栏**并入页面滚动流**,向上滑动时跟着内容一起滑走 * (所以它本身不固定、也不自己处理状态栏留白)。 * * 🔴 **顶栏不放汉堡按钮**(用户 2026-10-12 明确要求去掉): * 开抽屉改由**屏幕边缘滑动**触发(见 `Drawer.ets` 的 parallelGesture)—— * 从左边缘向右滑 ⇒ 抽屉在左;从右边缘向左滑 ⇒ 抽屉在右。 * ⇒ 图标能一直贴到最左边,视觉上更好看。 * ⚠️ 别再加回汉堡按钮;抽屉的其它入口是「顶栏头像」与「抽屉底部账号区」。 * * ⚠️ 顶栏**不放**「设置」—— 与 Web 端一致:设置收在抽屉底部的账号区里。 */ import { FbColors, FbIcon, FbMetric } from '../common/Theme'; import { FbAppState, fbAppState } from '../common/Store'; import { fbModuleOf } from '../model/Modules'; import { FbAvatar } from './Widgets'; @ComponentV2 export struct FbTopBar { @Param app: FbAppState = fbAppState(); /** 右侧额外操作(各模块页自己往里塞「新建」「搜索」等按钮) */ @BuilderParam actions: () => void; build() { Row({ space: 10 }) { // ---- 应用图标(贴最左:抽屉改由边缘滑动触发,这里不再有汉堡按钮)---- // ⚠️ 必须给描边:logo 是「米色底(74%) + 砖红图案(24%)」的实心方图, // 放在白色/米色上时底板与背景几乎同色,只剩砖红图案发飘、看不清。 // 一层极浅的描边就能把底板"托"出来(本机范本 SyncCalendar 也给了描边)。 Image($r('app.media.fb_logo')) .width(30) .height(30) .borderRadius(8) .border({ width: 1, color: FbColors.line }) .flexShrink(0) Column({ space: 0 }) { Text('家书') .fontSize(19) .fontWeight(FontWeight.Bold) .fontColor(FbColors.ink) .maxLines(1) // 副标题显示当前模块名 —— "品牌 + 当前位置"一行说清 Text(this.moduleName()) .fontSize(FbMetric.fontTiny) .fontColor(FbColors.muted) .maxLines(1) } .alignItems(HorizontalAlign.Start) .layoutWeight(1) // ---- 右:各模块自己的操作 ---- this.actions() // 通知铃铛(未读角标) Stack({ alignContent: Alignment.TopEnd }) { Button({ type: ButtonType.Circle }) { Image(FbIcon.ui('bell')) .width(18) .height(18) .renderMode(ImageRenderMode.Template) .fillColor(FbColors.muted) } .width(36) .height(36) .backgroundColor(Color.Transparent) .stateEffect(true) .onClick(() => { this.app.switchModule('__notifications'); }) if (this.app.unread > 0) { Text(this.app.unread > 99 ? '99+' : this.app.unread.toString()) .fontSize(10) .fontColor(Color.White) .backgroundColor(FbColors.red) .borderRadius(FbMetric.radiusPill) .padding({ left: 5, right: 5, top: 1, bottom: 1 }) .margin({ top: 2, right: 0 }) } } // 头像(点开账号菜单) FbAvatar({ name: this.app.session.me.name, color: this.app.session.me.avatarColor, dia: 32, fontSizeVp: 14 }) .margin({ left: 2 }) } .width('100%') .height(FbMetric.topBarH) // 左内边距=pagePad(与下面各区块的左边线对齐);右侧 10(图标可略贴边) .padding({ left: FbMetric.pagePad, right: 10, top: 4, bottom: 4 }) .alignItems(VerticalAlign.Center) // 顶栏底色 = 白色(与下面的个人信息卡同色) .backgroundColor(FbColors.surface) // 底线:与下方内容(同是白色卡)之间给一条极浅的分隔,避免"两块白糊在一起" .border({ width: { bottom: 1 }, color: FbColors.line2 }) } private moduleName(): string { const m = fbModuleOf(this.app.activeModule); return m !== undefined ? m.name : '家书'; } }