Showing
6 changed files
with
69 additions
and
19 deletions
| 1 | -import { SPHelper, Logger, ToastUtils } from 'wdKit'; | 1 | +import { SPHelper, Logger, ToastUtils, EmitterUtils, EmitterEventId } from 'wdKit'; |
| 2 | import { ContentDetailDTO, Action, ContentDTO, batchLikeAndCollectResult } from 'wdBean'; | 2 | import { ContentDetailDTO, Action, ContentDTO, batchLikeAndCollectResult } from 'wdBean'; |
| 3 | import { ProcessUtils } from 'wdRouter'; | 3 | import { ProcessUtils } from 'wdRouter'; |
| 4 | import router from '@ohos.router'; | 4 | import router from '@ohos.router'; |
| @@ -11,6 +11,11 @@ import { TrackConstants } from 'wdTracking/Index'; | @@ -11,6 +11,11 @@ import { TrackConstants } from 'wdTracking/Index'; | ||
| 11 | 11 | ||
| 12 | const TAG = 'CarderInteraction' | 12 | const TAG = 'CarderInteraction' |
| 13 | 13 | ||
| 14 | +interface parsedObj { | ||
| 15 | + contentId: string, | ||
| 16 | + likeStatus: string | ||
| 17 | +} | ||
| 18 | + | ||
| 14 | /** | 19 | /** |
| 15 | * 卡片 分享、评论、点赞公用组件 | 20 | * 卡片 分享、评论、点赞公用组件 |
| 16 | */ | 21 | */ |
| @@ -47,6 +52,25 @@ export struct CarderInteraction { | @@ -47,6 +52,25 @@ export struct CarderInteraction { | ||
| 47 | // console.log(TAG, 'this.isShowComment', this.isShowComment) | 52 | // console.log(TAG, 'this.isShowComment', this.isShowComment) |
| 48 | // console.log(TAG, 'this.isShowLike', this.isShowLike) | 53 | // console.log(TAG, 'this.isShowLike', this.isShowLike) |
| 49 | // console.log(TAG, 'router.getState().name', router.getState().name) | 54 | // console.log(TAG, 'router.getState().name', router.getState().name) |
| 55 | + EmitterUtils.receiveEvent(EmitterEventId.LIKE_CHANGE_STATUS, (val: string | undefined) => { | ||
| 56 | + // console.log(TAG,'val点赞', val) | ||
| 57 | + if (val === undefined) { | ||
| 58 | + console.error('Value is undefined'); | ||
| 59 | + return; | ||
| 60 | + } | ||
| 61 | + | ||
| 62 | + try { | ||
| 63 | + const parsedVal: parsedObj = JSON.parse(val); | ||
| 64 | + if (parsedVal.contentId === this.contentDetailData.newsId + '') { | ||
| 65 | + // console.log(TAG,'params点赞状态', parsedVal.likeStatus) | ||
| 66 | + this.likeBean['likeStatus'] = parsedVal.likeStatus | ||
| 67 | + // console.log(TAG,'this.likeBean点赞状态', this.likeBean['likeStatus']) | ||
| 68 | + } | ||
| 69 | + } catch (error) { | ||
| 70 | + console.error('Error parsing JSON:', error); | ||
| 71 | + } | ||
| 72 | + }); | ||
| 73 | + | ||
| 50 | } | 74 | } |
| 51 | 75 | ||
| 52 | 76 |
| @@ -53,6 +53,11 @@ import { onlyWifiLoadImg } from '../utils/lazyloadImg'; | @@ -53,6 +53,11 @@ import { onlyWifiLoadImg } from '../utils/lazyloadImg'; | ||
| 53 | const TAG = 'DynamicDetailComponent' | 53 | const TAG = 'DynamicDetailComponent' |
| 54 | const PATTERN_DATE_CN_RN: string = 'yyyy年MM月dd日 HH:mm'; | 54 | const PATTERN_DATE_CN_RN: string = 'yyyy年MM月dd日 HH:mm'; |
| 55 | 55 | ||
| 56 | +interface parsedObj { | ||
| 57 | + contentId: string, | ||
| 58 | + likeStatus: string | ||
| 59 | +} | ||
| 60 | + | ||
| 56 | 61 | ||
| 57 | /** | 62 | /** |
| 58 | * 动态详情页UI | 63 | * 动态详情页UI |
| @@ -782,11 +787,11 @@ export struct DynamicDetailComponent { | @@ -782,11 +787,11 @@ export struct DynamicDetailComponent { | ||
| 782 | } | 787 | } |
| 783 | ] | 788 | ] |
| 784 | } | 789 | } |
| 785 | - console.error(TAG, JSON.stringify(this.contentDetailData)) | 790 | + // console.error(TAG,'CarderInteraction', JSON.stringify(params.contentList)) |
| 786 | let data = await MultiPictureDetailViewModel.getInteractDataStatus(params) | 791 | let data = await MultiPictureDetailViewModel.getInteractDataStatus(params) |
| 787 | - console.error(TAG, '查询用户对作品点赞、收藏状态', JSON.stringify(data)) | 792 | + // console.error(TAG, 'CarderInteraction 查询用户对作品点赞、收藏状态', JSON.stringify(data)) |
| 788 | this.newsStatusOfUser = data[0]; | 793 | this.newsStatusOfUser = data[0]; |
| 789 | - Logger.info(TAG, `newsStatusOfUser:${JSON.stringify(this.newsStatusOfUser)}`) | 794 | + // Logger.info(TAG, `newsStatusOfUser:${JSON.stringify(this.newsStatusOfUser)}`) |
| 790 | } catch (exception) { | 795 | } catch (exception) { |
| 791 | console.error(TAG, JSON.stringify(exception)) | 796 | console.error(TAG, JSON.stringify(exception)) |
| 792 | } | 797 | } |
| @@ -808,7 +813,7 @@ export struct DynamicDetailComponent { | @@ -808,7 +813,7 @@ export struct DynamicDetailComponent { | ||
| 808 | } | 813 | } |
| 809 | let data = await MultiPictureDetailViewModel.getBatchAttentionStatus(params) | 814 | let data = await MultiPictureDetailViewModel.getBatchAttentionStatus(params) |
| 810 | this.followStatus = data[0]?.status; | 815 | this.followStatus = data[0]?.status; |
| 811 | - Logger.info(TAG, `followStatus:${JSON.stringify(this.followStatus)}`) | 816 | + // Logger.info(TAG, `followStatus:${JSON.stringify(this.followStatus)}`) |
| 812 | } catch (exception) { | 817 | } catch (exception) { |
| 813 | this.followStatus = '0'; | 818 | this.followStatus = '0'; |
| 814 | } | 819 | } |
| @@ -882,7 +887,7 @@ export struct DynamicDetailComponent { | @@ -882,7 +887,7 @@ export struct DynamicDetailComponent { | ||
| 882 | status: this.followStatus == '0' ? 1 : 0, | 887 | status: this.followStatus == '0' ? 1 : 0, |
| 883 | } | 888 | } |
| 884 | ContentDetailRequest.postInteractAccentionOperate(params2).then(res => { | 889 | ContentDetailRequest.postInteractAccentionOperate(params2).then(res => { |
| 885 | - console.log('关注号主==', JSON.stringify(res.data)) | 890 | + // console.log('关注号主==', JSON.stringify(res.data)) |
| 886 | if (this.followStatus == '1') { | 891 | if (this.followStatus == '1') { |
| 887 | this.followStatus = '0' | 892 | this.followStatus = '0' |
| 888 | TrackingContent.follow(true,this.contentDetailData.rmhInfo == null ?"":this.contentDetailData.rmhInfo.rmhId,this.contentDetailData.rmhInfo == null ?"":this.contentDetailData.rmhInfo.rmhName,TrackConstants.PageName.DynamicDetail,TrackConstants.PageName.DynamicDetail,this.pageParam) | 893 | TrackingContent.follow(true,this.contentDetailData.rmhInfo == null ?"":this.contentDetailData.rmhInfo.rmhId,this.contentDetailData.rmhInfo == null ?"":this.contentDetailData.rmhInfo.rmhName,TrackConstants.PageName.DynamicDetail,TrackConstants.PageName.DynamicDetail,this.pageParam) |
| @@ -915,7 +920,14 @@ export struct DynamicDetailComponent { | @@ -915,7 +920,14 @@ export struct DynamicDetailComponent { | ||
| 915 | } else { | 920 | } else { |
| 916 | this.interactDataDTO.likeNum = Number(this.interactDataDTO.likeNum) - 1 | 921 | this.interactDataDTO.likeNum = Number(this.interactDataDTO.likeNum) - 1 |
| 917 | } | 922 | } |
| 918 | - console.log('点赞、取消点赞==', this.newsStatusOfUser?.likeStatus, this.interactDataDTO?.likeNum) | 923 | + let parsedVal: parsedObj = { |
| 924 | + contentId: params.contentId, | ||
| 925 | + likeStatus: this.newsStatusOfUser.likeStatus | ||
| 926 | + } | ||
| 927 | + | ||
| 928 | + EmitterUtils.sendEvent(EmitterEventId.LIKE_CHANGE_STATUS, JSON.stringify(parsedVal)) | ||
| 929 | + // console.log(TAG, 'CarderInteraction 点赞parsedVal', JSON.stringify(parsedVal)) | ||
| 930 | + // console.log('点赞、取消点赞==', this.newsStatusOfUser?.likeStatus, this.interactDataDTO?.likeNum) | ||
| 919 | 931 | ||
| 920 | //内容点赞、取消点赞Tracking 1点赞 0取消点赞 | 932 | //内容点赞、取消点赞Tracking 1点赞 0取消点赞 |
| 921 | TrackingContent.like(this.newsStatusOfUser?.likeStatus == '1', TrackConstants.PageName.DynamicDetail, TrackConstants.PageName.DynamicDetail, | 933 | TrackingContent.like(this.newsStatusOfUser?.likeStatus == '1', TrackConstants.PageName.DynamicDetail, TrackConstants.PageName.DynamicDetail, |
| @@ -440,10 +440,10 @@ export struct ImageAndTextPageComponent { | @@ -440,10 +440,10 @@ export struct ImageAndTextPageComponent { | ||
| 440 | userName:this.contentDetailData?.userInfo?.userName || '' + '', | 440 | userName:this.contentDetailData?.userInfo?.userName || '' + '', |
| 441 | channelId:String(this.contentDetailData?.reLInfo?.channelId) || '' + '' | 441 | channelId:String(this.contentDetailData?.reLInfo?.channelId) || '' + '' |
| 442 | } | 442 | } |
| 443 | - console.log(TAG, '点赞、取消点赞params', JSON.stringify(params)) | 443 | + // console.log(TAG, '点赞、取消点赞params', JSON.stringify(params)) |
| 444 | PageRepository.postExecuteLike(params).then(res => { | 444 | PageRepository.postExecuteLike(params).then(res => { |
| 445 | // console.log(TAG, '点赞、res', JSON.stringify(res)) | 445 | // console.log(TAG, '点赞、res', JSON.stringify(res)) |
| 446 | - console.log(TAG, '点赞、取消点赞 this.newsStatusOfUser', JSON.stringify(this.newsStatusOfUser)) | 446 | + // console.log(TAG, '点赞、取消点赞 this.newsStatusOfUser', JSON.stringify(this.newsStatusOfUser)) |
| 447 | if (this.newsStatusOfUser) { | 447 | if (this.newsStatusOfUser) { |
| 448 | //内容点赞、取消点赞Tracking 1点赞 0取消点赞 | 448 | //内容点赞、取消点赞Tracking 1点赞 0取消点赞 |
| 449 | this.newsStatusOfUser.likeStatus = this.newsStatusOfUser?.likeStatus == '1' ? '0' : '1' | 449 | this.newsStatusOfUser.likeStatus = this.newsStatusOfUser?.likeStatus == '1' ? '0' : '1' |
| @@ -452,7 +452,7 @@ export struct ImageAndTextPageComponent { | @@ -452,7 +452,7 @@ export struct ImageAndTextPageComponent { | ||
| 452 | } else { | 452 | } else { |
| 453 | this.likeNum = Number(this.likeNum) - 1 | 453 | this.likeNum = Number(this.likeNum) - 1 |
| 454 | } | 454 | } |
| 455 | - console.log(TAG, '点赞newsStatusOfUser.likeStatus ', this.newsStatusOfUser.likeStatus) | 455 | + // console.log(TAG, '点赞newsStatusOfUser.likeStatus ', this.newsStatusOfUser.likeStatus) |
| 456 | // this.queryContentInteractCount() | 456 | // this.queryContentInteractCount() |
| 457 | TrackingContent.like(this.newsStatusOfUser?.likeStatus == '1', TrackConstants.PageName.My, TrackConstants.PageName.My) | 457 | TrackingContent.like(this.newsStatusOfUser?.likeStatus == '1', TrackConstants.PageName.My, TrackConstants.PageName.My) |
| 458 | } else { | 458 | } else { |
| @@ -28,7 +28,7 @@ export struct Card19Component { | @@ -28,7 +28,7 @@ export struct Card19Component { | ||
| 28 | this.titleInit(); | 28 | this.titleInit(); |
| 29 | const curRouter = router.getState().name; | 29 | const curRouter = router.getState().name; |
| 30 | this.clicked = hasClicked(this.contentDTO.objectId, curRouter) | 30 | this.clicked = hasClicked(this.contentDTO.objectId, curRouter) |
| 31 | - console.log('card19',JSON.stringify(this.contentDTO)) | 31 | + // console.log('card19',JSON.stringify(this.contentDTO)) |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | titleInit() { | 34 | titleInit() { |
| @@ -19,6 +19,10 @@ interface ILikeStyleResp { | @@ -19,6 +19,10 @@ interface ILikeStyleResp { | ||
| 19 | url: Resource; | 19 | url: Resource; |
| 20 | name: string; | 20 | name: string; |
| 21 | } | 21 | } |
| 22 | +interface parsedObj { | ||
| 23 | + contentId: string, | ||
| 24 | + likeStatus: string | ||
| 25 | +} | ||
| 22 | 26 | ||
| 23 | @Component | 27 | @Component |
| 24 | export struct LikeComponent { | 28 | export struct LikeComponent { |
| @@ -59,18 +63,18 @@ export struct LikeComponent { | @@ -59,18 +63,18 @@ export struct LikeComponent { | ||
| 59 | this.likesStyle = this.contentDetailData.likesStyle | 63 | this.likesStyle = this.contentDetailData.likesStyle |
| 60 | this.openLikes = this.contentDetailData.openLikes == 1 ? true : false | 64 | this.openLikes = this.contentDetailData.openLikes == 1 ? true : false |
| 61 | } | 65 | } |
| 62 | - console.log(TAG, 'this.contentDetailData', JSON.stringify(this.contentDetailData)) | ||
| 63 | - console.log(TAG, 'this.componentType', this.componentType) | ||
| 64 | - console.log(TAG, 'this.likesStyle', this.likesStyle) | ||
| 65 | - console.log(TAG, 'this.openLikes', this.openLikes) | 66 | + // console.log(TAG, 'this.contentDetailData', JSON.stringify(this.contentDetailData)) |
| 67 | + // console.log(TAG, 'this.componentType', this.componentType) | ||
| 68 | + // console.log(TAG, 'this.likesStyle', this.likesStyle) | ||
| 69 | + // console.log(TAG, 'this.openLikes', this.openLikes) | ||
| 66 | this.onDataUpdated() | 70 | this.onDataUpdated() |
| 67 | this.contentTrackingDict() | 71 | this.contentTrackingDict() |
| 68 | } | 72 | } |
| 69 | 73 | ||
| 70 | onDataUpdated() { | 74 | onDataUpdated() { |
| 71 | - console.log(TAG, '点赞点击') | ||
| 72 | if (this.data) { | 75 | if (this.data) { |
| 73 | if (this.data['contentType'] !== undefined ) { | 76 | if (this.data['contentType'] !== undefined ) { |
| 77 | + console.log(TAG, 'CarderInteraction 点赞点击') | ||
| 74 | //获取点赞状态 | 78 | //获取点赞状态 |
| 75 | this.getLikeStatus() | 79 | this.getLikeStatus() |
| 76 | //获取点赞数 | 80 | //获取点赞数 |
| @@ -458,6 +462,7 @@ export struct LikeComponent { | @@ -458,6 +462,7 @@ export struct LikeComponent { | ||
| 458 | this.likeCount-- | 462 | this.likeCount-- |
| 459 | TrackingContent.like(false,this.pageId,this.pageName,this.pageParam) | 463 | TrackingContent.like(false,this.pageId,this.pageName,this.pageParam) |
| 460 | } | 464 | } |
| 465 | + | ||
| 461 | } | 466 | } |
| 462 | 467 | ||
| 463 | if (this.likeCount <= 0) { | 468 | if (this.likeCount <= 0) { |
| @@ -479,19 +484,25 @@ export struct LikeComponent { | @@ -479,19 +484,25 @@ export struct LikeComponent { | ||
| 479 | { | 484 | { |
| 480 | contentId: this.data['contentId'], | 485 | contentId: this.data['contentId'], |
| 481 | contentType: this.data['contentType'], | 486 | contentType: this.data['contentType'], |
| 482 | - contentRelId: this.data['contentRelId'] || '' + '', | 487 | + contentRelId: this.data['contentRelId'] == "0" ? '' : this.data['contentRelId'] || '' + '', |
| 483 | } | 488 | } |
| 484 | ] | 489 | ] |
| 485 | } | 490 | } |
| 486 | - console.log(TAG, "查询点赞状态params", JSON.stringify(params)) | 491 | + // console.log(TAG, "CarderInteraction 查询点赞状态params", JSON.stringify(params)) |
| 487 | ContentDetailRequest.postBatchLikeAndCollectStatus(params).then(res => { | 492 | ContentDetailRequest.postBatchLikeAndCollectStatus(params).then(res => { |
| 488 | - console.log(TAG, '查询点赞、收藏状态==', JSON.stringify(res.data)) | 493 | + // console.log(TAG, 'CarderInteraction 查询点赞、收藏状态==', JSON.stringify(res.data)) |
| 489 | if (res.data) { | 494 | if (res.data) { |
| 490 | if(res.data[0].likeStatus) { | 495 | if(res.data[0].likeStatus) { |
| 491 | this.likeStatus = res.data[0].likeStatus ? true : false | 496 | this.likeStatus = res.data[0].likeStatus ? true : false |
| 492 | } else { | 497 | } else { |
| 493 | this.likeStatus = false | 498 | this.likeStatus = false |
| 494 | } | 499 | } |
| 500 | + // CarderInteraction组件交互 | ||
| 501 | + if (this.data['likeStatus'] == "1") { | ||
| 502 | + this.likeStatus = true | ||
| 503 | + } else if (this.data['likeStatus'] == "0") { | ||
| 504 | + this.likeStatus = false | ||
| 505 | + } | ||
| 495 | } | 506 | } |
| 496 | }).catch(() => { | 507 | }).catch(() => { |
| 497 | this.likeStatus = false | 508 | this.likeStatus = false |
-
Please register or login to post a comment