yanlu

jira: desc:人民号主页,下拉刷新

... ... @@ -19,7 +19,6 @@ import {
struct PeopleShipHomePage {
// Todo 传入数据 后续在修改
creatorId: string = (router.getParams() as Record<string, string>)['creatorId'];
@State arr: number[] = []
// 页面详情数据
@Provide detailModel: PeopleShipUserDetailData = {} as PeopleShipUserDetailData
// 每个分类数量
... ... @@ -108,9 +107,12 @@ struct PeopleShipHomePage {
Logger.debug('PeopleShipHomePage', '获取页面信息', `${JSON.stringify(this.detailModel)}`)
// 获取关注
// 登录后获取,是否关注
if (HttpUrlUtils.getUserId()) {
let followList: QueryListIsFollowedItem[] = await PeopleShipHomePageDataModel.getHomePageFollowListStatusData(this.creatorId)
Logger.debug('PeopleShipHomePage', '获取关注信息', `${JSON.stringify(followList)}`)
this.findFollowStata(followList)
}
} catch (exception) {
... ... @@ -128,14 +130,17 @@ struct PeopleShipHomePage {
}
handleChangeAttentionStata() {
if (!this.isLoadingAttention) {
return
}
// 未登录,跳转登录
if (!HttpUrlUtils.getUserId()) {
this.isLoadingAttention = false
WDRouterRule.jumpWithPage(WDRouterPage.loginPage)
return
}
let status = 0
if (this.isAttention == '0') {
status = 1
... ...
... ... @@ -20,24 +20,26 @@ import { RefreshLayoutBean } from '../page/RefreshLayoutBean'
import CustomRefreshLoadLayout from '../page/CustomRefreshLoadLayout'
import { ErrorComponent } from '../view/ErrorComponent';
import NoMoreLayout from '../page/NoMoreLayout';
import { LazyDataSource } from 'wdKit';
// import { LazyDataSource } from 'wdKit';
import { CustomPullToRefresh } from '../reusable/CustomPullToRefresh'
const TAG = 'PeopleShipHomeArticleListComponent';
@Component
export struct PeopleShipHomeArticleListComponent {
// @State arr: ContentDTO[] = []
@State arr: LazyDataSource<ContentDTO> = new LazyDataSource();
@State arr: ContentDTO[] = []
// @State arr: LazyDataSource<ContentDTO> = new LazyDataSource();
@State typeModel: ArticleTypeData = new ArticleTypeData()
@State creatorId: string = ''
@Consume detailModel: PeopleShipUserDetailData
@State private viewType: number = 1;
currentIndex: number = 0
@State private viewType: number = 1
currentIndex: number = 1
@Link @Watch('onChange') currentTopSelectedIndex: number
@State private hasMore: boolean = true
@State currentPage: number = 1
@State private currentPage: number = 1
@State private isLoading: boolean = false
@Consume topHeight: number
private scroller: Scroller = new Scroller()
build() {
if (this.viewType == 1) {
... ... @@ -46,7 +48,34 @@ export struct PeopleShipHomeArticleListComponent {
} else if (this.viewType == 2) {
ErrorComponent()
} else {
CustomPullToRefresh({
alldata:this.arr,
scroller:this.scroller,
hasMore: this.hasMore,
customList:()=>{
this.ListLayout()
},
onRefresh:(resolve)=>{
this.currentPage = 1
this.getPeopleShipPageArticleList(resolve)
},
onLoadMore:(resolve)=> {
if (this.hasMore === false) {
if(resolve) {
resolve('')
}
return
}
if(!this.isLoading && this.hasMore){
//加载分页数据
this.getPeopleShipPageArticleList(resolve)
}else {
if(resolve) {
resolve('')
}
}
},
})
}
}
... ... @@ -62,10 +91,10 @@ export struct PeopleShipHomeArticleListComponent {
@Builder
ListLayout() {
List() {
List({scroller: this.scroller}) {
// 下拉刷新
LazyForEach(this.arr, (item: ContentDTO) => {
ForEach(this.arr, (item: ContentDTO) => {
ListItem() {
CardParser({ contentDTO: item })
}.width("100%")
... ... @@ -74,25 +103,25 @@ export struct PeopleShipHomeArticleListComponent {
// 加载更多
ListItem() {
if (!this.hasMore) {
if (!this.hasMore && !this.isLoading) {
NoMoreLayout()
}
}
}
.width("100%")
.height("100%")
.edgeEffect(EdgeEffect.Spring)
.edgeEffect(EdgeEffect.None)
.nestedScroll({
scrollForward: NestedScrollMode.PARENT_FIRST,
scrollBackward: NestedScrollMode.SELF_FIRST
})
.onReachEnd(() => {
if(!this.isLoading && this.hasMore){
//加载分页数据
this.getPeopleShipPageArticleList()
}
})
// .onReachEnd(() => {
// if(!this.isLoading && this.hasMore){
// //加载分页数据
// this.getPeopleShipPageArticleList()
// }
// })
}
aboutToAppear() {
... ... @@ -109,16 +138,28 @@ export struct PeopleShipHomeArticleListComponent {
}
}
private async getPeopleShipPageArticleList() {
private async getPeopleShipPageArticleList(resolve?: (value: string | PromiseLike<string>) => void) {
Logger.info(`获取页面信息PeopleShipHomeArticleListComponent${this.typeModel.type}`)
if (this.isLoading) {
if (resolve) {
resolve('')
}
return
}
try {
this.isLoading = true
let listData: ArticleListData = await PeopleShipHomePageDataModel.getPeopleShipHomePageArticleListData(this.creatorId, this.currentPage, 20, this.typeModel.type)
Logger.debug(TAG, `获取页面信息, ${listData.list.length}`);
Logger.debug(TAG, `已更新值最新, ${this.currentPage}`);
if (resolve ) {
if (this.currentPage == 1) {
resolve('已更新至最新')
}else {
resolve('')
}
}
if (listData && listData.list && listData.list.length > 0) {
this.viewType = 3;
if (listData.list.length === 20) {
... ... @@ -130,15 +171,18 @@ export struct PeopleShipHomeArticleListComponent {
} else {
this.viewType = 1;
}
this.isLoading = false
this.queryArticleContentInteractCount(listData)
Logger.debug(TAG, '展示的总数', `${this.arr.totalCount()}`)
Logger.debug(TAG, '展示的总数', `${this.arr.length}`)
}catch (exception) {
if (resolve) {
resolve('')
}
this.isLoading = false
if (this.arr.totalCount() == 0) {
if (this.arr.length == 0) {
this.viewType = 2
}
}
}
/**
... ...
... ... @@ -15,13 +15,13 @@ export struct PeopleShipHomePageHeadComponent {
.borderWidth('1vp')
.borderStyle(BorderStyle.Solid)
.borderColor(Color.White)
.objectFit(ImageFit.Auto)
.objectFit(ImageFit.Cover)
if(this.authIcon.length > 0 ) {
Image( this.authIcon )
.width(this.iconDiameter)
.height(this.iconDiameter)
.borderRadius(this.iconDiameter/2)
.objectFit(ImageFit.Auto)
.objectFit(ImageFit.Cover)
.margin({
right: '-3vp'
})
... ...
... ... @@ -10,7 +10,7 @@ export struct CustomPullToRefresh {
onLoadMore: (resolve?: (value: string | PromiseLike<string>) => void) => void = () => {
}
///是否存在上拉更多
@State hasMore: boolean = true
@Prop hasMore: boolean = true
refreshConfigurator: PullToRefreshConfigurator = new PullToRefreshConfigurator().setHasLoadMore(this.hasMore);
build() {
Column(){
... ...