陈剑华

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,6 +239,7 @@ export struct CardSourceInfo {
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
if (!this.onlyShowCornerAndSource) {
// 点
if (this.showDot()) {
... ... @@ -232,6 +280,8 @@ export struct CardSourceInfo {
}
}
}
}
.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;
}
/**
... ...