wangliang_wd

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

@@ -9,12 +9,13 @@ import { RefreshLayoutBean } from './RefreshLayoutBean'; @@ -9,12 +9,13 @@ import { RefreshLayoutBean } from './RefreshLayoutBean';
9 import { CompDTO, ContentDTO } from 'wdBean' 9 import { CompDTO, ContentDTO } from 'wdBean'
10 import LoadMoreLayout from './LoadMoreLayout' 10 import LoadMoreLayout from './LoadMoreLayout'
11 import NoMoreLayout from './NoMoreLayout' 11 import NoMoreLayout from './NoMoreLayout'
12 -import { CompParser } from '../CompParser'  
13 import CustomRefreshLoadLayout from './CustomRefreshLoadLayout'; 12 import CustomRefreshLoadLayout from './CustomRefreshLoadLayout';
14 import { CustomSelectUI } from '../view/CustomSelectUI'; 13 import { CustomSelectUI } from '../view/CustomSelectUI';
15 import { CustomBottomFuctionUI } from '../view/CustomBottomFuctionUI'; 14 import { CustomBottomFuctionUI } from '../view/CustomBottomFuctionUI';
16 import { BigPicCardComponent } from '../view/BigPicCardComponent'; 15 import { BigPicCardComponent } from '../view/BigPicCardComponent';
17 16
  17 +import { CustomPullToRefresh } from '../reusable/CustomPullToRefresh';
  18 +
18 @Entry 19 @Entry
19 @Component 20 @Component
20 struct BrowsingHistoryPage { 21 struct BrowsingHistoryPage {
@@ -25,6 +26,8 @@ struct BrowsingHistoryPage { @@ -25,6 +26,8 @@ struct BrowsingHistoryPage {
25 @State selectDatas :ContentDTO[] = []; 26 @State selectDatas :ContentDTO[] = [];
26 @Provide deleteNum :number = 0; 27 @Provide deleteNum :number = 0;
27 @Provide isAllSelect:boolean = false 28 @Provide isAllSelect:boolean = false
  29 + private scroller: Scroller = new Scroller();
  30 +
28 aboutToAppear(){ 31 aboutToAppear(){
29 this.getData() 32 this.getData()
30 } 33 }
@@ -37,15 +40,33 @@ struct BrowsingHistoryPage { @@ -37,15 +40,33 @@ struct BrowsingHistoryPage {
37 this.selectDatas = [] 40 this.selectDatas = []
38 this.deleteNum = 0 41 this.deleteNum = 0
39 }}) 42 }})
40 - if (this.browSingModel.viewType == ViewType.LOADING){  
41 - this.LoadingLayout()  
42 - }else if(this.browSingModel.viewType == ViewType.ERROR){  
43 - ErrorComponent()  
44 - }else if(this.browSingModel.viewType == ViewType.EMPTY){  
45 - EmptyComponent()  
46 - }else { 43 +
  44 + CustomPullToRefresh({
  45 + alldata:this.allDatas,
  46 + scroller:this.scroller,
  47 + customList:()=>{
47 this.ListLayout() 48 this.ListLayout()
  49 + },
  50 + onRefresh:(resolve)=>{
  51 + this.browSingModel.currentPage = 0
  52 + this.getData(resolve)
  53 + },
  54 + onLoadMore:(resolve)=> {
  55 + this.browSingModel.currentPage++
  56 + this.getData()
48 } 57 }
  58 + })
  59 +
  60 +
  61 + // if (this.browSingModel.viewType == ViewType.LOADING){
  62 + // this.LoadingLayout()
  63 + // }else if(this.browSingModel.viewType == ViewType.ERROR){
  64 + // ErrorComponent()
  65 + // }else if(this.browSingModel.viewType == ViewType.EMPTY){
  66 + // EmptyComponent()
  67 + // }else {
  68 + // this.ListLayout()
  69 + // }
