Showing
1 changed file
with
17 additions
and
2 deletions
| @@ -16,6 +16,11 @@ export struct PlayerTitleView { | @@ -16,6 +16,11 @@ export struct PlayerTitleView { | ||
| 16 | @State rmhPlatform: number = 0 // 1是人民号 | 16 | @State rmhPlatform: number = 0 // 1是人民号 |
| 17 | @State isOverLines: boolean = false | 17 | @State isOverLines: boolean = false |
| 18 | @State summary: string = '' | 18 | @State summary: string = '' |
| 19 | + | ||
| 20 | + @State private titleLines: number = 0 | ||
| 21 | + @State private summaryLines: number = 0 | ||
| 22 | + | ||
| 23 | + | ||
| 19 | dialogController: CustomDialogController = new CustomDialogController({ | 24 | dialogController: CustomDialogController = new CustomDialogController({ |
| 20 | builder: DetailDialog({ | 25 | builder: DetailDialog({ |
| 21 | name: this.getName(), | 26 | name: this.getName(), |
| @@ -104,6 +109,13 @@ export struct PlayerTitleView { | @@ -104,6 +109,13 @@ export struct PlayerTitleView { | ||
| 104 | this.summary = this.getSummary() | 109 | this.summary = this.getSummary() |
| 105 | } | 110 | } |
| 106 | 111 | ||
| 112 | + | ||
| 113 | + private updateSummaryLines() { | ||
| 114 | + this.summaryLines = Math.max(1, 4 - this.titleLines) | ||
| 115 | + this.isOverLines = this.summary.length > this.clipText(this.summary, 14, this.summaryLines, this.windowWidth - 150 - vp2px(50)).length | ||
| 116 | + } | ||
| 117 | + | ||
| 118 | + | ||
| 107 | build() { | 119 | build() { |
| 108 | Column() { | 120 | Column() { |
| 109 | if (this.getName()) { | 121 | if (this.getName()) { |
| @@ -133,7 +145,10 @@ export struct PlayerTitleView { | @@ -133,7 +145,10 @@ export struct PlayerTitleView { | ||
| 133 | .fontFamily('PingFang SC-Regular') | 145 | .fontFamily('PingFang SC-Regular') |
| 134 | .textOverflow({ overflow: TextOverflow.Ellipsis }) | 146 | .textOverflow({ overflow: TextOverflow.Ellipsis }) |
| 135 | .margin({ bottom: 2 }) //8 | 147 | .margin({ bottom: 2 }) //8 |
| 136 | - | 148 | + .onAreaChange((oldArea: Area, newArea: Area) => { |
| 149 | + this.titleLines = Math.ceil((newArea.height as number) / 20) // 20是行高 | ||
| 150 | + this.updateSummaryLines() | ||
| 151 | + }) | ||
| 137 | /** | 152 | /** |
| 138 | * 标题大于三行或存在简介显示查看详情按钮 | 153 | * 标题大于三行或存在简介显示查看详情按钮 |
| 139 | */ | 154 | */ |
| @@ -161,7 +176,7 @@ export struct PlayerTitleView { | @@ -161,7 +176,7 @@ export struct PlayerTitleView { | ||
| 161 | // } else { | 176 | // } else { |
| 162 | if(this.summary) { | 177 | if(this.summary) { |
| 163 | Text() { | 178 | Text() { |
| 164 | - Span(this.clipText(this.summary, 14, 3, this.windowWidth - 150 - vp2px(50))) | 179 | + Span(this.clipText(this.summary, 14, this.summaryLines, this.windowWidth - 150 - vp2px(50))) |
| 165 | .fontSize(14) | 180 | .fontSize(14) |
| 166 | .fontColor(Color.White) | 181 | .fontColor(Color.White) |
| 167 | .lineHeight(21) | 182 | .lineHeight(21) |
-
Please register or login to post a comment