yangchenggong1_wd

fix:bug[17409 ]我的评论无法刷新

@@ -7,6 +7,7 @@ import { EmptyComponent } from '../../view/EmptyComponent'; @@ -7,6 +7,7 @@ import { EmptyComponent } from '../../view/EmptyComponent';
7 import { ChildCommentComponent } from './ChildCommentComponent'; 7 import { ChildCommentComponent } from './ChildCommentComponent';
8 import { MineCommentListDetailItem } from '../../../viewmodel/MineCommentListDetailItem'; 8 import { MineCommentListDetailItem } from '../../../viewmodel/MineCommentListDetailItem';
9 import { OtherUserCommentLikeStatusRequestItem } from '../../../viewmodel/OtherUserCommentLikeStatusRequestItem'; 9 import { OtherUserCommentLikeStatusRequestItem } from '../../../viewmodel/OtherUserCommentLikeStatusRequestItem';
  10 +import { CustomPullToRefresh } from '../../reusable/CustomPullToRefresh';
10 11
11 const TAG = "HomePageBottomCommentComponent" 12 const TAG = "HomePageBottomCommentComponent"
12 13
@@ -22,6 +23,7 @@ export struct HomePageBottomCommentComponent { @@ -22,6 +23,7 @@ export struct HomePageBottomCommentComponent {
22 @State count: number = 0; 23 @State count: number = 0;
23 @Link commentNum: number 24 @Link commentNum: number
24 @State isGetRequest: boolean = false 25 @State isGetRequest: boolean = false
  26 + private scroller: Scroller = new Scroller();
25 27
26 aboutToAppear() { 28 aboutToAppear() {
27 this.getNewPageData() 29 this.getNewPageData()
@@ -42,39 +44,31 @@ export struct HomePageBottomCommentComponent { @@ -42,39 +44,31 @@ export struct HomePageBottomCommentComponent {
42 .offset({ y: "-200lpx" }) 44 .offset({ y: "-200lpx" })
43 } 45 }
44 } else { 46 } else {
45 - List({ space: 3 }) {  
46 - LazyForEach(this.data_comment, (item: CommentListItem, index: number = 0) => {  
47 - ListItem() {  
48 - ChildCommentComponent({  
49 - data: item,  
50 - levelHead: UserDataLocal.getUserLevelHeaderUrl(),  
51 - isLastItem: index === this.data_comment.totalCount() - 1  
52 - }) 47 + CustomPullToRefresh({
  48 + alldata:this.data_comment,
  49 + scroller:this.scroller,
  50 + customList:()=>{
  51 + this.ListLayout()
  52 + },
  53 + onRefresh:(resolve)=>{
  54 + this.curPageNum = 1;
  55 + this.hasMore = true
  56 + this.isGetRequest = false
  57 + this.data_comment.clear()
  58 +
  59 + if (!this.isLoading){
  60 + this.getNewPageData()
  61 + if(resolve) resolve('刷新成功')
53 } 62 }
54 - }, (item: CommentListItem, index: number) => index.toString())  
55 -  
56 - //没有更多数据 显示提示  
57 - if (!this.hasMore) {  
58 - ListItem() {  
59 - ListHasNoMoreDataUI() 63 + },
  64 + onLoadMore:(resolve)=> {
  65 + console.log(TAG, "触底了");
  66 + if (!this.isLoading) {
  67 + this.isLoading = true
  68 + //加载分页数据
  69 + this.getNewPageData()
60 } 70 }
61 } 71 }
62 - }  
63 - .cachedCount(15)  
64 - .layoutWeight(1)  
65 - .scrollBar(BarState.Off)  
66 - .edgeEffect(EdgeEffect.None)  
67 - .nestedScroll({  
68 - scrollForward: NestedScrollMode.PARENT_FIRST,  
69 - scrollBackward: NestedScrollMode.SELF_FIRST  
70 - })  
71 - .onReachEnd(() => {  
72 - console.log(TAG, "触底了");  
73 - if (!this.isLoading) {  
74 - this.isLoading = true  
75 - //加载分页数据  
76 - this.getNewPageData()  
77 - }  
78 }) 72 })
79 } 73 }
80 }.layoutWeight(1) 74 }.layoutWeight(1)
@@ -82,6 +76,35 @@ export struct HomePageBottomCommentComponent { @@ -82,6 +76,35 @@ export struct HomePageBottomCommentComponent {
82 .width('100%') 76 .width('100%')
83 } 77 }
84 78
  79 + @Builder ListLayout(){
  80 + List({ space: 3,scroller: this.scroller }) {
  81 + LazyForEach(this.data_comment, (item: CommentListItem, index: number = 0) => {
  82 + ListItem() {
  83 + ChildCommentComponent({
  84 + data: item,
  85 + levelHead: UserDataLocal.getUserLevelHeaderUrl(),
  86 + isLastItem: index === this.data_comment.totalCount() - 1
  87 + })
  88 + }
  89 + }, (item: CommentListItem, index: number) => index.toString())
  90 +
  91 + //没有更多数据 显示提示
  92 + if (!this.hasMore) {
  93 + ListItem() {
  94 + ListHasNoMoreDataUI()
  95 + }
  96 + }
  97 + }
  98 + .cachedCount(15)
  99 + .layoutWeight(1)
  100 + .scrollBar(BarState.Off)
  101 + .edgeEffect(EdgeEffect.None)
  102 + .nestedScroll({
  103 + scrollForward: NestedScrollMode.PARENT_FIRST,
  104 + scrollBackward: NestedScrollMode.SELF_FIRST
  105 + })
  106 + }
  107 +
