陈剑华

fix: 19347 卡片来源显示规则-来源过长时,不符合省略优先级

... ... @@ -3,6 +3,8 @@ import { CommonConstants, CompStyle } from 'wdConstant/Index';
import { DateTimeUtils, Logger } from 'wdKit/Index';
import router from '@ohos.router'
import { SearchShowRed, textItem, titleInitRes } from '../../utils/searchShowRed';
import measure from '@ohos.measure'
import display from '@ohos.display';
@Reusable
@Component
... ... @@ -20,10 +22,13 @@ export struct CardSourceInfo {
@State authorMarked: boolean = false;
@State authorArr: textItem[] = []
@State onlyShowCornerAndSource: boolean = false;
aboutToAppear(): void {
this.processText();
this.titleInit();
this.calcContentSpace();
}
titleInit() {
... ... @@ -171,6 +176,48 @@ export struct CardSourceInfo {
return flag;
}
getContentSize(textContent: string, fontSize: number ) {
return px2vp(Number(measure.measureTextSize({
textContent,
fontSize
}).width))
}
calcContentSpace() {
if (this.isLimited()) return;
const screenWidth = px2vp(display.getDefaultDisplaySync().width)
let leftSpace = screenWidth;
const souceSize = this.getContentSize(this.displayText, 12);
const cornerSize = this.getContentSize(this.contentDTO.cornerMark || this.contentDTO.corner, 12);
const dotSize = 11;
const timeSize = this.getContentSize(this.handleTimeStr(), 12);
const commentNum = this.getContentDtoBean()?.interactData?.commentNum
let commentSize = 0;
if (commentNum) {
commentSize = this.getContentSize(`${this.handlerNum(commentNum.toString())}评`, 12);
}
if (this.contentDTO.cornerMark || this.contentDTO.corner) {
leftSpace = leftSpace - cornerSize
}
if (this.showTime()) {
leftSpace = leftSpace - dotSize - timeSize
}
if (!this.isEllipsisActive) {
leftSpace = leftSpace - dotSize - commentSize
}
if (leftSpace < souceSize) {
this.onlyShowCornerAndSource = true;
}
}
build() {
Column(){
Flex({ justifyContent: FlexAlign.Start, direction: FlexDirection.Row }) {
... ... @@ -192,47 +239,50 @@ export struct CardSourceInfo {
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
// 点
if (this.showDot()) {
Image($r("app.media.point"))
.width(11)
.height(11)
.visibility(!this.isEllipsisActive ? Visibility.Visible : Visibility.Hidden)
if (!this.onlyShowCornerAndSource) {
// 点
if (this.showDot()) {
}
Image($r("app.media.point"))
.width(11)
.height(11)
.visibility(!this.isEllipsisActive ? Visibility.Visible : Visibility.Hidden)
// 发布日期
if (this.showTime()) {
Text(this.handleTimeStr())
.fontSize(12)
.fontColor($r("app.color.color_B0B0B0"))
.flexShrink(0)
.margin({ right: 4 })
.visibility(!this.isEllipsisActive ? Visibility.Visible : Visibility.Hidden)
}
}
// 评论数
// if (!this.contentDTO.cornerMark && !this.contentDTO.corner && !this.isEllipsisActive) {
if (!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())}评`)
// 发布日期
if (this.showTime()) {
Text(this.handleTimeStr())
.fontSize(12)
.fontColor($r("app.color.color_B0B0B0"))
.flexShrink(0)
} else {
.margin({ right: 4 })
.visibility(!this.isEllipsisActive ? Visibility.Visible : Visibility.Hidden)
}
if (this.contentDTO.objectType !=='2' && this.isCompInnerSource && this.contentDTO.interactData && this.contentDTO.interactData?.commentNum > 0) {
Text(`${this.handlerNum(this.contentDTO.interactData?.commentNum.toString())}评`)
// 评论数
// if (!this.contentDTO.cornerMark && !this.contentDTO.corner && !this.isEllipsisActive) {
if (!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())}评`)
.fontSize(12)
.fontColor($r("app.color.color_B0B0B0"))
.flexShrink(0)
}
} else {
if (this.contentDTO.objectType !=='2' && this.isCompInnerSource && this.contentDTO.interactData && this.contentDTO.interactData?.commentNum > 0) {
Text(`${this.handlerNum(this.contentDTO.interactData?.commentNum.toString())}评`)
.fontSize(12)
.fontColor($r("app.color.color_B0B0B0"))
.flexShrink(0)
}
}
}
}
}
.width(CommonConstants.FULL_WIDTH)
... ... @@ -260,6 +310,7 @@ export struct CardSourceInfo {
}
.width(CommonConstants.FULL_WIDTH)
.margin({ top: this.viewShowData ? 8 : 0 })
.clip(true)
}
... ... @@ -268,13 +319,17 @@ export struct CardSourceInfo {
* @returns
*/
private getContentDtoBean(): ContentDTO {
let content = new ContentDTO
if (this.compDTO == undefined) {
return this.contentDTO
content = this.contentDTO
}
if (this.compDTO.operDataList.length == 0) {
return this.contentDTO
content = this.contentDTO
}
if (!content) {
content = this.compDTO.operDataList[0]
}
return this.compDTO.operDataList[0]
return content;
}
/**
... ...