CarderInteraction.ets
3.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import { SPHelper,Logger,ToastUtils } from 'wdKit';
import { ContentDetailDTO, Action, ContentDTO,batchLikeAndCollectResult } from 'wdBean';
import { ProcessUtils } from 'wdRouter';
import router from '@ohos.router';
import { batchLikeAndCollectParams } from 'wdDetailPlayApi/src/main/ets/request/ContentDetailRequest';
import { MultiPictureDetailViewModel } from '../viewmodel/MultiPictureDetailViewModel';
import { SpConstants } from 'wdConstant/Index';
import { WDShare } from 'wdShare/Index';
const TAG = 'CarderInteraction'
/**
* 卡片 分享、评论、点赞公用组件
*/
@Component
export struct CarderInteraction {
@Prop contentDTO: ContentDTO
@State contentId: string = ''
@State contentDetailData: ContentDetailDTO = {} as ContentDetailDTO
@State newsStatusOfUser: batchLikeAndCollectResult = {} as batchLikeAndCollectResult// 点赞、收藏状态
build() {
Row(){
Row(){
Image($r('app.media.CarderInteraction_share'))
.width(18)
.height(18)
Text('分享')
.margin({left:4})
.fontSize(14)
.fontColor('#666666')
}
.justifyContent(FlexAlign.Center)
.onClick(()=>{
this.getContentDetailData()
})
Row(){
Image($r('app.media.CarderInteraction_comment'))
.width(18)
.height(18)
Text('评论')
.margin({left:4})
.fontSize(14)
.fontColor('#666666')
}
.justifyContent(FlexAlign.Center)
.onClick(()=>{
ProcessUtils.processPage(this.contentDTO)
})
Row(){
Image($r('app.media.CarderInteraction_like'))
.width(18)
.height(18)
Text('点赞')
.margin({left:4})
.fontSize(14)
.fontColor('#666666')
}
.justifyContent(FlexAlign.Center)
.onClick(()=>{
ProcessUtils.processPage(this.contentDTO)
// ToastUtils.showToast('点赞为公共方法,待开发', 1000)
})
}
.width('100%')
.margin({top:11})
.padding({
left:21,
right:21
})
.justifyContent(FlexAlign.SpaceBetween)
.alignItems(VerticalAlign.Center)
}
/**
* 请求(动态)详情页数据
* */
private async getContentDetailData() {
try {
let data = await MultiPictureDetailViewModel.getDetailData(this.contentDTO.relId, this.contentDTO.objectId, this.contentDTO.relType)
this.contentDetailData = data[0];
console.log('动态详情',JSON.stringify(this.contentDetailData))
WDShare.shareContent(this.contentDetailData)
} catch (exception) {
console.log('请求失败',JSON.stringify(exception))
}
this.getInteractDataStatus()
}
// 已登录->查询用户对作品点赞、收藏状态
private async getInteractDataStatus() {
// 未登录,跳转登录
const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
if (!user_id) {
return
}
try {
const params: batchLikeAndCollectParams = {
contentList: [
{
contentId: this.contentDetailData?.newsId + '',
contentType: this.contentDetailData?.newsType + '',
}
]
}
console.error(TAG, JSON.stringify(this.contentDetailData))
let data = await MultiPictureDetailViewModel.getInteractDataStatus(params)
console.error(TAG, '查询用户对作品点赞、收藏状态', JSON.stringify(data))
this.newsStatusOfUser = data[0];
Logger.info(TAG, `newsStatusOfUser:${JSON.stringify(this.newsStatusOfUser)}`)
} catch (exception) {
console.error(TAG, JSON.stringify(exception))
}
}
}