陈剑华

feat: 18017 稿件未配置来源,未展示评论数、发布时间

@@ -36,6 +36,30 @@ export struct CardSourceInfo { @@ -36,6 +36,30 @@ export struct CardSourceInfo {
36 return flag; 36 return flag;
37 } 37 }
38 38
  39 + /**
  40 + * 全域数字显示规则
  41 + * 1、当数量为千位以內时,显示数字,不保留小数点,比如 4585
  42 + * 2、当数量为万位~1亿时,显示xx 万,保留小数点后一位,比如1517.9w、2.9w
  43 + * 3、当数量为1亿~千亿时,显示XX 亿,保留小数点后一位,比如1517.9亿、2.9亿
  44 + * 4、不进行四舍五入
  45 + * 5、0 和空 不显示
  46 + */
  47 + handlerNum(number: string) {
  48 + const num = number??'0';
  49 + if (Number.parseInt(num) <= 9999) {
  50 + return Number.parseInt(num).toString()
  51 + } else if (Number.parseInt(num) > 9999 && Number.parseInt(num) <= 99999999) {
  52 + const num1: string = num.slice(0, -4); // 万
  53 + const num2: string = num.slice(-4, -3); // 千
  54 + return num2 === '0' ? num1 +'万' : num1 + '.' + num2 + '万'
  55 + } else if (Number.parseInt(num) > 99999999) {
  56 + const num1: string = num.slice(0, -8); // 亿
  57 + const num2: string = num.slice(-8, -7);
  58 + return num2 === '0' ? num1 +'亿' : num1 + '.' + num2 + '亿'
  59 + }
  60 + return num
  61 + }
  62 +
39 isTwoDaysAgo(date: string) { 63 isTwoDaysAgo(date: string) {
40 const twoDaysAgo = new Date(); 64 const twoDaysAgo = new Date();
41 twoDaysAgo.setDate(twoDaysAgo.getDate() - 2); 65 twoDaysAgo.setDate(twoDaysAgo.getDate() - 2);
@@ -109,7 +133,7 @@ export struct CardSourceInfo { @@ -109,7 +133,7 @@ export struct CardSourceInfo {
109 .margin({right: 4}) 133 .margin({right: 4})
110 } 134 }
111 if (this.getContentDtoBean()?.interactData?.commentNum) { 135 if (this.getContentDtoBean()?.interactData?.commentNum) {
112 - Text(`${this.getContentDtoBean()?.interactData?.commentNum}评`) 136 + Text(`${this.handlerNum(this.getContentDtoBean()?.interactData?.commentNum.toString())}评`)
113 .fontSize($r("app.float.font_size_11")) 137 .fontSize($r("app.float.font_size_11"))
114 .fontColor($r("app.color.color_B0B0B0")) 138 .fontColor($r("app.color.color_B0B0B0"))
115 .flexShrink(0) 139 .flexShrink(0)