yangsunyue_wd

desc:热门评论点赞相关 90%

... ... @@ -562,6 +562,12 @@ export class HttpUrlUtils {
return url
}
/*评论点赞*/
static getCommentLikeUrl() {
let url = HttpUrlUtils._hostUrl + "/api/rmrb-comment/comment/zh/c/commentLike"
return url
}
/*levleIcon*/
static getBatchUserUrl() {
let url = HttpUrlUtils._hostUrl + "/api/rmrb-user-point/auth/level/zh/c/batchUser"
... ...
... ... @@ -35,13 +35,6 @@ export class commentListModel extends PageModel{
list: commentItemModel[] = []
}
export class commentStatusListModel extends PageModel{
pageNum: number = 0
pageSize: number = 0
totalCount: number = 0
hasNext: number = 0
list: commentStatusModel[] = []
}
@Observed
... ... @@ -68,8 +61,7 @@ export class commentItemModel {
fromUserType: WDPublicUserType = 0
id: string = ''
likeNum: string = ''
/*是否点赞*/
isLike: boolean = false
mySelf: string = ''
parentId: string = ''
region: string = ''
... ... @@ -104,7 +96,8 @@ export class commentItemModel {
shareInfo:commentItemShareInfoModel = new commentItemShareInfoModel;
api_commentId:string = '';
api_status:string = '';
/*评论点赞状态 0-未点赞 1-已点赞*/
api_status:boolean = false;
api_level:string = '';
api_levelHead:string = 'http';
... ... @@ -116,6 +109,7 @@ export class commentItemModel {
}
@Observed
export class commentItemShareInfoModel {
shareCoverUrl: string = ''
shareSummary: string = ''
... ... @@ -123,9 +117,20 @@ export class commentItemShareInfoModel {
shareUrl: string = ''
}
@Observed
export class commentStatusListModel extends PageModel{
pageNum: number = 0
pageSize: number = 0
totalCount: number = 0
hasNext: number = 0
list: commentStatusModel[] = []
}
@Observed
export class commentStatusModel {
commentId:string = '';
status:string = '';
status:boolean = false;
level:string = '';
levelHead:string = '';
... ... @@ -137,3 +142,5 @@ export class commentStatusModel {
authIcon:string = '';
}
... ...
... ... @@ -35,16 +35,17 @@ export struct QualityCommentsComponent {
this.fullScreen();
// commentViewModel.fetchQualityCommentListLocal(getContext()).then(commentListModel => {
// this.allDatas.push(...commentListModel.list)
// })
commentViewModel.fetchQualityCommentList('1').then((commentListModel) => {
if (commentListModel && commentListModel.list && commentListModel.list.length > 0) {
// commentListModel.hasMore = true;
// this.browSingModel.viewType = ViewType.LOADED;
commentListModel.list.forEach(element => {
this.allDatas.push(new commentItemModel())
});
this.allDatas.push(...commentListModel.list)
// if (commentListModel.list.length === this.browSingModel.pageSize) {
// this.browSingModel.currentPage++;
// this.browSingModel.hasMore = true;
... ... @@ -103,7 +104,7 @@ export struct QualityCommentsComponent {
left: { anchor: "__container__", align: HorizontalAlign.Start }
})
.offset({
y: (this.topSafeHeight / 2) + 'px'
y: (this.topSafeHeight / 2) + 'px'
})
.margin({ left: 16 })
.onClick(() => {
... ... @@ -131,15 +132,14 @@ export struct QualityCommentsComponent {
left: { anchor: "__container__", align: HorizontalAlign.Start }
})
.offset({
y: (this.topSafeHeight / 2) + 'px'
y: (this.topSafeHeight / 2) + 'px'
})
.margin({ left: 16 })
.onClick(() => {
router.back()
})
Text('精选评论')
// .height('42lpx')
Text('精选评论')// .height('42lpx')
.maxLines(1)
.id("title")
.fontSize('35lpx')
... ... @@ -147,11 +147,11 @@ export struct QualityCommentsComponent {
.fontColor($r('app.color.color_222222'))
.lineHeight('42lpx')
.alignRules({
center: {anchor: "__container__", align: VerticalAlign.Center},
middle: {anchor: "__container__", align: HorizontalAlign.Center}
center: { anchor: "__container__", align: VerticalAlign.Center },
middle: { anchor: "__container__", align: HorizontalAlign.Center }
})
.offset({
y: (this.topSafeHeight / 2) + 'px'
y: (this.topSafeHeight / 2) + 'px'
})
}
.visibility(this.tileOpacity > 0 ? 0 : 1)
... ... @@ -315,17 +315,24 @@ struct QualityCommentItem {
}
Row() {
//comment_like_select
Image($r(this.item.likeNum ? 'app.media.comment_like_select' : 'app.media.comment_like_normal'))
Image($r(this.item.api_status ? 'app.media.comment_like_select' : 'app.media.comment_like_normal'))
.width(16)
.height(16)
if (this.item.likeNum) {
if (this.item.likeNum && this.item.likeNum != '0') {
Text(this.item.likeNum)
.fontColor(this.item.isLike ? '#ED2800' : '#999999')
.fontColor(this.item.api_status ? '#ED2800' : '#999999')
.fontSize(14)
.margin({ left: 3 })
}
}
}.onClick(() => {
this.item.api_status = !this.item.api_status
// commentViewModel.commnetLikeChange(this.item)
commentViewModel.commentLike(this.item).then(() => {
}).catch(() => {
// commentViewModel.commnetLikeChange(this.item)
})
})
}
}.height(38).width('100%').justifyContent(FlexAlign.SpaceBetween)
... ...
import { Logger, ResourcesUtils } from 'wdKit/Index';
import { Logger, ResourcesUtils, UserDataLocal } from 'wdKit/Index';
import { HttpBizUtil, HttpUrlUtils, ResponseDTO } from 'wdNetwork/Index';
import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest';
import { commentItemModel, commentListModel, commentStatusListModel, commentStatusModel } from '../model/CommentModel';
... ... @@ -48,7 +48,7 @@ class CommentViewModel {
}
/*获取热门评论*/
fetchQualityCommentList(pageNum: string): Promise<commentListModel> {
fetchQualityCommentList(pageNum: string): Promise<commentListModel> {
let url = HttpUrlUtils.getQualityCommentUrl() + `?&pageSize=${10}&pageNum=${pageNum}`
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return new Promise<commentListModel>((success, fail) => {
... ... @@ -63,15 +63,11 @@ class CommentViewModel {
}
let listData = data.data as commentListModel
this.fetchCommentStatusAndConfigAuthIcon(listData).then((commentListModel) =>{
this.fetchCommentStatusAndConfigAuthIcon(listData).then((commentListModel) => {
console.log(TAG, 'fetchCommentStatusAndConfigAuthIcon完成')
success(commentListModel)
})
// return this.fetchCommentStatusAndConfigAuthIcon(listData)
// this.fetchCommentStatusAndConfigAuthIcon(listData)
// success(listData)
}, (error: Error) => {
fail(error.message)
Logger.debug(TAG, error.toString())
... ... @@ -79,8 +75,49 @@ class CommentViewModel {
})
}
/*点赞*/
commentLike(model: commentItemModel) {
return new Promise<void>((success, fail) => {
let url = HttpUrlUtils.getCommentLikeUrl()
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
let bean: Record<string, string> = {};
// commentId number
// 被点赞的评论ID
// targetId string
// 被点赞的内容ID
// targetType number
// 内容类别,1:点播,2:直播,3:活动,4:广告,5:专题,6:链接,7:榜单,8:图文,9:组图,10:H5新闻,11:频道,12:组件,13:音频,14:动态(13和14为中文版新增)
// status number
// 点赞状态 0:取消点赞 1:点赞
// userName string
// 【迭代二新增】当前用户的用户名
// userHeaderUrl string
// 【迭代二新增】当前用户的头像url
bean['commentId'] = model.id;
bean['targetId'] = model.targetId;
bean['targetType'] = model.targetType;
bean['status'] = model.api_status ? '1' : '0';
bean['userName'] = UserDataLocal.getUserId();
bean['userHeaderUrl'] = UserDataLocal.getUserHeaderUrl();
HttpRequest.post<ResponseDTO<commentStatusModel[]>>(url, bean, headers).then((data: ResponseDTO<commentStatusModel[]>) => {
if (data.code != 0) {
fail()
return
}
success()
}, (error: Error) => {
fail()
Logger.debug(TAG, error.toString())
})
})
}
/*多接口批查*/
fetchCommentStatusAndConfigAuthIcon(model: commentListModel): Promise<commentListModel> {
fetchCommentStatusAndConfigAuthIcon(model: commentListModel): Promise<commentListModel> {
let commentIDs: string[] = [];
... ... @@ -142,7 +179,7 @@ class CommentViewModel {
return
}
let listData = data.data as commentStatusModel[]
//点赞
for (const element of listData) {
for (const commentModel of model.list) {
if (element.commentId == commentModel.id) {
... ... @@ -265,6 +302,22 @@ class CommentViewModel {
}
commnetLikeChange(model:commentItemModel){
model.api_status = !model.api_status
//点赞
if (model.api_status) {
model.likeNum = (Number.parseInt(model.likeNum) + 1) + ''
}
//取消点赞
if (!model.api_status) {
model.likeNum = (Number.parseInt(model.likeNum) - 1) + ''
if (Number.parseInt(model.likeNum) < 0) {
model.likeNum = '0'
}
}
}
}
... ...