chenjun3_wd

添加早晚报信息源 发布时间

@@ -152,6 +152,8 @@ export struct MorningEveningPaperComponent { @@ -152,6 +152,8 @@ export struct MorningEveningPaperComponent {
152 if (imageSource) { 152 if (imageSource) {
153 this.pickColor(imageSource) 153 this.pickColor(imageSource)
154 154
  155 + } else {
  156 + this.mixedBgColor = this.pageInfoBean.backgroundColor
155 } 157 }
156 158
157 } 159 }
@@ -390,6 +390,33 @@ export struct PaperSingleColumn999CardView { @@ -390,6 +390,33 @@ export struct PaperSingleColumn999CardView {
390 private item: ContentDTO = {} as ContentDTO; 390 private item: ContentDTO = {} as ContentDTO;
391 private index: number = -1; 391 private index: number = -1;
392 392
  393 + getPublishTime(): string {
  394 + const publishTimestamp = parseInt(this.item?.publishTime)
  395 + const currentTime = Date.now(); // 当前时间戳
  396 +
  397 + // 计算差异
  398 + const timeDifference = currentTime - publishTimestamp;
  399 +
  400 + // 转换为分钟、小时和天
  401 + const minutes = Math.floor(timeDifference / (1000 * 60));
  402 + const hours = Math.floor(timeDifference / (1000 * 60 * 60));
  403 + const days = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
  404 +
  405 + // 根据时间差返回对应的字符串
  406 + let result: string;
  407 +
  408 + if (minutes < 60) {
  409 + result = `${minutes}分钟前`;
  410 + } else if (hours < 24) {
  411 + result = `${hours}小时前`;
  412 + } else {
  413 + result = `${days}天前`;
  414 + }
  415 +
  416 + console.log(result);
  417 + return result
  418 + }
  419 +
393 build() { 420 build() {
394 Column() { 421 Column() {
395 Text(this.item?.newsTitle) 422 Text(this.item?.newsTitle)
@@ -429,14 +456,33 @@ export struct PaperSingleColumn999CardView { @@ -429,14 +456,33 @@ export struct PaperSingleColumn999CardView {
429 } 456 }
430 if (this.item?.visitorComment) { 457 if (this.item?.visitorComment) {
431 Row() { 458 Row() {
432 - Text(this.item?.visitorComment + "评")  
433 - .fontSize(12)  
434 - .fontColor(Color.Gray)  
435 - .margin({ left: 22 }) 459 + Row() {
  460 + Text(this.item?.source)
  461 + .fontSize(12)
  462 + .fontColor(Color.Gray)
  463 + .margin({ left: 22 })
  464 + Image($r('app.media.point'))
  465 + .width(16)
  466 + .height(16)
  467 + .margin({ top: 10, bottom: 10 })
  468 + Text(this.getPublishTime())
  469 + .fontSize(12)
  470 + .fontColor(Color.Gray)
  471 + Text(this.item?.visitorComment + "评")
  472 + .fontSize(12)
  473 + .fontColor(Color.Gray)
  474 + .margin({ left: 6 })
  475 + }
  476 + .justifyContent(FlexAlign.Start)
  477 +
436 Image($r('app.media.icon_forward')) 478 Image($r('app.media.icon_forward'))
437 .width(16) 479 .width(16)
438 .height(16) 480 .height(16)
439 .margin({ left: 10, right: 22, top: 10, bottom: 10 }) 481 .margin({ left: 10, right: 22, top: 10, bottom: 10 })
  482 + .alignRules({
  483 + center: { anchor: '__container__', align: VerticalAlign.Center },
  484 + right: { anchor: '__container__', align: HorizontalAlign.End }
  485 + })
440 }.width(CommonConstants.FULL_PARENT) 486 }.width(CommonConstants.FULL_PARENT)
441 .justifyContent(FlexAlign.SpaceBetween) 487 .justifyContent(FlexAlign.SpaceBetween)
442 } 488 }