2026-10-11 22:07:48 +08:00
|
|
|
/**
|
|
|
|
|
* 家书 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';
|
2026-10-18 03:35:39 +08:00
|
|
|
import { fbGroupResource } from '../../model/DemoData';
|
|
|
|
|
import { parseResources } from '../../data/FbParse';
|
|
|
|
|
import { loadModule } from '../../data/FbModuleLoad';
|
2026-10-11 22:07:48 +08:00
|
|
|
import { FbEmptyBox, FbIconButton, FbPrimaryButton, FbTag } from '../../components/Widgets';
|
2026-10-12 12:06:00 +08:00
|
|
|
import { FB_DOCK_RESERVE } from '../../components/FloatDock';
|
2026-10-18 03:35:39 +08:00
|
|
|
import { fbOnScroll, fbOnTouch } from '../../common/FbScroll';
|
|
|
|
|
import { FbModuleSettingsSheet } from '../../components/FbModuleSettingsSheet';
|
|
|
|
|
import { FB_SET_RESOURCES } from '../../model/FbSettingsMenus';
|
2026-10-11 22:07:48 +08:00
|
|
|
|
|
|
|
|
@ComponentV2
|
|
|
|
|
export struct FbResourcesPage {
|
2026-10-12 10:06:55 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 顶栏插槽:由 Index.ets 传入,放在本页滚动流最前面 ⇒ 随页面一起滚走。
|
|
|
|
|
* 🔴 用户要求「向上滑动时标题栏跟着一起滑走」。
|
|
|
|
|
*/
|
|
|
|
|
@BuilderParam topBar: () => void;
|
2026-10-11 22:07:48 +08:00
|
|
|
@Param app: FbAppState = fbAppState();
|
|
|
|
|
|
|
|
|
|
/** 模块主题色(资源 = 靛蓝) */
|
|
|
|
|
private accent: string = '#5566A8';
|
2026-10-18 03:35:39 +08:00
|
|
|
/**
|
|
|
|
|
* 模块设置浮层是否打开(右上角三条横线点开的那个)。
|
|
|
|
|
*
|
|
|
|
|
* 🔴 用户 2026-10-16:「所有页面的设置按钮全部都改成和网页版一致,
|
|
|
|
|
* 就是**三个横线**那种设置按钮。」
|
|
|
|
|
* 网页版的做法:动作区最右一个 ☰ → 点开是**这个模块的设置菜单**。
|
|
|
|
|
*/
|
|
|
|
|
@Local settingsOpen: boolean = false;
|
|
|
|
|
|
|
|
|
|
@Local all: FbResourceItem[] = [];
|
2026-10-11 22:07:48 +08:00
|
|
|
/** 当前筛选类别('' = 全部) */
|
|
|
|
|
@Local kindFilter: string = '';
|
|
|
|
|
|
2026-10-18 03:35:39 +08:00
|
|
|
/**
|
|
|
|
|
* 页面出现:先读缓存、再拉接口(本地优先,见 FbModuleRepo 的说明)。
|
|
|
|
|
*
|
|
|
|
|
* ⚠️ 不在这里打开本地库 —— `EntryAbility.onCreate` 已统一打开。
|
|
|
|
|
*/
|
|
|
|
|
aboutToAppear(): void {
|
|
|
|
|
this.load();
|
|
|
|
|
}
|
2026-10-12 10:06:55 +08:00
|
|
|
|
2026-10-18 03:35:39 +08:00
|
|
|
private async load(): Promise<void> {
|
|
|
|
|
await loadModule<FbResourceItem[]>('resources', parseResources,
|
|
|
|
|
(rows: FbResourceItem[]): void => {
|
|
|
|
|
this.all = rows;
|
|
|
|
|
},
|
|
|
|
|
(note: string): void => {
|
|
|
|
|
this.syncNote = note;
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 顶部提示(同步失败 / 未登录时显示一行小字) */
|
|
|
|
|
@Local syncNote: string = '';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 设置浮层开着 ⇒ 让底部悬浮快捷栏让位。
|
|
|
|
|
*
|
|
|
|
|
* 🔴 悬浮栏在**更外层 Index 的 Stack** 里,层级比本页高 ⇒
|
|
|
|
|
* 浮层底部的按钮会被它盖住、点击被抢走(名册/日程页都踩过)。
|
|
|
|
|
*/
|
|
|
|
|
@Monitor('settingsOpen')
|
|
|
|
|
onSettingsChanged(): void {
|
|
|
|
|
fbAppState().sheetCount = this.settingsOpen ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
build() {
|
|
|
|
|
// 🔴 外层 Stack:**模块设置浮层**要浮在页面之上
|
|
|
|
|
// (本页原来是 Scroll 直接作根,没有 Stack,这里补一层)
|
|
|
|
|
Stack({ alignContent: Alignment.Bottom }) {
|
|
|
|
|
|
|
|
|
|
Scroll() {
|
|
|
|
|
Column() {
|
|
|
|
|
this.topBar()
|
|
|
|
|
|
|
|
|
|
// ---- 页头 ----
|
|
|
|
|
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')
|
|
|
|
|
})
|
|
|
|
|
// 🔴 设置按钮 = 网页版那种**三条横线**(☰)—— 用户 2026-10-16。
|
|
|
|
|
// 点开是本模块的设置菜单(条目照网页版 `templates/<模块>/_settings_menu.php`)。
|
|
|
|
|
FbIconButton({
|
|
|
|
|
icon: $r('app.media.fb_ic_menu'),
|
|
|
|
|
tint: FbColors.muted,
|
|
|
|
|
onTap: (): void => {
|
|
|
|
|
this.settingsOpen = true;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
.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() + ' 项')
|
2026-10-12 10:06:55 +08:00
|
|
|
.fontSize(FbMetric.fontTiny)
|
|
|
|
|
.fontColor(FbColors.faint)
|
|
|
|
|
}
|
|
|
|
|
.width('100%')
|
2026-10-18 03:35:39 +08:00
|
|
|
.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)
|
|
|
|
|
}
|
|
|
|
|
.width('100%')
|
|
|
|
|
.padding({ left: FbMetric.pagePad, right: FbMetric.pagePad, bottom: 24 })
|
|
|
|
|
.scrollBar(BarState.Off)
|
|
|
|
|
.edgeEffect(EdgeEffect.Spring)
|
|
|
|
|
}
|
2026-10-12 10:06:55 +08:00
|
|
|
}
|
2026-10-18 03:35:39 +08:00
|
|
|
.width('100%')
|
|
|
|
|
// 底部悬浮快捷栏的预留:它浮在内容之上,不留白会压住最后一屏
|
|
|
|
|
.padding({ bottom: FB_DOCK_RESERVE })
|
2026-10-11 22:07:48 +08:00
|
|
|
}
|
2026-10-12 10:06:55 +08:00
|
|
|
.width('100%')
|
2026-10-18 03:35:39 +08:00
|
|
|
.height('100%')
|
|
|
|
|
.scrollBar(BarState.Off)
|
|
|
|
|
.edgeEffect(EdgeEffect.Spring)
|
|
|
|
|
// 🔴 滚动方向上报(驱动底部悬浮栏随滚收起 / 唤回)—— 见 common/FbScroll.ets
|
|
|
|
|
.onDidScroll(fbOnScroll)
|
|
|
|
|
|
|
|
|
|
// 🔴 触摸方向兜底(内容不足一屏的页面滚不动,只能靠手指位移判断)
|
|
|
|
|
// 与上面的 `onDidScroll` 互补、互不冲突 —— 见 common/FbScroll.ets
|
|
|
|
|
.onTouch(fbOnTouch)
|
|
|
|
|
.align(Alignment.TopStart)
|
|
|
|
|
// ---- 模块设置浮层(右上角三条横线点开的那个)----
|
|
|
|
|
if (this.settingsOpen) {
|
|
|
|
|
Column()
|
|
|
|
|
.width('100%')
|
|
|
|
|
.height('100%')
|
|
|
|
|
.backgroundColor('#00000066')
|
|
|
|
|
.onClick((): void => {
|
|
|
|
|
this.settingsOpen = false;
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
FbModuleSettingsSheet({
|
|
|
|
|
title: '资源设置',
|
|
|
|
|
items: FB_SET_RESOURCES,
|
|
|
|
|
onClose: (): void => {
|
|
|
|
|
this.settingsOpen = false;
|
|
|
|
|
},
|
|
|
|
|
onPick: (action: string): void => {
|
|
|
|
|
// 条目里 `action === ''` 的是「暂未开放」(组件里已画灰、点了不响应)
|
|
|
|
|
// ⇒ 这里只需处理已实现的;目前都还没有,保持浮层开着即可。
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
}
|
2026-10-11 22:07:48 +08:00
|
|
|
}
|
|
|
|
|
.width('100%')
|
|
|
|
|
.height('100%')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** 一项资源卡 */
|
|
|
|
|
@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;
|
|
|
|
|
}
|
|
|
|
|
}
|