v0.1.0 界面框架:抽屉骨架 + 13 个模块页面

对应服务端 FamilyBook(家书)的鸿蒙客户端首版。本轮只做**界面框架**,
数据全部是演示数据 —— 服务端尚无客户端接口,所有增删改只做入口与样式,
不落任何数据。

## 骨架
左侧抽屉 + 右侧内容。抽屉两套形态由窗口短边决定(≥600vp 为宽屏):
宽屏常驻侧栏、窄屏滑出层。判据取「短边」而非「宽度」,因为短边在旋转时
不变,比例接近 1:1 的设备横竖屏布局天然一致。

## 模块(与 Web 端 Module::LIST 一一对应,key 即路由名)
首页、家谱、名册、观影、旅程、日程、资源、任务、纪念日、财务、读书、
导航、笔记;另有通知消息、个人设置两个附加页。

## 与 Web 端保持一致的几处
· 模块清单唯一来源在 model/Modules.ets,加模块只改那一处;
· 模块主题色三档由主色按 HSL 压明度算出,预设色板与 Web 端逐值一致;
· 术语沿用 Web 端固定下来的口径(旅程 ⊃ 行程;观影的「影院」不单独占
  抽屉位,从模块内设置进);
· 页面结构照 Web 端的信息层次(首页信息面板 / 财务概览在账目之前 /
  纪念日「即将到来」在顶 / 任务按状态而非按看板)。

## 编译验证
hvigorw assembleHap --mode module -p product=default
→ BUILD SUCCESSFUL,0 error / 0 warning(含一次删 build 后的干净重建)

过程中修掉的编译期问题:
· Circle().fill() 是 API 26 才有的重载(compatibleSdk 是 24)
  → 换「方块 + 圆角」画圆,零版本风险;
· setWindowBackgroundColor 对 phone/tablet 不可用 → 去掉(页面已铺满同色);
· window.getLastWindow() 只有异步版 → 由 Ability 侧同步取窗存 AppStorage;
· 颜色类 @Param 声明成 string 导致传 Resource 报错 → 统一改 ResourceColor;
· 页面在 pages/<模块>/ 下,公共件 import 相对路径要多退一级。

