张善主

feat(动态):操作

@@ -47,6 +47,10 @@ export class HttpUrlUtils { @@ -47,6 +47,10 @@ export class HttpUrlUtils {
47 */ 47 */
48 static readonly INTERACT_DATA_PATH: string = "/api/rmrb-contact/contact/zh/c/content/interactData"; 48 static readonly INTERACT_DATA_PATH: string = "/api/rmrb-contact/contact/zh/c/content/interactData";
49 /** 49 /**
  50 + * 查询各类型内容动态数据接口V2:其他场景的均调用V2---api缓存1-2s
  51 + */
  52 + static readonly INTERACT_V2_DATA_PATH: string = "/api/rmrb-contact/contact/zh/c/v2/content/interactData";
  53 + /**
50 * 查询视频频道推荐楼层 54 * 查询视频频道推荐楼层
51 */ 55 */
52 static readonly DISPLAY_REC_COMPINFO: string = "/api/rmrb-bff-display-zh/display/zh/c/rec/compInfo"; 56 static readonly DISPLAY_REC_COMPINFO: string = "/api/rmrb-bff-display-zh/display/zh/c/rec/compInfo";
1 -import { AccountManagerUtils, Logger, DateTimeUtils, SPHelper } from 'wdKit'; 1 +import { AccountManagerUtils, Logger, DateTimeUtils, SPHelper, NumberFormatterUtils } from 'wdKit';
2 import { MultiPictureDetailViewModel } from '../viewmodel/MultiPictureDetailViewModel'; 2 import { MultiPictureDetailViewModel } from '../viewmodel/MultiPictureDetailViewModel';
3 import { ContentDetailDTO,postBatchAttentionStatusParams, 3 import { ContentDetailDTO,postBatchAttentionStatusParams,
4 PhotoListBean, 4 PhotoListBean,
5 ContentDTO, 5 ContentDTO,
6 - RmhInfoDTO, } from 'wdBean'; 6 + batchLikeAndCollectResult,
  7 + RmhInfoDTO,
  8 + InteractDataDTO, } from 'wdBean';
7 import media from '@ohos.multimedia.media'; 9 import media from '@ohos.multimedia.media';
8 import { OperRowListView } from './view/OperRowListView'; 10 import { OperRowListView } from './view/OperRowListView';
9 import { WDPlayerController } from 'wdPlayer/Index'; 11 import { WDPlayerController } from 'wdPlayer/Index';
10 import { 12 import {
11 batchLikeAndCollectParams, 13 batchLikeAndCollectParams,
12 - batchLikeAndCollectResult,  
13 ContentDetailRequest, 14 ContentDetailRequest,
14 contentListParams, 15 contentListParams,
15 postExecuteCollectRecordParams, 16 postExecuteCollectRecordParams,
@@ -32,25 +33,23 @@ export struct DynamicDetailComponent { @@ -32,25 +33,23 @@ export struct DynamicDetailComponent {
32 private relId: string = '' 33 private relId: string = ''
33 private contentId: string = '' 34 private contentId: string = ''
34 private relType: string = '' 35 private relType: string = ''
35 - //出参 fixme 模拟数据用json转换 36 +
  37 + //出参
36 @State contentDetailData: ContentDetailDTO = {} as ContentDetailDTO 38 @State contentDetailData: ContentDetailDTO = {} as ContentDetailDTO
37 - //变量 39 + //UI
38 scroller: Scroller = new Scroller(); 40 scroller: Scroller = new Scroller();
  41 +
  42 + //点赞 收藏 评论 数量
  43 + @State interactDataDTO: InteractDataDTO = {} as InteractDataDTO
39 /** 44 /**
40 - * 默认未关注 点击去关注 45 + * 关注状态:默认未关注 点击去关注
41 */ 46 */
42 @State followStatus: String = '0'; 47 @State followStatus: String = '0';
43 - @State newsStatusOfUser: batchLikeAndCollectResult | undefined = undefined // 点赞、收藏状态  
44 48
  49 + @State newsStatusOfUser: batchLikeAndCollectResult | undefined = undefined// 点赞、收藏状态
45 //跳转 50 //跳转
46 private mJumpInfo: ContentDTO = {} as ContentDTO; 51 private mJumpInfo: ContentDTO = {} as ContentDTO;
47 52
48 - // 获取当前所有的display对象  
49 - promise: Promise<Array<display.Display>> = display.getAllDisplays()  
50 -  
51 - // 屏幕宽度(单位px)  
52 - @State screenWidth: number = 0;  
53 -  
54 async aboutToAppear() { 53 async aboutToAppear() {
55 await this.getContentDetailData() 54 await this.getContentDetailData()
56 } 55 }
@@ -327,17 +326,28 @@ export struct DynamicDetailComponent { @@ -327,17 +326,28 @@ export struct DynamicDetailComponent {
327 .margin({ top: $r('app.float.margin_24')}) 326 .margin({ top: $r('app.float.margin_24')})
328 //点赞 327 //点赞
329 Row(){ 328 Row(){
330 - Image($r('app.media.icon_like_selected_redheart')) 329 + Image(this.newsStatusOfUser?.likeStatus == '1'?
  330 + $r('app.media.icon_like_selected_redheart')
  331 + :$r('app.media.icon_like_unselect_grey_redheart'))
331 .width($r('app.float.margin_24')) 332 .width($r('app.float.margin_24'))
332 .height($r('app.float.margin_24')) 333 .height($r('app.float.margin_24'))
333 .objectFit(ImageFit.Cover) 334 .objectFit(ImageFit.Cover)
334 - Text("2.6万") 335 + Text(NumberFormatterUtils.formatNumberWithWan(this.interactDataDTO?.likeNum))
335 .fontColor($r('app.color.color_999999')) 336 .fontColor($r('app.color.color_999999'))
336 .fontSize($r('app.float.font_size_16')) 337 .fontSize($r('app.float.font_size_16'))
337 .lineHeight($r('app.float.margin_20')) 338 .lineHeight($r('app.float.margin_20'))
338 .margin({ left: $r('app.float.margin_2')}) 339 .margin({ left: $r('app.float.margin_2')})
339 } 340 }
  341 + .width($r('app.float.margin_154'))
  342 + .height($r('app.float.margin_40'))
340 .margin({top:$r('app.float.margin_16')}) 343 .margin({top:$r('app.float.margin_16')})
  344 + .borderWidth($r('app.float.margin_1'))
  345 + .borderColor($r('app.color.color_EDEDED'))
  346 + .borderRadius($r('app.float.margin_20'))
  347 + .onClick((event: ClickEvent) => {
  348 + //点赞操作
  349 + this.toggleLikeStatus()
  350 + })
341 Blank().layoutWeight(1) 351 Blank().layoutWeight(1)
342 //fixme 评论组件 352 //fixme 评论组件
343 } 353 }
@@ -405,27 +415,30 @@ export struct DynamicDetailComponent { @@ -405,27 +415,30 @@ export struct DynamicDetailComponent {
405 this.getBatchAttentionStatus() 415 this.getBatchAttentionStatus()
406 this.getInteractDataStatus() 416 this.getInteractDataStatus()
407 this.makeJumpInfo() 417 this.makeJumpInfo()
  418 + this.interactDataV2()
408 } 419 }
409 420
410 - // 查询当前登录用户点赞状态  
411 - private async getInteractDataStatus() {  
412 - //未登录  
413 - if(!AccountManagerUtils.isLoginSync() || this.contentDetailData?.openLikes != 1){  
414 - return 421 +
  422 + private async interactDataV2() {
  423 + this.interactDataDTO = await MultiPictureDetailViewModel.interactDataV2(
  424 + this.contentDetailData?.newsId+'',this.contentDetailData?.newsType+'',this.contentDetailData.reLInfo == null ?'':this.contentDetailData.reLInfo?.relId,this.contentDetailData.rmhPlatform)
415 } 425 }
  426 +
  427 + // 已登录->查询用户对作品点赞、收藏状态
  428 + private async getInteractDataStatus() {
416 try { 429 try {
417 const params: batchLikeAndCollectParams = { 430 const params: batchLikeAndCollectParams = {
418 contentList: [ 431 contentList: [
419 { 432 {
420 - contentId: this.contentDetailData?.newsId + '',  
421 - contentType: this.contentDetailData?.newsType + '', 433 + contentId: this.contentDetailData[0]?.newsId + '',
  434 + contentType: this.contentDetailData[0]?.newsType + '',
422 } 435 }
423 ] 436 ]
424 } 437 }
425 console.error(TAG, JSON.stringify(this.contentDetailData)) 438 console.error(TAG, JSON.stringify(this.contentDetailData))
426 let data = await MultiPictureDetailViewModel.getInteractDataStatus(params) 439 let data = await MultiPictureDetailViewModel.getInteractDataStatus(params)
427 console.error(TAG, '查询用户对作品点赞、收藏状态', JSON.stringify(data)) 440 console.error(TAG, '查询用户对作品点赞、收藏状态', JSON.stringify(data))
428 - // this.newsStatusOfUser = data[0]; 441 + this.newsStatusOfUser = data[0];
429 Logger.info(TAG, `newsStatusOfUser:${JSON.stringify(this.newsStatusOfUser)}`) 442 Logger.info(TAG, `newsStatusOfUser:${JSON.stringify(this.newsStatusOfUser)}`)
430 } catch (exception) { 443 } catch (exception) {
431 console.error(TAG, JSON.stringify(exception)) 444 console.error(TAG, JSON.stringify(exception))
@@ -524,6 +537,37 @@ export struct DynamicDetailComponent { @@ -524,6 +537,37 @@ export struct DynamicDetailComponent {
524 } 537 }
525 }) 538 })
526 } 539 }
  540 +
  541 + /**
  542 + * 点赞、取消点赞
  543 + */
  544 + async toggleLikeStatus() {
  545 + // 未登录,跳转登录
  546 + const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
  547 + if (!user_id) {
  548 + WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
  549 + return
  550 + }
  551 + const params: postExecuteLikeParams = {
  552 + status: this.newsStatusOfUser?.likeStatus === '1' ? '0' : '1',
  553 + contentId: this.contentDetailData?.newsId + '',
  554 + contentType: this.contentDetailData?.newsType + '',
  555 + }
  556 + ContentDetailRequest.postExecuteLike(params).then(res => {
  557 +
  558 + if (this.newsStatusOfUser) {
  559 + this.newsStatusOfUser.likeStatus = this.newsStatusOfUser?.likeStatus === '1' ? '0' : '1'
  560 + if (this.newsStatusOfUser.likeStatus === '1') {
  561 + this.interactDataDTO.likeNum = Number(this.interactDataDTO.likeNum) + 1
  562 + } else {
  563 + this.interactDataDTO.likeNum = Number(this.interactDataDTO.likeNum) - 1
  564 + }
  565 + console.log('点赞、取消点赞==', this.newsStatusOfUser?.likeStatus, this.interactDataDTO?.likeNum)
  566 + // this.queryContentInteractCount()
  567 + }
  568 +
  569 + })
  570 + }
527 } 571 }
528 572
529 interface radiusType { 573 interface radiusType {
1 import HashMap from '@ohos.util.HashMap'; 1 import HashMap from '@ohos.util.HashMap';
2 import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork'; 2 import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
3 -import { DateTimeUtils, Logger } from 'wdKit'; 3 +import { DateTimeUtils, Logger, StringUtils } from 'wdKit';
4 import { 4 import {
5 batchLikeAndCollectResult, 5 batchLikeAndCollectResult,
6 CompInfoBean, 6 CompInfoBean,
@@ -128,6 +128,19 @@ export class PageRepository { @@ -128,6 +128,19 @@ export class PageRepository {
128 return url; 128 return url;
129 } 129 }
130 130
  131 + static getInteractDataV2Url(contentId: string, contentType: string, contentRelId: string,rmhPlatform:number) {
  132 + let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_V2_DATA_PATH;
  133 + url = url + "?contentId=" + contentId
  134 + + "&contentType=" + contentType
  135 + if(!StringUtils.isEmpty(contentRelId)){
  136 + url = url + "&contentRelId=" + contentRelId;
  137 + }
  138 + url = url + "&rmhPlatform=" + rmhPlatform;
  139 + url = url + "&detail=" + '1';
  140 + Logger.info(TAG, "getInteractDataV2Url url = " + url)
  141 + return url;
  142 + }
  143 +
131 static getInteractDataUrl() { 144 static getInteractDataUrl() {
132 let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_DATA_PATH; 145 let url = HttpUrlUtils.getHost() + HttpUrlUtils.INTERACT_DATA_PATH;
133 Logger.info(TAG, "getInteractDataUrl url = " + url) 146 Logger.info(TAG, "getInteractDataUrl url = " + url)
@@ -253,6 +266,12 @@ export class PageRepository { @@ -253,6 +266,12 @@ export class PageRepository {
253 return WDHttp.get<ResponseDTO<ContentDetailDTO[]>>(url, headers) 266 return WDHttp.get<ResponseDTO<ContentDetailDTO[]>>(url, headers)
254 }; 267 };
255 268
  269 + static fetchInteractDataV2(contentId: string, contentType: string, contentRelId: string,rmhPlatform:number) {
  270 + let url = PageRepository.getInteractDataV2Url(contentId, contentType, contentRelId,rmhPlatform)
  271 + let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
  272 + return WDHttp.get<ResponseDTO<InteractDataDTO>>(url, headers)
  273 + };
  274 +
256 static fetchInteractData(param: object) { 275 static fetchInteractData(param: object) {
257 let url = PageRepository.getInteractDataUrl() 276 let url = PageRepository.getInteractDataUrl()
258 let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); 277 let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
@@ -5,7 +5,8 @@ import { ContentDetailDTO, @@ -5,7 +5,8 @@ import { ContentDetailDTO,
5 batchLikeAndCollectResult, 5 batchLikeAndCollectResult,
6 postBatchAttentionStatusParams, 6 postBatchAttentionStatusParams,
7 postBatchAttentionStatusResult, 7 postBatchAttentionStatusResult,
8 - postInteractBrowsOperateParams 8 + postInteractBrowsOperateParams,
  9 + InteractDataDTO
9 } from 'wdBean'; 10 } from 'wdBean';
10 import { PageRepository } from '../repository/PageRepository'; 11 import { PageRepository } from '../repository/PageRepository';
11 12
@@ -106,4 +107,28 @@ export class MultiPictureDetailViewModel { @@ -106,4 +107,28 @@ export class MultiPictureDetailViewModel {
106 }) 107 })
107 } 108 }
108 109
  110 + //查询点赞数量
  111 + static async interactDataV2(contentId: string, contentType: string, contentRelId: string,rmhPlatform:number): Promise<InteractDataDTO> {
  112 + return new Promise<InteractDataDTO>((success, error) => {
  113 + Logger.info(TAG, `interactDataV2 start`);
  114 + PageRepository.fetchInteractDataV2(contentId, contentType, contentRelId,rmhPlatform).then((resDTO: ResponseDTO<InteractDataDTO>) => {
  115 + if (!resDTO || !resDTO.data) {
  116 + Logger.error(TAG, 'interactDataV2 is empty');
  117 + error('resDTO is empty');
  118 + return
  119 + }
  120 + if (resDTO.code != 0) {
  121 + Logger.error(TAG, `interactDataV2 then code:${resDTO.code}, message:${resDTO.message}`);
  122 + error('resDTO Response Code is failure');
  123 + return
  124 + }
  125 + Logger.info(TAG, "interactDataV2 then,navResDTO.timestamp:" + resDTO.timestamp);
  126 + success(resDTO.data);
  127 + }).catch((err: Error) => {
  128 + Logger.error(TAG, `interactDataV2 catch, error.name : ${err.name}, error.message:${err.message}`);
  129 + error(err);
  130 + })
  131 + })
  132 + }
  133 +
109 } 134 }
@@ -117,6 +117,10 @@ @@ -117,6 +117,10 @@
117 "value": "28vp" 117 "value": "28vp"
118 }, 118 },
119 { 119 {
  120 + "name": "margin_40",
  121 + "value": "40vp"
  122 + },
  123 + {
120 "name": "margin_48", 124 "name": "margin_48",
121 "value": "48vp" 125 "value": "48vp"
122 }, 126 },
@@ -129,6 +133,10 @@ @@ -129,6 +133,10 @@
129 "value": "60vp" 133 "value": "60vp"
130 }, 134 },
131 { 135 {
  136 + "name": "margin_154",
  137 + "value": "154vp"
  138 + },
  139 + {
132 "name": "single_row_03_img_height", 140 "name": "single_row_03_img_height",
133 "value": "88vp" 141 "value": "88vp"
134 }, 142 },
@@ -185,6 +193,10 @@ @@ -185,6 +193,10 @@
185 "value": "24vp" 193 "value": "24vp"
186 }, 194 },
187 { 195 {
  196 + "name": "margin_1",
  197 + "value": "1vp"
  198 + },
  199 + {
188 "name": "margin_6", 200 "name": "margin_6",
189 "value": "6vp" 201 "value": "6vp"
190 }, 202 },