CardView.ets
6.76 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
187
188
189
190
191
192
193
import { ContentDTO } from 'wdBean';
import { CommonConstants } from 'wdConstant';
import { Logger } from 'wdKit';
import { CompUtils } from '../utils/CompUtils';
const TAG = 'CardView';
/**
* 卡片结构:上下结构
* 卡片宽度:充满父窗口
* 卡片高度,由3部分:
* 1.上部图片高度由图片的宽度及宽高比决定,上部图片宽度占父窗口'100%',宽高比为16:9
* 2.一行title文字高度
* 3.一行author头像及名称高度
*/
@Component
export struct SingleColumn01CardView {
private item: ContentDTO = {} as ContentDTO;
private index: number = -1;
build() {
Column() {
RelativeContainer() {
// 1.海报图片
Image(this.item.hImageUrl)
.width(CommonConstants.FULL_PARENT)
.aspectRatio(CompUtils.ASPECT_RATIO_16_9)
.borderRadius($r("app.float.border_radius_6"))
.alignRules({
top: { anchor: '__container__', align: VerticalAlign.Top },
left: { anchor: '__container__', align: HorizontalAlign.Start }
})
.id('img_cover')
// 2.视频时长(Duration)
if (this.item.startTime) {
Text(this.item.startTime)
.width(CommonConstants.FULL_PARENT)// .height($r('app.float.duration_bg_height'))
.padding(10)
.fontColor(Color.White)
.fontSize($r('app.float.font_size_12'))
.fontWeight(FontWeight.Normal)
.textAlign(TextAlign.End)
.align(Alignment.Center)
.maxLines(CompUtils.MAX_LINES_1)// .backgroundColor(Color.Red)
.linearGradient({
direction: GradientDirection.Top, // 渐变方向:to Top/从下往上
colors: [[0x7508111A, 0.0], [0x7508111A, 0.3], [Color.Transparent, 1.0]]
})
.borderRadius($r("app.float.border_radius_6"))
.alignRules({
bottom: { anchor: 'img_cover', align: VerticalAlign.Bottom }
})
.id('txt_duration')
}
}
.width(CommonConstants.FULL_PARENT)
.aspectRatio(CompUtils.ASPECT_RATIO_16_9)
// 3.标题1行/title
Text(this.item.title)
.width(CommonConstants.FULL_PARENT)
.margin({ top: 4, left: 6, right: 6 })// .backgroundColor(Color.Brown)
.fontWeight(FontWeight.Normal)
.textAlign(TextAlign.Start)
.fontSize($r('app.float.font_size_14'))
.fontColor($r('app.color.color_333333'))
.maxLines(CompUtils.MAX_LINES_1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
.padding({ bottom: 8 })
.backgroundColor(Color.White)
.borderRadius($r("app.float.border_radius_6"))
.hoverEffect(HoverEffect.Scale)
.onClick((event: ClickEvent) => {
Logger.info(TAG, `SingleColumn01CardView onClick event index: ${this.index}`);
})
}
}
/**
* 卡片结构:上下结构,上部分再左右结构(左图右文)
* 卡片宽度:充满父窗口
* 卡片高度,由2部分组成:
* 1.左侧图片高度由图片的宽度及宽高比决定,左侧图片宽度占父窗口'38%',宽高比为3:4;右侧文本及按钮等垂直线性排列
* 2.最多3行description文字高度
*/
@Component
export struct SingleColumn02CardView {
private item: ContentDTO = {} as ContentDTO;
private index: number = -1;
build() {
Column() {
Row() {
Image(this.item.vImageUrl)
.width('38%')
.aspectRatio(CompUtils.ASPECT_RATIO_3_4)
.borderRadius($r("app.float.border_radius_6"))
// Blank()
Column() {
Text(this.item.title)
.margin({ right: 20 })
.fontColor($r('app.color.color_333333'))
.fontSize($r('app.float.font_size_16'))
.fontWeight(FontWeight.Bold)// .textAlign(TextAlign.Start)
.maxLines(CompUtils.MAX_LINES_1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
if (this.item.heatValue) {
Text() {
Span(`热度 `)
.fontColor($r('app.color.color_666666'))
Span(`${this.item.heatValue}`)
.fontColor($r('app.color.color_333333'))
}
.height(20)
.margin({ top: 8, right: 20 })
.fontSize($r('app.float.font_size_14'))
.maxLines(CompUtils.MAX_LINES_1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
if (this.item.startTime) {
Text() {
Span(`开始 `)
.fontColor($r('app.color.color_666666'))
Span(`${this.item.startTime}`)
.fontColor($r('app.color.color_333333'))
}
.height(20)
.margin({ top: 8, right: 20 })
.fontSize($r('app.float.font_size_14'))
.maxLines(CompUtils.MAX_LINES_1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
if (this.item.endTime) {
Text() {
Span(`结束 `)
.fontColor($r('app.color.color_666666'))
Span(`${this.item.endTime}`)
.fontColor($r('app.color.color_333333'))
}
.height(20)
.margin({ top: 8, right: 20 })
.fontSize($r('app.float.font_size_14'))
.maxLines(CompUtils.MAX_LINES_1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
Text('即将开始')
.width(96)
.height(34)
.margin({ top: 15 })
.backgroundImage($r('app.media.bg_event_status_no_start'))
.fontColor($r('app.color.color_FE4B05'))
.fontSize($r('app.float.font_size_14'))
.textAlign(TextAlign.Center)
.maxLines(CompUtils.MAX_LINES_1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
.width('62%')
.margin({ left: 12, right: 12, top: 8, bottom: 8 })
// .backgroundColor(Color.Red)
.alignItems(HorizontalAlign.Start) // 内容靠左对齐
}
.width(CommonConstants.FULL_PARENT)
.alignItems(VerticalAlign.Top)
// .backgroundColor(Color.Orange)
Text(this.item.description)
.width(CommonConstants.FULL_PARENT)
.margin({ top: 4, left: 6, right: 6 })// .backgroundColor(Color.Brown)
.fontWeight(FontWeight.Normal)
.textAlign(TextAlign.Start)
.fontSize($r('app.float.font_size_14'))
.fontColor($r('app.color.color_666666'))
.maxLines(CompUtils.MAX_LINES_3)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
.padding({ bottom: 8 })
.backgroundColor(Color.White)
.borderRadius($r("app.float.border_radius_6"))
.hoverEffect(HoverEffect.Scale)
.onClick((event: ClickEvent) => {
Logger.info(TAG, `SingleColumn02CardView onClick event index: ${this.index}`);
})
}
}