ZhSingleRow06.ets
7.7 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
import { commentInfo, CompDTO, ContentDTO, Params, batchLikeAndCollectResult } from 'wdBean';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import { DateTimeUtils, SPHelper, Logger } from 'wdKit/Index';
import { ProcessUtils } from 'wdRouter';
import { SpConstants } from 'wdConstant/Index'
import {
batchLikeAndCollectParams,
} from 'wdDetailPlayApi/src/main/ets/request/ContentDetailRequest';
import { MultiPictureDetailViewModel } from '../../viewmodel/MultiPictureDetailViewModel';
import commentViewModel from '../../components/comment/viewmodel/CommentViewModel';
import { commentItemModel } from '../../components/comment/model/CommentModel'
import { onlyWifiLoadImg } from '../../utils/lazyloadImg';
import { InfomationCardClick } from '../../utils/infomationCardClick';
/**
* 精选评论卡
* Zh_Single_Row-06
*/
const TAG = 'Zh_Single_Row-06'
@Entry
@Component
export struct ZhSingleRow06 {
@State pageId: string = '';
@State pageName: string = '';
@State compDTO: CompDTO = {} as CompDTO
@State newsStatusOfUser: batchLikeAndCollectResult = {
likeStatus: '0'
} as batchLikeAndCollectResult // 点赞、收藏状态
@State loadImg: boolean = false;
async aboutToAppear(): Promise<void> {
console.log('Zh_Single_Row-06', JSON.stringify(this.compDTO.operDataList[0]?.commentInfo))
this.getInteractDataStatus()
this.loadImg = await onlyWifiLoadImg();
}
/**
* 点赞、取消点赞
*/
async toggleLikeStatus() {
// 未登录,跳转登录
const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
if (!user_id) {
WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
return
}
const commentInfo = this.compDTO.operDataList[0]?.commentInfo as commentInfo;
// commentLikeChange(this.item)
// this.newsStatusOfUser.likeStatus = this.newsStatusOfUser.likeStatus === '1' ? '0' : '1';
const commentLikeParam = {
targetId: commentInfo.newsId || '',
id: commentInfo.commentId,
targetType: commentInfo?.objectType || '',
api_status: this.newsStatusOfUser?.likeStatus == '1' ? false : true
} as commentItemModel;
commentViewModel.commentLike(commentLikeParam).then(() => {
this.newsStatusOfUser.likeStatus = this.newsStatusOfUser.likeStatus === '1' ? '0' : '1';
}).catch((err: Error) => {
console.log('06-err', JSON.stringify(err))
})
}
// 已登录->查询用户对作品点赞、收藏状态
async getInteractDataStatus() {
// 未登录,跳转登录
const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
if (!user_id) {
return
}
try {
const params: batchLikeAndCollectParams = {
contentList: [
{
contentId: this.compDTO.operDataList[0]?.commentInfo?.newsId + '',
contentType: this.compDTO.operDataList[0]?.commentInfo?.newsType + '',
contentRelId: this.compDTO.operDataList[0]?.commentInfo?.relId + '',
}
]
}
let data = await MultiPictureDetailViewModel.getInteractDataStatus(params)
Logger.info(TAG, 'ZhSingleRow06-data', JSON.stringify(data))
this.newsStatusOfUser = data[0];
Logger.info(TAG, `ZhSingleRow06-newsStatusOfUser:${JSON.stringify(this.newsStatusOfUser)}`)
} catch (exception) {
console.error(TAG, JSON.stringify(exception))
}
}
build() {
Column() {
//顶部
if (this.compDTO.operDataList?.length > 0) {
this.CompHeader(this.compDTO)
}
Column(){
Text(this.compDTO.operDataList[0]?.commentInfo?.commentTitle)
.fontWeight(500)
.maxLines(4)
.textOverflow({overflow: TextOverflow.Ellipsis})
.lineHeight(23)
.fontSize(16)
.margin({bottom: this.compDTO.operDataList[0]?.commentInfo?.commentPics ? 0 : 10})
.padding({bottom: this.compDTO.operDataList[0]?.commentInfo?.commentPics ? 0 : 10})
.textAlign(TextAlign.Start)
.width('100%')
.border({width: { bottom: this.compDTO.operDataList[0]?.commentInfo?.commentPics ? 0 : 1 }})
.borderColor(0xf4f4f4)
Text('[动画表情]')
.fontWeight(500)
.lineHeight(23)
.fontSize(16)
.margin({bottom: 10})
.padding({bottom: 10})
.textAlign(TextAlign.Start)
.width('100%')
.border({width: {bottom: 1}})
.borderColor(0xf4f4f4)
.visibility(this.compDTO.operDataList[0]?.commentInfo?.commentPics ? Visibility.Visible : Visibility.None)
Flex({justifyContent: FlexAlign.Start}) {
Image($r('app.media.icon_clip'))
.width(16)
.height(16)
.margin({right: 5})
Text(this.compDTO.operDataList[0]?.commentInfo?.newsTitle)
.maxLines(1)
.textOverflow({overflow: TextOverflow.Ellipsis})
.fontSize(14)
.fontColor(0x666666)
}
.width('100%')
}
.width("100%")
.padding({top: 12, bottom: 12, left: 10, right: 10})
.backgroundColor(0xf9f9f9)
.borderRadius(4)
.margin({bottom: 12})
.onClick(() => {
ProcessUtils.commentGotoWeb(this.compDTO.operDataList[0]?.commentInfo as commentInfo)
})
Row() {
Text(DateTimeUtils.getCommentTime(this.compDTO.operDataList[0]?.commentInfo?.publishTime))
.fontSize(12)
.fontColor(0x999999)
Row(){
Image(Number(this.newsStatusOfUser?.likeStatus) == 1 ? $r('app.media.icon_like_select') : $r('app.media.icon_like'))
.width(16)
.height(16)
.margin({right: 3})
Text(Number(this.newsStatusOfUser?.likeStatus) == 1 ? '已赞' : '点赞')
.fontSize(15)
.fontColor(0x999999)
}
.onClick(() => {
this.toggleLikeStatus()
})
}
.justifyContent(FlexAlign.SpaceBetween)
.width('100%')
}
.padding({
left: 10,
right: 10,
top: $r('app.float.card_comp_pagePadding_tb'),
bottom: $r('app.float.card_comp_pagePadding_tb')
})
.backgroundColor(0xffffff)
.width('100%')
.onClick(() => {
InfomationCardClick.track(this.compDTO, this.compDTO.operDataList[0], this.pageId, this.pageName)
})
}
@Builder
CompHeader(item: CompDTO) {
Row() {
Row() {
Image(
this.loadImg
? item.operDataList[0]?.commentInfo?.userHeaderUrl
? item.operDataList[0].commentInfo.userHeaderUrl
: commentViewModel.adjustUserType(item.operDataList[0].commentInfo?.userType)
? $r('app.media.WDAccountOwnerHedaerDefaultIcon')
: $r('app.media.WDAccountDefaultIcon')
: $r('app.media.icon_default_head_mater'))
.width(32)
.height(32)
.borderRadius(16)
.margin({right: 8})
Text(item.operDataList[0]?.commentInfo?.userName)
.lineHeight(32)
.fontSize(14)
.fontColor(0x222222)
.maxLines(1)
.fontWeight(500)
.textOverflow({overflow: TextOverflow.Ellipsis})
}
.onClick(() => {
ProcessUtils.commentGotoWeb(item.operDataList[0]?.commentInfo as commentInfo)
})
Row() {
Image($r("app.media.icon_elite_comment"))
.width(45)
.height(22)
.margin({ right: 1 })
Image($r("app.media.more"))
.width(14)
.height(14)
}
.onClick(() => {
WDRouterRule.jumpWithPage(WDRouterPage.QualityCommentsPage)
})
}
.margin({bottom: 10})
.justifyContent(FlexAlign.SpaceBetween)
.width('100%')
}
}
@Extend(Text)
function textOverflowStyle(maxLine: number) {
.maxLines(maxLine)
.textOverflow({ overflow: TextOverflow.Ellipsis })
}