RmhTitle.ets
8.51 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
253
254
255
256
/**
* 这里是人民号动态中的顶部信息:人民号logo,名字,描述,关注等
*/
import {
ContentDetailRequest,
postInteractAccentionOperateParams
} from 'wdDetailPlayApi/src/main/ets/request/ContentDetailRequest';
import { RmhInfoDTO, CompDTO, ContentDTO } from 'wdBean'
import { CommonConstants } from 'wdConstant/Index';
import { DateTimeUtils, SPHelper, Logger, ToastUtils, DisplayUtils } from 'wdKit';
import { SpConstants } from 'wdConstant/Index'
import { ProcessUtils, WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import router from '@ohos.router'
import { postBatchAttentionStatusParams } from 'wdBean/Index';
import { MultiPictureDetailViewModel } from '../../viewmodel/MultiPictureDetailViewModel'
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { InfomationCardClick } from '../../utils/infomationCardClick'
import measure from '@ohos.measure'
@Component
export struct RmhTitle {
@State compDTO: CompDTO = new CompDTO()
@State contentDTO: ContentDTO = new ContentDTO();
@State pageId: string = '';
@State pageName: string = '';
@Prop rmhInfo: RmhInfoDTO
@Prop publishTime: string | undefined
@State loadImg: boolean = false;
isPeopleShipHome: boolean = false;
// 当前页面没有使用,并且会导致奔溃
// @Consume @Watch('pageShowForUpdateData') pageShow:number
/**
* 是否需要隐藏发布时间超过2天的时间展示,默认不隐藏
*/
@Prop hideTime: boolean
/**
* 默认未关注 点击去关注
*/
@State followStatus: string = '0';
/**
* 关注号主
*/
async handleAccention() {
// 未登录,跳转登录
const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
if (!user_id) {
WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
return
}
const params2: postInteractAccentionOperateParams = {
attentionUserType: this.rmhInfo?.userType || '', //被关注用户类型(1 普通用户 2 视频号 3 矩阵号)
attentionUserId: this.rmhInfo?.userId || '', // 被关注用户号主id
attentionCreatorId: this.rmhInfo?.rmhId || '', // 被关注用户号主id
status: this.followStatus == '0' ? 1 : 0,
}
ContentDetailRequest.postInteractAccentionOperate(params2).then(res => {
console.log('rmhTitle-data', JSON.stringify(res.data))
InfomationCardClick.track(
this.compDTO,
this.contentDTO,
this.pageId,
this.pageName,
'follow', // like, commentClick, follow
this.followStatus == '0' ? true : false,
)
if (this.followStatus == '1') {
this.followStatus = '0'
} else {
this.followStatus = '1'
// 弹窗样式与何时调用待确认
ContentDetailRequest.postPointLevelOperate({ operateType: 6 }).then((res) => {
console.log('关注号主获取积分==', JSON.stringify(res.data))
if (res.data?.showToast) {
ToastUtils.showToast(res.data.ruleName + '+' + res.data.rulePoint + '积分', 1000);
}
})
}
})
}
/**
* 查询当前登录用户是否关注作品号主
* */
async getBatchAttentionStatus() {
try {
const params: postBatchAttentionStatusParams = {
creatorIds: [{ creatorId: this.rmhInfo?.rmhId ?? '' }]
}
let data = await MultiPictureDetailViewModel.getBatchAttentionStatus(params)
this.followStatus = data[0]?.status;
Logger.info(`rmhTitle-followStatus:${JSON.stringify(this.followStatus)}`)
} catch (exception) {
Logger.info(`rmhTitle-followStatus:${JSON.stringify(exception)}`)
}
}
async aboutToAppear(): Promise<void> {
//关注查询限制
if (this.rmhInfo?.cnIsAttention) {
this.getBatchAttentionStatus()
}
const curRouter = router.getState().name;
if (curRouter === 'MainPage') {
this.hideTime = true;
}
this.loadImg = await onlyWifiLoadImg();
}
pageShowForUpdateData(): void {
if (this.rmhInfo?.cnIsAttention) {
this.getBatchAttentionStatus()
}
}
getDaysBetweenDates(date: number) {
const oneDay = 24 * 60 * 60 * 1000; // 一天的毫秒数
const time1 = new Date().getTime(); // 今天日期的时间戳
const time2 = new Date(date).getTime(); // 要比较日期的时间戳
const diffDays = Math.round(Math.abs((time1 - time2) / oneDay)); // 两个日期时间戳差值除以一天的毫秒数得到天数,取绝对值并四舍五入
return diffDays;
}
showTime() {
return !(this.hideTime && this.getDaysBetweenDates(Number(this.publishTime)) > 2)
}
build() {
Flex() {
if (this.rmhInfo.userType != '5') {
Stack() {
Image(
this.loadImg
? this.rmhInfo?.rmhHeadUrl
: this.rmhInfo.userType == '1'
? $r('app.media.default_head_userPage')
: $r('app.media.AccountOwner_DefaultIcon'))
.alt(
this.rmhInfo.userType == '1'?$r('app.media.default_head_userPage'):
$r('app.media.AccountOwner_DefaultIcon'))
.width(36)
.height(36)
.borderRadius(18)
.border({
width: 0.5,
color: '#0D000000', // 5% 透明度的黑色
style: BorderStyle.Solid
})
Image(this.rmhInfo?.authIcon)
.width(14)
.height(14)
.borderRadius(50)
}
.margin({ right: 8 })
.alignContent(Alignment.BottomEnd)
.flexShrink(0)
}
Column() {
Text(this.rmhInfo?.rmhName)
.fontSize(15)
.fontColor($r('app.color.color_222222'))
.fontWeight(600)
.alignSelf(ItemAlign.Start)
.height(21)
.lineHeight(21)
.margin({bottom: 1})
// Flex({alignContent: FlexAlign.Start, wrap: FlexWrap.NoWrap}) {
Row() {
if (this.showTime()) {
if (this.publishTime) {
Text(DateTimeUtils.getCommentTime(Number.parseFloat(this.publishTime)))
.fontSize($r("app.float.font_size_12"))
.fontColor($r("app.color.color_B0B0B0"))
.height(14)
.lineHeight(14)
}
if (this.publishTime && this.rmhInfo?.rmhDesc) {
Image($r('app.media.point'))
.width(14)
.height(14)
}
}
if(this.rmhInfo?.rmhDesc != undefined){
Text(this.rmhInfo?.rmhDesc.replaceAll('\n', ''))
.fontSize($r("app.float.font_size_12"))
.fontColor($r("app.color.color_B0B0B0"))
.maxLines(1)
.alignSelf(ItemAlign.Start)
.textOverflow({ overflow: TextOverflow.Ellipsis })
.textAlign(TextAlign.Start)
.height(14)
.lineHeight(14)
.width('calc(100% - 54vp)')
// .constraintSize({maxWidth:(DisplayUtils.getDeviceWidth() - 32 - 36 - 18 - this.getTextWidth(DateTimeUtils.getCommentTime(Number.parseFloat(this.publishTime))))})
}
}
.height(14)
.align(Alignment.Start)
.width('100%')
// }
// .width('calc(100% - 36vp - 8vp)')
}
.justifyContent(FlexAlign.SpaceBetween)
.width('100%')
Blank()
if (this.rmhInfo?.cnIsAttention) {
Column() {
Row(){
if (Number(this.followStatus) === 0) {
Image($r('app.media.rmh_follow'))
.width(16)
.height(16)
}
Text(Number(this.followStatus) === 0 ? '关注' : '已关注')
.fontSize($r('app.float.font_size_13'))
.fontColor(Number(this.followStatus) === 0 ? $r('app.color.color_ED2800') : 0xc6c6c6)
}.margin({top:4})
.height(36)
}
.flexShrink(0)
.onClick(() => {
this.handleAccention();
})
.height(36)
}
}
.width(CommonConstants.FULL_WIDTH)
.height(36)
.margin({ bottom: 10 })
.onClick(()=>{
///个人主页 动态头像不能跳转
if (this.isPeopleShipHome) return
// 跳转号主
ProcessUtils.gotoPeopleShipHomePage( this.rmhInfo?.rmhId,this.rmhInfo?.banControl,this.rmhInfo?.cnMainControl,this.rmhInfo?.userId,this.rmhInfo?.userType)
})
}
// 获取文本宽度
private getTextWidth(text: string) {
let size = measure.measureTextSize({
textContent: text,
fontSize: $r("app.float.font_size_12")
})
return px2vp(Number(size.width))
}
}