PlayerTitleView.ets
2.88 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
import measure from '@ohos.measure'
import { ContentDetailDTO } from 'wdBean/Index'
import { DetailDialog } from './DetailDialog'
import { componentUtils } from '@kit.ArkUI'
@Preview
@Component
export struct PlayerTitleView {
@Consume contentDetailData: ContentDetailDTO
@Consume windowWidth: number
@Consume isOpenDetail: boolean
@Consume isDragging: boolean
@State titleHeight: number = 0
dialogController: CustomDialogController = new CustomDialogController({
builder: DetailDialog({
name: this.getName(),
title: this.getTitle(),
summary: this.getSummary(),
isOpenDetail: this.isOpenDetail
}),
autoCancel: false,
customStyle: true,
alignment: DialogAlignment.Bottom
})
getName(): string {
// authTitle
return this.contentDetailData?.rmhInfo?.rmhName || ''
}
getIcon(): string {
return this.contentDetailData?.rmhInfo?.authIcon || ''
}
getTitle(): string {
return this.contentDetailData?.newsTitle || ''
}
getSummary(): string {
return this.contentDetailData?.newIntroduction || ''
}
aboutToAppear(): void {
const info = measure.measureTextSize({
textContent: this.getTitle(),
fontSize: 15,
fontWeight: 400,
lineHeight: 20,
constraintWidth: this.windowWidth - 100 - 16 - 22 + 'px',
})
this.titleHeight = info?.height as number || 0
console.log('titleHeight:', this.titleHeight,)
}
build() {
Column() {
if (this.getName()) {
Row() {
Text("@" + this.getName())
.fontColor(Color.White)
.fontSize(17)
.maxLines(1)
.lineHeight(25)
.fontWeight(600)
.textOverflow({ overflow: TextOverflow.Ellipsis })
if (this.getIcon()) {
Image(this.getIcon()).height(10).margin({ left: 4 })
}
}.margin({ bottom: 8 })
}
Text(this.getTitle())
.fontColor(Color.White)
.fontSize(15)
.maxLines(3)
.lineHeight(20)
.fontWeight(400)
.textOverflow({ overflow: TextOverflow.Ellipsis })
.margin({ bottom: 8 })
/**
* 标题大于三行或存在简介显示查看详情按钮
*/
if (this.titleHeight > 200 || this.getSummary()) {
Text('查看详情 > ')
.padding({ left: 6, right: 6, top: 4, bottom: 4 })
.borderRadius(2)
.backgroundColor('#99636363')
.fontColor(Color.White)
.fontSize(12)
.lineHeight(14)
.fontWeight(400)
.margin({ bottom: 8 })
.onClick(() => {
this.isOpenDetail = true
this.dialogController?.open()
})
}
}
.width(this.windowWidth - 100 + 'px')
.padding({ left: 16, right: 22 })
.alignItems(HorizontalAlign.Start)
.visibility(this.isOpenDetail || this.isDragging ? Visibility.None : Visibility.Visible)
}
}