Showing
4 changed files
with
144 additions
and
15 deletions
| @@ -854,6 +854,13 @@ export class HttpUrlUtils { | @@ -854,6 +854,13 @@ export class HttpUrlUtils { | ||
| 854 | return url; | 854 | return url; |
| 855 | } | 855 | } |
| 856 | 856 | ||
| 857 | + //获取点赞数 | ||
| 858 | + static getLikeCount() { | ||
| 859 | + let url = HttpUrlUtils._hostUrl + "/api/rmrb-contact/contact/zh/c/v2/content/interactData"; | ||
| 860 | + return url; | ||
| 861 | + } | ||
| 862 | + | ||
| 863 | + | ||
| 857 | //搜索推荐 | 864 | //搜索推荐 |
| 858 | static getSearchSuggestDataUrl() { | 865 | static getSearchSuggestDataUrl() { |
| 859 | let url = HttpUrlUtils._hostUrl + HttpUrlUtils.SEARCH_SUGGEST_DATA_PATH | 866 | let url = HttpUrlUtils._hostUrl + HttpUrlUtils.SEARCH_SUGGEST_DATA_PATH |
| 1 | import { Logger } from 'wdKit/Index' | 1 | import { Logger } from 'wdKit/Index' |
| 2 | import { LikeViewModel } from '../../viewmodel/LikeViewModel' | 2 | import { LikeViewModel } from '../../viewmodel/LikeViewModel' |
| 3 | +import { SPHelper } from 'wdKit'; | ||
| 4 | +import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'; | ||
| 5 | +import { SpConstants } from 'wdConstant/Index'; | ||
| 6 | + | ||
| 3 | 7 | ||
| 4 | const TAG = 'LikeComponent'; | 8 | const TAG = 'LikeComponent'; |
| 5 | 9 | ||
| @@ -9,6 +13,8 @@ export struct LikeComponent { | @@ -9,6 +13,8 @@ export struct LikeComponent { | ||
| 9 | viewModel: LikeViewModel = new LikeViewModel() | 13 | viewModel: LikeViewModel = new LikeViewModel() |
| 10 | @Prop data: Record<string, string> | 14 | @Prop data: Record<string, string> |
| 11 | enableBtn = true | 15 | enableBtn = true |
| 16 | + componentType : number = 1 //1: 底部栏目样式 2: 新闻页中间位置样式 | ||
| 17 | + @State likeCount: number = 0 //点赞数 | ||
| 12 | 18 | ||
| 13 | //上层传值 样例 | 19 | //上层传值 样例 |
| 14 | // this.data['contentId'] = '30035444649' //必须 | 20 | // this.data['contentId'] = '30035444649' //必须 |
| @@ -23,34 +29,100 @@ export struct LikeComponent { | @@ -23,34 +29,100 @@ export struct LikeComponent { | ||
| 23 | if (this.data) { | 29 | if (this.data) { |
| 24 | //获取点赞状态 | 30 | //获取点赞状态 |
| 25 | this.getLikeStatus() | 31 | this.getLikeStatus() |
| 32 | + //获取点赞数 | ||
| 33 | + this.getLikeCount() | ||
| 26 | } | 34 | } |
| 27 | 35 | ||
| 28 | } | 36 | } |
| 29 | 37 | ||
| 30 | build() { | 38 | build() { |
| 31 | - Column() { | ||
| 32 | - Image(this.likeStatus ? $r('app.media.icon_like_select') : $r('app.media.icon_like_default')) | ||
| 33 | - .width(24) | ||
| 34 | - .height(24) | ||
| 35 | - .onClick(() => { | ||
| 36 | - if (!this.enableBtn) { | ||
| 37 | - return | ||
| 38 | - } | ||
| 39 | - if (this.likeStatus) { | ||
| 40 | - //1 | ||
| 41 | - this.executeLike('0') | ||
| 42 | - } else { | ||
| 43 | - //0 | ||
| 44 | - this.executeLike('1') | 39 | + if (this.componentType == 2){ |
| 40 | + //2: 新闻页中间位置样式 | ||
| 41 | + Column() { | ||
| 42 | + | ||
| 43 | + Button(){ | ||
| 44 | + | ||
| 45 | + Row(){ | ||
| 46 | + Image(this.likeStatus ? $r('app.media.icon_like_select') : $r('app.media.icon_like_default')) | ||
| 47 | + .width(20) | ||
| 48 | + .height(20) | ||
| 49 | + Text(this.likeCount.toString()) | ||
| 50 | + .height(20) | ||
| 51 | + .margin({ | ||
| 52 | + right: 0, | ||
| 53 | + left: 4 | ||
| 54 | + }) | ||
| 55 | + .fontColor(this.likeStatus ? '#ED2800' : '#222222') | ||
| 56 | + .fontSize('16') | ||
| 45 | } | 57 | } |
| 58 | + .justifyContent(FlexAlign.Center) | ||
| 59 | + .width('100%') | ||
| 60 | + .height('100%') | ||
| 61 | + | ||
| 62 | + } | ||
| 63 | + .width('100%') | ||
| 64 | + .height('100%') | ||
| 65 | + .backgroundColor(Color.White) | ||
| 66 | + .type(ButtonType.Capsule) | ||
| 67 | + .borderColor('#EDEDED') | ||
| 68 | + .borderRadius(20) | ||
| 69 | + .borderWidth(1) | ||
| 70 | + .onClick(()=>{ | ||
| 71 | + | ||
| 72 | + this.clickButtonEvent() | ||
| 73 | + | ||
| 46 | }) | 74 | }) |
| 47 | - }.width(24).height(24) | 75 | + |
| 76 | + } | ||
| 77 | + .width(154) | ||
| 78 | + .height(40) | ||
| 79 | + | ||
| 80 | + | ||
| 81 | + }else { | ||
| 82 | + //1: 底部栏目样式 默认样式 | ||
| 83 | + Column() { | ||
| 84 | + Image(this.likeStatus ? $r('app.media.icon_like_select') : $r('app.media.icon_like_default')) | ||
| 85 | + .width(24) | ||
| 86 | + .height(24) | ||
| 87 | + .onClick(() => { | ||
| 88 | + this.clickButtonEvent() | ||
| 89 | + }) | ||
| 90 | + }.width(24).height(24) | ||
| 91 | + } | ||
| 92 | + | ||
| 93 | + } | ||
| 94 | + | ||
| 95 | + async clickButtonEvent(){ | ||
| 96 | + // 未登录,跳转登录 | ||
| 97 | + const user_id = await SPHelper.default.get(SpConstants.USER_ID, '') | ||
| 98 | + if (!user_id) { | ||
| 99 | + WDRouterRule.jumpWithPage(WDRouterPage.loginPage) | ||
| 100 | + return | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + if (!this.enableBtn) { | ||
| 104 | + return | ||
| 105 | + } | ||
| 106 | + if (this.likeStatus) { | ||
| 107 | + //1 | ||
| 108 | + this.executeLike('0') | ||
| 109 | + } else { | ||
| 110 | + //0 | ||
| 111 | + this.executeLike('1') | ||
| 112 | + } | ||
| 113 | + | ||
| 48 | } | 114 | } |
| 49 | 115 | ||
| 50 | executeLike(status: string) { | 116 | executeLike(status: string) { |
| 51 | this.data['status'] = status | 117 | this.data['status'] = status |
| 52 | this.viewModel.executeLike2(this.data).then(() => { | 118 | this.viewModel.executeLike2(this.data).then(() => { |
| 53 | this.likeStatus = !this.likeStatus | 119 | this.likeStatus = !this.likeStatus |
| 120 | + //点赞和取消点赞成功后更新点赞数 | ||
| 121 | + if(this.likeStatus){ | ||
| 122 | + this.likeCount ++ | ||
| 123 | + }else { | ||
| 124 | + this.likeCount -- | ||
| 125 | + } | ||
| 54 | this.enableBtn = true | 126 | this.enableBtn = true |
| 55 | }).catch(() => { | 127 | }).catch(() => { |
| 56 | this.enableBtn = true | 128 | this.enableBtn = true |
| @@ -69,5 +141,19 @@ export struct LikeComponent { | @@ -69,5 +141,19 @@ export struct LikeComponent { | ||
| 69 | }) | 141 | }) |
| 70 | } | 142 | } |
| 71 | 143 | ||
| 144 | + //获取点赞数 | ||
| 145 | + getLikeCount() { | ||
| 146 | + this.viewModel.getLikeCount(this.data).then((data) => { | ||
| 147 | + if (data && data['data']) { | ||
| 148 | + this.likeCount = data['data']['likeNum'] | ||
| 149 | + }else { | ||
| 150 | + this.likeCount = 0 | ||
| 151 | + } | ||
| 152 | + }).catch(() => { | ||
| 153 | + this.likeCount = 0 | ||
| 154 | + }) | ||
| 155 | + } | ||
| 156 | + | ||
| 157 | + | ||
| 72 | 158 | ||
| 73 | } | 159 | } |
| @@ -43,5 +43,27 @@ export class LikeModel { | @@ -43,5 +43,27 @@ export class LikeModel { | ||
| 43 | 43 | ||
| 44 | 44 | ||
| 45 | 45 | ||
| 46 | + getLikeCount(data: Record<string, string>) { | ||
| 47 | + let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | ||
| 48 | + let channelId : string = data['channelId'] | ||
| 49 | + let contentId : string = data['contentId'] | ||
| 50 | + let contentType : string = data['contentType'] | ||
| 51 | + let detail : string = '1' | ||
| 52 | + let url = HttpUrlUtils.getLikeCount() + `?channelId=${channelId}&contentId=${contentId}&contentType=${contentType}&detail=${detail}` | ||
| 53 | + return new Promise<object>((success, fail) => { | ||
| 54 | + HttpBizUtil.get<ResponseDTO<object>>(url, headers).then((data: ResponseDTO<object>) => { | ||
| 55 | + if (data.code != 0) { | ||
| 56 | + fail(data.message) | ||
| 57 | + return | ||
| 58 | + } | ||
| 59 | + success(data) | ||
| 60 | + }, (error: Error) => { | ||
| 61 | + fail(error.message) | ||
| 62 | + Logger.debug("LoginViewModel:error ", error.toString()) | ||
| 63 | + }) | ||
| 64 | + }) | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + | ||
| 46 | 68 | ||
| 47 | } | 69 | } |
| @@ -48,5 +48,19 @@ export class LikeViewModel { | @@ -48,5 +48,19 @@ export class LikeViewModel { | ||
| 48 | } | 48 | } |
| 49 | 49 | ||
| 50 | 50 | ||
| 51 | + //点赞数 | ||
| 52 | + getLikeCount(bean: Record<string, string>) { | ||
| 53 | + | ||
| 54 | + return new Promise<object>((success, fail) => { | ||
| 55 | + this.likeModel.getLikeCount(bean).then((data) => { | ||
| 56 | + success(data) | ||
| 57 | + }).catch((error: string) => { | ||
| 58 | + fail(error) | ||
| 59 | + }) | ||
| 60 | + }) | ||
| 61 | + | ||
| 62 | + } | ||
| 63 | + | ||
| 64 | + | ||
| 51 | 65 | ||
| 52 | } | 66 | } |
-
Please register or login to post a comment