2026-10-11 22:07:48 +08:00
|
|
|
/**
|
|
|
|
|
* 家书 FamilyBook · 顶栏(鸿蒙端)
|
|
|
|
|
*
|
2026-10-12 10:06:55 +08:00
|
|
|
* 用户 2026-10-12 定的形态:
|
|
|
|
|
* · **应用图标 + 「家书」标题**贴左上(下行小字显示当前模块);
|
2026-10-12 12:06:00 +08:00
|
|
|
* · **点图标 = 开抽屉**(用户要求:汉堡按钮去掉后,把这个功能挪到图标上);
|
2026-10-12 10:06:55 +08:00
|
|
|
* · 顶栏底色**白色**(与下面的个人信息卡同色,连成一片);
|
2026-10-12 12:06:00 +08:00
|
|
|
* · 顶栏**并入页面滚动流**,向上滑动时跟着内容一起滑走。
|
2026-10-11 22:07:48 +08:00
|
|
|
*
|
2026-10-12 12:06:00 +08:00
|
|
|
* 🔴 开抽屉的三个入口:
|
|
|
|
|
* ① **点顶栏图标**(本组件)—— 用户新增要求;
|
|
|
|
|
* ② **应用内水平滑动**(向右滑→左边出、向左滑→右边出,见 `Drawer.ets`);
|
|
|
|
|
* ③ 底部**悬浮快捷栏**(首页几个常用模块直达,见 `Pages` 里的 FloatDock)。
|
|
|
|
|
* ⚠️ 屏幕边缘是**系统手势区**,应用收不到,所以不做边缘滑动。
|
2026-10-11 23:20:49 +08:00
|
|
|
*
|
2026-10-12 10:06:55 +08:00
|
|
|
* ⚠️ 顶栏**不放**「设置」—— 与 Web 端一致:设置收在抽屉底部的账号区里。
|
2026-10-11 22:07:48 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
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 }) {
|
2026-10-12 12:06:00 +08:00
|
|
|
// ---- 应用图标(贴最左;**点它开抽屉**)----
|
2026-10-12 10:06:55 +08:00
|
|
|
// ⚠️ 必须给描边:logo 是「米色底(74%) + 砖红图案(24%)」的实心方图,
|
|
|
|
|
// 放在白色/米色上时底板与背景几乎同色,只剩砖红图案发飘、看不清。
|
|
|
|
|
// 一层极浅的描边就能把底板"托"出来(本机范本 SyncCalendar 也给了描边)。
|
2026-10-12 12:06:00 +08:00
|
|
|
//
|
|
|
|
|
// 🔴 点击事件直接挂在 Image 上,**不套 Button** ——
|
|
|
|
|
// Button 自带最小尺寸与内边距,会把图标挤离左边线(用户要"图标靠左")。
|
2026-10-12 08:43:32 +08:00
|
|
|
Image($r('app.media.fb_logo'))
|
|
|
|
|
.width(30)
|
|
|
|
|
.height(30)
|
|
|
|
|
.borderRadius(8)
|
2026-10-12 10:06:55 +08:00
|
|
|
.border({ width: 1, color: FbColors.line })
|
2026-10-12 08:43:32 +08:00
|
|
|
.flexShrink(0)
|
2026-10-12 12:06:00 +08:00
|
|
|
.onClick(() => {
|
|
|
|
|
// 点图标 ⇒ 开抽屉(沿用上次的方向 drawerSide,默认左边)
|
|
|
|
|
this.app.drawerOpen = true;
|
|
|
|
|
})
|
2026-10-12 08:43:32 +08:00
|
|
|
|
2026-10-11 22:07:48 +08:00
|
|
|
Column({ space: 0 }) {
|
2026-10-12 08:43:32 +08:00
|
|
|
Text('家书')
|
|
|
|
|
.fontSize(19)
|
|
|
|
|
.fontWeight(FontWeight.Bold)
|
2026-10-11 22:07:48 +08:00
|
|
|
.fontColor(FbColors.ink)
|
2026-10-11 23:20:49 +08:00
|
|
|
.maxLines(1)
|
2026-10-12 10:06:55 +08:00
|
|
|
// 副标题显示当前模块名 —— "品牌 + 当前位置"一行说清
|
2026-10-12 08:43:32 +08:00
|
|
|
Text(this.moduleName())
|
|
|
|
|
.fontSize(FbMetric.fontTiny)
|
2026-10-12 10:06:55 +08:00
|
|
|
.fontColor(FbColors.muted)
|
2026-10-12 08:43:32 +08:00
|
|
|
.maxLines(1)
|
2026-10-11 22:07:48 +08:00
|
|
|
}
|
|
|
|
|
.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)
|
2026-10-11 23:20:49 +08:00
|
|
|
.stateEffect(true)
|
2026-10-11 22:07:48 +08:00
|
|
|
.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%')
|
2026-10-12 08:43:32 +08:00
|
|
|
.height(FbMetric.topBarH)
|
2026-10-12 11:37:45 +08:00
|
|
|
// 左内边距=pagePad(与下面各区块的左边线对齐);右侧 10(图标可略贴边)
|
|
|
|
|
.padding({ left: FbMetric.pagePad, right: 10, top: 4, bottom: 4 })
|
2026-10-12 08:43:32 +08:00
|
|
|
.alignItems(VerticalAlign.Center)
|
2026-10-12 10:06:55 +08:00
|
|
|
// 顶栏底色 = 白色(与下面的个人信息卡同色)
|
|
|
|
|
.backgroundColor(FbColors.surface)
|
|
|
|
|
// 底线:与下方内容(同是白色卡)之间给一条极浅的分隔,避免"两块白糊在一起"
|
|
|
|
|
.border({ width: { bottom: 1 }, color: FbColors.line2 })
|
2026-10-11 22:07:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private moduleName(): string {
|
|
|
|
|
const m = fbModuleOf(this.app.activeModule);
|
|
|
|
|
return m !== undefined ? m.name : '家书';
|
|
|
|
|
}
|
|
|
|
|
}
|