CardSourceInfo.ets
5 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
import { CompDTO, ContentDTO } from 'wdBean'
import { CommonConstants } from 'wdConstant/Index';
import { DateTimeUtils } from 'wdKit/Index';
import { JSON } from '@kit.ArkTS';
import router from '@ohos.router'
@Component
export struct CardSourceInfo {
@State contentDTO: ContentDTO = new ContentDTO();
@ObjectLink compDTO: CompDTO
handleTimeStr() {
return DateTimeUtils.getCommentTime(
this.contentDTO.publishTime.includes(' ')
? Number.parseFloat(new Date(this.contentDTO.publishTime).getTime().toString())
: Number.parseFloat(this.contentDTO.publishTime)
)
}
showTime() {
console.log('curRouter', this.contentDTO.publishTime)
const curRouter = router.getState().name;
const publishTime = this.contentDTO.publishTime.includes(' ')
? new Date(this.contentDTO.publishTime).getTime().toString()
: this.contentDTO.publishTime
let flag: boolean = false;
if (curRouter === 'MainPage') {
if (this.isTwoDaysAgo(publishTime)) {
console.log('curRouter 01')
flag = false
} else {
console.log('curRouter 02')
flag = true;
}
} else {
console.log('curRouter 03')
flag = true;
}
return flag;
}
isTwoDaysAgo(date: string) {
const twoDaysAgo = new Date();
twoDaysAgo.setDate(twoDaysAgo.getDate() - 2);
console.log('curRouter', date)
return parseInt(date) < twoDaysAgo.getTime()
}
build() {
Flex({ alignItems: ItemAlign.Center }) {
if (this.contentDTO.corner) {
Text(this.contentDTO.corner)
.fontSize($r("app.float.font_size_11"))
.fontColor($r("app.color.color_ED2800"))
.margin({ right: 2 })
}
if(this.contentDTO.cornerMark){
Text(this.contentDTO.cornerMark)
.fontSize($r("app.float.font_size_11"))
.fontColor($r("app.color.color_ED2800"))
.margin({ right: 2 })
}
if (this.contentDTO.rmhPlatform === 1) {
Text(this.contentDTO.rmhInfo?.rmhName)
.fontSize($r("app.float.font_size_11"))
.fontColor($r("app.color.color_B0B0B0"))
.maxLines(1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
} else if (this.contentDTO.source) {
Text(`${this.contentDTO.source}`)
.fontSize($r("app.float.font_size_11"))
.fontColor($r("app.color.color_B0B0B0"))
.maxLines(1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
if (((this.contentDTO.rmhPlatform === 1 && this.contentDTO.rmhInfo?.rmhName && this.contentDTO.rmhInfo?.rmhName != '') || (this.contentDTO.source && this.contentDTO.source != '')) && (this.getContentDtoBean()?.interactData?.commentNum
// || DateTimeUtils.getCommentTime(Number.parseFloat(this.contentDTO.publishTime)) != ''
|| (this.contentDTO.isSearch || this.contentDTO.isCollection ||
!this.contentDTO.isSearch && DateTimeUtils.getCommentTime
(Number
.parseFloat(this
.contentDTO.publishTime))
.indexOf
('-') === -1)
)) {
Image($r("app.media.point"))
.width(11)
.height(11)
}
// 新闻tab下的卡片,2天之前的不显示时间。但是如果是搜索情况下展示的卡片,显示时间
// if (this.contentDTO.isSearch || this.contentDTO.isCollection ||
// (!this.contentDTO.isSearch &&
// DateTimeUtils.getCommentTime(Number.parseFloat(this.contentDTO.publishTime)).indexOf('-') === -1)) {
//
// Text(DateTimeUtils.getCommentTime(Number.parseFloat(this.contentDTO.publishTime)))
// .fontSize($r("app.float.font_size_11"))
// .fontColor($r("app.color.color_B0B0B0"))
// .flexShrink(0);
// }
// if (this.contentDTO.source && this.showTime()) {
// Text(this.handleTimeStr())
// .fontSize($r("app.float.font_size_11"))
// .fontColor($r("app.color.color_B0B0B0"))
// .flexShrink(0)
// .margin({right: 4})
// }
if (this.showTime()) {
Text(this.handleTimeStr())
.fontSize($r("app.float.font_size_11"))
.fontColor($r("app.color.color_B0B0B0"))
.flexShrink(0)
.margin({right: 4})
}
if (this.getContentDtoBean()?.interactData?.commentNum && this.contentDTO.source) {
Text(`${this.getContentDtoBean()?.interactData?.commentNum}评`)
.fontSize($r("app.float.font_size_11"))
.fontColor($r("app.color.color_B0B0B0"))
.flexShrink(0)
.visibility(Number(this.getContentDtoBean()?.interactData?.commentNum) === 0 ? Visibility.None :
Visibility.Visible)
}
}
.width(CommonConstants.FULL_WIDTH)
.margin({ top: 8 })
}
/**
* 获取稿件业务对象
* @returns
*/
private getContentDtoBean(): ContentDTO {
if (this.compDTO == undefined) {
return this.contentDTO
}
if (this.compDTO.operDataList.length == 0) {
return this.contentDTO
}
return this.compDTO.operDataList[0]
}
}