Showing
1 changed file
with
56 additions
and
25 deletions
| 1 | -import { commentInfo, CompDTO, ContentDTO, Params } from 'wdBean'; | 1 | +import { commentInfo, CompDTO, ContentDTO, Params, batchLikeAndCollectResult } from 'wdBean'; |
| 2 | import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'; | 2 | import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'; |
| 3 | -import { DateTimeUtils, SPHelper } from 'wdKit/Index'; | 3 | +import { DateTimeUtils, SPHelper, Logger } from 'wdKit/Index'; |
| 4 | import { ProcessUtils } from 'wdRouter'; | 4 | import { ProcessUtils } from 'wdRouter'; |
| 5 | import { SpConstants } from 'wdConstant/Index' | 5 | import { SpConstants } from 'wdConstant/Index' |
| 6 | +import { | ||
| 7 | + batchLikeAndCollectParams, | ||
| 8 | + ContentDetailRequest, | ||
| 9 | + contentListParams, | ||
| 10 | + postExecuteCollectRecordParams, | ||
| 11 | + postExecuteLikeParams, | ||
| 12 | + postInteractAccentionOperateParams | ||
| 13 | +} from 'wdDetailPlayApi/src/main/ets/request/ContentDetailRequest'; | ||
| 14 | +import { MultiPictureDetailViewModel } from '../../viewmodel/MultiPictureDetailViewModel'; | ||
| 6 | 15 | ||
| 7 | /** | 16 | /** |
| 8 | * 精选评论卡 | 17 | * 精选评论卡 |
| 9 | * Zh_Single_Row-06 | 18 | * Zh_Single_Row-06 |
| 10 | */ | 19 | */ |
| 11 | const TAG = 'Zh_Single_Row-06' | 20 | const TAG = 'Zh_Single_Row-06' |
| 12 | - | ||
| 13 | -// interface commentInfo { | ||
| 14 | -// commentTitle: string, | ||
| 15 | -// newsTitle: string, | ||
| 16 | -// userName: string, | ||
| 17 | -// userHeaderUrl: string, | ||
| 18 | -// publishTime: number | ||
| 19 | -// } | ||
| 20 | -// interface operDataListItem { | ||
| 21 | -// commentInfo: commentInfo | ||
| 22 | -// } | ||
| 23 | -// interface CommentData{ | ||
| 24 | -// operDataList: Array<operDataListItem> | ||
| 25 | -// } | ||
| 26 | - | ||
| 27 | @Entry | 21 | @Entry |
| 28 | @Component | 22 | @Component |
| 29 | export struct ZhSingleRow06 { | 23 | export struct ZhSingleRow06 { |
| 30 | @State compDTO: CompDTO = {} as CompDTO | 24 | @State compDTO: CompDTO = {} as CompDTO |
| 31 | - @State likeBl: boolean = false; | 25 | + @State newsStatusOfUser: batchLikeAndCollectResult = {} as batchLikeAndCollectResult // 点赞、收藏状态 |
| 26 | + | ||
| 27 | + aboutToAppear(): void { | ||
| 28 | + this.getInteractDataStatus() | ||
| 29 | + } | ||
| 32 | 30 | ||
| 33 | - async likeAction() { | 31 | + /** |
| 32 | + * 点赞、取消点赞 | ||
| 33 | + */ | ||
| 34 | + async toggleLikeStatus() { | ||
| 35 | + // 未登录,跳转登录 | ||
| 34 | const user_id = await SPHelper.default.get(SpConstants.USER_ID, '') | 36 | const user_id = await SPHelper.default.get(SpConstants.USER_ID, '') |
| 35 | if (!user_id) { | 37 | if (!user_id) { |
| 36 | WDRouterRule.jumpWithPage(WDRouterPage.loginPage) | 38 | WDRouterRule.jumpWithPage(WDRouterPage.loginPage) |
| 37 | return | 39 | return |
| 38 | } | 40 | } |
| 41 | + const params: postExecuteLikeParams = { | ||
| 42 | + status: this.newsStatusOfUser?.likeStatus === '1' ? '0' : '1', | ||
| 43 | + contentId: this.compDTO.operDataList[0]?.commentInfo?.newsId + '', | ||
| 44 | + contentType: this.compDTO.operDataList[0]?.commentInfo?.newsType + '', | ||
| 45 | + } | ||
| 46 | + ContentDetailRequest.postExecuteLike(params).then(res => { | ||
| 47 | + this.newsStatusOfUser.likeStatus = this.newsStatusOfUser?.likeStatus === '1' ? '0' : '1' | ||
| 48 | + }) | ||
| 49 | + } | ||
| 39 | 50 | ||
| 40 | - if (this.likeBl) { | ||
| 41 | - this.likeBl = false; | ||
| 42 | - } else { | ||
| 43 | - this.likeBl = true; | 51 | + // 已登录->查询用户对作品点赞、收藏状态 |
| 52 | + private async getInteractDataStatus() { | ||
| 53 | + // 未登录,跳转登录 | ||
| 54 | + const user_id = await SPHelper.default.get(SpConstants.USER_ID, '') | ||
| 55 | + if (!user_id) { | ||
| 56 | + return | ||
| 57 | + } | ||
| 58 | + try { | ||
| 59 | + const params: batchLikeAndCollectParams = { | ||
| 60 | + contentList: [ | ||
| 61 | + { | ||
| 62 | + contentId: this.compDTO.operDataList[0]?.commentInfo?.newsId + '', | ||
| 63 | + contentType: this.compDTO.operDataList[0]?.commentInfo?.newsType + '', | ||
| 64 | + } | ||
| 65 | + ] | ||
| 66 | + } | ||
| 67 | + let data = await MultiPictureDetailViewModel.getInteractDataStatus(params) | ||
| 68 | + console.error(TAG, 'ZhSingleRow06-data', JSON.stringify(data)) | ||
| 69 | + this.newsStatusOfUser = data[0]; | ||
| 70 | + Logger.info(TAG, `ZhSingleRow06-newsStatusOfUser:${JSON.stringify(this.newsStatusOfUser)}`) | ||
| 71 | + } catch (exception) { | ||
| 72 | + console.error(TAG, JSON.stringify(exception)) | ||
| 44 | } | 73 | } |
| 45 | } | 74 | } |
| 46 | 75 | ||
| @@ -95,7 +124,7 @@ export struct ZhSingleRow06 { | @@ -95,7 +124,7 @@ export struct ZhSingleRow06 { | ||
| 95 | .fontColor(0x999999) | 124 | .fontColor(0x999999) |
| 96 | 125 | ||
| 97 | Row(){ | 126 | Row(){ |
| 98 | - Image(this.likeBl ? $r('app.media.icon_like_select') : $r('app.media.icon_like')) | 127 | + Image(this.newsStatusOfUser?.likeStatus == '1' ? $r('app.media.icon_like_select') : $r('app.media.icon_like')) |
| 99 | .width(16) | 128 | .width(16) |
| 100 | .height(16) | 129 | .height(16) |
| 101 | .margin({right: 3}) | 130 | .margin({right: 3}) |
| @@ -103,9 +132,11 @@ export struct ZhSingleRow06 { | @@ -103,9 +132,11 @@ export struct ZhSingleRow06 { | ||
| 103 | Text('点赞') | 132 | Text('点赞') |
| 104 | .fontSize(15) | 133 | .fontSize(15) |
| 105 | .fontColor(0x999999) | 134 | .fontColor(0x999999) |
| 135 | + .onClick(() => { | ||
| 136 | + }) | ||
| 106 | } | 137 | } |
| 107 | .onClick(() => { | 138 | .onClick(() => { |
| 108 | - this.likeAction() | 139 | + this.toggleLikeStatus() |
| 109 | }) | 140 | }) |
| 110 | } | 141 | } |
| 111 | .justifyContent(FlexAlign.SpaceBetween) | 142 | .justifyContent(FlexAlign.SpaceBetween) |
-
Please register or login to post a comment