CardSourceInfo.ets
8.08 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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
import { CompDTO, ContentDTO } from 'wdBean'
import { CommonConstants, CompStyle } from 'wdConstant/Index';
import { DateTimeUtils, Logger } from 'wdKit/Index';
import router from '@ohos.router'
@Reusable
@Component
export struct CardSourceInfo {
@State @Watch('checkData') contentDTO: ContentDTO = new ContentDTO();
@ObjectLink compDTO: CompDTO
// 特殊稿件内部item展示的来源信息
isCompInnerSource: boolean = false
// 是否有展示的信息,如来源,标签、时间、评论
@State viewShowData: boolean = true
private maxLength: number = 16;
@State private isEllipsisActive: boolean = false;
@State private displayText: string = '';
aboutToAppear(): void {
this.processText();
}
private isLimited(): boolean {
return this.compDTO.compStyle === CompStyle.Card_13
|| this.compDTO.compStyle === CompStyle.Card_14
|| this.compDTO.compStyle === CompStyle.Card_06
|| this.compDTO.compStyle === CompStyle.Card_21;
}
processText() {
const sourceText = this.contentDTO.rmhPlatform === 1 ? this.contentDTO.rmhInfo?.rmhName : this.contentDTO.source;
if (this.isLimited() && sourceText.length > this.maxLength) {
this.displayText = sourceText.substring(0, this.maxLength) + '...';
this.isEllipsisActive = true;
} else {
this.displayText = sourceText;
this.isEllipsisActive = false;
}
//Logger.warn(`cj2024 sourceText displayText=${this.displayText} isEllipsisActive=${this.isEllipsisActive}`)
}
aboutToReuse(params: Record<string, object>): void {
this.contentDTO = params.contentDTO as ContentDTO
}
aboutToRecycle(): void {
}
aboutToDisappear(): void {
}
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)) {
flag = false
} else {
flag = true;
}
} else {
flag = true;
}
return flag;
}
showCommentNum() {
const curRouter = router.getState().name;
// return curRouter !== 'PeopleShipHomePage'
return true
}
/**
* 全域数字显示规则
* 1、当数量为千位以內时,显示数字,不保留小数点,比如 4585
* 2、当数量为万位~1亿时,显示xx 万,保留小数点后一位,比如1517.9w、2.9w
* 3、当数量为1亿~千亿时,显示XX 亿,保留小数点后一位,比如1517.9亿、2.9亿
* 4、不进行四舍五入
* 5、0 和空 不显示
*/
handlerNum(number: string) {
const num = number ?? '0';
if (Number.parseInt(num) <= 9999) {
return Number.parseInt(num).toString()
} else if (Number.parseInt(num) > 9999 && Number.parseInt(num) <= 99999999) {
const num1: string = num.slice(0, -4); // 万
const num2: string = num.slice(-4, -3); // 千
return num2 === '0' ? num1 + '万' : num1 + '.' + num2 + '万'
} else if (Number.parseInt(num) > 99999999) {
let num1: string = num.slice(0, -8); // 亿
let num2: string = num.slice(-8, -7);
const num3: string = `0.${num.slice(-7, -6)}`
if (Math.round(Number(num3)) > Number(num3)) {
if (`${Number(num2) + 1}`.length === 2) {
num1 = `${Number(num1) + 1}`
num2 = '0'
}
}
return num2 === '0' ? num1 + '亿' : num1 + '.' + num2 + '亿'
}
return num
}
isTwoDaysAgo(date: string) {
const twoDaysAgo = new Date();
twoDaysAgo.setDate(twoDaysAgo.getDate() - 2);
console.log('curRouter', date)
return parseInt(date) < twoDaysAgo.getTime()
}
build() {
Flex({ justifyContent: FlexAlign.Start, direction: FlexDirection.Row }) {
// 标签
if (this.contentDTO.cornerMark || this.contentDTO.corner) {
Text(this.contentDTO.cornerMark || this.contentDTO.corner)
.fontSize($r("app.float.font_size_11"))
.fontColor($r("app.color.color_ED2800"))
.margin({ right: 6 })
.flexShrink(0)
}
// 来源信息
if (this.contentDTO.rmhPlatform === 1 || this.contentDTO.source) {
Text(this.displayText)
.fontSize($r("app.float.font_size_11"))
.fontColor($r("app.color.color_B0B0B0"))
.maxLines(1)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}
// 点
if ((this.showTime()&&(this.contentDTO.rmhPlatform === 1 || this.contentDTO.source)) || ((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)
.visibility(!this.isEllipsisActive ? Visibility.Visible : Visibility.Hidden)
}
// 发布日期
if (this.showTime() && !this.isEllipsisActive) {
Text(this.handleTimeStr())
.fontSize($r("app.float.font_size_11"))
.fontColor($r("app.color.color_B0B0B0"))
.flexShrink(0)
.margin({ right: 4 })
}
// 评论数
if (!this.contentDTO.cornerMark && !this.contentDTO.corner && !this.isEllipsisActive) {
if (this.contentDTO.objectType !=='2' && !this.isCompInnerSource && Number(this.getContentDtoBean()?.interactData?.commentNum) > 0 &&
this.showCommentNum()) {
Text(`${this.handlerNum(this.getContentDtoBean()?.interactData?.commentNum.toString())}评`)
.fontSize($r("app.float.font_size_11"))
.fontColor($r("app.color.color_B0B0B0"))
.flexShrink(0)
} else {
if (this.contentDTO.objectType !=='2' && this.isCompInnerSource && this.contentDTO.interactData && this.contentDTO.interactData?.commentNum > 0) {
Text(`${this.handlerNum(this.contentDTO.interactData?.commentNum.toString())}评`)
.fontSize($r("app.float.font_size_11"))
.fontColor($r("app.color.color_B0B0B0"))
.flexShrink(0)
}
}
}
}
.width(CommonConstants.FULL_WIDTH)
.margin({ top: this.viewShowData ? 8 : 0 })
}
/**
* 获取稿件业务对象
* @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]
}
/**
* 检测是否有展示的数据
*/
checkData() {
let have = false
if (this.contentDTO.corner) {
have = true
}
if (this.contentDTO.cornerMark) {
have = true
}
if (this.contentDTO.rmhPlatform === 1) {
have = true
} else if (this.contentDTO.source) {
have = true
}
// 发布日期
if (this.showTime()) {
have = true
}
// 评论数
if (this.contentDTO.objectType !=='2' && !this.isCompInnerSource && Number(this.getContentDtoBean()?.interactData?.commentNum) > 0 &&
this.showCommentNum()) {
have = true
} else {
if (this.contentDTO.objectType !=='2' && this.isCompInnerSource && this.contentDTO.interactData && this.contentDTO.interactData?.commentNum > 0) {
have = true
}
}
if (have) {
} else {
this.viewShowData = false
}
}
}