王士厅

直播详情页互动组件点赞组件完善

... ... @@ -3,16 +3,10 @@ import { SPHelper } from 'wdKit';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import { SpConstants } from 'wdConstant/Index';
import measure from '@ohos.measure'
import {
ContentDetailRequest,
postExecuteLikeParams,
} from 'wdDetailPlayApi/src/main/ets/request/ContentDetailRequest';
import { ParamType, TrackConstants, TrackingContent } from 'wdTracking/Index';
import {
ContentDetailDTO,
contentListParams,
} from 'wdBean';
import { PageRepository } from '../../repository/PageRepository';
import { LiveModel } from '../../viewmodel/LiveModel';
import { HttpUtils } from 'wdNetwork/Index';
... ... @@ -26,15 +20,14 @@ interface ILikeStyleResp {
@Component
export struct LiveLikeComponent {
private LiveModel: LiveModel = new LiveModel()
@Consume contentDetailData: ContentDetailDTO
@Prop @Watch('onDetailUpdated') contentDetailData: ContentDetailDTO
@Prop pageComponentType: number
@State likesStyle: string = "love" // 点赞样式 love爱心型 thumb点赞手势 mourning 蜡烛(默哀) pray 祈福
@State likeStatus: boolean = false
@State openLikes: boolean = false // 是否可以点赞 1:可以 0:不可以
@Prop @Watch('onDataUpdated') data: Record<string, string>
enableBtn = true
styleType: number = 1 //1: 白色背景(图文底部栏) 2: 黑色背景(图集底部栏) 3 透明背景
@State likeCount: number = 0 //点赞数
@State likeBean: Record<string, string> = {}
pageParam: ParamType = {}
PageName: string = ''
... ... @@ -49,27 +42,21 @@ export struct LiveLikeComponent {
// 内容用 是否开启点赞 1是 0否;
// this.contentDetailData.openLikes == 1
async aboutToAppear() {
this.onDetailUpdated()
this.contentTrackingDict()
}
async onDetailUpdated() {
// 2:竖屏直播页 4:横屏直播页
// 点赞样式 love爱心型 thumb点赞手势 mourning 蜡烛(默哀) pray 祈福
this.likesStyle = this.contentDetailData?.liveInfo?.likesStyle
this.openLikes = this.contentDetailData?.liveInfo?.likeEnable == 1 ? true : false
console.log(TAG, 'this.contentDetailData', JSON.stringify(this.contentDetailData))
console.log(TAG, 'this.likesStyle', this.likesStyle)
console.log(TAG, 'this.openLikes', this.openLikes)
this.onDataUpdated()
this.contentTrackingDict()
}
onDataUpdated() {
console.log(TAG, '点赞点击')
if (this.data) {
if (this.data['contentType'] !== 'undefined') {
//获取点赞状态
this.getLikeStatus()
//获取点赞数
this.getLikeCount()
}
}
// 点赞需要数据
this.likeBean['contentId'] = this.contentDetailData.newsId + ''
//获取点赞状态
this.getLikeStatus()
//获取点赞数
this.getLikeCount()
}
contentTrackingDict(){
... ... @@ -156,7 +143,7 @@ export struct LiveLikeComponent {
}
async clickButtonEvent() {
console.log(TAG, '点赞点击')
console.log(TAG, 'clickButtonEvent 点赞点击')
// 未登录,跳转登录
const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
if (!user_id) {
... ... @@ -164,51 +151,22 @@ export struct LiveLikeComponent {
WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
return
}
// if (!this.enableBtn) {
// return
// }
this.executeLike(this.likeStatus ? '0' : '1')
this.executeLike()
}
executeLike(status: string) {
console.log(TAG, '点赞接口调用', status)
const params: postExecuteLikeParams = {
status: Number(status),
contentId: this.data['contentId'],
contentType: this.data['contentType']
}
if(this.data['relType']) {
params.relType = this.data['relType']
}
if(this.data['contentRelId']) {
params.contentRelId = this.data['contentRelId']
}
if(this.data['channelId']) {
params.channelId = this.data['channelId']
async executeLike() {
const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
if (!user_id) {
console.log(TAG, '查询点赞状态,未登录')
return
}
console.log(TAG, "点赞 params", JSON.stringify(params))
ContentDetailRequest.postExecuteLike(params).then((data) => {
this.LiveModel.getLiveRoomNumberLike(this.likeBean['contentId'], 1, HttpUtils.getDeviceId()).then((data) => {
console.log(TAG, '点赞接口调用成功', JSON.stringify(data))
this.likeCount = data
// 直播点赞一直增加
if (this.contentDetailData.liveInfo) {
this.likeStatus = true
this.likeCount++
TrackingContent.like(true,this.PageName,this.PageName,this.pageParam)
}
if (this.likeCount <= 0) {
this.likeCount = 0
}
this.enableBtn = true
}).catch(() => {
this.enableBtn = true
})
}
... ... @@ -218,7 +176,7 @@ export struct LiveLikeComponent {
console.log(TAG, '查询点赞状态,未登录')
return
}
this.LiveModel.getLiveLike(this.data['contentId'], user_id, HttpUtils.getDeviceId()).then(data => {
this.LiveModel.getLiveLike(this.likeBean['contentId'], user_id, HttpUtils.getDeviceId()).then(data => {
console.log(TAG, '查询点赞、收藏状态==', JSON.stringify(data))
this.likeStatus = data
}).catch(() => {
... ... @@ -230,18 +188,10 @@ export struct LiveLikeComponent {
* 获取点赞数
*/
getLikeCount() {
// console.error(TAG, 'contentDetailData2222', JSON.stringify(this.contentDetailData))
const params: contentListParams = {
contentList: [{
contentId: this.contentDetailData?.newsId + '',
contentType: this.contentDetailData?.newsType,
}]
}
console.log(TAG, '查询点赞、收藏数量', JSON.stringify(params))
PageRepository.getContentInteract(params).then(res => {
console.log(TAG, '查询点赞、收藏数量 res', JSON.stringify(res))
if (res.data) {
this.likeCount = Number(res.data[0]?.likeNum)
this.LiveModel.getLiveRoomData(this.likeBean['contentId']).then(data => {
console.log(TAG, '查询点赞、收藏数量 res', JSON.stringify(data))
if (data) {
this.likeCount = Number(data.likeNum)
} else {
this.likeCount = 0
}
... ...
... ... @@ -66,7 +66,6 @@ export struct LiveOperRowListView {
@State bgColor: ResourceColor = Color.White
@State interactData: InteractDataDTO = {} as InteractDataDTO
@State newsStatusOfUser: batchLikeAndCollectResult | undefined = undefined // 点赞、收藏状态
@State likeBean: Record<string, string> = {}
@State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0
@State dialogController: CustomDialogController | null = null;
pageParam: ParamType = {}
... ... @@ -112,29 +111,8 @@ export struct LiveOperRowListView {
this.getInteractDataStatus()
}
await this.queryContentInteractCount()
// 点赞需要数据
this.likeBean['contentId'] = this.contentDetailData.newsId + ''
if(this.contentDetailData.userInfo?.userName) {
this.likeBean['userName'] = this.contentDetailData.userInfo?.userName + ''
}
this.likeBean['contentType'] = this.contentDetailData.newsType + ''
if(this.contentDetailData.newsTitle) {
this.likeBean['title'] = this.contentDetailData.newsTitle + ''
}
if(this.contentDetailData.userInfo?.headPhotoUrl) {
this.likeBean['userHeaderUrl'] = this.contentDetailData.userInfo?.headPhotoUrl + ''
}
if(this.contentDetailData.reLInfo?.channelId) {
this.likeBean['channelId'] = this.contentDetailData.reLInfo?.channelId + ''
}
if(this.contentDetailData?.reLInfo?.relType) {
this.likeBean['relType'] = this.contentDetailData?.reLInfo?.relType + ''
}
if(this.contentDetailData?.reLInfo?.relId) {
this.likeBean['contentRelId'] = this.contentDetailData?.reLInfo?.relId + ''
}
console.info(TAG, 'contentDetailData----', JSON.stringify(this.contentDetailData))
console.info(TAG, 'likeBean----', JSON.stringify(this.likeBean))
console.info(TAG, 'this.operationButtonList', JSON.stringify(this.operationButtonList))
// 评论需要数据
/* this.publishCommentModel.targetId = this.contentDetailData.newsId + ''
... ... @@ -267,7 +245,7 @@ export struct LiveOperRowListView {
builderLike() {
Column() {
LiveLikeComponent({
data: this.likeBean,
contentDetailData: this.contentDetailData,
styleType: this.styleType,
pageComponentType: this.pageComponentType
})
... ...
... ... @@ -118,6 +118,7 @@ export class LiveModel {
fail(data.message)
return
}
console.log('LiveLikeComponent data.data', data.data)
success(data.data)
}, (error: Error) => {
fail(error.message)
... ...