SpacialTopicPageComponent.ets
9.46 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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
import { Action, H5ReceiveDetailBean, ContentDetailDTO, InteractDataDTO, TopicInfo } from 'wdBean';
import { WdWebComponent } from 'wdWebComponent';
import { CommonConstants } from 'wdConstant'
import { BridgeWebViewControl } from 'wdJsBridge/Index';
import { NativeCallH5Type } from 'wdWebComponent/src/main/ets/pages/NativeCallH5Type';
import { OperRowListView } from './view/OperRowListView';
import DetailViewModel from '../viewmodel/DetailViewModel';
import { publishCommentModel } from '../components/comment/model/PublishCommentModel';
import { EmptyComponent } from '../components/view/EmptyComponent';
import { NetworkUtil, WindowModel } from 'wdKit';
import { viewBlogItemInsightIntentShare } from '../utils/InsightIntentShare'
import { common } from '@kit.AbilityKit';
import { PageRepository } from '../repository/PageRepository';
import { CommentDialogView } from './CommentDialogView';
import { faceDetector } from '@kit.CoreVisionKit';
import { channelSkeleton } from './skeleton/channelSkeleton';
const TAG: string = 'SpacialTopicPageComponent'
//专题详情页
@Component
export struct SpacialTopicPageComponent {
webviewControl: BridgeWebViewControl = new BridgeWebViewControl()
scroller: Scroller = new Scroller();
action: Action = {} as Action
@State webUrl: string = '';
@State subjectData: string = '';
@State index: number = 0
@State currentIndex: number = 0
@State isPageEnd: boolean = false
@State showCommentList: boolean = false
@State interactData: InteractDataDTO = {} as InteractDataDTO
@Prop reload: number = 0;
@Provide contentDetailData: ContentDetailDTO = {} as ContentDetailDTO
private h5ReceiveAppData: H5ReceiveDetailBean = { dataSource: '2' } as H5ReceiveDetailBean
private webPrepared = false;
private dataPrepared = false;
@State publishCommentModel: publishCommentModel = new publishCommentModel()
@State operationButtonList: string[] = ['comment', 'collect', 'share']
@State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0
@State isNetConnected: boolean = true
@Provide topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0
@State showComment: boolean = false
@State topicInfo: TopicInfo = {} as TopicInfo
private trySendData2H5() {
if (!this.webPrepared || !this.dataPrepared) {
return
}
// 数据、web组件,都准备好了,开始塞详情数据
this.sendContentData2H5(this.h5ReceiveAppData)
}
private onWebPrepared() {
this.webPrepared = true
this.trySendData2H5()
}
private sendContentData2H5(h5ReceiveAppData: H5ReceiveDetailBean) {
this.webviewControl.callHandle(NativeCallH5Type.jsCall_receiveAppData,
JSON.stringify(h5ReceiveAppData), (data: string) => {
})
}
//意图上报
private viewBlogInsightIntentShare(){
let context = getContext(this) as common.UIAbilityContext;
viewBlogItemInsightIntentShare(context,this.contentDetailData)
}
async getWebviewPageData (){
let pageId = this.action.params?.extra?.pageId
let relId: string = ''
let relType: string = ''
let contentId: string = ''
if (this.action && this.action.params) {
if (this.action.params.contentID) {
contentId = this.action.params.contentID;
}
if (this.action && this.action.params && this.action.params.extra) {
if (this.action.params.extra.relId) {
relId = this.action.params.extra.relId;
}
if (this.action.params.extra.relType) {
relType = this.action.params.extra.relType
}
}
}
if(pageId){
// let pageInfoMsg = await PageRepository.fetchMorningEveningPageInfo(pageId)
// let pageCompInfoMsg = await PageRepository.fetchMorningEveningCompInfo(Number(pageId), groupId, refreshTime, topicId, 1, 20)
// let res = {
// dataJson: {
// pageInfoResponseMap: pageInfoMsg,
// compInfoResponseMap: pageCompInfoMsg,
// },
// }
}
}
private async getDetail() {
this.isNetConnected = NetworkUtil.isNetConnected()
let contentId: string = ''
let relId: string = ''
let relType: string = ''
if (this.action && this.action.params) {
if (this.action.params.contentID) {
contentId = this.action.params.contentID;
}
if (this.action && this.action.params && this.action.params.extra) {
if (this.action.params.extra.relId) {
relId = this.action.params.extra.relId;
}
if (this.action.params.extra.relType) {
relType = this.action.params.extra.relType
}
}
let pageId = this.action.params.extra?.pageId
console.log('pageIdpageId',pageId)
if(pageId){
let pageInfoMsg = await PageRepository.fetchMorningEveningPageInfo(pageId,contentId)
let detailBeans = await DetailViewModel.getDetailPageData(relId, contentId, relType)
if (detailBeans?.length > 0) {
this.contentDetailData = JSON.parse(JSON.stringify(detailBeans[0]));
this.viewBlogInsightIntentShare()
// if (this.contentDetailData[0]?.openComment) {
this.publishCommentModel.targetId = String(this.contentDetailData?.newsId || '')
this.publishCommentModel.targetRelId = String(this.contentDetailData?.reLInfo?.relId || '')
this.publishCommentModel.targetTitle = this.contentDetailData?.newsTitle
this.publishCommentModel.targetRelType = String(this.contentDetailData?.reLInfo?.relType || '')
this.publishCommentModel.targetRelObjectId = String(this.contentDetailData?.reLInfo?.relObjectId || '')
this.publishCommentModel.keyArticle = String(this.contentDetailData?.keyArticle || '')
this.publishCommentModel.targetType = String(this.contentDetailData?.newsType || '')
this.publishCommentModel.visitorComment = String(this.contentDetailData?.visitorComment || '')
// }
this.subjectData = 'dasdasdadas'
//TODO
// this.trySendData2H5()
}
if(pageInfoMsg && pageInfoMsg.data){
this.contentDetailData.openComment = Number(pageInfoMsg.data.topicInfo?.commentFlag)
this.contentDetailData.commentDisplay = Number(pageInfoMsg.data.topicInfo?.commentShowFlag)
console.log('contentDetailData pageInfoMsg.data', JSON.stringify(pageInfoMsg.data))
this.topicInfo = pageInfoMsg.data.topicInfo
this.contentDetailData.newsId = Number(this.topicInfo.topicId)
this.contentDetailData.newsType = this.topicInfo.topicType
if(this.topicInfo?.shareOpen === 1){
this.contentDetailData.shareInfo.shareOpen = this.topicInfo?.shareOpen
console.log('contentDetailData this.topicInfo', JSON.stringify(this.topicInfo))
if (!this.operationButtonList.includes('share')) {
this.operationButtonList.push('share');
}
} else {
this.operationButtonList = this.operationButtonList.filter(e =>e !== 'share')
}
}
console.log('contentDetailData', JSON.stringify(this.contentDetailData))
}
}
}
build() {
Column() {
Stack({ alignContent: Alignment.Bottom }) {
Column() {
Text(this.contentDetailData?.newsTitle)
.backgroundColor(Color.White)
.width('100%')
.height(40)
.fontSize(18)
.textAlign(TextAlign.Center)
.fontWeight(500)
.visibility(this.action?.params?.backVisibility && this.isPageEnd ? Visibility.Visible : Visibility.None)
if(this.subjectData.length > 0){
WdWebComponent({
webviewControl: this.webviewControl,
webUrl: this.webUrl,
reload: this.reload,
onWebPrepared: this.onWebPrepared.bind(this),
isPageEnd: $isPageEnd,
subjectData: this.subjectData
})
}
}
.width(CommonConstants.FULL_WIDTH)
.height(CommonConstants.FULL_HEIGHT)
.padding({ bottom: this.action?.params?.backVisibility ? 115 : 75 })
if (!this.isNetConnected) {
EmptyComponent({
emptyType: 1,
emptyButton: true,
retry: () => {
this.getDetail()
}
}).padding({ bottom: 200 })
} else {
if (!this.isPageEnd) {
channelSkeleton().padding({ top:`${this.topSafeHeight}px`,bottom: this.bottomSafeHeight })
}
}
//底部交互区
OperRowListView({
contentDetailData: this.contentDetailData,
publishCommentModel: this.publishCommentModel,
operationButtonList: this.operationButtonList,
topicInfo: this.topicInfo,
styleType: 1,
onCommentIconClick:()=>{
this.showCommentList = true
}
})
//全部评论
CommentDialogView({
index: $index,
currentIndex: $currentIndex,
showCommentList: $showCommentList,
publishCommentModel: $publishCommentModel,
interactData: $interactData,
}).visibility(this.showComment?Visibility.Visible:Visibility.Hidden)
}
}.width(CommonConstants.FULL_WIDTH).height(CommonConstants.FULL_HEIGHT)
}
aboutToAppear() {
if (!this.action?.params?.backVisibility) {
// WindowModel.shared.setWindowLayoutFullScreen(true)
}
this.webUrl = this.action?.params?.url || ''
this.getDetail()
}
aboutToDisappear() {
if (!this.action?.params?.backVisibility) {
// WindowModel.shared.setWindowLayoutFullScreen(false)
}
}
}