chenjun

来源超过16个字符时隐藏时间和评论

1 import { CompDTO, ContentDTO } from 'wdBean' 1 import { CompDTO, ContentDTO } from 'wdBean'
2 import { CommonConstants } from 'wdConstant/Index'; 2 import { CommonConstants } from 'wdConstant/Index';
3 -import { DateTimeUtils } from 'wdKit/Index'; 3 +import { DateTimeUtils, Logger } from 'wdKit/Index';
4 import router from '@ohos.router' 4 import router from '@ohos.router'
5 5
6 @Reusable 6 @Reusable
@@ -12,8 +12,24 @@ export struct CardSourceInfo { @@ -12,8 +12,24 @@ export struct CardSourceInfo {
12 isCompInnerSource: boolean = false 12 isCompInnerSource: boolean = false
13 // 是否有展示的信息,如来源,标签、时间、评论 13 // 是否有展示的信息,如来源,标签、时间、评论
14 @State viewShowData: boolean = true 14 @State viewShowData: boolean = true
  15 + private maxLength: number = 16;
  16 + @State private isEllipsisActive: boolean = false;
  17 + @State private displayText: string = '';
15 18
16 aboutToAppear(): void { 19 aboutToAppear(): void {
  20 + this.processText();
  21 + }
  22 +
  23 + processText() {
  24 + const sourceText = this.contentDTO.rmhPlatform === 1 ? this.contentDTO.rmhInfo?.rmhName : this.contentDTO.source;
  25 + if (sourceText.length > this.maxLength) {
  26 + this.displayText = sourceText.substring(0, this.maxLength) + '...';
  27 + this.isEllipsisActive = true;
  28 + } else {
  29 + this.displayText = sourceText;
  30 + this.isEllipsisActive = false;
  31 + }
  32 + //Logger.warn(`cj2024 sourceText displayText=${this.displayText} isEllipsisActive=${this.isEllipsisActive}`)
17 } 33 }
18 34
19 aboutToReuse(params: Record<string, object>): void { 35 aboutToReuse(params: Record<string, object>): void {
@@ -110,7 +126,7 @@ export struct CardSourceInfo { @@ -110,7 +126,7 @@ export struct CardSourceInfo {
110 126
111 // 来源信息 127 // 来源信息
112 if (this.contentDTO.rmhPlatform === 1 || this.contentDTO.source) { 128 if (this.contentDTO.rmhPlatform === 1 || this.contentDTO.source) {
113 - Text(this.contentDTO.rmhPlatform === 1 ? this.contentDTO.rmhInfo?.rmhName : this.contentDTO.source) 129 + Text(this.displayText)
114 .fontSize($r("app.float.font_size_11")) 130 .fontSize($r("app.float.font_size_11"))
115 .fontColor($r("app.color.color_B0B0B0")) 131 .fontColor($r("app.color.color_B0B0B0"))
116 .maxLines(1) 132 .maxLines(1)
@@ -134,11 +150,12 @@ export struct CardSourceInfo { @@ -134,11 +150,12 @@ export struct CardSourceInfo {
134 Image($r("app.media.point")) 150 Image($r("app.media.point"))
135 .width(11) 151 .width(11)
136 .height(11) 152 .height(11)
  153 + .visibility(!this.isEllipsisActive ? Visibility.Visible : Visibility.Hidden)
137 154
138 } 155 }
139 156
140 // 发布日期 157 // 发布日期
141 - if (this.showTime()) { 158 + if (this.showTime() && !this.isEllipsisActive) {
142 Text(this.handleTimeStr()) 159 Text(this.handleTimeStr())
143 .fontSize($r("app.float.font_size_11")) 160 .fontSize($r("app.float.font_size_11"))
144 .fontColor($r("app.color.color_B0B0B0")) 161 .fontColor($r("app.color.color_B0B0B0"))
@@ -147,7 +164,7 @@ export struct CardSourceInfo { @@ -147,7 +164,7 @@ export struct CardSourceInfo {
147 } 164 }
148 165
149 // 评论数 166 // 评论数
150 - if (!this.contentDTO.cornerMark && !this.contentDTO.corner) { 167 + if (!this.contentDTO.cornerMark && !this.contentDTO.corner && !this.isEllipsisActive) {
151 if (this.contentDTO.objectType !=='2' && !this.isCompInnerSource && Number(this.getContentDtoBean()?.interactData?.commentNum) > 0 && 168 if (this.contentDTO.objectType !=='2' && !this.isCompInnerSource && Number(this.getContentDtoBean()?.interactData?.commentNum) > 0 &&
152 this.showCommentNum()) { 169 this.showCommentNum()) {
153 Text(`${this.handlerNum(this.getContentDtoBean()?.interactData?.commentNum.toString())}评`) 170 Text(`${this.handlerNum(this.getContentDtoBean()?.interactData?.commentNum.toString())}评`)