guochunsong

优化过长问题,合并datetimeUtils代码

... ... @@ -99,33 +99,32 @@ export struct AlbumCardComponent {
.height(154)
Row() {
Text(this.compDTO.operDataList[0].source)
.fontSize(13)
.fontColor(0xB0B0B0)
.margin({
left: 16
})
Image($r('app.media.point'))
.width(16)
.height(16)
Text('45分钟')
.fontSize(13)
.fontColor(0xB0B0B0)
if (this.compDTO.operDataList[0].source) {
Text(this.compDTO.operDataList[0].source)
.fontSize(13)
.fontColor(0xB0B0B0)
Image($r('app.media.point'))
.width(16)
.height(16)
}
if (this.compDTO.operDataList[0].publishTime && this.compDTO.operDataList[0].publishTime.length === 13) {
Text(DateTimeUtils.getCommentTime(Number.parseFloat(this.compDTO.operDataList[0].publishTime)))
.fontSize(13)
.fontColor(0xB0B0B0)
}
Text('328评')
.fontSize(13)
.fontColor(0xB0B0B0)
.margin({
left: 6
})
}
}.margin({ left: 24 })
.width(375)
.height(16)
.id('label')
}
.width(375)
// .backgroundColor(0x000000)
}
}
\ No newline at end of file
... ...
... ... @@ -95,7 +95,6 @@ export struct SingleImageCardAppComponent {
.width(16)
.height(16)
.margin(10)
.backgroundColor(Color.Brown)
}.width(FULL_PARENT)
.justifyContent(FlexAlign.SpaceBetween)
}
... ...
... ... @@ -34,20 +34,27 @@ export struct SingleImageCardComponent {
.textOverflow({ overflow: TextOverflow.Ellipsis })// 超出的部分显示省略号。
.height("80%")
Row() {
Text(this.compDTO.operDataList[0].source ? this.compDTO.operDataList[0].source : '人民日报')
.height(40)
.fontSize(14)
.fontColor(Color.Gray)
Image($r('app.media.point'))
.width(16)
.height(16)
Text('45分钟前')
.height(40)
.fontSize(14)
.fontColor(Color.Gray)
if (this.compDTO.operDataList[0].source) {
Text(this.compDTO.operDataList[0].source)
.height(40)
.fontSize($r('app.float.font_size_12'))
.fontColor(Color.Gray)
.maxLines(1)
.textOverflow({ overflow: TextOverflow.Ellipsis })// 超出的部分显示省略号。
.width('50%')
Image($r('app.media.point'))
.width(16)
.height(16)
}
if (this.compDTO.operDataList[0].publishTime && this.compDTO.operDataList[0].publishTime.length === 13) {
Text(DateTimeUtils.getCommentTime(Number.parseFloat(this.compDTO.operDataList[0].publishTime)))
.height(40)
.fontSize($r('app.float.font_size_12'))
.fontColor(Color.Gray)
}
Text(this.compDTO.operDataList[0].visitorComment + '评')
.height(40)
.fontSize(14)
.fontSize($r('app.float.font_size_12'))
.fontColor(Color.Gray)
.padding({
left: 10
... ...
... ... @@ -45,6 +45,7 @@ export class DateTimeUtils {
static readonly PATTERN_DATE_TIME_MS: string = 'yyyyMMddHHmmssSSS'; // 时间中包含毫秒
static readonly PATTERN_DATE_TIME_WITHOUT_SECOND: string = 'yyyyMMddHHmm'; // 时间中不包含秒
static readonly PATTERN_DATE_TIME_SIMPLIFY: string = 'MM/dd HH:mm'; // 精简的日期+时间(不包含年份和秒), 月/日 时:分
static readonly PATTERN_DATE_SLASH_WITHOUT_YEAR2: string = 'MM-dd'; // 日期中不包含年份
// 仅日期格式(不包含时间)
static readonly PATTERN_DATE_DEFAULT: string = 'yyyyMMdd'; // 年月日
... ... @@ -428,6 +429,34 @@ export class DateTimeUtils {
static isBefore(_date: Date, dateToCompare: Date): boolean {
return _date.getTime() < dateToCompare.getTime();
}
/**
* 获取文章发布时间
* */
public static getCommentTime(publishTime: number): string {
let currentTime: number = new Date().getTime();
let timeGap = currentTime - publishTime;
let timeStr = ""
if (timeGap >= 60 * 60 * 1000 * 48) {
let publishYear = new Date(publishTime).getFullYear();
let currentYear = new Date(currentTime).getFullYear();
if (publishYear == currentYear) {
timeStr = this.formatDate(publishTime, DateTimeUtils.PATTERN_DATE_SLASH_WITHOUT_YEAR2)
} else {
timeStr = this.formatDate(publishTime)
}
} else if (timeGap > 60 * 60 * 1000 * 24) {
timeStr = Math.floor(timeGap / (60 * 60 * 1000 * 24)) + "天前";
} else if (timeGap > 60 * 60 * 1000) { // 1小时-24小时
timeStr = Math.floor(timeGap / (60 * 60 * 1000)) + "小时前";
} else if (timeGap > 60 * 1000) { // 1分钟-59分钟
timeStr = Math.floor(timeGap / (60 * 1000)) + "分钟前";
} else { // 1秒钟-59秒钟
timeStr = "刚刚";
}
return timeStr;
}
}
// const dateTimeUtils = new DateTimeUtils()
\ No newline at end of file
... ...