wangliang_wd

feat:增加下拉刷新SDK,我的收藏增加下拉刷新功能

... ... @@ -9,12 +9,13 @@ import { RefreshLayoutBean } from './RefreshLayoutBean';
import { CompDTO, ContentDTO } from 'wdBean'
import LoadMoreLayout from './LoadMoreLayout'
import NoMoreLayout from './NoMoreLayout'
import { CompParser } from '../CompParser'
import CustomRefreshLoadLayout from './CustomRefreshLoadLayout';
import { CustomSelectUI } from '../view/CustomSelectUI';
import { CustomBottomFuctionUI } from '../view/CustomBottomFuctionUI';
import { BigPicCardComponent } from '../view/BigPicCardComponent';
import { CustomPullToRefresh } from '../reusable/CustomPullToRefresh';
@Entry
@Component
struct BrowsingHistoryPage {
... ... @@ -25,6 +26,8 @@ struct BrowsingHistoryPage {
@State selectDatas :ContentDTO[] = [];
@Provide deleteNum :number = 0;
@Provide isAllSelect:boolean = false
private scroller: Scroller = new Scroller();
aboutToAppear(){
this.getData()
}
... ... @@ -37,15 +40,33 @@ struct BrowsingHistoryPage {
this.selectDatas = []
this.deleteNum = 0
}})
if (this.browSingModel.viewType == ViewType.LOADING){
this.LoadingLayout()
}else if(this.browSingModel.viewType == ViewType.ERROR){
ErrorComponent()
}else if(this.browSingModel.viewType == ViewType.EMPTY){
EmptyComponent()
}else {
CustomPullToRefresh({
alldata:this.allDatas,
scroller:this.scroller,
customList:()=>{
this.ListLayout()
},
onRefresh:(resolve)=>{
this.browSingModel.currentPage = 0
this.getData(resolve)
},
onLoadMore:(resolve)=> {
this.browSingModel.currentPage++
this.getData()
}
})
// if (this.browSingModel.viewType == ViewType.LOADING){
// this.LoadingLayout()
// }else if(this.browSingModel.viewType == ViewType.ERROR){
// ErrorComponent()
// }else if(this.browSingModel.viewType == ViewType.EMPTY){
// EmptyComponent()
// }else {
// this.ListLayout()
// }
if (this.isEditState){
CustomBottomFuctionUI({
... ... @@ -64,34 +85,27 @@ struct BrowsingHistoryPage {
}
@Builder ListLayout() {
List() {
List({scroller: this.scroller}) {
// 下拉刷新
ListItem() {
RefreshLayout({
refreshBean: new RefreshLayoutBean(this.browSingModel.isVisiblePullDown, this.browSingModel.pullDownRefreshImage,
this.browSingModel.pullDownRefreshText, this.browSingModel.pullDownRefreshHeight)
})
}
ForEach(this.allDatas, (compDTO: ContentDTO, compIndex: number) => {
ListItem() {
this.newCompParser(compDTO,compIndex)
}
})
// 加载更多
ListItem() {
if (this.browSingModel.hasMore) {
LoadMoreLayout({
refreshBean: new RefreshLayoutBean(this.browSingModel.isVisiblePullUpLoad, this.browSingModel.pullUpLoadImage,
this.browSingModel.pullUpLoadText, this.browSingModel.pullUpLoadHeight)
})
// LoadMoreLayout({
// refreshBean: new RefreshLayoutBean(this.browSingModel.isVisiblePullUpLoad, this.browSingModel.pullUpLoadImage,
// this.browSingModel.pullUpLoadText, this.browSingModel.pullUpLoadHeight)
// })
} else {
NoMoreLayout()
}
}
}
.height(CommonConstants.FULL_PARENT)
.edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
}
@Builder
... ... @@ -117,9 +131,9 @@ struct BrowsingHistoryPage {
$r('app.media.ic_pull_up_load'), $r('app.string.pull_up_load_text'), this.browSingModel.pullDownRefreshHeight) })
}
async getData() {
this.browSingModel.currentPage = 1
async getData(resolve?: (value: string | PromiseLike<string>) => void){
MyCollectionViewModel.fetchMyCollectList(2,'1',this.browSingModel.currentPage,getContext(this)).then(collectionItem => {
if(resolve) resolve('刷新成功')
if (collectionItem && collectionItem.list && collectionItem.list.length > 0) {
this.browSingModel.viewType = ViewType.LOADED;
this.allDatas.push(...collectionItem.list)
... ...
... ... @@ -4,17 +4,13 @@ import PageModel from '../../viewmodel/PageModel';
import { CommonConstants, ViewType } from 'wdConstant'
import { EmptyComponent,WDViewDefaultType } from '../view/EmptyComponent'
import { ErrorComponent } from '../view/ErrorComponent'
import RefreshLayout from './RefreshLayout'
import { RefreshLayoutBean } from './RefreshLayoutBean';
import { CompDTO, ContentDTO } from 'wdBean'
import LoadMoreLayout from './LoadMoreLayout'
import { ContentDTO } from 'wdBean'
import NoMoreLayout from './NoMoreLayout'
import { CompParser } from '../CompParser'
import CustomRefreshLoadLayout from './CustomRefreshLoadLayout';
import { CustomSelectUI } from '../view/CustomSelectUI';
import { CustomBottomFuctionUI } from '../view/CustomBottomFuctionUI';
import { BigPicCardComponent } from '../view/BigPicCardComponent';
import { contentListItemParams } from '../../model/MyCollectionModel';
import { CustomPullToRefresh } from '../reusable/CustomPullToRefresh';
@Entry
@Component
... ... @@ -26,6 +22,10 @@ struct MyCollectionListPage {
@State selectDatas :ContentDTO[] = [];
@Provide deleteNum :number = 0;
@Provide isAllSelect:boolean = false
@State currentPage: number = 1;
private scroller: Scroller = new Scroller();
aboutToAppear(){
this.getData()
}
... ... @@ -38,14 +38,31 @@ struct MyCollectionListPage {
this.selectDatas = []
this.deleteNum = 0
}})
if (this.browSingModel.viewType == ViewType.LOADING){
this.LoadingLayout()
}else if(this.browSingModel.viewType == ViewType.ERROR){
if(this.browSingModel.viewType == ViewType.ERROR){
ErrorComponent()
}else if(this.browSingModel.viewType == ViewType.EMPTY){
EmptyComponent({emptyType:WDViewDefaultType.WDViewDefaultType_NoCollection})
}else {
CustomPullToRefresh({
alldata:this.allDatas,
scroller:this.scroller,
customList:()=>{
this.ListLayout()
},
onRefresh:(resolve)=>{
this.currentPage = 1
this.getData(resolve)
},
onLoadMore:(resolve)=> {
if (this.browSingModel.hasMore === false) {
if(resolve) resolve('')
return
}
this.currentPage++
this.getData(resolve)
}
})
}
if (this.isEditState){
... ... @@ -65,34 +82,19 @@ struct MyCollectionListPage {
}
@Builder ListLayout() {
List() {
// 下拉刷新
ListItem() {
RefreshLayout({
refreshBean: new RefreshLayoutBean(this.browSingModel.isVisiblePullDown, this.browSingModel.pullDownRefreshImage,
this.browSingModel.pullDownRefreshText, this.browSingModel.pullDownRefreshHeight)
})
}
List({scroller: this.scroller}) {
ForEach(this.allDatas, (compDTO: ContentDTO, compIndex: number) => {
ListItem() {
this.newCompParser(compDTO,compIndex)
}
})
// 加载更多
ListItem() {
if (this.browSingModel.hasMore) {
LoadMoreLayout({
refreshBean: new RefreshLayoutBean(this.browSingModel.isVisiblePullUpLoad, this.browSingModel.pullUpLoadImage,
this.browSingModel.pullUpLoadText, this.browSingModel.pullUpLoadHeight)
})
} else {
NoMoreLayout()
}
if (this.browSingModel.hasMore === false) NoMoreLayout()
}
}
.height(CommonConstants.FULL_PARENT)
.edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
}
@Builder
... ... @@ -113,22 +115,16 @@ struct MyCollectionListPage {
}
}
@Builder LoadingLayout() {
CustomRefreshLoadLayout({ refreshBean: new RefreshLayoutBean(true,
$r('app.media.ic_pull_up_load'), $r('app.string.pull_up_load_text'), this.browSingModel.pullDownRefreshHeight) })
}
async getData() {
this.browSingModel.currentPage = 1
MyCollectionViewModel.fetchMyCollectList(1,'1',this.browSingModel.currentPage,getContext(this)).then(collectionItem => {
async getData(resolve?: (value: string | PromiseLike<string>) => void) {
MyCollectionViewModel.fetchMyCollectList(1,'1',this.currentPage,getContext(this)).then(collectionItem => {
if(resolve) resolve('刷新成功')
if (collectionItem && collectionItem.list && collectionItem.list.length > 0) {
this.browSingModel.viewType = ViewType.LOADED;
this.allDatas.push(...collectionItem.list)
if (collectionItem.list.length === this.browSingModel.pageSize) {
this.browSingModel.currentPage++;
this.browSingModel.hasMore = true;
} else {
if (this.currentPage === 1) this.allDatas = []
this.allDatas = this.allDatas.concat(...collectionItem.list)
if (collectionItem.totalCount === this.allDatas.length) {
this.browSingModel.hasMore = false;
} else {
this.browSingModel.hasMore = true;
}
} else {
this.browSingModel.viewType = ViewType.EMPTY;
... ...
import { PullToRefresh, PullToRefreshConfigurator } from '@ohos/pulltorefresh';
@Component
export struct CustomPullToRefresh {
@Link alldata: Object[];
scroller: Scroller = new Scroller();
@BuilderParam customList: () => void;
onRefresh: (resolve?: (value: string | PromiseLike<string>) => void) => void = () => {
}
onLoadMore: (resolve?: (value: string | PromiseLike<string>) => void) => void = () => {
}
///是否存在上拉更多
@State hasMore: boolean = true
refreshConfigurator: PullToRefreshConfigurator = new PullToRefreshConfigurator().setHasLoadMore(this.hasMore);
build() {
Column(){
PullToRefresh({
data:this.alldata,
scroller:this.scroller,
refreshConfigurator:this.refreshConfigurator,
customList:()=>{
this.customList();
},
onRefresh:()=>{
return new Promise<string>((resolve, reject) => {
this.onRefresh(resolve)
});
},
onLoadMore:()=>{
return new Promise<string>((resolve, reject) => {
this.onLoadMore(resolve)
});
},
customLoad: null,
customRefresh: null,
})
}
}
}
\ No newline at end of file
... ...
... ... @@ -34,7 +34,7 @@ export class RefreshConstants {
/**
* The refresh and load height.
*/
static readonly CUSTOM_LAYOUT_HEIGHT: number = 70;
static readonly CUSTOM_LAYOUT_HEIGHT: number = 90;
/**
* Full the width.
*/
... ...
... ... @@ -5,7 +5,8 @@
"lockfileVersion": 3,
"ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
"specifiers": {
"@ohos/hypium@1.0.16": "@ohos/hypium@1.0.16"
"@ohos/hypium@1.0.16": "@ohos/hypium@1.0.16",
"@ohos/pulltorefresh@^2.0.5": "@ohos/pulltorefresh@2.0.5"
},
"packages": {
"@ohos/hypium@1.0.16": {
... ... @@ -13,6 +14,12 @@
"integrity": "sha512-PC3jpwKERg68V+4dmKU+SLjNps9i5JcQH57rQriaTsh62NBgVZs4SceMmNOtrIOyldbEJ5mXSwoZwiG/nkRmTw==",
"resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.16.har",
"registryType": "ohpm"
},
"@ohos/pulltorefresh@2.0.5": {
"name": "@ohos/pulltorefresh",
"integrity": "sha512-mgBvJ6Ga70LmAoPKTOEPLFJluHUEAaBt2+7wF7R6223Vw6UEbZrof1MyvVOLEHk8Uc64ASIMW/TNQ8AHraTV5A==",
"resolved": "https://repo.harmonyos.com/ohpm/@ohos/pulltorefresh/-/pulltorefresh-2.0.5.har",
"registryType": "ohpm"
}
}
}
\ No newline at end of file
... ...
... ... @@ -8,5 +8,8 @@
"description": "Please describe the basic information.",
"main": "",
"version": "1.0.0",
"dependencies": {}
"dependencies": {
"@ohos/pulltorefresh": "^2.0.5"
},
"dynamicDependencies": {}
}
\ No newline at end of file
... ...