LiveFollowComponent.ets
4.26 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
/**
* 直播详情 关注相关信息
*/
import {
ContentDetailRequest,
postInteractAccentionOperateParams
} from 'wdDetailPlayApi/src/main/ets/request/ContentDetailRequest';
import { ContentDetailDTO, Params, postBatchAttentionStatusParams, RmhInfoDTO } from 'wdBean/Index';
import { SpConstants } from 'wdConstant/Index';
import { Logger, SPHelper, ToastUtils } from 'wdKit/Index';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import { MultiPictureDetailViewModel } from '../../viewmodel/MultiPictureDetailViewModel';
const TAG = 'LiveFollowComponent'
@Component
export struct LiveFollowComponent {
@Prop rmhInfo: RmhInfoDTO
@Consume contentDetailData: ContentDetailDTO
@Consume @Watch('getBatchAttentionStatus') pageShow: number
aboutToAppear(): void {
this.getBatchAttentionStatus()
}
/**
* 默认未关注 点击去关注
*/
@State followStatus: String = '0';
build() {
Stack() {
Stack()
.height(22)
.width(150)
.backgroundColor('#000000')
.opacity(0.3)
.borderRadius({
topLeft: 90,
bottomLeft: 90
})
Row() {
Image(this.rmhInfo.rmhHeadUrl)
.width(24)
.height(24)
.borderRadius(90)
.onClick(() => {
// 跳转到号主页
if (this.contentDetailData.rmhInfo?.cnMainControl === 1) {
const params: Params = {
creatorId: this.contentDetailData.rmhInfo.rmhId,
pageID: ''
}
WDRouterRule.jumpWithPage(WDRouterPage.peopleShipHomePage, params)
}
})
Text(this.rmhInfo.rmhName)
.fontColor(Color.White)
.maxLines(1)
.fontWeight(500)
.fontSize('12fp')
.layoutWeight(1)
.margin({
left: 4,
right: 6
})
Blank()
Text(this.followStatus === '0' ? '关注' : '已关注')
.fontColor(Color.White)
.fontWeight(500)
.fontSize('10fp')
.padding({
left: 8,
right: 8,
top: 3,
bottom: 3
})
.borderRadius(2)
.margin({ right: 2 })
.backgroundColor(this.followStatus === '0' ? $r('app.color.color_ED2800') : $r('app.color.color_CCCCCC'))
.visibility(this.followStatus === '0' ? Visibility.Visible : Visibility.None)
.onClick(() => {
this.handleAccention()
})
}
.height(22)
.width(150)
}
}
/**
* 查询当前登录用户是否关注作品号主
* */
private async getBatchAttentionStatus() {
try {
const params: postBatchAttentionStatusParams = {
creatorIds: [{ creatorId: this.rmhInfo?.rmhId ?? '' }]
}
let data = await MultiPictureDetailViewModel.getBatchAttentionStatus(params)
this.followStatus = data[0]?.status;
Logger.info(TAG, `followStatus:${JSON.stringify(this.followStatus)}`)
} catch (exception) {
}
}
/**
* 关注号主
*/
async handleAccention() {
// 未登录,跳转登录
const user_id = await SPHelper.default.get(SpConstants.USER_ID, '')
if (!user_id) {
WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
return
}
const params2: postInteractAccentionOperateParams = {
attentionUserType: this.rmhInfo?.userType || '', //被关注用户类型(1 普通用户 2 视频号 3 矩阵号)
attentionUserId: this.rmhInfo?.userId || '', // 被关注用户号主id
attentionCreatorId: this.rmhInfo?.rmhId || '', // 被关注用户号主id
status: this.followStatus == '0' ? 1 : 0,
}
ContentDetailRequest.postInteractAccentionOperate(params2).then(res => {
console.log('关注号主==', JSON.stringify(res.data))
if (this.followStatus == '1') {
this.followStatus = '0'
} else {
this.followStatus = '1'
// 弹窗样式与何时调用待确认
ContentDetailRequest.postPointLevelOperate({ operateType: 6 }).then((res) => {
console.log('关注号主获取积分==', JSON.stringify(res.data))
if (res.data?.showToast) {
ToastUtils.showToast(res.data.ruleName + '+' + res.data.rulePoint + '积分', 1000);
}
})
}
})
}
}