(首轮编译 95 error / 18 warn,逐条定位到 5 类根因后归零。)
This commit is contained in:
2026-10-11 22:07:48 +08:00
commit 41e3aa3d95
80 changed files with 6985 additions and 0 deletions
@@ -0,0 +1,438 @@
/**
* 家书 FamilyBook · 首页(鸿蒙端)
*
* 对应 Web 端 `templates/home.php`。版面照搬它的三段:
* ① hero(家庭名 + 格言 + 我的资料/家谱两个快捷入口)
* ② 信息面板(问候 + 日期/星期/农历 + 日子标记 | 右侧天气)
* ③ 今天的日程 + 近期任务(两块并排;窄屏上下堆叠)
* ④ 「往年的今天」回忆条
* ⑤ 模块入口卡片(12 个模块的关键数字)
*
* ⚠️ 只做**界面**,不做交互实现:卡片点了切模块(前端状态),不发请求。
*/
import { FbColors, FbMetric, fbPalette } from '../../common/Theme';
import { FbAppState, fbAppState } from '../../common/Store';
import { FbModuleCard, FbCalEvent, FbTaskItem, FbKinChip } from '../../model/Types';
import {
FB_DEMO_EVENTS_TODAY, FB_DEMO_EVENTS_SOON, FB_DEMO_KIN, FB_DEMO_MARKS,
FB_DEMO_MODULE_CARDS, FB_DEMO_TASKS, FB_DEMO_WEATHER, FB_DEMO_WEEK_STAT
} from '../../model/DemoData';
import { FbAvatar, FbDot, FbDotLine, FbSectionTitle, FbStatTriple, FbTag } from '../../components/Widgets';
@ComponentV2
export struct FbHomePage {
@Param app: FbAppState = fbAppState();
/** 顶栏右侧插槽(由外层传入,本页不用,留空占位以保持签名统一) */
@BuilderParam topActions: () => void;
private cards: FbModuleCard[] = FB_DEMO_MODULE_CARDS;
private todayEvents: FbCalEvent[] = FB_DEMO_EVENTS_TODAY;
private soonEvents: FbCalEvent[] = FB_DEMO_EVENTS_SOON;
private tasks: FbTaskItem[] = FB_DEMO_TASKS;
/** 问候语时段(与 Web 端 home.php 里那段 PHP 同口径) */
private hello(): string {
const h: number = new Date().getHours();
if (h < 5) {
return '夜深了';
}
if (h < 11) {
return '早上好';
}
if (h < 13) {
return '中午好';
}
if (h < 18) {
return '下午好';
}
return '晚上好';
}
/** 今天的日期与星期 */
private dateLine(): string {
const d: Date = new Date();
const week: string[] = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
return (d.getMonth() + 1).toString() + ' 月 ' + d.getDate().toString() + ' 日 · '
+ week[d.getDay()];
}
/** 天气图标(按文案粗略映射到已有的几个图标上,不引外部图) */
private weatherIcon(): Resource {
// TODO(接口):真实天气码 → 图标映射。现在只区分「有太阳/没太阳」两种。
return this.weather().text.indexOf('晴') >= 0
? $r('app.media.fb_ic_days')
: $r('app.media.fb_ic_calendar');
}
private weather() {
return FB_DEMO_WEATHER;
}
build() {
Scroll() {
Column({ space: 0 }) {
// ==================== ① hero ====================
Row({ space: 12 }) {
Image($r('app.media.fb_logo'))
.width(52)
.height(52)
.borderRadius(14)
Column({ space: 3 }) {
Text(this.app.session.familyTitle)
.fontSize(FbMetric.fontH1)
.fontWeight(FontWeight.Medium)
.fontColor(FbColors.ink)
Text(this.app.session.slogan)
.fontSize(FbMetric.fontTiny)
.fontColor(FbColors.muted)
.maxLines(2)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
.alignItems(HorizontalAlign.Start)
.layoutWeight(1)
// 两个快捷入口:我的资料 / 我的家谱
Row({ space: 8 }) {
this.heroAction($r('app.media.fb_ic_user'), 'people')
this.heroAction($r('app.media.fb_ic_kin'), 'kin')
}
}
.width('100%')
.padding({ left: FbMetric.pagePad, right: FbMetric.pagePad, top: 16, bottom: 14 })
.alignItems(VerticalAlign.Center)
// ==================== ② 信息面板 ====================
Column({ space: 12 }) {
Row() {
Column({ space: 6 }) {
Row({ space: 4 }) {
Text(this.hello())
.fontSize(FbMetric.fontBody)
.fontWeight(FontWeight.Medium)
.fontColor(FbColors.ink)
Text(',' + this.app.session.me.name)
.fontSize(FbMetric.fontBody)
.fontColor(FbColors.muted)
}
Row({ space: 8 }) {
Text(this.dateLine())
.fontSize(FbMetric.fontSmall)
.fontColor(FbColors.ink)
Text('八月廿二')
.fontSize(FbMetric.fontTiny)
.fontColor(FbColors.faint)
}
// 日子标记(节气 / 节日 / 生日)
Flex({ wrap: FlexWrap.Wrap }) {
ForEach(FB_DEMO_MARKS, (mk: string, idx: number) => {
FbTag({ text: mk, tone: idx === 0 ? 'green' : 'brand' })
.margin({ right: 6, top: 2 })
}, (mk: string, idx: number): string => 'mk_' + idx.toString() + '_' + mk)
}
.width('100%')
}
.alignItems(HorizontalAlign.Start)
.layoutWeight(1)
// 天气靠右
Row({ space: 8 }) {
Column({ space: 0 }) {
Text(this.weather().temp.toString() + '°')
.fontSize(26)
.fontWeight(FontWeight.Medium)
.fontColor(FbColors.ink)
Text(this.weather().text + ' · ' + this.weather().wind)
.fontSize(FbMetric.fontTiny)
.fontColor(FbColors.muted)
.maxLines(1)
}
.alignItems(HorizontalAlign.End)
Image(this.weatherIcon())
.width(30)
.height(30)
.renderMode(ImageRenderMode.Template)
.fillColor(fbPalette('#B0763A').brand)
}
.alignItems(VerticalAlign.Center)
}
.width('100%')
.alignItems(VerticalAlign.Top)
Divider().color(FbColors.line2)
FbStatTriple({
labelA: '未来七天日程',
valueA: FB_DEMO_WEEK_STAT.events.toString(),
labelB: '待办',
valueB: FB_DEMO_WEEK_STAT.todos.toString(),
labelC: '逾期',
valueC: FB_DEMO_WEEK_STAT.overdue.toString(),
cAlarm: FB_DEMO_WEEK_STAT.overdue > 0
})
}
.width('100%')
.padding(FbMetric.cardPad)
.backgroundColor(FbColors.surface)
.borderRadius(FbMetric.radius)
.margin({ left: FbMetric.pagePad, right: FbMetric.pagePad })
// ==================== ③ 今天的日程 + 近期任务 ====================
Column({ space: 0 }) {
FbSectionTitle({ title: '今天的日程', extra: this.todayEvents.length.toString() + ' 条' })
Column({ space: 10 }) {
if (this.todayEvents.length === 0) {
FbDotLine({ label: '今天没有安排,过得轻松一点', muted: true })
} else {
ForEach(this.todayEvents, (ev: FbCalEvent) => {
Row({ space: 10 }) {
Text(ev.allDay ? '全天' : ev.time)
.fontSize(FbMetric.fontTiny)
.fontColor(FbColors.muted)
.width(46)
Column() {
FbDot({ dia: 8, fillC: ev.color })
}
.width(8)
Text(ev.title)
.fontSize(FbMetric.fontSmall)
.fontColor(FbColors.ink)
.layoutWeight(1)
.maxLines(1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
Text(ev.calName)
.fontSize(10)
.fontColor(Color.White)
.backgroundColor(ev.color)
.borderRadius(4)
.padding({ left: 5, right: 5, top: 1, bottom: 1 })
}
.width('100%')
.alignItems(VerticalAlign.Center)
}, (ev: FbCalEvent): string => 'tev_' + ev.id.toString())
}
}
.width('100%')
.padding(FbMetric.cardPad)
.backgroundColor(FbColors.surface)
.borderRadius(FbMetric.radius)
}
.width('100%')
.padding({ left: FbMetric.pagePad, right: FbMetric.pagePad, top: 8 })
Column({ space: 0 }) {
FbSectionTitle({
title: '近期任务',
extra: '进行中与已逾期'
})
Column({ space: 10 }) {
ForEach(this.recentTasks(), (t: FbTaskItem) => {
Row({ space: 10 }) {
FbDot({ dia: 8, fillC: t.overdue ? '#C0533F' : t.boardColor })
Text(t.title)
.fontSize(FbMetric.fontSmall)
.fontColor(FbColors.ink)
.layoutWeight(1)
.maxLines(1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
if (t.childTotal > 0) {
Text(t.childDone.toString() + '/' + t.childTotal.toString())
.fontSize(FbMetric.fontTiny)
.fontColor(FbColors.faint)
}
if (t.dueText.length > 0) {
Text(t.dueText)
.fontSize(FbMetric.fontTiny)
.fontColor(t.overdue ? FbColors.red : FbColors.faint)
}
}
.width('100%')
.alignItems(VerticalAlign.Center)
}, (t: FbTaskItem): string => 'htk_' + t.id.toString())
}
.width('100%')
.padding(FbMetric.cardPad)
.backgroundColor(FbColors.surface)
.borderRadius(FbMetric.radius)
}
.width('100%')
.padding({ left: FbMetric.pagePad, right: FbMetric.pagePad, top: 12 })
// ==================== ④ 我的家人 ====================
Column({ space: 0 }) {
FbSectionTitle({ title: '我的家人', extra: '以我为中心 · 上下三代' })
Flex({ wrap: FlexWrap.Wrap }) {
ForEach(FB_DEMO_KIN, (k: FbKinChip) => {
Column({ space: 4 }) {
FbAvatar({ name: k.shown, color: k.avatarColor, dia: 42, fontSizeVp: 17 })
Text(k.shown)
.fontSize(FbMetric.fontTiny)
.fontColor(FbColors.ink)
.maxLines(1)
Text(k.kinship)
.fontSize(10)
.fontColor(FbColors.faint)
.maxLines(1)
}
.width(64)
.padding({ top: 6, bottom: 6 })
}, (k: FbKinChip): string => 'kin_' + k.id.toString())
}
.width('100%')
.padding(FbMetric.cardPad)
.backgroundColor(FbColors.surface)
.borderRadius(FbMetric.radius)
}
.width('100%')
.padding({ left: FbMetric.pagePad, right: FbMetric.pagePad, top: 12 })
// ==================== ⑤ 未来七天 ====================
Column({ space: 0 }) {
FbSectionTitle({ title: '未来七天', extra: this.soonEvents.length.toString() + ' 条' })
Column({ space: 10 }) {
ForEach(this.soonEvents, (ev: FbCalEvent) => {
Row({ space: 10 }) {
Text(ev.date)
.fontSize(FbMetric.fontTiny)
.fontColor(FbColors.muted)
.width(44)
Text(ev.allDay ? '全天' : ev.time)
.fontSize(FbMetric.fontTiny)
.fontColor(FbColors.faint)
.width(40)
FbDot({ dia: 7, fillC: ev.color })
Text(ev.title)
.fontSize(FbMetric.fontSmall)
.fontColor(FbColors.ink)
.layoutWeight(1)
.maxLines(1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
.width('100%')
.alignItems(VerticalAlign.Center)
}, (ev: FbCalEvent): string => 'sev_' + ev.id.toString())
}
.width('100%')
.padding(FbMetric.cardPad)
.backgroundColor(FbColors.surface)
.borderRadius(FbMetric.radius)
}
.width('100%')
.padding({ left: FbMetric.pagePad, right: FbMetric.pagePad, top: 12 })
// ==================== ⑥ 模块入口 ====================
Column({ space: 0 }) {
FbSectionTitle({ title: '全部模块', extra: this.cards.length.toString() + ' 个' })
Flex({ wrap: FlexWrap.Wrap, justifyContent: FlexAlign.SpaceBetween }) {
ForEach(this.cards, (c: FbModuleCard) => {
this.moduleCard(c)
}, (c: FbModuleCard): string => 'mc_' + c.key)
}
.width('100%')
}
.width('100%')
.padding({ left: FbMetric.pagePad, right: FbMetric.pagePad, top: 12, bottom: 28 })
}
.width('100%')
}
.width('100%')
.height('100%')
.scrollBar(BarState.Off)
.edgeEffect(EdgeEffect.Spring)
.align(Alignment.TopStart)
}
/** hero 上的方形快捷入口 */
@Builder
heroAction(icon: Resource, target: string) {
Button({ type: ButtonType.ROUNDED_RECTANGLE }) {
Image(icon)
.width(20)
.height(20)
.renderMode(ImageRenderMode.Template)
.fillColor(FbColors.muted)
}
.width(40)
.height(40)
.backgroundColor(FbColors.inputBg)
.borderRadius(FbMetric.radiusS)
.onClick(() => {
this.app.switchModule(target);
})
}
/** 一块模块入口卡(图标 + 模块名 + 一句关键数字) */
@Builder
moduleCard(c: FbModuleCard) {
Column({ space: 8 }) {
Row({ space: 8 }) {
Image(this.cardIcon(c.key))
.width(18)
.height(18)
.renderMode(ImageRenderMode.Template)
.fillColor(fbPalette(c.color).brand)
Text(c.name)
.fontSize(FbMetric.fontSmall)
.fontWeight(FontWeight.Medium)
.fontColor(FbColors.ink)
.layoutWeight(1)
.maxLines(1)
}
.width('100%')
.alignItems(VerticalAlign.Center)
Text(c.big)
.fontSize(20)
.fontWeight(FontWeight.Medium)
.fontColor(fbPalette(c.color).brand)
.maxLines(1)
Text(c.lines.length > 0 ? c.lines[0] : '')
.fontSize(FbMetric.fontTiny)
.fontColor(FbColors.faint)
.maxLines(1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
.width('48.5%')
.padding(14)
.backgroundColor(FbColors.surface)
.borderRadius(FbMetric.radius)
.margin({ bottom: 10 })
.alignItems(HorizontalAlign.Start)
.onClick(() => {
this.app.switchModule(c.key);
})
}
/** 卡片图标(按模块 key 取) */
private cardIcon(key: string): Resource {
switch (key) {
case 'people': return $r('app.media.fb_ic_people');
case 'kin': return $r('app.media.fb_ic_kin');
case 'movies': return $r('app.media.fb_ic_movies');
case 'trips': return $r('app.media.fb_ic_trips');
case 'calendar': return $r('app.media.fb_ic_calendar');
case 'resources': return $r('app.media.fb_ic_resources');
case 'tasks': return $r('app.media.fb_ic_tasks');
case 'days': return $r('app.media.fb_ic_days');
case 'ledger': return $r('app.media.fb_ic_ledger');
case 'books': return $r('app.media.fb_ic_books');
case 'nav': return $r('app.media.fb_ic_nav');
case 'notes': return $r('app.media.fb_ic_notes');
default: return $r('app.media.fb_ic_home');
}
}
/** 首页只放「进行中 + 已逾期」两类任务(与 Web 端同一取舍) */
private recentTasks(): FbTaskItem[] {
return this.tasks.filter((t: FbTaskItem): boolean => t.status === 'doing' || t.overdue);
}
}