Showing
1 changed file
with
31 additions
and
2 deletions
| @@ -10,6 +10,7 @@ import { CommentCustomDialog } from './CommentCustomDialog' | @@ -10,6 +10,7 @@ import { CommentCustomDialog } from './CommentCustomDialog' | ||
| 10 | import { publishCommentModel } from '../model/PublishCommentModel'; | 10 | import { publishCommentModel } from '../model/PublishCommentModel'; |
| 11 | import { ifaa } from '@kit.OnlineAuthenticationKit'; | 11 | import { ifaa } from '@kit.OnlineAuthenticationKit'; |
| 12 | import { HttpUrlUtils } from 'wdNetwork/Index'; | 12 | import { HttpUrlUtils } from 'wdNetwork/Index'; |
| 13 | +import NoMoreLayout from '../../page/NoMoreLayout'; | ||
| 13 | 14 | ||
| 14 | const TAG = 'CommentComponent'; | 15 | const TAG = 'CommentComponent'; |
| 15 | 16 | ||
| @@ -19,6 +20,8 @@ const testString = '因为读书的人\n是低着头向上看的人\n身处一 | @@ -19,6 +20,8 @@ const testString = '因为读书的人\n是低着头向上看的人\n身处一 | ||
| 19 | @Preview | 20 | @Preview |
| 20 | @Component | 21 | @Component |
| 21 | export struct CommentComponent { | 22 | export struct CommentComponent { |
| 23 | + @State hasMore: boolean = true; | ||
| 24 | + @State currentPage: number = 1; | ||
| 22 | // @State private browSingModel: commentListModel = new commentListModel() | 25 | // @State private browSingModel: commentListModel = new commentListModel() |
| 23 | /*必传*/ | 26 | /*必传*/ |
| 24 | @ObjectLink publishCommentModel: publishCommentModel | 27 | @ObjectLink publishCommentModel: publishCommentModel |
| @@ -167,7 +170,19 @@ export struct CommentComponent { | @@ -167,7 +170,19 @@ export struct CommentComponent { | ||
| 167 | } | 170 | } |
| 168 | } | 171 | } |
| 169 | }, (item: commentItemModel, index: number) => JSON.stringify(item) + index.toString()) | 172 | }, (item: commentItemModel, index: number) => JSON.stringify(item) + index.toString()) |
| 173 | + | ||
| 174 | + // 加载更多 | ||
| 175 | + ListItem() { | ||
| 176 | + if (this.hasMore === false) NoMoreLayout() | ||
| 177 | + } | ||
| 170 | } | 178 | } |
| 179 | + | ||
| 180 | + .onReachEnd(()=>{ | ||
| 181 | + if (this.hasMore) { | ||
| 182 | + this.getData() | ||
| 183 | + } | ||
| 184 | + | ||
| 185 | + }) | ||
| 171 | .enableScrollInteraction(false) | 186 | .enableScrollInteraction(false) |
| 172 | } | 187 | } |
| 173 | 188 | ||
| @@ -175,10 +190,22 @@ export struct CommentComponent { | @@ -175,10 +190,22 @@ export struct CommentComponent { | ||
| 175 | 190 | ||
| 176 | //获取数据 | 191 | //获取数据 |
| 177 | async getData() { | 192 | async getData() { |
| 178 | - commentViewModel.fetchContentCommentList('1', this.publishCommentModel.targetId, this.publishCommentModel.targetType) | 193 | + commentViewModel.fetchContentCommentList(this.currentPage + '', this.publishCommentModel.targetId, this.publishCommentModel.targetType) |
| 179 | .then(commentListModel => { | 194 | .then(commentListModel => { |
| 180 | - this.publishCommentModel.totalCommentNumer = commentListModel.totalCount + '' | 195 | + this.currentPage++ |
| 196 | + | ||
| 197 | + if (Number.parseInt(commentListModel.totalCommentNum) > Number.parseInt(this.publishCommentModel.totalCommentNumer)) { | ||
| 198 | + this.publishCommentModel.totalCommentNumer = commentListModel.totalCommentNum + '' | ||
| 199 | + } | ||
| 200 | + | ||
| 201 | + if (commentListModel.hasNext === 0) { | ||
| 202 | + this.hasMore = false; | ||
| 203 | + } else { | ||
| 204 | + this.hasMore = true; | ||
| 205 | + } | ||
| 206 | + | ||
| 181 | if (commentListModel && commentListModel.list && commentListModel.list.length > 0) { | 207 | if (commentListModel && commentListModel.list && commentListModel.list.length > 0) { |
| 208 | + | ||
| 182 | commentListModel.list.forEach(element => { | 209 | commentListModel.list.forEach(element => { |
| 183 | element.hasMore = Number.parseInt(element.childCommentNum) ? true : false | 210 | element.hasMore = Number.parseInt(element.childCommentNum) ? true : false |
| 184 | let newModel = commentViewModel.deepCopyCommentItemModel(element) | 211 | let newModel = commentViewModel.deepCopyCommentItemModel(element) |
| @@ -189,6 +216,8 @@ export struct CommentComponent { | @@ -189,6 +216,8 @@ export struct CommentComponent { | ||
| 189 | }); | 216 | }); |
| 190 | 217 | ||
| 191 | 218 | ||
| 219 | + }else{ | ||
| 220 | + this.hasMore = false | ||
| 192 | } | 221 | } |
| 193 | }) | 222 | }) |
| 194 | 223 |
-
Please register or login to post a comment