49 70
50 if (this.isEditState){ 71 if (this.isEditState){
51 CustomBottomFuctionUI({ 72 CustomBottomFuctionUI({
@@ -64,34 +85,27 @@ struct BrowsingHistoryPage { @@ -64,34 +85,27 @@ struct BrowsingHistoryPage {
64 } 85 }
65 86
66 @Builder ListLayout() { 87 @Builder ListLayout() {
67 - List() { 88 + List({scroller: this.scroller}) {
68 // 下拉刷新 89 // 下拉刷新
69 - ListItem() {  
70 - RefreshLayout({  
71 - refreshBean: new RefreshLayoutBean(this.browSingModel.isVisiblePullDown, this.browSingModel.pullDownRefreshImage,  
72 - this.browSingModel.pullDownRefreshText, this.browSingModel.pullDownRefreshHeight)  
73 - })  
74 - }  
75 -  
76 ForEach(this.allDatas, (compDTO: ContentDTO, compIndex: number) => { 90 ForEach(this.allDatas, (compDTO: ContentDTO, compIndex: number) => {
77 ListItem() { 91 ListItem() {
78 this.newCompParser(compDTO,compIndex) 92 this.newCompParser(compDTO,compIndex)
79 } 93 }
80 }) 94 })
81 -  
82 // 加载更多 95 // 加载更多
83 ListItem() { 96 ListItem() {
84 if (this.browSingModel.hasMore) { 97 if (this.browSingModel.hasMore) {
85 - LoadMoreLayout({  
86 - refreshBean: new RefreshLayoutBean(this.browSingModel.isVisiblePullUpLoad, this.browSingModel.pullUpLoadImage,  
87 - this.browSingModel.pullUpLoadText, this.browSingModel.pullUpLoadHeight)  
88 - }) 98 + // LoadMoreLayout({
  99 + // refreshBean: new RefreshLayoutBean(this.browSingModel.isVisiblePullUpLoad, this.browSingModel.pullUpLoadImage,
  100 + // this.browSingModel.pullUpLoadText, this.browSingModel.pullUpLoadHeight)
  101 + // })
89 } else { 102 } else {
90 NoMoreLayout() 103 NoMoreLayout()
91 } 104 }
92 } 105 }
93 } 106 }
94 .height(CommonConstants.FULL_PARENT) 107 .height(CommonConstants.FULL_PARENT)
  108 + .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
95 } 109 }
96 110
97 @Builder 111 @Builder
@@ -117,9 +131,9 @@ struct BrowsingHistoryPage { @@ -117,9 +131,9 @@ struct BrowsingHistoryPage {
117 $r('app.media.ic_pull_up_load'), $r('app.string.pull_up_load_text'), this.browSingModel.pullDownRefreshHeight) }) 131 $r('app.media.ic_pull_up_load'), $r('app.string.pull_up_load_text'), this.browSingModel.pullDownRefreshHeight) })
118 } 132 }
119 133
120 - async getData() {  
121 - this.browSingModel.currentPage = 1 134 + async getData(resolve?: (value: string | PromiseLike<string>) => void){
122 MyCollectionViewModel.fetchMyCollectList(2,'1',this.browSingModel.currentPage,getContext(this)).then(collectionItem => { 135 MyCollectionViewModel.fetchMyCollectList(2,'1',this.browSingModel.currentPage,getContext(this)).then(collectionItem => {
  136 + if(resolve) resolve('刷新成功')
123 if (collectionItem && collectionItem.list && collectionItem.list.length > 0) { 137 if (collectionItem && collectionItem.list && collectionItem.list.length > 0) {
124 this.browSingModel.viewType = ViewType.LOADED; 138 this.browSingModel.viewType = ViewType.LOADED;
125 this.allDatas.push(...collectionItem.list) 139 this.allDatas.push(...collectionItem.list)
@@ -4,17 +4,13 @@ import PageModel from '../../viewmodel/PageModel'; @@ -4,17 +4,13 @@ import PageModel from '../../viewmodel/PageModel';
4 import { CommonConstants, ViewType } from 'wdConstant' 4 import { CommonConstants, ViewType } from 'wdConstant'
5 import { EmptyComponent,WDViewDefaultType } from '../view/EmptyComponent' 5 import { EmptyComponent,WDViewDefaultType } from '../view/EmptyComponent'
6 import { ErrorComponent } from '../view/ErrorComponent' 6 import { ErrorComponent } from '../view/ErrorComponent'
7 -import RefreshLayout from './RefreshLayout'  
8 -import { RefreshLayoutBean } from './RefreshLayoutBean';  
9 -import { CompDTO, ContentDTO } from 'wdBean'  
10 -import LoadMoreLayout from './LoadMoreLayout' 7 +import { ContentDTO } from 'wdBean'
11 import NoMoreLayout from './NoMoreLayout' 8 import NoMoreLayout from './NoMoreLayout'
12 -import { CompParser } from '../CompParser'  
13 -import CustomRefreshLoadLayout from './CustomRefreshLoadLayout';  
14 import { CustomSelectUI } from '../view/CustomSelectUI'; 9 import { CustomSelectUI } from '../view/CustomSelectUI';
15 import { CustomBottomFuctionUI } from '../view/CustomBottomFuctionUI'; 10 import { CustomBottomFuctionUI } from '../view/CustomBottomFuctionUI';
16 import { BigPicCardComponent } from '../view/BigPicCardComponent'; 11 import { BigPicCardComponent } from '../view/BigPicCardComponent';
17 import { contentListItemParams } from '../../model/MyCollectionModel'; 12 import { contentListItemParams } from '../../model/MyCollectionModel';
  13 +import { CustomPullToRefresh } from '../reusable/CustomPullToRefresh';
18 14
19 @Entry 15 @Entry
20 @Component 16 @Component
@@ -26,6 +22,10 @@ struct MyCollectionListPage { @@ -26,6 +22,10 @@ struct MyCollectionListPage {
26 @State selectDatas :ContentDTO[] = []; 22 @State selectDatas :ContentDTO[] = [];
27 @Provide deleteNum :number = 0; 23 @Provide deleteNum :number = 0;
28 @Provide isAllSelect:boolean = false 24 @Provide isAllSelect:boolean = false
  25 +
  26 + @State currentPage: number = 1;
  27 + private scroller: Scroller = new Scroller();
  28 +
29 aboutToAppear(){ 29 aboutToAppear(){
30 this.getData() 30 this.getData()
31 } 31 }
@@ -38,14 +38,31 @@ struct MyCollectionListPage { @@ -38,14 +38,31 @@ struct MyCollectionListPage {
38 this.selectDatas = [] 38 this.selectDatas = []
39 this.deleteNum = 0 39 this.deleteNum = 0
40 }}) 40 }})
41 - if (this.browSingModel.viewType == ViewType.LOADING){  
42 - this.LoadingLayout()  
43 - }else if(this.browSingModel.viewType == ViewType.ERROR){ 41 +
  42 + if(this.browSingModel.viewType == ViewType.ERROR){
44 ErrorComponent() 43 ErrorComponent()
45 }else if(this.browSingModel.viewType == ViewType.EMPTY){ 44 }else if(this.browSingModel.viewType == ViewType.EMPTY){
46 EmptyComponent({emptyType:WDViewDefaultType.WDViewDefaultType_NoCollection}) 45 EmptyComponent({emptyType:WDViewDefaultType.WDViewDefaultType_NoCollection})
47 }else { 46 }else {
  47 + CustomPullToRefresh({
  48 + alldata:this.allDatas,
  49 + scroller:this.scroller,
  50 + customList:()=>{
48 this.ListLayout() 51 this.ListLayout()
  52 + },
  53 + onRefresh:(resolve)=>{
  54 + this.currentPage = 1
  55 + this.getData(resolve)
  56 + },
  57 + onLoadMore:(resolve)=> {
  58 + if (this.browSingModel.hasMore === false) {
  59 + if(resolve) resolve('')
  60 + return
  61 + }
  62 + this.currentPage++
  63 + this.getData(resolve)
  64 + }
  65 + })
49 } 66 }
50 67
51 if (this.isEditState){ 68 if (this.isEditState){
@@ -65,34 +82,19 @@ struct MyCollectionListPage { @@ -65,34 +82,19 @@ struct MyCollectionListPage {
65 } 82 }
66 83
67 @Builder ListLayout() { 84 @Builder ListLayout() {
68 - List() {  
69 - // 下拉刷新  
70 - ListItem() {  
71 - RefreshLayout({  
72 - refreshBean: new RefreshLayoutBean(this.browSingModel.isVisiblePullDown, this.browSingModel.pullDownRefreshImage,  
73 - this.browSingModel.pullDownRefreshText, this.browSingModel.pullDownRefreshHeight)  
74 - })  
75 - }  
76 - 85 + List({scroller: this.scroller}) {
77 ForEach(this.allDatas, (compDTO: ContentDTO, compIndex: number) => { 86 ForEach(this.allDatas, (compDTO: ContentDTO, compIndex: number) => {
78 ListItem() { 87 ListItem() {
79 this.newCompParser(compDTO,compIndex) 88 this.newCompParser(compDTO,compIndex)
80 } 89 }
81 }) 90 })
82 -  
83 // 加载更多 91 // 加载更多
84 ListItem() { 92 ListItem() {
85 - if (this.browSingModel.hasMore) {  
86 - LoadMoreLayout({  
87 - refreshBean: new RefreshLayoutBean(this.browSingModel.isVisiblePullUpLoad, this.browSingModel.pullUpLoadImage,  
88 - this.browSingModel.pullUpLoadText, this.browSingModel.pullUpLoadHeight)  
89 - })  
90 - } else {  
91 - NoMoreLayout()  
92 - } 93 + if (this.browSingModel.hasMore === false) NoMoreLayout()
93 } 94 }
94 } 95 }
95 .height(CommonConstants.FULL_PARENT) 96 .height(CommonConstants.FULL_PARENT)
  97 + .edgeEffect(EdgeEffect.None) // 必须设置列表为滑动到边缘无效果
96 } 98 }
97 99
98 @Builder 100 @Builder
@@ -113,22 +115,16 @@ struct MyCollectionListPage { @@ -113,22 +115,16 @@ struct MyCollectionListPage {
113 } 115 }
114 } 116 }
115 117
116 - @Builder LoadingLayout() {  
117 - CustomRefreshLoadLayout({ refreshBean: new RefreshLayoutBean(true,  
118 - $r('app.media.ic_pull_up_load'), $r('app.string.pull_up_load_text'), this.browSingModel.pullDownRefreshHeight) })  
119 - }  
120 -  
121 - async getData() {  
122 - this.browSingModel.currentPage = 1  
123 - MyCollectionViewModel.fetchMyCollectList(1,'1',this.browSingModel.currentPage,getContext(this)).then(collectionItem => { 118 + async getData(resolve?: (value: string | PromiseLike<string>) => void) {
  119 + MyCollectionViewModel.fetchMyCollectList(1,'1',this.currentPage,getContext(this)).then(collectionItem => {
  120 + if(resolve) resolve('刷新成功')
124 if (collectionItem && collectionItem.list && collectionItem.list.length > 0) { 121 if (collectionItem && collectionItem.list && collectionItem.list.length > 0) {
125 - this.browSingModel.viewType = ViewType.LOADED;  
126 - this.allDatas.push(...collectionItem.list)  
127 - if (collectionItem.list.length === this.browSingModel.pageSize) {  
128 - this.browSingModel.currentPage++;  
129 - this.browSingModel.hasMore = true;  
130 - } else { 122 + if (this.currentPage === 1) this.allDatas = []
  123 + this.allDatas = this.allDatas.concat(...collectionItem.list)
  124 + if (collectionItem.totalCount === this.allDatas.length) {
131 this.browSingModel.hasMore = false; 125 this.browSingModel.hasMore = false;
  126 + } else {
  127 + this.browSingModel.hasMore = true;
132 } 128 }
133 } else { 129 } else {
134 this.browSingModel.viewType = ViewType.EMPTY; 130 this.browSingModel.viewType = ViewType.EMPTY;
  1 +import { PullToRefresh, PullToRefreshConfigurator } from '@ohos/pulltorefresh';
  2 +
  3 +@Component
  4 +export struct CustomPullToRefresh {
  5 + @Link alldata: Object[];
  6 + scroller: Scroller = new Scroller();
  7 + @BuilderParam customList: () => void;
  8 + onRefresh: (resolve?: (value: string | PromiseLike<string>) => void) => void = () => {
  9 + }
  10 + onLoadMore: (resolve?: (value: string | PromiseLike<string>) => void) => void = () => {
  11 + }
  12 + ///是否存在上拉更多
  13 + @State hasMore: boolean = true
  14 + refreshConfigurator: PullToRefreshConfigurator = new PullToRefreshConfigurator().setHasLoadMore(this.hasMore);
  15 + build() {
  16 + Column(){
  17 + PullToRefresh({
  18 + data:this.alldata,
  19 + scroller:this.scroller,
  20 + refreshConfigurator:this.refreshConfigurator,
  21 + customList:()=>{
  22 + this.customList();
  23 + },
  24 + onRefresh:()=>{
  25 + return new Promise<string>((resolve, reject) => {
  26 + this.onRefresh(resolve)
  27 + });
  28 + },
  29 + onLoadMore:()=>{
  30 + return new Promise<string>((resolve, reject) => {
  31 + this.onLoadMore(resolve)
  32 + });
  33 + },
  34 + customLoad: null,
  35 + customRefresh: null,
  36 + })
  37 + }
  38 + }
  39 +}
@@ -34,7 +34,7 @@ export class RefreshConstants { @@ -34,7 +34,7 @@ export class RefreshConstants {
34 /** 34 /**
35 * The refresh and load height. 35 * The refresh and load height.
36 */ 36 */
37 - static readonly CUSTOM_LAYOUT_HEIGHT: number = 70; 37 + static readonly CUSTOM_LAYOUT_HEIGHT: number = 90;
38 /** 38 /**
39 * Full the width. 39 * Full the width.
40 */ 40 */
@@ -5,7 +5,8 @@ @@ -5,7 +5,8 @@
5 "lockfileVersion": 3, 5 "lockfileVersion": 3,
6 "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.", 6 "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
7 "specifiers": { 7 "specifiers": {
8 - "@ohos/hypium@1.0.16": "@ohos/hypium@1.0.16" 8 + "@ohos/hypium@1.0.16": "@ohos/hypium@1.0.16",
  9 + "@ohos/pulltorefresh@^2.0.5": "@ohos/pulltorefresh@2.0.5"
9 }, 10 },
10 "packages": { 11 "packages": {
11 "@ohos/hypium@1.0.16": { 12 "@ohos/hypium@1.0.16": {
@@ -13,6 +14,12 @@ @@ -13,6 +14,12 @@
13 "integrity": "sha512-PC3jpwKERg68V+4dmKU+SLjNps9i5JcQH57rQriaTsh62NBgVZs4SceMmNOtrIOyldbEJ5mXSwoZwiG/nkRmTw==", 14 "integrity": "sha512-PC3jpwKERg68V+4dmKU+SLjNps9i5JcQH57rQriaTsh62NBgVZs4SceMmNOtrIOyldbEJ5mXSwoZwiG/nkRmTw==",
14 "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.16.har", 15 "resolved": "https://repo.harmonyos.com/ohpm/@ohos/hypium/-/hypium-1.0.16.har",
15 "registryType": "ohpm" 16 "registryType": "ohpm"
  17 + },
  18 + "@ohos/pulltorefresh@2.0.5": {
  19 + "name": "@ohos/pulltorefresh",
  20 + "integrity": "sha512-mgBvJ6Ga70LmAoPKTOEPLFJluHUEAaBt2+7wF7R6223Vw6UEbZrof1MyvVOLEHk8Uc64ASIMW/TNQ8AHraTV5A==",
  21 + "resolved": "https://repo.harmonyos.com/ohpm/@ohos/pulltorefresh/-/pulltorefresh-2.0.5.har",
  22 + "registryType": "ohpm"
16 } 23 }
17 } 24 }
18 } 25 }
@@ -8,5 +8,8 @@ @@ -8,5 +8,8 @@
8 "description": "Please describe the basic information.", 8 "description": "Please describe the basic information.",
9 "main": "", 9 "main": "",
10 "version": "1.0.0", 10 "version": "1.0.0",
11 - "dependencies": {} 11 + "dependencies": {
  12 + "@ohos/pulltorefresh": "^2.0.5"
  13 + },
  14 + "dynamicDependencies": {}
12 } 15 }