zhenghy

精选评论通顶通底

... ... @@ -18,11 +18,10 @@ const TAG = 'QualityCommentsComponent';
@Preview
@Component
export struct QualityCommentsComponent {
//刷新
@State viewType:number = ViewType.LOADING;
@State viewType: number = ViewType.LOADING;
@State hasMore: boolean = true;
@State currentPage: number = 1;
@State currentPage: number = 1;
private scroller: Scroller = new Scroller();
@State tileOpacity: number = 0;
firstPositionY: number = 0;
... ... @@ -32,11 +31,9 @@ export struct QualityCommentsComponent {
currentWindowColor: string = '#FF4202'
@State allDatas: LazyDataSource<commentItemModel> = new LazyDataSource();
@State dialogController: CustomDialogController | null = null;
/*必传*/
@State publishCommentModel: publishCommentModel = new publishCommentModel()
aboutToDisappear(): void {
// windowClass.setWindowSystemBarProperties({ statusBarColor: '#000' })
this.dialogController = null // 将dialogController置空
... ... @@ -55,7 +52,7 @@ export struct QualityCommentsComponent {
this.showAlert()
}
showAlert(){
showAlert() {
this.dialogController = new CustomDialogController({
builder: CommentCustomDialog({
confirm: (value: Record<string, string>) => {
... ... @@ -74,9 +71,11 @@ export struct QualityCommentsComponent {
})
}
getData(resolve?: (value: string | PromiseLike<string>) => void){
getData(resolve?: (value: string | PromiseLike<string>) => void) {
commentViewModel.fetchQualityCommentList(this.currentPage + '').then((commentListModel) => {
if(resolve) resolve('刷新成功')
if (resolve) {
resolve('刷新成功')
}
if (commentListModel && commentListModel.list && commentListModel.list.length > 0) {
if (this.currentPage === 1) {
... ... @@ -143,6 +142,7 @@ export struct QualityCommentsComponent {
.height(this.topSafeHeight + vp2px(44) + 'px')
.width('100%')
.backgroundColor($r('app.color.color_transparent'))
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
}
/*导航栏*/
... ... @@ -187,62 +187,66 @@ export struct QualityCommentsComponent {
.height(this.topSafeHeight + vp2px(44) + 'px')
.width('100%')
.backgroundColor($r('app.color.white'))
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP])
}
build() {
Column() {
Stack({ alignContent: Alignment.Top }) {
Scroll() {
Column() {
Stack() {
this.titleHeader()
if(this.viewType == ViewType.ERROR){
ErrorComponent()
}else if(this.viewType == ViewType.EMPTY){
EmptyComponent({emptyType:WDViewDefaultType.WDViewDefaultType_NoComment})
}else {
Stack({ alignContent: Alignment.Top }) {
Scroll() {
Column() {
Stack() {
this.titleHeader()
if (this.viewType == ViewType.ERROR) {
ErrorComponent()
} else if (this.viewType == ViewType.EMPTY) {
EmptyComponent({ emptyType: WDViewDefaultType.WDViewDefaultType_NoComment })
} else {
this.listLayout()
}
}
}.alignContent(Alignment.Top)
}.backgroundColor(this.currentWindowColor).width('100%')
}.alignContent(Alignment.Top)
}
.friction(0.6)
.scrollBar(BarState.Off)
.edgeEffect(EdgeEffect.None)
.width('100%')
.height('100%')
this.TabbarTransparent()
this.TabbarNormal()
.backgroundColor(this.currentWindowColor).width('100%')
}
.friction(0.6)
.scrollBar(BarState.Off)
.edgeEffect(EdgeEffect.None)
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
this.TabbarTransparent()
this.TabbarNormal()
}
.expandSafeArea([SafeAreaType.SYSTEM], [SafeAreaEdge.TOP, SafeAreaEdge.BOTTOM])
}
@Builder
listLayout(){
List({ space: 12, scroller:this.scroller }) {
listLayout() {
List({ space: 12, scroller: this.scroller }) {
// ListItemGroup({ header: this.titleHeader() })
LazyForEach(this.allDatas, (item: commentItemModel, index: number) => {
ListItem() {
QualityCommentItem({ item: item, index: index , dialogController:this.dialogController, publishCommentModel:this.publishCommentModel}).margin({ left: 12, right: 12 })
QualityCommentItem({
item: item,
index: index,
dialogController: this.dialogController,
publishCommentModel: this.publishCommentModel
}).margin({ left: 12, right: 12 })
}
})
// 加载更多
ListItem() {
if (this.hasMore === false) NoMoreLayout()
if (this.hasMore === false) {
NoMoreLayout()
}
}
// ListItem() {
//
// }.height(`${this.bottomSafeHeight}` + 'px')
}.onReachEnd(()=>{
}
.onReachEnd(() => {
this.currentPage++
this.getData()
})
... ... @@ -255,14 +259,9 @@ export struct QualityCommentsComponent {
scrollBackward: NestedScrollMode.SELF_FIRST
})
}
}
@Component
struct QualityCommentItem {
@ObjectLink publishCommentModel: publishCommentModel
... ... @@ -279,7 +278,8 @@ struct QualityCommentItem {
Image(this.item.fromUserHeader)
.alt($r(commentViewModel.adjustUserType(this.item.fromUserType) ? 'app.media.WDAccountOwnerHedaerDefaultIcon' : 'app.media.WDAccountDefaultIcon'))
.alt($r(commentViewModel.adjustUserType(this.item.fromUserType) ?
'app.media.WDAccountOwnerHedaerDefaultIcon' : 'app.media.WDAccountDefaultIcon'))
.width(50)
.height(50)
.borderRadius(25)
... ... @@ -296,7 +296,7 @@ struct QualityCommentItem {
}
)
.onClick(() => {
this.jumpToAccountOwner()
this.jumpToAccountOwner()
})
Text(this.item.fromUserName)
.fontSize(14)
... ... @@ -376,7 +376,7 @@ struct QualityCommentItem {
Row() {
Image($r('app.media.comment_icon_pinglun')).width(16).height(16)
}.height('100%')
.onClick(()=>{
.onClick(() => {
this.replyComment()
})
... ...