Showing
5 changed files
with
73 additions
and
12 deletions
| @@ -843,6 +843,13 @@ export class HttpUrlUtils { | @@ -843,6 +843,13 @@ export class HttpUrlUtils { | ||
| 843 | let url = HttpUrlUtils._hostUrl + "/api/rmrb-interact/interact/zh/c/like/executeLike"; | 843 | let url = HttpUrlUtils._hostUrl + "/api/rmrb-interact/interact/zh/c/like/executeLike"; |
| 844 | return url; | 844 | return url; |
| 845 | } | 845 | } |
| 846 | + | ||
| 847 | + //获取点赞状态 | ||
| 848 | + static getLikeStatus() { | ||
| 849 | + let url = HttpUrlUtils._hostUrl + "/api/rmrb-interact/interact/zh/c/batchLikeAndCollect/status"; | ||
| 850 | + return url; | ||
| 851 | + } | ||
| 852 | + | ||
| 846 | //搜索推荐 | 853 | //搜索推荐 |
| 847 | static getSearchSuggestDataUrl() { | 854 | static getSearchSuggestDataUrl() { |
| 848 | let url = HttpUrlUtils._hostUrl + HttpUrlUtils.SEARCH_SUGGEST_DATA_PATH | 855 | let url = HttpUrlUtils._hostUrl + HttpUrlUtils.SEARCH_SUGGEST_DATA_PATH |
| @@ -14,6 +14,8 @@ export { PageComponent } from "./src/main/ets/components/page/PageComponent" | @@ -14,6 +14,8 @@ export { PageComponent } from "./src/main/ets/components/page/PageComponent" | ||
| 14 | 14 | ||
| 15 | export { BottomNavigationComponent } from "./src/main/ets/components/page/BottomNavigationComponent" | 15 | export { BottomNavigationComponent } from "./src/main/ets/components/page/BottomNavigationComponent" |
| 16 | 16 | ||
| 17 | +export { LikeComponent } from "./src/main/ets/components/view/LikeComponent" | ||
| 18 | + | ||
| 17 | export { TopNavigationComponent } from "./src/main/ets/components/page/TopNavigationComponent" | 19 | export { TopNavigationComponent } from "./src/main/ets/components/page/TopNavigationComponent" |
| 18 | 20 | ||
| 19 | export { LabelComponent } from "./src/main/ets/components/view/LabelComponent" | 21 | export { LabelComponent } from "./src/main/ets/components/view/LabelComponent" |
| 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 | 3 | ||
| 4 | +const TAG = 'LikeComponent'; | ||
| 5 | + | ||
| 4 | @Component | 6 | @Component |
| 5 | export struct LikeComponent { | 7 | export struct LikeComponent { |
| 6 | @State likeStatus: boolean = false | 8 | @State likeStatus: boolean = false |
| @@ -15,17 +17,12 @@ export struct LikeComponent { | @@ -15,17 +17,12 @@ export struct LikeComponent { | ||
| 15 | // this.data['title'] = '开创两校交流先河!克罗地亚教育代表团访问同济大学' | 17 | // this.data['title'] = '开创两校交流先河!克罗地亚教育代表团访问同济大学' |
| 16 | // this.data['userHeaderUrl'] = "" | 18 | // this.data['userHeaderUrl'] = "" |
| 17 | // this.data['channelId'] = "2059" //必须 | 19 | // this.data['channelId'] = "2059" //必须 |
| 18 | - // this.data['status'] = "1" //必须 | 20 | + // this.data['status'] = "1" |
| 19 | 21 | ||
| 20 | aboutToAppear(): void { | 22 | aboutToAppear(): void { |
| 21 | if (this.data) { | 23 | if (this.data) { |
| 22 | - Logger.debug("ddd: " + this.data['status']) | ||
| 23 | - if (this.data['status'] == '1') { | ||
| 24 | - this.likeStatus = true | ||
| 25 | - } else { | ||
| 26 | - this.likeStatus = false | ||
| 27 | - } | ||
| 28 | - | 24 | + //获取点赞状态 |
| 25 | + this.getLikeStatus() | ||
| 29 | } | 26 | } |
| 30 | 27 | ||
| 31 | } | 28 | } |
| @@ -41,10 +38,10 @@ export struct LikeComponent { | @@ -41,10 +38,10 @@ export struct LikeComponent { | ||
| 41 | } | 38 | } |
| 42 | if (this.likeStatus) { | 39 | if (this.likeStatus) { |
| 43 | //1 | 40 | //1 |
| 44 | - this.executeLike('1') | 41 | + this.executeLike('0') |
| 45 | } else { | 42 | } else { |
| 46 | //0 | 43 | //0 |
| 47 | - this.executeLike('0') | 44 | + this.executeLike('1') |
| 48 | } | 45 | } |
| 49 | }) | 46 | }) |
| 50 | }.width(24).height(24) | 47 | }.width(24).height(24) |
| @@ -59,4 +56,18 @@ export struct LikeComponent { | @@ -59,4 +56,18 @@ export struct LikeComponent { | ||
| 59 | this.enableBtn = true | 56 | this.enableBtn = true |
| 60 | }) | 57 | }) |
| 61 | } | 58 | } |
| 59 | + | ||
| 60 | + getLikeStatus() { | ||
| 61 | + this.viewModel.getLikeStatus(this.data).then((data) => { | ||
| 62 | + if (data && data['data'].length && data['data'][0]['likeStatus']) { | ||
| 63 | + this.likeStatus = data['data'][0]['likeStatus'] | ||
| 64 | + }else { | ||
| 65 | + this.likeStatus = false | ||
| 66 | + } | ||
| 67 | + }).catch(() => { | ||
| 68 | + this.likeStatus = false | ||
| 69 | + }) | ||
| 70 | + } | ||
| 71 | + | ||
| 72 | + | ||
| 62 | } | 73 | } |
| 1 | import { HashMap } from '@kit.ArkTS'; | 1 | import { HashMap } from '@kit.ArkTS'; |
| 2 | import { Logger } from 'wdKit/Index'; | 2 | import { Logger } from 'wdKit/Index'; |
| 3 | -import { HttpUrlUtils, ResponseDTO } from 'wdNetwork/Index'; | 3 | +import { HttpBizUtil, HttpUrlUtils, ResponseDTO } from 'wdNetwork/Index'; |
| 4 | import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest'; | 4 | import { HttpRequest } from 'wdNetwork/src/main/ets/http/HttpRequest'; |
| 5 | 5 | ||
| 6 | export class LikeModel { | 6 | export class LikeModel { |
| @@ -8,7 +8,7 @@ export class LikeModel { | @@ -8,7 +8,7 @@ export class LikeModel { | ||
| 8 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | 8 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); |
| 9 | 9 | ||
| 10 | return new Promise<object>((success, fail) => { | 10 | return new Promise<object>((success, fail) => { |
| 11 | - HttpRequest.post<ResponseDTO<object>>(HttpUrlUtils.executeLike(), data, headers).then((data: ResponseDTO<object>) => { | 11 | + HttpBizUtil.post<ResponseDTO<object>>(HttpUrlUtils.executeLike(), data, headers).then((data: ResponseDTO<object>) => { |
| 12 | if (data.code != 0) { | 12 | if (data.code != 0) { |
| 13 | fail(data.message) | 13 | fail(data.message) |
| 14 | return | 14 | return |
| @@ -20,4 +20,28 @@ export class LikeModel { | @@ -20,4 +20,28 @@ export class LikeModel { | ||
| 20 | }) | 20 | }) |
| 21 | }) | 21 | }) |
| 22 | } | 22 | } |
| 23 | + | ||
| 24 | + | ||
| 25 | + getLikeStatus(data: Record<string, string>) { | ||
| 26 | + let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | ||
| 27 | + let model : Record<string,Record<string,string>[]> = {} | ||
| 28 | + model['contentList'] = [data] | ||
| 29 | + | ||
| 30 | + return new Promise<object>((success, fail) => { | ||
| 31 | + HttpBizUtil.post<ResponseDTO<object>>(HttpUrlUtils.getLikeStatus(), model, headers).then((data: ResponseDTO<object>) => { | ||
| 32 | + if (data.code != 0) { | ||
| 33 | + fail(data.message) | ||
| 34 | + return | ||
| 35 | + } | ||
| 36 | + success(data) | ||
| 37 | + }, (error: Error) => { | ||
| 38 | + fail(error.message) | ||
| 39 | + Logger.debug("LoginViewModel:error ", error.toString()) | ||
| 40 | + }) | ||
| 41 | + }) | ||
| 42 | + } | ||
| 43 | + | ||
| 44 | + | ||
| 45 | + | ||
| 46 | + | ||
| 23 | } | 47 | } |
| @@ -21,6 +21,7 @@ export class LikeViewModel { | @@ -21,6 +21,7 @@ export class LikeViewModel { | ||
| 21 | this.likeModel.executeLike(bean) | 21 | this.likeModel.executeLike(bean) |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | + //点赞 | ||
| 24 | executeLike2(bean: Record<string, string>) { | 25 | executeLike2(bean: Record<string, string>) { |
| 25 | 26 | ||
| 26 | return new Promise<object>((success, fail) => { | 27 | return new Promise<object>((success, fail) => { |
| @@ -32,4 +33,20 @@ export class LikeViewModel { | @@ -32,4 +33,20 @@ export class LikeViewModel { | ||
| 32 | }) | 33 | }) |
| 33 | 34 | ||
| 34 | } | 35 | } |
| 36 | + | ||
| 37 | + //点赞状态 | ||
| 38 | + getLikeStatus(bean: Record<string, string>) { | ||
| 39 | + | ||
| 40 | + return new Promise<object>((success, fail) => { | ||
| 41 | + this.likeModel.getLikeStatus(bean).then((data) => { | ||
| 42 | + success(data) | ||
| 43 | + }).catch((error: string) => { | ||
| 44 | + fail(error) | ||
| 45 | + }) | ||
| 46 | + }) | ||
| 47 | + | ||
| 48 | + } | ||
| 49 | + | ||
| 50 | + | ||
| 51 | + | ||
| 35 | } | 52 | } |
-
Please register or login to post a comment