InteractMComponent.ets
5.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import { ContentDTO } from 'wdBean/Index';
import { ProcessUtils } from 'wdRouter/Index';
import { InteractMessageModel } from '../../model/InteractMessageModel'
import { DateTimeUtils} from 'wdKit/Index'
@Component
export struct InteractMComponent {
messageModel:InteractMessageModel = new InteractMessageModel;
///"remark": "{"beReply":"乐事薯片,大家的最爱!!",
// "headUrl":"https: //uatjdcdnphoto.aikan.pdnews.cn//zhbj/img/user/2023122211/2A59F725E69849A38CEE8823B0D9D141.jpg",
// "contentId":"30035774121","contentRelObjectid":"2012","contentTitle":"乐事推出华夏风光限定罐七款城市地标包装让出游“有滋有味”",
// "commentContent":"大家都爱吃!!","userName":"人民日报网友a8dKCV","userId":"504964178466309","contentRelId":"500002866426",
// "shareUrl":"https: //pd-people-uat.pdnews.cn/column/30035774121-500002866426","userType":"1",
// "contentRelType":"1","visitor":"0","contentType":"8"}",
build() {
Row(){
Image(this.messageModel.InteractMsubM.headUrl)
.alt($r('app.media.default_head'))
.width(36)
.height(36)
.borderRadius(18)
Column(){
Row(){
Text(this.messageModel.InteractMsubM.userName)
.fontSize('14fp').fontColor('#222222')
Text(this.buildContentString())
.fontSize('14fp').fontColor('#999999')
.margin({left:5})
}.width('100%')
Text(this.getPublishTime(this.messageModel.time,DateTimeUtils.getDateTimestamp(this.messageModel.time)+""))
.margin({top:2})
.fontSize('12fp').fontColor('#B0B0B0').margin({top:10,bottom:10})
if (this.messageModel.contentType === '208' || this.messageModel.contentType === '209'){
Text(this.messageModel.message)
.margin({bottom:10})
.fontSize('16fp').fontColor('#222222')
.width('100%')
.constraintSize({maxHeight:500})
}
if(this.messageModel.contentType != '211' && this.messageModel.contentType != '210'){
Column(){
if (this.messageModel.contentType === '207' || this.messageModel.contentType === '209'){
Text('[你的评论]'+this.buildCommentContent()).fontSize('14fp').fontColor('#666666').constraintSize({maxHeight:500})
.margin({top:15,bottom:10})
.width('100%')
Divider()
.color('#EDEDED')
.backgroundColor('#EDEDED')
.width('100%')
.height(1)
}
Row(){
Image($r('app.media.MessageOriginTextIcon'))
.width('12')
.height('12')
Text(this.messageModel.InteractMsubM.contentTitle)
.fontSize('12fp')
.fontColor('#666666')
.maxLines(1)
.width('90%')
.textOverflow({overflow:TextOverflow.Ellipsis})
Blank()
Image($r('app.media.mine_user_edit'))
.width('12')
.height('12')
}.margin({top:10,bottom:15})
}.padding({left:10,right:10}).alignItems(HorizontalAlign.Start).backgroundColor('#f5f5f5').borderRadius(5)
.onClick(()=>{
let contentDTO :ContentDTO = new ContentDTO();
contentDTO.objectType = this.messageModel.InteractMsubM.contentType
contentDTO.objectId = this.messageModel.InteractMsubM.contentId
ProcessUtils.processPage(contentDTO)
})
}
}.padding({left:5,right:5}).alignItems(HorizontalAlign.Start).width('90%')
}.padding({top:10,left:16,right:16}).width('100%').alignItems(VerticalAlign.Top)
}
buildContentString(): string {
let contentString: string = ''
if (this.messageModel.contentType === '206') {
contentString = '赞了你的作品'
}else if(this.messageModel.contentType === '207'){
contentString = '赞了你的评论'
}else if(this.messageModel.contentType === '208'){
contentString = '评论了你的作品'
}else if(this.messageModel.contentType === '209'){
contentString = '回复了你的评论'
}else if(this.messageModel.contentType === '210'){
contentString = '转发了您的作品'
}else if(this.messageModel.contentType === '211'){
contentString = '关注了你'
}
return contentString;
}
buildCommentContent(): string {
let contentString : string = this.messageModel.contentType === '207'?this.messageModel.message:this.messageModel.InteractMsubM.beReply;
return contentString;
}
getPublishTime(data:string,publishTime: string): string {
const publishTimestamp = parseInt(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}分钟前`;
if (minutes === 0) {
result = `刚刚`;
}
} else if (hours < 24) {
result = `${hours}小时前`;
} else {
result = `${days}天前`;
if (days > 1) {
let arr = data.split(" ")
if (arr.length === 2) {
let arr2 = arr[0].split("-")
if (arr2.length === 3) {
result = `${arr2[1]}-${arr2[2]}`
}
} else {
//原始数据是时间戳 需要转成dateString
let time = DateTimeUtils.formatDate(Number(publishTime))
let arr = time.split("-")
if (arr.length === 3) {
result = `${arr[1]}-${arr[2]}`
}
}
}
}
console.log(result);
return result
}
}