WaterFlowComponent.ets
2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { CompDTO, ContentDTO } from 'wdBean';
import { BreakPointType, Logger } from 'wdKit';
import { MasonryLayout01CardView } from './CardView';
import { EmptyComponent } from './EmptyComponent';
const TAG = 'WaterFlowComponent';
/**
* 瀑布流组件样式:
* 'Masonry_Layout-01', // 双列瀑布流/瀑布流卡:视频、直播、专题、活动
*/
@Component
export struct WaterFlowComponent {
@StorageLink('currentBreakpoint') currentBreakpoint: string = 'XS';
@State compDTO: CompDTO = {} as CompDTO
readonly WATER_FLOW_COLUMNS_TEMPLATE_TWO: string = '1fr 1fr';
readonly WATER_FLOW_COLUMNS_TEMPLATE_FOUR: string = '1fr 1fr 1fr 1fr';
aboutToAppear() {
Logger.info(TAG, `aboutToAppear, beanList:${this.compDTO?.operDataList?.length}, currentBreakpoint:${this.currentBreakpoint}`);
}
aboutToDisappear() {
Logger.info(TAG, 'aboutToDisappear');
}
onPageShow() {
Logger.info(TAG, 'onPageShow');
}
onPageHide() {
Logger.info(TAG, 'onPageHide');
}
onBackPress() {
Logger.info(TAG, 'onBackPress');
}
build() {
if (this.compDTO && this.compDTO?.operDataList?.length > 0) {
WaterFlow({ footer: (): void => this.itemFoot() }) {
ForEach(this.compDTO?.operDataList, (item: ContentDTO, index: number) => {
FlowItem() {
this.buildFlowItemComponent(item, index)
}
})
}
.margin({ left: $r('app.float.main_margin'), right: $r('app.float.main_margin') })
.padding({ bottom: 14 })
.layoutDirection(FlexDirection.Column)
.columnsTemplate(this.buildColumnsTemplate())
.columnsGap(4)
.rowsGap(14)
} else {
EmptyComponent({ emptyHeight: 100 })
}
}
public buildColumnsTemplate(): string {
return new BreakPointType({
xs: this.WATER_FLOW_COLUMNS_TEMPLATE_TWO,
sm: this.WATER_FLOW_COLUMNS_TEMPLATE_TWO,
md: this.WATER_FLOW_COLUMNS_TEMPLATE_FOUR,
lg: this.WATER_FLOW_COLUMNS_TEMPLATE_FOUR
}).getValue(this.currentBreakpoint)
}
@Builder
itemFoot() {
Column() {
// Text($r('app.string.footer_text'))
// .fontColor(Color.Gray)
// .fontSize($r('app.float.font_size_10'))
// .width(CommonConstants.FULL_PARENT)
// .height(20)
// .textAlign(TextAlign.Center)
}
}
@Builder
buildFlowItemComponent(item: ContentDTO, index: number) {
MasonryLayout01CardView({
item: item,
index: index
})
}
}