ZhGridLayout02.ets
4.98 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import { CompDTO, ContentDTO, LiveRoomDataBean } from 'wdBean';
import { CommonConstants } from 'wdConstant/Index';
import { Logger } from 'wdKit/Index';
import { ProcessUtils } from 'wdRouter';
import PageViewModel from '../../viewmodel/PageViewModel';
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
const TAG = 'Zh_Grid_Layout-02';
const FULL_PARENT: string = '100%';
let listSize: number = 2;
/**
* 双图卡
* 枚举值Zh_Grid_Layout-02
* Zh_Grid_Layout-02
*
*/
@Component
export struct ZhGridLayout02 {
@State compDTO: CompDTO = {} as CompDTO
@State operDataList: ContentDTO[] = []
@State loadImg: boolean = false;
@State liveRoomList: LiveRoomDataBean[] = []
currentPage = 1
pageSize = 12
async aboutToAppear(): Promise<void> {
Logger.debug(TAG, 'aboutToAppear ' + this.compDTO.objectTitle)
this.currentPage = 1
PageViewModel.getLiveReviewUrl(this.currentPage, this.pageSize).then((liveReviewDTO) => {
this.operDataList = []
this.operDataList.push(...liveReviewDTO.list)
this.getLiveRoomDataInfo(this.operDataList)
})
this.loadImg = await onlyWifiLoadImg();
}
build() {
Column() {
Scroll() {
Column() {
Row() {
Image($r("app.media.redLine"))
.width(3)
.height(16)
.margin({ right: 4 })
Text(this.compDTO.objectTitle)
.fontSize($r("app.float.font_size_17"))
.fontColor($r("app.color.color_222222"))
.fontWeight(600)
}
.justifyContent(FlexAlign.Start)
.margin({ top: 16, bottom: 8 })
.width(CommonConstants.FULL_WIDTH)
GridRow({
gutter: { x: 12, y: 13 },
columns: { sm: listSize, md: 2 },
breakpoints: { value: ['320vp', '520vp', '840vp'] }
}) {
ForEach(this.operDataList, (item: ContentDTO, index: number) => {
GridCol() {
this.buildItemCard(item);
}
})
}
}
}
.width("100%")
.height("100%")
// .layoutWeight(1)
.edgeEffect(EdgeEffect.None)
.scrollBar(BarState.Off)
.onReachStart(() => {
Logger.debug(TAG, 'onReachStart')
})
.onReachEnd(() => {
Logger.debug(TAG, 'onReachEnd')
this.addItems()
})
.nestedScroll({
scrollForward: NestedScrollMode.PARENT_FIRST,
scrollBackward: NestedScrollMode.SELF_FIRST
})
}
.width(CommonConstants.FULL_WIDTH)
// .width("100%")
.height("100%")
.padding({ left: 16, right: 16 })
// .layoutWeight(1)
}
/**
* 组件项
*
* @param programmeBean item 组件项, 上面icon,下面标题
*/
@Builder
buildItemCard(item: ContentDTO) {
Column() {
Stack({ alignContent: Alignment.BottomEnd }) {
Image(this.loadImg ? item.fullColumnImgUrls[0].url : '')
.backgroundColor(0xf5f5f5)
.width('100%')
.height(95)
.borderRadius(4)
if (this.getLiveRoomNumber(item).length > 0) {
Text(this.getLiveRoomNumber(item))
.fontSize('11vp')
.fontWeight(400)
.fontColor(Color.White)
.margin({
right: '5vp',
bottom: '5vp'
})
}
}
Text(item.newsTitle)
.margin({top:'6'})
.fontSize(13)
.maxLines(2)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
.width('100%')
.onClick(() => {
ProcessUtils.processPage(item)
})
}
// 获取评论数
async getLiveRoomDataInfo(list: ContentDTO[]) {
const reserveIds = this.getLiveDetailIds(list)
PageViewModel.getLiveRoomBatchInfo(reserveIds).then((result) => {
if (result && result.length > 0) {
this.liveRoomList.push(...result)
}
}).catch(() => {
})
}
// 判断是否预约
getLiveRoomNumber(item: ContentDTO): string {
const objc = this.liveRoomList.find((element: LiveRoomDataBean) => {
return element.liveId.toString() == item.objectId
})
if (objc && objc.pv && objc.pv > 0) {
return this.computeShowNum(objc.pv)
}
return ''
}
addItems() {
Logger.debug(TAG, 'addItems')
this.currentPage++
PageViewModel.getLiveReviewUrl(this.currentPage, this.pageSize).then((liveReviewDTO) => {
this.operDataList.push(...liveReviewDTO.list)
this.getLiveRoomDataInfo(this.operDataList)
Logger.debug(TAG, 'addItems after: ' + this.operDataList.length)
})
}
private getLiveDetailIds(list: ContentDTO[]): string {
let idList: string[] = []
list.forEach(item => {
idList.push(item.objectId)
});
return idList.join(',')
}
private computeShowNum(count: number): string {
if (count >= 10000) {
let num = (count / 10000).toFixed(1)
if (Number(num.substring(num.length - 1)) == 0) {
num = num.substring(0, num.length - 2)
}
return num + '万人参加'
}
return `${count}人参加`
}
}