chenjun3_wd

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

... ... @@ -152,6 +152,8 @@ export struct MorningEveningPaperComponent {
if (imageSource) {
this.pickColor(imageSource)
} else {
this.mixedBgColor = this.pageInfoBean.backgroundColor
}
}
... ...
... ... @@ -390,6 +390,33 @@ export struct PaperSingleColumn999CardView {
private item: ContentDTO = {} as ContentDTO;
private index: number = -1;
getPublishTime(): string {
const publishTimestamp = parseInt(this.item?.publishTime)
const currentTime = Date.now(); // 当前时间戳
// 计算差异
const timeDifference = currentTime - publishTimestamp;
// 转换为分钟、小时和天
const minutes = Math.floor(timeDifference / (1000 * 60));
const hours = Math.floor(timeDifference / (1000 * 60 * 60));
const days = Math.floor(timeDifference / (1000 * 60 * 60 * 24));
// 根据时间差返回对应的字符串
let result: string;
if (minutes < 60) {
result = `${minutes}分钟前`;
} else if (hours < 24) {
result = `${hours}小时前`;
} else {
result = `${days}天前`;
}
console.log(result);
return result
}
build() {
Column() {
Text(this.item?.newsTitle)
... ... @@ -429,14 +456,33 @@ export struct PaperSingleColumn999CardView {
}
if (this.item?.visitorComment) {
Row() {
Text(this.item?.visitorComment + "评")
.fontSize(12)
.fontColor(Color.Gray)
.margin({ left: 22 })
Row() {
Text(this.item?.source)
.fontSize(12)
.fontColor(Color.Gray)
.margin({ left: 22 })
Image($r('app.media.point'))
.width(16)
.height(16)
.margin({ top: 10, bottom: 10 })
Text(this.getPublishTime())
.fontSize(12)
.fontColor(Color.Gray)
Text(this.item?.visitorComment + "评")
.fontSize(12)
.fontColor(Color.Gray)
.margin({ left: 6 })
}
.justifyContent(FlexAlign.Start)
Image($r('app.media.icon_forward'))
.width(16)
.height(16)
.margin({ left: 10, right: 22, top: 10, bottom: 10 })
.alignRules({
center: { anchor: '__container__', align: VerticalAlign.Center },
right: { anchor: '__container__', align: HorizontalAlign.End }
})
}.width(CommonConstants.FULL_PARENT)
.justifyContent(FlexAlign.SpaceBetween)
}
... ...