对应服务端 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 类根因后归零。)
224 lines
7.0 KiB
Plaintext
224 lines
7.0 KiB
Plaintext
/**
|
|
* 家书 FamilyBook · 资源模块(鸿蒙端)
|
|
*
|
|
* 对应 Web 端 `templates/resources/index.php`。
|
|
* 资源 = 证件 / 资料 / 附件的集合(户口本、房产证、学籍资料…),可共享给某个成员。
|
|
*
|
|
* 端上形态:**按类别分组的卡片列表**,卡片右侧显示归属人与附件数;
|
|
* 那一排「类别筛选胶囊」对应 Web 端页头的分类入口。
|
|
*/
|
|
|
|
import { FbColors, FbMetric } from '../../common/Theme';
|
|
import { FbAppState, fbAppState } from '../../common/Store';
|
|
import { FbGroup, FbResourceItem } from '../../model/Types';
|
|
import { FB_DEMO_RESOURCES, fbGroupResource } from '../../model/DemoData';
|
|
import { FbEmptyBox, FbIconButton, FbPrimaryButton, FbTag } from '../../components/Widgets';
|
|
|
|
@ComponentV2
|
|
export struct FbResourcesPage {
|
|
@Param app: FbAppState = fbAppState();
|
|
|
|
/** 模块主题色(资源 = 靛蓝) */
|
|
private accent: string = '#5566A8';
|
|
private all: FbResourceItem[] = FB_DEMO_RESOURCES;
|
|
/** 当前筛选类别('' = 全部) */
|
|
@Local kindFilter: string = '';
|
|
|
|
build() {
|
|
Column() {
|
|
// ---- 页头 ----
|
|
Row({ space: 8 }) {
|
|
Column({ space: 2 }) {
|
|
Text(this.all.length.toString() + ' 项资源')
|
|
.fontSize(FbMetric.fontTitle)
|
|
.fontWeight(FontWeight.Medium)
|
|
.fontColor(FbColors.ink)
|
|
Text('证件 / 资料 / 附件,可共享给家庭成员')
|
|
.fontSize(FbMetric.fontTiny)
|
|
.fontColor(FbColors.faint)
|
|
}
|
|
.alignItems(HorizontalAlign.Start)
|
|
.layoutWeight(1)
|
|
|
|
FbPrimaryButton({
|
|
label: '添加',
|
|
bg: this.accent,
|
|
icon: $r('app.media.fb_ic_plus')
|
|
})
|
|
FbIconButton({ icon: $r('app.media.fb_ic_gear'), tint: FbColors.muted })
|
|
}
|
|
.width('100%')
|
|
.padding({ left: FbMetric.pagePad, right: FbMetric.pagePad, top: 12, bottom: 8 })
|
|
.alignItems(VerticalAlign.Center)
|
|
|
|
// ---- 类别筛选 ----
|
|
Row({ space: 8 }) {
|
|
this.kindChip('全部', '')
|
|
this.kindChip('证件', 'document')
|
|
this.kindChip('资料', 'material')
|
|
Blank()
|
|
Text('共享给我 ' + this.sharedCount().toString() + ' 项')
|
|
.fontSize(FbMetric.fontTiny)
|
|
.fontColor(FbColors.faint)
|
|
}
|
|
.width('100%')
|
|
.padding({ left: FbMetric.pagePad, right: FbMetric.pagePad, bottom: 8 })
|
|
.alignItems(VerticalAlign.Center)
|
|
|
|
// ---- 列表 ----
|
|
if (this.filtered().length === 0) {
|
|
FbEmptyBox({
|
|
title: '这里还没有资源',
|
|
hint: '家里的证件、资料和附件都可以收进来,需要时一键共享',
|
|
icon: $r('app.media.fb_ic_resources')
|
|
})
|
|
} else {
|
|
List({ space: 0 }) {
|
|
ForEach(this.groups(), (g: FbGroup<FbResourceItem>) => {
|
|
ListItemGroup({ header: this.groupHeader(g.title, g.items.length.toString() + ' 项') }) {
|
|
ForEach(g.items, (r: FbResourceItem) => {
|
|
ListItem() {
|
|
this.resourceCard(r)
|
|
}
|
|
}, (r: FbResourceItem): string => 'res_' + r.id.toString())
|
|
}
|
|
}, (g: FbGroup<FbResourceItem>): string => 'rsg_' + g.key)
|
|
}
|
|
.layoutWeight(1)
|
|
.width('100%')
|
|
.padding({ left: FbMetric.pagePad, right: FbMetric.pagePad, bottom: 24 })
|
|
.scrollBar(BarState.Off)
|
|
.edgeEffect(EdgeEffect.Spring)
|
|
}
|
|
}
|
|
.width('100%')
|
|
.height('100%')
|
|
.backgroundColor(FbColors.paper)
|
|
.alignItems(HorizontalAlign.Start)
|
|
}
|
|
|
|
/** 一项资源卡 */
|
|
@Builder
|
|
resourceCard(r: FbResourceItem) {
|
|
Row({ space: 12 }) {
|
|
// 类别图标底
|
|
Stack({ alignContent: Alignment.Center }) {
|
|
Image(this.kindIcon(r.kind))
|
|
.width(19)
|
|
.height(19)
|
|
.renderMode(ImageRenderMode.Template)
|
|
.fillColor(this.accent)
|
|
}
|
|
.width(42)
|
|
.height(42)
|
|
.borderRadius(FbMetric.radiusS)
|
|
.backgroundColor(this.accent + '14')
|
|
|
|
Column({ space: 4 }) {
|
|
Row({ space: 6 }) {
|
|
Text(r.name)
|
|
.fontSize(FbMetric.fontBody)
|
|
.fontWeight(FontWeight.Medium)
|
|
.fontColor(FbColors.ink)
|
|
.maxLines(1)
|
|
.textOverflow({ overflow: TextOverflow.Ellipsis })
|
|
.layoutWeight(1)
|
|
if (r.shared) {
|
|
FbTag({ text: '已共享', tone: 'green' })
|
|
}
|
|
}
|
|
.width('100%')
|
|
.alignItems(VerticalAlign.Center)
|
|
|
|
Row({ space: 10 }) {
|
|
Text('归属 ' + r.ownerName)
|
|
.fontSize(10)
|
|
.fontColor(FbColors.muted)
|
|
Row({ space: 3 }) {
|
|
Image($r('app.media.fb_ic_resources'))
|
|
.width(11)
|
|
.height(11)
|
|
.renderMode(ImageRenderMode.Template)
|
|
.fillColor(FbColors.faint)
|
|
Text(r.fileCount.toString() + ' 个附件')
|
|
.fontSize(10)
|
|
.fontColor(FbColors.faint)
|
|
}
|
|
Text(r.updatedAt)
|
|
.fontSize(10)
|
|
.fontColor(FbColors.faint)
|
|
}
|
|
.alignItems(VerticalAlign.Center)
|
|
}
|
|
.alignItems(HorizontalAlign.Start)
|
|
.layoutWeight(1)
|
|
|
|
Image($r('app.media.fb_ic_forward'))
|
|
.width(13)
|
|
.height(13)
|
|
.renderMode(ImageRenderMode.Template)
|
|
.fillColor(FbColors.faint)
|
|
}
|
|
.width('100%')
|
|
.padding(14)
|
|
.backgroundColor(FbColors.surface)
|
|
.borderRadius(FbMetric.radius)
|
|
.margin({ bottom: 8 })
|
|
.alignItems(VerticalAlign.Center)
|
|
}
|
|
|
|
@Builder
|
|
kindChip(label: string, key: string) {
|
|
Text(label)
|
|
.fontSize(FbMetric.fontSmall)
|
|
.fontColor(this.kindFilter === key ? Color.White : FbColors.muted)
|
|
.backgroundColor(this.kindFilter === key ? this.accent : FbColors.inputBg)
|
|
.padding({ left: 12, right: 12, top: 6, bottom: 6 })
|
|
.borderRadius(FbMetric.radiusPill)
|
|
.onClick(() => {
|
|
this.kindFilter = key;
|
|
})
|
|
}
|
|
|
|
@Builder
|
|
groupHeader(title: string, count: string) {
|
|
Row({ space: 8 }) {
|
|
Text(title)
|
|
.fontSize(FbMetric.fontSmall)
|
|
.fontWeight(FontWeight.Medium)
|
|
.fontColor(FbColors.ink)
|
|
Text(count)
|
|
.fontSize(FbMetric.fontTiny)
|
|
.fontColor(FbColors.faint)
|
|
Blank()
|
|
}
|
|
.width('100%')
|
|
.padding({ left: 4, right: 4, top: 12, bottom: 8 })
|
|
.backgroundColor(FbColors.paper)
|
|
}
|
|
|
|
private kindIcon(kind: string): Resource {
|
|
if (kind === 'document') {
|
|
return $r('app.media.fb_ic_lock');
|
|
}
|
|
if (kind === 'material') {
|
|
return $r('app.media.fb_ic_book');
|
|
}
|
|
return $r('app.media.fb_ic_resources');
|
|
}
|
|
|
|
private filtered(): FbResourceItem[] {
|
|
if (this.kindFilter.length === 0) {
|
|
return this.all;
|
|
}
|
|
return this.all.filter((r: FbResourceItem): boolean => r.kind === this.kindFilter);
|
|
}
|
|
|
|
private groups(): FbGroup<FbResourceItem>[] {
|
|
return fbGroupResource(this.filtered());
|
|
}
|
|
|
|
private sharedCount(): number {
|
|
return this.all.filter((r: FbResourceItem): boolean => r.shared).length;
|
|
}
|
|
} |