Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
yuanfeiyang02
2024-04-26 11:32:11 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
41bcd54eccd5b2adfde7f32314ae32282edb4cbf
41bcd54e
1 parent
119ef20e
feat:稿件点赞组件增加稿件详情页中间位置按钮类型
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
131 additions
and
2 deletions
sight_harmony/commons/wdNetwork/src/main/ets/http/HttpUrlUtils.ets
sight_harmony/features/wdComponent/src/main/ets/components/view/LikeComponent.ets
sight_harmony/features/wdComponent/src/main/ets/model/LikeModel.ets
sight_harmony/features/wdComponent/src/main/ets/viewmodel/LikeViewModel.ets
sight_harmony/commons/wdNetwork/src/main/ets/http/HttpUrlUtils.ets
View file @
41bcd54
...
...
@@ -854,6 +854,13 @@ export class HttpUrlUtils {
return url;
}
//获取点赞数
static getLikeCount() {
let url = HttpUrlUtils._hostUrl + "/api/rmrb-contact/contact/zh/c/v2/content/interactData";
return url;
}
//搜索推荐
static getSearchSuggestDataUrl() {
let url = HttpUrlUtils._hostUrl + HttpUrlUtils.SEARCH_SUGGEST_DATA_PATH
...
...
sight_harmony/features/wdComponent/src/main/ets/components/view/LikeComponent.ets
View file @
41bcd54
import { Logger } from 'wdKit/Index'
import { LikeViewModel } from '../../viewmodel/LikeViewModel'
import { SPHelper } from 'wdKit';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import { SpConstants } from 'wdConstant/Index';
const TAG = 'LikeComponent';
...
...
@@ -9,6 +13,8 @@ export struct LikeComponent {
viewModel: LikeViewModel = new LikeViewModel()
@Prop data: Record<string, string>
enableBtn = true
componentType : number = 1 //1: 底部栏目样式 2: 新闻页中间位置样式
@State likeCount: number = 0 //点赞数
//上层传值 样例
// this.data['contentId'] = '30035444649' //必须
...
...
@@ -23,16 +29,77 @@ export struct LikeComponent {
if (this.data) {
//获取点赞状态
this.getLikeStatus()
//获取点赞数
this.getLikeCount()
}
}
build() {
if (this.componentType == 2){
//2: 新闻页中间位置样式
Column() {
Button(){
Row(){
Image(this.likeStatus ? $r('app.media.icon_like_select') : $r('app.media.icon_like_default'))
.width(20)
.height(20)
Text(this.likeCount.toString())
.height(20)
.margin({
right: 0,
left: 4
})
.fontColor(this.likeStatus ? '#ED2800' : '#222222')
.fontSize('16')
}
.justifyContent(FlexAlign.Center)
.width('100%')
.height('100%')
}
.width('100%')
.height('100%')
.backgroundColor(Color.White)
.type(ButtonType.Capsule)
.borderColor('#EDEDED')
.borderRadius(20)
.borderWidth(1)
.onClick(()=>{
this.clickButtonEvent()
})
}
.width(154)
.height(40)
}else {
//1: 底部栏目样式 默认样式
Column() {
Image(this.likeStatus ? $r('app.media.icon_like_select') : $r('app.media.icon_like_default'))
.width(24)
.height(24)
.onClick(() => {
this.clickButtonEvent()
})
}.width(24).height(24)
}
}
async clickButtonEvent(){
// 未登录,跳转登录
const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
if (!user_id) {
WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
return
}
if (!this.enableBtn) {
return
}
...
...
@@ -43,14 +110,19 @@ export struct LikeComponent {
//0
this.executeLike('1')
}
})
}.width(24).height(24)
}
executeLike(status: string) {
this.data['status'] = status
this.viewModel.executeLike2(this.data).then(() => {
this.likeStatus = !this.likeStatus
//点赞和取消点赞成功后更新点赞数
if(this.likeStatus){
this.likeCount ++
}else {
this.likeCount --
}
this.enableBtn = true
}).catch(() => {
this.enableBtn = true
...
...
@@ -69,5 +141,19 @@ export struct LikeComponent {
})
}
//获取点赞数
getLikeCount() {
this.viewModel.getLikeCount(this.data).then((data) => {
if (data && data['data']) {
this.likeCount = data['data']['likeNum']
}else {
this.likeCount = 0
}
}).catch(() => {
this.likeCount = 0
})
}
}
\ No newline at end of file
...
...
sight_harmony/features/wdComponent/src/main/ets/model/LikeModel.ets
View file @
41bcd54
...
...
@@ -43,5 +43,27 @@ export class LikeModel {
getLikeCount(data: Record<string, string>) {
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
let channelId : string = data['channelId']
let contentId : string = data['contentId']
let contentType : string = data['contentType']
let detail : string = '1'
let url = HttpUrlUtils.getLikeCount() + `?channelId=${channelId}&contentId=${contentId}&contentType=${contentType}&detail=${detail}`
return new Promise<object>((success, fail) => {
HttpBizUtil.get<ResponseDTO<object>>(url, headers).then((data: ResponseDTO<object>) => {
if (data.code != 0) {
fail(data.message)
return
}
success(data)
}, (error: Error) => {
fail(error.message)
Logger.debug("LoginViewModel:error ", error.toString())
})
})
}
}
\ No newline at end of file
...
...
sight_harmony/features/wdComponent/src/main/ets/viewmodel/LikeViewModel.ets
View file @
41bcd54
...
...
@@ -48,5 +48,19 @@ export class LikeViewModel {
}
//点赞数
getLikeCount(bean: Record<string, string>) {
return new Promise<object>((success, fail) => {
this.likeModel.getLikeCount(bean).then((data) => {
success(data)
}).catch((error: string) => {
fail(error)
})
})
}
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment