chenjun

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

import { CompDTO, ContentDTO } from 'wdBean'
import { CommonConstants } from 'wdConstant/Index';
import { DateTimeUtils } from 'wdKit/Index';
import { DateTimeUtils, Logger } from 'wdKit/Index';
import router from '@ohos.router'
@Reusable
... ... @@ -12,8 +12,24 @@ export struct CardSourceInfo {
isCompInnerSource: boolean = false
// 是否有展示的信息,如来源,标签、时间、评论
@State viewShowData: boolean = true
private maxLength: number = 16;
@State private isEllipsisActive: boolean = false;
@State private displayText: string = '';
aboutToAppear(): void {
this.processText();
}
processText() {
const sourceText = this.contentDTO.rmhPlatform === 1 ? this.contentDTO.rmhInfo?.rmhName : this.contentDTO.source;
if (sourceText.length > this.maxLength) {
this.displayText = sourceText.substring(0, this.maxLength) + '...';
this.isEllipsisActive = true;
} else {
this.displayText = sourceText;
this.isEllipsisActive = false;
}
//Logger.warn(`cj2024 sourceText displayText=${this.displayText} isEllipsisActive=${this.isEllipsisActive}`)
}
aboutToReuse(params: Record<string, object>): void {
... ... @@ -110,7 +126,7 @@ export struct CardSourceInfo {
// 来源信息
if (this.contentDTO.rmhPlatform === 1 || this.contentDTO.source) {
Text(this.contentDTO.rmhPlatform === 1 ? this.contentDTO.rmhInfo?.rmhName : this.contentDTO.source)
Text(this.displayText)
.fontSize($r("app.float.font_size_11"))
.fontColor($r("app.color.color_B0B0B0"))
.maxLines(1)
... ... @@ -134,11 +150,12 @@ export struct CardSourceInfo {
Image($r("app.media.point"))
.width(11)
.height(11)
.visibility(!this.isEllipsisActive ? Visibility.Visible : Visibility.Hidden)
}
// 发布日期
if (this.showTime()) {
if (this.showTime() && !this.isEllipsisActive) {
Text(this.handleTimeStr())
.fontSize($r("app.float.font_size_11"))
.fontColor($r("app.color.color_B0B0B0"))
... ... @@ -147,7 +164,7 @@ export struct CardSourceInfo {
}
// 评论数
if (!this.contentDTO.cornerMark && !this.contentDTO.corner) {
if (!this.contentDTO.cornerMark && !this.contentDTO.corner && !this.isEllipsisActive) {
if (this.contentDTO.objectType !=='2' && !this.isCompInnerSource && Number(this.getContentDtoBean()?.interactData?.commentNum) > 0 &&
this.showCommentNum()) {
Text(`${this.handlerNum(this.getContentDtoBean()?.interactData?.commentNum.toString())}评`)
... ...