chenjun

title和summary总行数为4

... ... @@ -16,6 +16,11 @@ export struct PlayerTitleView {
@State rmhPlatform: number = 0 // 1是人民号
@State isOverLines: boolean = false
@State summary: string = ''
@State private titleLines: number = 0
@State private summaryLines: number = 0
dialogController: CustomDialogController = new CustomDialogController({
builder: DetailDialog({
name: this.getName(),
... ... @@ -104,6 +109,13 @@ export struct PlayerTitleView {
this.summary = this.getSummary()
}
private updateSummaryLines() {
this.summaryLines = Math.max(1, 4 - this.titleLines)
this.isOverLines = this.summary.length > this.clipText(this.summary, 14, this.summaryLines, this.windowWidth - 150 - vp2px(50)).length
}
build() {
Column() {
if (this.getName()) {
... ... @@ -133,7 +145,10 @@ export struct PlayerTitleView {
.fontFamily('PingFang SC-Regular')
.textOverflow({ overflow: TextOverflow.Ellipsis })
.margin({ bottom: 2 }) //8
.onAreaChange((oldArea: Area, newArea: Area) => {
this.titleLines = Math.ceil((newArea.height as number) / 20) // 20是行高
this.updateSummaryLines()
})
/**
* 标题大于三行或存在简介显示查看详情按钮
*/
... ... @@ -161,7 +176,7 @@ export struct PlayerTitleView {
// } else {
if(this.summary) {
Text() {
Span(this.clipText(this.summary, 14, 3, this.windowWidth - 150 - vp2px(50)))
Span(this.clipText(this.summary, 14, this.summaryLines, this.windowWidth - 150 - vp2px(50)))
.fontSize(14)
.fontColor(Color.White)
.lineHeight(21)
... ...