PageComponent.ets
2.42 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
import { CompDTO, CompStyle, GroupDTO, ViewType } from 'wdBean';
import {
BannerComponent,
EmptyComponent,
ErrorComponent,
GridLayout01Component,
LabelComponent,
LoadingComponent,
SingleColumnComponent,
SingleRow03Component,
WaterFlowComponent,
} from 'wdComponent';
import { CommonConstants } from 'wdConstant';
import { LazyDataSource, Logger, StringUtils } from 'wdKit';
const TAG = 'PageComponent';
@Component
export struct PageComponent {
@Prop viewType: number = ViewType.LOADED;
// Group数据及子组件数据
@State groupList: LazyDataSource<GroupDTO> = new LazyDataSource();
build() {
if (this.viewType == ViewType.LOADING) {
LoadingComponent()
} else if (this.viewType == ViewType.ERROR) {
ErrorComponent()
} else if (this.viewType == ViewType.EMPTY) {
EmptyComponent()
} else {
List() {
LazyForEach(this.groupList, (groupDTO: GroupDTO, groupIndex: number) => {
ListItem() {
Column() {
ForEach(groupDTO.compList, (compDTO: CompDTO, compIndex: number) => {
this.componentBuilder(compDTO, groupIndex, compIndex)
})
}
}
})
}
.cachedCount(5)
.height(CommonConstants.FULL_PARENT)
}
}
@Builder
componentBuilder(compDTO: CompDTO, groupIndex: number, compIndex: number) {
if (compDTO.compStyle === CompStyle.Label_03) {
LabelComponent({ compDTO: compDTO })
} else if (compDTO.compStyle === CompStyle.Carousel_Layout_01) {
BannerComponent({ compDTO: compDTO })
} else if (compDTO.compStyle === CompStyle.Single_Row_03) {
SingleRow03Component({ dataList: compDTO.operDataList })
} else if (compDTO.compStyle === CompStyle.Single_Column_01 || compDTO.compStyle === CompStyle.Single_Column_02) {
SingleColumnComponent({ compDTO: compDTO })
} else if (compDTO.compStyle === CompStyle.Grid_Layout_01) {
GridLayout01Component({ dataList: compDTO.operDataList })
} else if (compDTO.compStyle === CompStyle.Masonry_Layout_01) {
WaterFlowComponent({ compDTO: compDTO })
} else {
// todo:组件未实现 / Component Not Implemented
Text(compDTO.compStyle)
.width(CommonConstants.FULL_PARENT)
.padding(10)
// .backgroundColor(Color.Brown) // 展示本页未实现的compStyle
}
}
aboutToAppear() {
Logger.info(TAG, `aboutToAppear, this.pageId: ${this.viewType}`);
}
}