VisitorCommentPage.ets
7.03 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
import { TAG } from '@ohos/hypium/src/main/Constant';
import { ContentDTO } from 'wdBean/Index';
import { SpConstants } from 'wdConstant/Index'
import { DateTimeUtils, LazyDataSource, Logger, NetworkUtil, SPHelper, StringUtils} from 'wdKit/Index'
import { ProcessUtils } from 'wdRouter/Index';
import { VisitorCommentComponent } from '../components/mine/home/VisitorCommentComponent';
import { CustomPullToRefresh } from '../components/reusable/CustomPullToRefresh';
import { CustomTitleUI } from '../components/reusable/CustomTitleUI';
import { ListHasNoMoreDataUI } from '../components/reusable/ListHasNoMoreDataUI';
import { EmptyComponent } from '../components/view/EmptyComponent';
import MinePageDatasModel from '../model/MinePageDatasModel';
import { CommentListItem } from '../viewmodel/CommentListItem';
@Entry
@Component
struct VisitorCommentPage {
@State data: LazyDataSource<CommentListItem> = new LazyDataSource();
@State bottomSafeHeight: number = AppStorage.get<number>('bottomSafeHeight') || 0
@State topSafeHeight: number = AppStorage.get<number>('topSafeHeight') || 0
@State count: number = 0;
@State isLoading: boolean = false
@State hasMore: boolean = true
curPageNum: number = 1;
@State isGetRequest: boolean = false
private scroller: Scroller = new Scroller();
@State isConnectNetwork : boolean = NetworkUtil.isNetConnected()
@State commentTime:string = ""
aboutToAppear(): void {
this.commentTime = SPHelper.default.getSync(SpConstants.FIRSTCOMMENTTIME, "") as string
if (StringUtils.isNotEmpty(this.commentTime)) {
this.getNewPageData(this.commentTime)
}else{
this.isGetRequest = true
}
}
build() {
Column(){
Column() {
//标题栏目
CustomTitleUI({ titleName: "评论列表" })
if (this.count == 0) {
if (this.isGetRequest == true) {
if(this.isConnectNetwork){
EmptyComponent({ emptyType: 11 })
.height('100%')
.width('100%')
}else{
EmptyComponent({ emptyType: 1,emptyHeight:"100%" ,retry: () => {
this.isConnectNetwork = NetworkUtil.isNetConnected()
if(this.isConnectNetwork){
this.curPageNum = 1;
this.hasMore = true
this.isGetRequest = false
this.data.clear()
if (!this.isLoading) {
this.getNewPageData(this.commentTime)
}
}
}})
.layoutWeight(1)
.width('100%')
}
}
} else {
Stack(){
Row()
.width("100%")
.height("100%")
.backgroundColor($r('app.color.white'))
CustomPullToRefresh({
alldata:this.data,
scroller:this.scroller,
customList:()=>{
this.ListLayout()
},
onRefresh:(resolve)=>{
this.curPageNum = 1;
this.hasMore = true
this.isGetRequest = false
this.data.clear()
if (!this.isLoading){
this.getNewPageData(this.commentTime)
if(resolve) resolve('刷新成功')
}
},
onLoadMore:(resolve)=> {
if (!this.isLoading) {
this.isLoading = true
this.getNewPageData(this.commentTime)
}
}
})
}
}
}
.backgroundColor($r('app.color.color_transparent'))
.height('100%')
.width('100%')
}.width("100%")
.height("100%")
.backgroundColor(Color.White)
.padding({top:px2vp(this.topSafeHeight),bottom:px2vp(this.bottomSafeHeight)})
}
@Builder ListLayout(){
List({ space:6,scroller: this.scroller }) {
LazyForEach(this.data, (item: CommentListItem, index: number) => {
ListItem() {
VisitorCommentComponent({
data: item,
isLastItem: index === this.data.totalCount() - 1
})
}
.onClick(() => {
let content = getParams(item)
ProcessUtils.processPage(content)
})
}, (item: CommentListItem, index: number) => index.toString())
//没有更多数据 显示提示
if (!this.hasMore) {
ListItem() {
ListHasNoMoreDataUI()
}.padding({bottom:px2vp(this.bottomSafeHeight) + 20})
}
}
.cachedCount(4)
.scrollBar(BarState.Off)
.edgeEffect(EdgeEffect.None)
.margin({ top: '23lpx'})
.layoutWeight(1)
}
getNewPageData(commentTime:string) {
this.isLoading = true
if (this.hasMore) {
MinePageDatasModel.visitorCommentListData( `${this.curPageNum}`, encodeURI(commentTime)).then((value) => {
if (!this.data || value.list.length == 0) {
this.hasMore = false
} else {
value.list.forEach((item) => {
let commentContent = item.commentContent
if (item.sensitiveShow === 0 && item.sensitiveExist === 1) {
commentContent = item.commentContentSensitive
}
let parentCommentContent = ""
if (item.parentCommentVo != null) {
parentCommentContent = item.parentCommentVo.commentContent
}
let parentCommentUserName = ""
if (item.parentCommentVo != null) {
parentCommentUserName = item.parentCommentVo.fromUserName
}
let publishTime =
DateTimeUtils.getCommentTime(DateTimeUtils.parseDate(item.createTime, DateTimeUtils.PATTERN_DATE_TIME_HYPHEN))
this.data.push(new CommentListItem(item.fromUserHeader, item.fromUserName,item.fromUserType, item.targetTitle, publishTime,
commentContent, item.likeNum, 0, item.id, item.targetId, item.targetType, item.targetRelId,
item.targetRelObjectId, item.targetRelType, item.targetStatus, item.checkStatus, parentCommentContent,
parentCommentUserName,item.h5Url))
})
this.data.notifyDataReload()
this.count = this.data.totalCount()
if (this.data.totalCount() < value.totalCount) {
this.curPageNum++
} else {
this.hasMore = false
}
}
this.isGetRequest = true
this.isLoading = false
}).catch((err: Error) => {
Logger.error(TAG, "get " + JSON.stringify(err))
this.isGetRequest = true
this.isLoading = false
})
}
}
}
function getParams(item: CommentListItem) : ContentDTO{
let contentDTO = new ContentDTO();
// contentDTO.objectType = item.targetType + ""
// contentDTO.objectId = item.targetId + ""
// contentDTO.newsTitle = item.targetTitle
// contentDTO.channelId =
// contentDTO.rmhPlatform =
contentDTO.objectId = item.targetId;
contentDTO.relType = item.targetRelType + "";
contentDTO.relId = item.targetRelId;
contentDTO.objectType = item.targetType + "";
contentDTO.newsTitle = item.targetTitle
return contentDTO
}