王士厅
... ... @@ -115,24 +115,29 @@ export struct CardSourceInfo {
* 5、0 和空 不显示
*/
handlerNum(number: string) {
const num = number ?? '0';
const num = number??'0';
if (Number.parseInt(num) <= 9999) {
return Number.parseInt(num).toString()
} else if (Number.parseInt(num) > 9999 && Number.parseInt(num) <= 99999999) {
const num1: string = num.slice(0, -4); // 万
const num2: string = num.slice(-4, -3); // 千
return num2 === '0' ? num1 + '万' : num1 + '.' + num2 + '万'
let num1: string = num.slice(0, -4); // 万
let num2: string = num.slice(-4, -3); // 千
const num3: string = num.slice(-3, -2); // 百
if (Math.round(Number(`0.${num3}`)) === 1) num2 = `${Number(num2) + 1}`
if (Number(num2) === 10) {
num2 = '0';
num1 = `${Number(num1) + 1}`
}
return num2 === '0' ? num1 +'万' : num1 + '.' + num2 + '万'
} else if (Number.parseInt(num) > 99999999) {
let num1: string = num.slice(0, -8); // 亿
let num2: string = num.slice(-8, -7);
const num3: string = `0.${num.slice(-7, -6)}`
if (Math.round(Number(num3)) > Number(num3)) {
if (`${Number(num2) + 1}`.length === 2) {
const num3: string = num.slice(-3, -2); // 百
if (Math.round(Number(`0.${num3}`)) === 1) num2 = `${Number(num2) + 1}`
if (Number(num2) === 10) {
num2 = '0';
num1 = `${Number(num1) + 1}`
num2 = '0'
}
}
return num2 === '0' ? num1 + '亿' : num1 + '.' + num2 + '亿'
return num2 === '0' ? num1 +'亿' : num1 + '.' + num2 + '亿'
}
return num
}
... ... @@ -177,10 +182,10 @@ export struct CardSourceInfo {
}
getContentSize(textContent: string, fontSize: number ) {
return px2vp(Number(measure.measureTextSize({
return Number(measure.measureTextSize({
textContent,
fontSize
}).width))
}).width)
}
calcContentSpace() {
... ... @@ -188,27 +193,25 @@ export struct CardSourceInfo {
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) {
const cornerSize = this.getContentSize(this.contentDTO.cornerMark || this.contentDTO.corner, 12);
leftSpace = leftSpace - cornerSize
}
if (this.showTime()) {
const timeSize = this.getContentSize(this.handleTimeStr(), 12);
leftSpace = leftSpace - dotSize - timeSize
}
if (!this.isEllipsisActive) {
let commentSize = 0;
const commentNum = this.getContentDtoBean()?.interactData?.commentNum
if (commentNum) {
commentSize = this.getContentSize(`${this.handlerNum(commentNum.toString())}评`, 12);
}
leftSpace = leftSpace - dotSize - commentSize
}
... ...