85 getNewPageData() { 108 getNewPageData() {
86 this.isLoading = true 109 this.isLoading = true
87 if (this.hasMore) { 110 if (this.hasMore) {
@@ -7,6 +7,7 @@ import { MineCommentListDetailItem } from '../../../viewmodel/MineCommentListDet @@ -7,6 +7,7 @@ import { MineCommentListDetailItem } from '../../../viewmodel/MineCommentListDet
7 import { OtherUserCommentLikeStatusRequestItem } from '../../../viewmodel/OtherUserCommentLikeStatusRequestItem'; 7 import { OtherUserCommentLikeStatusRequestItem } from '../../../viewmodel/OtherUserCommentLikeStatusRequestItem';
8 import { ChildCommentComponent } from './ChildCommentComponent'; 8 import { ChildCommentComponent } from './ChildCommentComponent';
9 import { EmptyComponent } from '../../view/EmptyComponent'; 9 import { EmptyComponent } from '../../view/EmptyComponent';
  10 +import { CustomPullToRefresh } from '../../reusable/CustomPullToRefresh';
10 11
11 const TAG = "HomePageBottomComponent" 12 const TAG = "HomePageBottomComponent"
12 /** 13 /**
@@ -23,6 +24,8 @@ export struct OtherHomePageBottomCommentComponent { @@ -23,6 +24,8 @@ export struct OtherHomePageBottomCommentComponent {
23 @Prop levelHead: string 24 @Prop levelHead: string
24 @Link commentNum: number 25 @Link commentNum: number
25 @State isGetRequest: boolean = false 26 @State isGetRequest: boolean = false
  27 + private scroller: Scroller = new Scroller();
  28 +
26 29
27 aboutToAppear() { 30 aboutToAppear() {
28 this.getNewPageData() 31 this.getNewPageData()
@@ -41,41 +44,31 @@ export struct OtherHomePageBottomCommentComponent { @@ -41,41 +44,31 @@ export struct OtherHomePageBottomCommentComponent {
41 .layoutWeight(1) 44 .layoutWeight(1)
42 } 45 }
43 } else { 46 } else {
44 - List({ space: 3 }) {  
45 - LazyForEach(this.data_comment, (item: CommentListItem, index: number = 0) => {  
46 - ListItem() {  
47 - ChildCommentComponent({  
48 - data: item,  
49 - levelHead: this.levelHead,  
50 - isLastItem: index === this.data_comment.totalCount() - 1  
51 - }) 47 + CustomPullToRefresh({
  48 + alldata:this.data_comment,
  49 + scroller:this.scroller,
  50 + customList:()=>{
  51 + this.ListLayout()
  52 + },
  53 + onRefresh:(resolve)=>{
  54 + this.curPageNum = 1;
  55 + this.hasMore = true
  56 + this.isGetRequest = false
  57 + this.data_comment.clear()
  58 +
  59 + if (!this.isLoading){
  60 + this.getNewPageData()
  61 + if(resolve) resolve('刷新成功')
52 } 62 }
53 - .onClick(() => {  
54 - })  
55 - }, (item: CommentListItem, index: number) => index.toString())  
56 -  
57 - //没有更多数据 显示提示  
58 - if (!this.hasMore) {  
59 - ListItem() {  
60 - ListHasNoMoreDataUI() 63 + },
  64 + onLoadMore:(resolve)=> {
  65 + console.log(TAG, "触底了");
  66 + if (!this.isLoading) {
  67 + this.isLoading = true
  68 + //加载分页数据
  69 + this.getNewPageData()
61 } 70 }
62 } 71 }
63 - }  
64 - .cachedCount(15)  
65 - .layoutWeight(1)  
66 - .scrollBar(BarState.Off)  
67 - .edgeEffect(EdgeEffect.None)  
68 - .nestedScroll({  
69 - scrollForward: NestedScrollMode.PARENT_FIRST,  
70 - scrollBackward: NestedScrollMode.SELF_FIRST  
71 - })  
72 - .onReachEnd(() => {  
73 - console.log(TAG, "触底了");  
74 - if (!this.isLoading) {  
75 - this.isLoading = true  
76 - //加载分页数据  
77 - this.getNewPageData()  
78 - }  
79 }) 72 })
80 } 73 }
81 } 74 }
@@ -84,6 +77,35 @@ export struct OtherHomePageBottomCommentComponent { @@ -84,6 +77,35 @@ export struct OtherHomePageBottomCommentComponent {
84 .justifyContent(FlexAlign.Start) 77 .justifyContent(FlexAlign.Start)
85 } 78 }
86 79
  80 + @Builder ListLayout(){
  81 + List({ space: 3 ,scroller: this.scroller}) {
  82 + LazyForEach(this.data_comment, (item: CommentListItem, index: number = 0) => {
  83 + ListItem() {
  84 + ChildCommentComponent({
  85 + data: item,
  86 + levelHead: this.levelHead,
  87 + isLastItem: index === this.data_comment.totalCount() - 1
  88 + })
  89 + }
  90 + }, (item: CommentListItem, index: number) => index.toString())
  91 +
  92 + //没有更多数据 显示提示
  93 + if (!this.hasMore) {
  94 + ListItem() {
  95 + ListHasNoMoreDataUI()
  96 + }
  97 + }
  98 + }
  99 + .cachedCount(15)
  100 + .layoutWeight(1)
  101 + .scrollBar(BarState.Off)
  102 + .edgeEffect(EdgeEffect.None)
  103 + .nestedScroll({
  104 + scrollForward: NestedScrollMode.PARENT_FIRST,
  105 + scrollBackward: NestedScrollMode.SELF_FIRST
  106 + })
  107 + }
  108 +
87 @Styles 109 @Styles
88 listStyle() { 110 listStyle() {
89 .backgroundColor(Color.White) 111 .backgroundColor(Color.White)