王士厅

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

@@ -3,16 +3,10 @@ import { SPHelper } from 'wdKit'; @@ -3,16 +3,10 @@ import { SPHelper } from 'wdKit';
3 import { WDRouterPage, WDRouterRule } from 'wdRouter/Index'; 3 import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
4 import { SpConstants } from 'wdConstant/Index'; 4 import { SpConstants } from 'wdConstant/Index';
5 import measure from '@ohos.measure' 5 import measure from '@ohos.measure'
6 -import {  
7 - ContentDetailRequest,  
8 - postExecuteLikeParams,  
9 -} from 'wdDetailPlayApi/src/main/ets/request/ContentDetailRequest';  
10 import { ParamType, TrackConstants, TrackingContent } from 'wdTracking/Index'; 6 import { ParamType, TrackConstants, TrackingContent } from 'wdTracking/Index';
11 import { 7 import {
12 ContentDetailDTO, 8 ContentDetailDTO,
13 - contentListParams,  
14 } from 'wdBean'; 9 } from 'wdBean';
15 -import { PageRepository } from '../../repository/PageRepository';  
16 import { LiveModel } from '../../viewmodel/LiveModel'; 10 import { LiveModel } from '../../viewmodel/LiveModel';
17 import { HttpUtils } from 'wdNetwork/Index'; 11 import { HttpUtils } from 'wdNetwork/Index';
18 12
@@ -26,15 +20,14 @@ interface ILikeStyleResp { @@ -26,15 +20,14 @@ interface ILikeStyleResp {
26 @Component 20 @Component
27 export struct LiveLikeComponent { 21 export struct LiveLikeComponent {
28 private LiveModel: LiveModel = new LiveModel() 22 private LiveModel: LiveModel = new LiveModel()
29 - @Consume contentDetailData: ContentDetailDTO 23 + @Prop @Watch('onDetailUpdated') contentDetailData: ContentDetailDTO
30 @Prop pageComponentType: number 24 @Prop pageComponentType: number
31 @State likesStyle: string = "love" // 点赞样式 love爱心型 thumb点赞手势 mourning 蜡烛(默哀) pray 祈福 25 @State likesStyle: string = "love" // 点赞样式 love爱心型 thumb点赞手势 mourning 蜡烛(默哀) pray 祈福
32 @State likeStatus: boolean = false 26 @State likeStatus: boolean = false
33 @State openLikes: boolean = false // 是否可以点赞 1:可以 0:不可以 27 @State openLikes: boolean = false // 是否可以点赞 1:可以 0:不可以
34 - @Prop @Watch('onDataUpdated') data: Record<string, string>  
35 - enableBtn = true  
36 styleType: number = 1 //1: 白色背景(图文底部栏) 2: 黑色背景(图集底部栏) 3 透明背景 28 styleType: number = 1 //1: 白色背景(图文底部栏) 2: 黑色背景(图集底部栏) 3 透明背景
37 @State likeCount: number = 0 //点赞数 29 @State likeCount: number = 0 //点赞数
  30 + @State likeBean: Record<string, string> = {}
38 pageParam: ParamType = {} 31 pageParam: ParamType = {}
39 PageName: string = '' 32 PageName: string = ''
40 33
@@ -49,28 +42,22 @@ export struct LiveLikeComponent { @@ -49,28 +42,22 @@ export struct LiveLikeComponent {
49 // 内容用 是否开启点赞 1是 0否; 42 // 内容用 是否开启点赞 1是 0否;
50 // this.contentDetailData.openLikes == 1 43 // this.contentDetailData.openLikes == 1
51 async aboutToAppear() { 44 async aboutToAppear() {
  45 + this.onDetailUpdated()
  46 + this.contentTrackingDict()
  47 + }
  48 + async onDetailUpdated() {
52 // 2:竖屏直播页 4:横屏直播页 49 // 2:竖屏直播页 4:横屏直播页
53 // 点赞样式 love爱心型 thumb点赞手势 mourning 蜡烛(默哀) pray 祈福 50 // 点赞样式 love爱心型 thumb点赞手势 mourning 蜡烛(默哀) pray 祈福
54 this.likesStyle = this.contentDetailData?.liveInfo?.likesStyle 51 this.likesStyle = this.contentDetailData?.liveInfo?.likesStyle
55 this.openLikes = this.contentDetailData?.liveInfo?.likeEnable == 1 ? true : false 52 this.openLikes = this.contentDetailData?.liveInfo?.likeEnable == 1 ? true : false
56 console.log(TAG, 'this.contentDetailData', JSON.stringify(this.contentDetailData)) 53 console.log(TAG, 'this.contentDetailData', JSON.stringify(this.contentDetailData))
57 - console.log(TAG, 'this.likesStyle', this.likesStyle)  
58 - console.log(TAG, 'this.openLikes', this.openLikes)  
59 - this.onDataUpdated()  
60 - this.contentTrackingDict()  
61 - }  
62 -  
63 - onDataUpdated() {  
64 - console.log(TAG, '点赞点击')  
65 - if (this.data) {  
66 - if (this.data['contentType'] !== 'undefined') { 54 + // 点赞需要数据
  55 + this.likeBean['contentId'] = this.contentDetailData.newsId + ''
67 //获取点赞状态 56 //获取点赞状态
68 this.getLikeStatus() 57 this.getLikeStatus()
69 //获取点赞数 58 //获取点赞数
70 this.getLikeCount() 59 this.getLikeCount()
71 } 60 }
72 - }  
73 - }  
74 61
75 contentTrackingDict(){ 62 contentTrackingDict(){
76 this.pageParam = { 63 this.pageParam = {
@@ -156,7 +143,7 @@ export struct LiveLikeComponent { @@ -156,7 +143,7 @@ export struct LiveLikeComponent {
156 } 143 }
157 144
158 async clickButtonEvent() { 145 async clickButtonEvent() {
159 - console.log(TAG, '点赞点击') 146 + console.log(TAG, 'clickButtonEvent 点赞点击')
160 // 未登录,跳转登录 147 // 未登录,跳转登录
161 const user_id = await SPHelper.default.get(SpConstants.USER_ID, '') 148 const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
162 if (!user_id) { 149 if (!user_id) {
@@ -164,51 +151,22 @@ export struct LiveLikeComponent { @@ -164,51 +151,22 @@ export struct LiveLikeComponent {
164 WDRouterRule.jumpWithPage(WDRouterPage.loginPage) 151 WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
165 return 152 return
166 } 153 }
167 -  
168 - // if (!this.enableBtn) {  
169 - // return  
170 - // }  
171 - this.executeLike(this.likeStatus ? '0' : '1') 154 + this.executeLike()
172 155
173 } 156 }
174 157
175 - executeLike(status: string) {  
176 - console.log(TAG, '点赞接口调用', status)  
177 -  
178 - const params: postExecuteLikeParams = {  
179 - status: Number(status),  
180 - contentId: this.data['contentId'],  
181 - contentType: this.data['contentType']  
182 - }  
183 - if(this.data['relType']) {  
184 - params.relType = this.data['relType']  
185 - }  
186 - if(this.data['contentRelId']) {  
187 - params.contentRelId = this.data['contentRelId']  
188 - }  
189 - if(this.data['channelId']) {  
190 - params.channelId = this.data['channelId'] 158 + async executeLike() {
  159 + const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
  160 + if (!user_id) {
  161 + console.log(TAG, '查询点赞状态,未登录')
  162 + return
191 } 163 }
192 -  
193 - console.log(TAG, "点赞 params", JSON.stringify(params))  
194 - ContentDetailRequest.postExecuteLike(params).then((data) => { 164 + this.LiveModel.getLiveRoomNumberLike(this.likeBean['contentId'], 1, HttpUtils.getDeviceId()).then((data) => {
195 165
196 console.log(TAG, '点赞接口调用成功', JSON.stringify(data)) 166 console.log(TAG, '点赞接口调用成功', JSON.stringify(data))
  167 + this.likeCount = data
197 168
198 - // 直播点赞一直增加  
199 - if (this.contentDetailData.liveInfo) {  
200 - this.likeStatus = true  
201 - this.likeCount++  
202 - TrackingContent.like(true,this.PageName,this.PageName,this.pageParam)  
203 - }  
204 -  
205 - if (this.likeCount <= 0) {  
206 - this.likeCount = 0  
207 - }  
208 -  
209 - this.enableBtn = true  
210 }).catch(() => { 169 }).catch(() => {
211 - this.enableBtn = true  
212 }) 170 })
213 } 171 }
214 172
@@ -218,7 +176,7 @@ export struct LiveLikeComponent { @@ -218,7 +176,7 @@ export struct LiveLikeComponent {
218 console.log(TAG, '查询点赞状态,未登录') 176 console.log(TAG, '查询点赞状态,未登录')
219 return 177 return
220 } 178 }
221 - this.LiveModel.getLiveLike(this.data['contentId'], user_id, HttpUtils.getDeviceId()).then(data => { 179 + this.LiveModel.getLiveLike(this.likeBean['contentId'], user_id, HttpUtils.getDeviceId()).then(data => {
222 console.log(TAG, '查询点赞、收藏状态==', JSON.stringify(data)) 180 console.log(TAG, '查询点赞、收藏状态==', JSON.stringify(data))
223 this.likeStatus = data 181 this.likeStatus = data
224 }).catch(() => { 182 }).catch(() => {
@@ -230,18 +188,10 @@ export struct LiveLikeComponent { @@ -230,18 +188,10 @@ export struct LiveLikeComponent {
230 * 获取点赞数 188 * 获取点赞数
231 */ 189 */
232 getLikeCount() { 190 getLikeCount() {
233 - // console.error(TAG, 'contentDetailData2222', JSON.stringify(this.contentDetailData))  
234 - const params: contentListParams = {  
235 - contentList: [{  
236 - contentId: this.contentDetailData?.newsId + '',  
237 - contentType: this.contentDetailData?.newsType,  
238 - }]  
239 - }  
240 - console.log(TAG, '查询点赞、收藏数量', JSON.stringify(params))  
241 - PageRepository.getContentInteract(params).then(res => {  
242 - console.log(TAG, '查询点赞、收藏数量 res', JSON.stringify(res))  
243 - if (res.data) {  
244 - this.likeCount = Number(res.data[0]?.likeNum) 191 + this.LiveModel.getLiveRoomData(this.likeBean['contentId']).then(data => {
  192 + console.log(TAG, '查询点赞、收藏数量 res', JSON.stringify(data))
  193 + if (data) {
  194 + this.likeCount = Number(data.likeNum)
245 } else { 195 } else {
246 this.likeCount = 0 196 this.likeCount = 0
247 } 197 }
@@ -66,7 +66,6 @@ export struct LiveOperRowListView { @@ -66,7 +66,6 @@ export struct LiveOperRowListView {
66 @State bgColor: ResourceColor = Color.White 66 @State bgColor: ResourceColor = Color.White
67 @State interactData: InteractDataDTO = {} as InteractDataDTO 67 @State interactData: InteractDataDTO = {} as InteractDataDTO
68 @State newsStatusOfUser: batchLikeAndCollectResult | undefined = undefined // 点赞、收藏状态 68 @State newsStatusOfUser: batchLikeAndCollectResult | undefined = undefined // 点赞、收藏状态
69 - @State likeBean: Record<string, string> = {}  
70 @State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0 69 @State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0
71 @State dialogController: CustomDialogController | null = null; 70 @State dialogController: CustomDialogController | null = null;
72 pageParam: ParamType = {} 71 pageParam: ParamType = {}
@@ -112,29 +111,8 @@ export struct LiveOperRowListView { @@ -112,29 +111,8 @@ export struct LiveOperRowListView {
112 this.getInteractDataStatus() 111 this.getInteractDataStatus()
113 } 112 }
114 await this.queryContentInteractCount() 113 await this.queryContentInteractCount()
115 - // 点赞需要数据  
116 - this.likeBean['contentId'] = this.contentDetailData.newsId + ''  
117 - if(this.contentDetailData.userInfo?.userName) {  
118 - this.likeBean['userName'] = this.contentDetailData.userInfo?.userName + ''  
119 - }  
120 - this.likeBean['contentType'] = this.contentDetailData.newsType + ''  
121 - if(this.contentDetailData.newsTitle) {  
122 - this.likeBean['title'] = this.contentDetailData.newsTitle + ''  
123 - }  
124 - if(this.contentDetailData.userInfo?.headPhotoUrl) {  
125 - this.likeBean['userHeaderUrl'] = this.contentDetailData.userInfo?.headPhotoUrl + ''  
126 - }  
127 - if(this.contentDetailData.reLInfo?.channelId) {  
128 - this.likeBean['channelId'] = this.contentDetailData.reLInfo?.channelId + ''  
129 - }  
130 - if(this.contentDetailData?.reLInfo?.relType) {  
131 - this.likeBean['relType'] = this.contentDetailData?.reLInfo?.relType + ''  
132 - }  
133 - if(this.contentDetailData?.reLInfo?.relId) {  
134 - this.likeBean['contentRelId'] = this.contentDetailData?.reLInfo?.relId + ''  
135 - } 114 +
136 console.info(TAG, 'contentDetailData----', JSON.stringify(this.contentDetailData)) 115 console.info(TAG, 'contentDetailData----', JSON.stringify(this.contentDetailData))
137 - console.info(TAG, 'likeBean----', JSON.stringify(this.likeBean))  
138 console.info(TAG, 'this.operationButtonList', JSON.stringify(this.operationButtonList)) 116 console.info(TAG, 'this.operationButtonList', JSON.stringify(this.operationButtonList))
139 // 评论需要数据 117 // 评论需要数据
140 /* this.publishCommentModel.targetId = this.contentDetailData.newsId + '' 118 /* this.publishCommentModel.targetId = this.contentDetailData.newsId + ''
@@ -267,7 +245,7 @@ export struct LiveOperRowListView { @@ -267,7 +245,7 @@ export struct LiveOperRowListView {
267 builderLike() { 245 builderLike() {
268 Column() { 246 Column() {
269 LiveLikeComponent({ 247 LiveLikeComponent({
270 - data: this.likeBean, 248 + contentDetailData: this.contentDetailData,
271 styleType: this.styleType, 249 styleType: this.styleType,
272 pageComponentType: this.pageComponentType 250 pageComponentType: this.pageComponentType
273 }) 251 })
@@ -118,6 +118,7 @@ export class LiveModel { @@ -118,6 +118,7 @@ export class LiveModel {
118 fail(data.message) 118 fail(data.message)
119 return 119 return
120 } 120 }
  121 + console.log('LiveLikeComponent data.data', data.data)
121 success(data.data) 122 success(data.data)
122 }, (error: Error) => { 123 }, (error: Error) => {
123 fail(error.message) 124 fail(error.message)