Card19Component.ets
2.65 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
import { ArticleListDTO, appStyleImagesDTO } from 'wdBean';
import { rmhTitle } from './rmhTitle'
const TAG = 'Card19Component';
/**
* 人民号-动态---19:动态图文卡人民号; 从无图--9图
*/
@Entry
@Component
export struct Card19Component {
@State articleListItem: ArticleListDTO = {} as ArticleListDTO
aboutToAppear(): void {
}
build() {
Column() {
// rmh信息
rmhTitle()
// 标题
if (this.articleListItem.title) {
Text(this.articleListItem.title)
.fontSize($r('app.float.font_size_17'))
.fontColor($r('app.color.color_222222'))
.textOverflowStyle(2)
.margin({ bottom: 8 })
}
// 图片-从无图到9图展示
createArticleListItem({ appStyleImages: this.articleListItem.appStyleImages })
//TODO 底部的:分享、评论、点赞 功能;需要引用一个公共组件
}
.padding({
left: $r('app.float.card_comp_pagePadding_lf'),
right: $r('app.float.card_comp_pagePadding_lf'),
top: $r('app.float.card_comp_pagePadding_tb'),
bottom: $r('app.float.card_comp_pagePadding_tb')
})
}
}
@Component
struct createArticleListItem {
@Prop appStyleImages: appStyleImagesDTO[]
build() {
if (this.appStyleImages.length === 1) {
Image(this.appStyleImages[0].fullUrl)
.width('66%')
.alignSelf(ItemAlign.Start)
} else if (this.appStyleImages.length > 4 || this.appStyleImages.length === 2 || this
.appStyleImages.length === 3) {
Flex({ wrap: FlexWrap.Wrap }) {
ForEach(this.appStyleImages, (item: appStyleImagesDTO, index: number) => {
Image(item.fullUrl)
.width('32%')
.aspectRatio(1)
.margin({ right: (index + 1) % 3 === 0 ? 0 : 2, bottom: 2 })
})
}
} else if (this.appStyleImages.length === 4) {
Flex({ wrap: FlexWrap.Wrap }) {
ForEach(this.appStyleImages.slice(0, 2), (item: appStyleImagesDTO, index: number) => {
Image(item.fullUrl)
.width('32%')
.aspectRatio(1)
.margin({ right: (index + 1) % 3 === 0 ? 0 : 2, bottom: 2 })
})
Rect()
.width('32%')
.aspectRatio(1)
.fill($r('app.color.color_transparent'))
ForEach(this.appStyleImages.slice(2, 4), (item: appStyleImagesDTO, index: number) => {
Image(item.fullUrl)
.width('32%')
.aspectRatio(1)
.margin({ right: (index + 1) % 3 === 0 ? 0 : 2, bottom: 2 })
})
}
}
}
}
@Extend(Text)
function textOverflowStyle(maxLine: number) {
.maxLines(maxLine)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}