Showing
4 changed files
with
63 additions
and
29 deletions
| @@ -99,33 +99,32 @@ export struct AlbumCardComponent { | @@ -99,33 +99,32 @@ export struct AlbumCardComponent { | ||
| 99 | .height(154) | 99 | .height(154) |
| 100 | 100 | ||
| 101 | Row() { | 101 | Row() { |
| 102 | - Text(this.compDTO.operDataList[0].source) | ||
| 103 | - .fontSize(13) | ||
| 104 | - .fontColor(0xB0B0B0) | ||
| 105 | - .margin({ | ||
| 106 | - left: 16 | ||
| 107 | - }) | ||
| 108 | - | ||
| 109 | - Image($r('app.media.point')) | ||
| 110 | - .width(16) | ||
| 111 | - .height(16) | ||
| 112 | - | ||
| 113 | - Text('45分钟') | ||
| 114 | - .fontSize(13) | ||
| 115 | - .fontColor(0xB0B0B0) | ||
| 116 | - | 102 | + if (this.compDTO.operDataList[0].source) { |
| 103 | + Text(this.compDTO.operDataList[0].source) | ||
| 104 | + .fontSize(13) | ||
| 105 | + .fontColor(0xB0B0B0) | ||
| 106 | + Image($r('app.media.point')) | ||
| 107 | + .width(16) | ||
| 108 | + .height(16) | ||
| 109 | + } | ||
| 110 | + if (this.compDTO.operDataList[0].publishTime && this.compDTO.operDataList[0].publishTime.length === 13) { | ||
| 111 | + Text(DateTimeUtils.getCommentTime(Number.parseFloat(this.compDTO.operDataList[0].publishTime))) | ||
| 112 | + .fontSize(13) | ||
| 113 | + .fontColor(0xB0B0B0) | ||
| 114 | + } | ||
| 117 | Text('328评') | 115 | Text('328评') |
| 118 | .fontSize(13) | 116 | .fontSize(13) |
| 119 | .fontColor(0xB0B0B0) | 117 | .fontColor(0xB0B0B0) |
| 120 | .margin({ | 118 | .margin({ |
| 121 | left: 6 | 119 | left: 6 |
| 122 | }) | 120 | }) |
| 123 | - } | 121 | + }.margin({ left: 24 }) |
| 124 | .width(375) | 122 | .width(375) |
| 125 | .height(16) | 123 | .height(16) |
| 126 | .id('label') | 124 | .id('label') |
| 127 | } | 125 | } |
| 128 | .width(375) | 126 | .width(375) |
| 127 | + | ||
| 129 | // .backgroundColor(0x000000) | 128 | // .backgroundColor(0x000000) |
| 130 | } | 129 | } |
| 131 | } | 130 | } |
| @@ -95,7 +95,6 @@ export struct SingleImageCardAppComponent { | @@ -95,7 +95,6 @@ export struct SingleImageCardAppComponent { | ||
| 95 | .width(16) | 95 | .width(16) |
| 96 | .height(16) | 96 | .height(16) |
| 97 | .margin(10) | 97 | .margin(10) |
| 98 | - .backgroundColor(Color.Brown) | ||
| 99 | }.width(FULL_PARENT) | 98 | }.width(FULL_PARENT) |
| 100 | .justifyContent(FlexAlign.SpaceBetween) | 99 | .justifyContent(FlexAlign.SpaceBetween) |
| 101 | } | 100 | } |
| @@ -34,20 +34,27 @@ export struct SingleImageCardComponent { | @@ -34,20 +34,27 @@ export struct SingleImageCardComponent { | ||
| 34 | .textOverflow({ overflow: TextOverflow.Ellipsis })// 超出的部分显示省略号。 | 34 | .textOverflow({ overflow: TextOverflow.Ellipsis })// 超出的部分显示省略号。 |
| 35 | .height("80%") | 35 | .height("80%") |
| 36 | Row() { | 36 | Row() { |
| 37 | - Text(this.compDTO.operDataList[0].source ? this.compDTO.operDataList[0].source : '人民日报') | ||
| 38 | - .height(40) | ||
| 39 | - .fontSize(14) | ||
| 40 | - .fontColor(Color.Gray) | ||
| 41 | - Image($r('app.media.point')) | ||
| 42 | - .width(16) | ||
| 43 | - .height(16) | ||
| 44 | - Text('45分钟前') | ||
| 45 | - .height(40) | ||
| 46 | - .fontSize(14) | ||
| 47 | - .fontColor(Color.Gray) | 37 | + if (this.compDTO.operDataList[0].source) { |
| 38 | + Text(this.compDTO.operDataList[0].source) | ||
| 39 | + .height(40) | ||
| 40 | + .fontSize($r('app.float.font_size_12')) | ||
| 41 | + .fontColor(Color.Gray) | ||
| 42 | + .maxLines(1) | ||
| 43 | + .textOverflow({ overflow: TextOverflow.Ellipsis })// 超出的部分显示省略号。 | ||
| 44 | + .width('50%') | ||
| 45 | + Image($r('app.media.point')) | ||
| 46 | + .width(16) | ||
| 47 | + .height(16) | ||
| 48 | + } | ||
| 49 | + if (this.compDTO.operDataList[0].publishTime && this.compDTO.operDataList[0].publishTime.length === 13) { | ||
| 50 | + Text(DateTimeUtils.getCommentTime(Number.parseFloat(this.compDTO.operDataList[0].publishTime))) | ||
| 51 | + .height(40) | ||
| 52 | + .fontSize($r('app.float.font_size_12')) | ||
| 53 | + .fontColor(Color.Gray) | ||
| 54 | + } | ||
| 48 | Text(this.compDTO.operDataList[0].visitorComment + '评') | 55 | Text(this.compDTO.operDataList[0].visitorComment + '评') |
| 49 | .height(40) | 56 | .height(40) |
| 50 | - .fontSize(14) | 57 | + .fontSize($r('app.float.font_size_12')) |
| 51 | .fontColor(Color.Gray) | 58 | .fontColor(Color.Gray) |
| 52 | .padding({ | 59 | .padding({ |
| 53 | left: 10 | 60 | left: 10 |
| @@ -45,6 +45,7 @@ export class DateTimeUtils { | @@ -45,6 +45,7 @@ export class DateTimeUtils { | ||
| 45 | static readonly PATTERN_DATE_TIME_MS: string = 'yyyyMMddHHmmssSSS'; // 时间中包含毫秒 | 45 | static readonly PATTERN_DATE_TIME_MS: string = 'yyyyMMddHHmmssSSS'; // 时间中包含毫秒 |
| 46 | static readonly PATTERN_DATE_TIME_WITHOUT_SECOND: string = 'yyyyMMddHHmm'; // 时间中不包含秒 | 46 | static readonly PATTERN_DATE_TIME_WITHOUT_SECOND: string = 'yyyyMMddHHmm'; // 时间中不包含秒 |
| 47 | static readonly PATTERN_DATE_TIME_SIMPLIFY: string = 'MM/dd HH:mm'; // 精简的日期+时间(不包含年份和秒), 月/日 时:分 | 47 | static readonly PATTERN_DATE_TIME_SIMPLIFY: string = 'MM/dd HH:mm'; // 精简的日期+时间(不包含年份和秒), 月/日 时:分 |
| 48 | + static readonly PATTERN_DATE_SLASH_WITHOUT_YEAR2: string = 'MM-dd'; // 日期中不包含年份 | ||
| 48 | 49 | ||
| 49 | // 仅日期格式(不包含时间) | 50 | // 仅日期格式(不包含时间) |
| 50 | static readonly PATTERN_DATE_DEFAULT: string = 'yyyyMMdd'; // 年月日 | 51 | static readonly PATTERN_DATE_DEFAULT: string = 'yyyyMMdd'; // 年月日 |
| @@ -428,6 +429,34 @@ export class DateTimeUtils { | @@ -428,6 +429,34 @@ export class DateTimeUtils { | ||
| 428 | static isBefore(_date: Date, dateToCompare: Date): boolean { | 429 | static isBefore(_date: Date, dateToCompare: Date): boolean { |
| 429 | return _date.getTime() < dateToCompare.getTime(); | 430 | return _date.getTime() < dateToCompare.getTime(); |
| 430 | } | 431 | } |
| 432 | + | ||
| 433 | + /** | ||
| 434 | + * 获取文章发布时间 | ||
| 435 | + * */ | ||
| 436 | + public static getCommentTime(publishTime: number): string { | ||
| 437 | + let currentTime: number = new Date().getTime(); | ||
| 438 | + let timeGap = currentTime - publishTime; | ||
| 439 | + let timeStr = "" | ||
| 440 | + if (timeGap >= 60 * 60 * 1000 * 48) { | ||
| 441 | + let publishYear = new Date(publishTime).getFullYear(); | ||
| 442 | + let currentYear = new Date(currentTime).getFullYear(); | ||
| 443 | + if (publishYear == currentYear) { | ||
| 444 | + timeStr = this.formatDate(publishTime, DateTimeUtils.PATTERN_DATE_SLASH_WITHOUT_YEAR2) | ||
| 445 | + } else { | ||
| 446 | + timeStr = this.formatDate(publishTime) | ||
| 447 | + } | ||
| 448 | + } else if (timeGap > 60 * 60 * 1000 * 24) { | ||
| 449 | + timeStr = Math.floor(timeGap / (60 * 60 * 1000 * 24)) + "天前"; | ||
| 450 | + } else if (timeGap > 60 * 60 * 1000) { // 1小时-24小时 | ||
| 451 | + timeStr = Math.floor(timeGap / (60 * 60 * 1000)) + "小时前"; | ||
| 452 | + } else if (timeGap > 60 * 1000) { // 1分钟-59分钟 | ||
| 453 | + timeStr = Math.floor(timeGap / (60 * 1000)) + "分钟前"; | ||
| 454 | + } else { // 1秒钟-59秒钟 | ||
| 455 | + timeStr = "刚刚"; | ||
| 456 | + } | ||
| 457 | + return timeStr; | ||
| 458 | + } | ||
| 459 | + | ||
| 431 | } | 460 | } |
| 432 | 461 | ||
| 433 | // const dateTimeUtils = new DateTimeUtils() | 462 | // const dateTimeUtils = new DateTimeUtils() |
-
Please register or login to post a comment