2026-10-11 22:07:48 +08:00
|
|
|
/**
|
|
|
|
|
* 家书 FamilyBook · 顶栏(鸿蒙端)
|
|
|
|
|
*
|
2026-10-12 10:06:55 +08:00
|
|
|
* 用户 2026-10-12 定的形态:
|
|
|
|
|
* · **应用图标 + 「家书」标题**贴左上(下行小字显示当前模块);
|
|
|
|
|
* · 顶栏底色**白色**(与下面的个人信息卡同色,连成一片);
|
|
|
|
|
* · 顶栏**并入页面滚动流**,向上滑动时跟着内容一起滑走
|
|
|
|
|
* (所以它本身不固定、也不自己处理状态栏留白)。
|
2026-10-11 22:07:48 +08:00
|
|
|
*
|
2026-10-12 10:06:55 +08:00
|
|
|
* 🔴 与状态栏的关系:顶栏是白色,而系统栏被涂成全透明、透出的是**根容器底色**。
|
|
|
|
|
* 所以要让"通知栏与顶栏融为一体",根容器在顶栏这一段必须是白色 ——
|
|
|
|
|
* 由 `Index.ets` 在顶部铺一层与顶栏同高的白色块来实现(页面滚动时它不动,
|
|
|
|
|
* 保证通知栏区域永远是白的,不会滚出内容)。
|
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 }) {
|
|
|
|
|
// ---- 左:窄屏显示抽屉按钮 ----
|
|
|
|
|
if (!this.app.wideLayout) {
|
|
|
|
|
Button({ type: ButtonType.Circle }) {
|
|
|
|
|
Image(FbIcon.ui('menu'))
|
|
|
|
|
.width(18)
|
|
|
|
|
.height(18)
|
|
|
|
|
.renderMode(ImageRenderMode.Template)
|
|
|
|
|
.fillColor(FbColors.ink)
|
|
|
|
|
}
|
|
|
|
|
.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.drawerOpen = true;
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-12 10:06:55 +08:00
|
|
|
// ---- 应用图标 ----
|
|
|
|
|
// ⚠️ 必须给描边:logo 是「米色底(74%) + 砖红图案(24%)」的实心方图,
|
|
|
|
|
// 放在白色/米色上时底板与背景几乎同色,只剩砖红图案发飘、看不清。
|
|
|
|
|
// 一层极浅的描边就能把底板"托"出来(本机范本 SyncCalendar 也给了描边)。
|
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-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)
|
|
|
|
|
.padding({ left: 14, right: 10, top: 4, bottom: 4 })
|
|
|
|
|
.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 : '家书';
|
|
|
|
|
}
|
|
|
|
|
}
|