wangliang_wd

feat:优化人民号刷新问题

@@ -2,6 +2,8 @@ import { PeopleShipRecommendComponent } from './PeopleShipRecommendComponent'; @@ -2,6 +2,8 @@ import { PeopleShipRecommendComponent } from './PeopleShipRecommendComponent';
2 import { PeopleShipMainViewModel } from '../../viewmodel/PeopleShipMainViewModel'; 2 import { PeopleShipMainViewModel } from '../../viewmodel/PeopleShipMainViewModel';
3 import { HttpUtils } from 'wdNetwork/Index'; 3 import { HttpUtils } from 'wdNetwork/Index';
4 import { Logger, DateTimeUtils, EmitterEventId, EmitterUtils } from 'wdKit'; 4 import { Logger, DateTimeUtils, EmitterEventId, EmitterUtils } from 'wdKit';
  5 +import { autoRefresh, onActionEnd, onActionStart, onActionUpdate,closeRefresh } from '../../utils/NewPullDownRefresh';
  6 +
5 import { 7 import {
6 RmhRecommendDTO, 8 RmhRecommendDTO,
7 ContentDTO, 9 ContentDTO,
@@ -27,6 +29,12 @@ import { PeopleShipNoMoreData } from '../reusable/PeopleShipNoMoreData'; @@ -27,6 +29,12 @@ import { PeopleShipNoMoreData } from '../reusable/PeopleShipNoMoreData';
27 import PageFollowHelper from '../../viewmodel/PageFollowHelper'; 29 import PageFollowHelper from '../../viewmodel/PageFollowHelper';
28 import { MineFollowListItem } from '../../viewmodel/MineFollowListItem'; 30 import { MineFollowListItem } from '../../viewmodel/MineFollowListItem';
29 import { GrayManageModel } from '../../viewmodel/GrayManageModel'; 31 import { GrayManageModel } from '../../viewmodel/GrayManageModel';
  32 +import RefreshLayout from '../refresh/RefreshLayout';
  33 +import { RefreshLayoutBean } from '../refresh/RefreshLayoutBean';
  34 +import { CommonConstants } from 'wdConstant';
  35 +import PageNoMoreLayout from '../page/PageNoMoreLayout';
  36 +import LoadMoreLayout from '../page/LoadMoreLayout';
  37 +import { NoMoreBean } from '../page/NoMoreBean';
30 38
31 const TAG = 'PeopleShipMainComponent'; 39 const TAG = 'PeopleShipMainComponent';
32 40
@@ -63,76 +71,133 @@ export struct PeopleShipMainComponent { @@ -63,76 +71,133 @@ export struct PeopleShipMainComponent {
63 @State private pageAttentionChange: boolean = false 71 @State private pageAttentionChange: boolean = false
64 // 国殇灰度管理 72 // 国殇灰度管理
65 GrayManage: SubscribedAbstractProperty<GrayManageModel> = AppStorage.link<GrayManageModel>('GrayManage') 73 GrayManage: SubscribedAbstractProperty<GrayManageModel> = AppStorage.link<GrayManageModel>('GrayManage')
  74 + private panOption: PanGestureOptions = new PanGestureOptions({ direction: PanDirection.Up | PanDirection.Down })
  75 +
  76 + ///刷新请求
  77 + onRefresh: () => void = () => {
  78 + this.currentPage = 1
  79 + this.getData()
  80 + }
  81 +
  82 + onRefreshMore: () => void = () => {
  83 + this.currentPage++;
  84 + this.getAttentionContentListData()
  85 + }
66 86
67 build() { 87 build() {
68 - if (this.viewType == ViewType.LOADING) {  
69 - this.LoadingLayout()  
70 - } else if (this.viewType == ViewType.ERROR) {  
71 - //缺省页  
72 - EmptyComponent({  
73 - emptyType: this.pageModel.emptyType,  
74 - emptyButton: true,  
75 - retry: () => {  
76 - this.getData()  
77 - }  
78 - })  
79 - .grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)  
80 - } else if (this.viewType == ViewType.EMPTY) {  
81 - //缺省页  
82 - EmptyComponent({  
83 - emptyType: this.pageModel.emptyType,  
84 - emptyButton: true,  
85 - retry: () => {  
86 - this.getData()  
87 - }  
88 - })  
89 - .grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)  
90 - } else {  
91 - if (this.followList.length == 0) {  
92 - CustomPullToRefresh({  
93 - alldata: this.rmhList,  
94 - scroller: this.listScroller,  
95 - hasMore: false,  
96 - customList: () => {  
97 - this.ListLayout()  
98 - },  
99 - onRefresh: (resolve) => {  
100 - this.currentPage = 1  
101 - this.getData(resolve)  
102 - }, 88 + Column(){
  89 + if (this.viewType == ViewType.LOADING) {
  90 + this.LoadingLayout()
  91 + } else if (this.viewType == ViewType.ERROR) {
  92 + //缺省页
  93 + EmptyComponent({
  94 + emptyType: this.pageModel.emptyType,
  95 + emptyButton: true,
  96 + retry: () => {
  97 + this.getData()
  98 + }
103 }) 99 })
104 - } else {  
105 - CustomPullToRefresh({  
106 - alldata: this.attentionList,  
107 - scroller: this.listScroller,  
108 - hasMore: this.hasMore,  
109 - customList: () => {  
110 - this.ListAttentionLayout()  
111 - },  
112 - onRefresh: (resolve) => {  
113 - this.currentPage = 1  
114 - this.getData(resolve)  
115 - },  
116 - onLoadMore: (resolve) => {  
117 - if (this.hasMore === false) {  
118 - if (resolve) {  
119 - resolve('')  
120 - }  
121 - return  
122 - }  
123 - if (!this.isLoading && this.hasMore) {  
124 - //加载分页数据  
125 - this.currentPage++;  
126 - this.getAttentionContentListData(resolve)  
127 - } else {  
128 - if (resolve) {  
129 - resolve('')  
130 - }  
131 - }  
132 - }, 100 + .grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
  101 + } else if (this.viewType == ViewType.EMPTY) {
  102 + //缺省页
  103 + EmptyComponent({
  104 + emptyType: this.pageModel.emptyType,
  105 + emptyButton: true,
  106 + retry: () => {
  107 + this.getData()
  108 + }
133 }) 109 })
  110 + .grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
  111 + }else {
  112 + if (this.followList.length == 0) {
  113 + this.ListLayout()
  114 + } else {
  115 + this.ListAttentionLayout()
  116 + }
134 } 117 }
  118 +
135 } 119 }
  120 + .parallelGesture(
  121 + PanGesture(this.panOption)
  122 + .onActionStart((event?: GestureEvent) => {
  123 + this.pageModel.isVisiblePullDown = true
  124 + onActionStart(this.pageModel, event)
  125 + })
  126 + .onActionUpdate((event?: GestureEvent) => {
  127 + onActionUpdate(this.pageModel, event,this.onRefreshMore)
  128 + })
  129 + .onActionEnd(() => {
  130 + onActionEnd(this.pageModel,this.onRefresh)
  131 + })
  132 + )
  133 + // if (this.viewType == ViewType.LOADING) {
  134 + // this.LoadingLayout()
  135 + // } else if (this.viewType == ViewType.ERROR) {
  136 + // //缺省页
  137 + // EmptyComponent({
  138 + // emptyType: this.pageModel.emptyType,
  139 + // emptyButton: true,
  140 + // retry: () => {
  141 + // this.getData()
  142 + // }
  143 + // })
  144 + // .grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
  145 + // } else if (this.viewType == ViewType.EMPTY) {
  146 + // //缺省页
  147 + // EmptyComponent({
  148 + // emptyType: this.pageModel.emptyType,
  149 + // emptyButton: true,
  150 + // retry: () => {
  151 + // this.getData()
  152 + // }
  153 + // })
  154 + // .grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
  155 + // } else {
  156 + // if (this.followList.length == 0) {
  157 + // CustomPullToRefresh({
  158 + // alldata: this.rmhList,
  159 + // scroller: this.listScroller,
  160 + // hasMore: false,
  161 + // customList: () => {
  162 + // this.ListLayout()
  163 + // },
  164 + // onRefresh: (resolve) => {
  165 + // this.currentPage = 1
  166 + // this.getData(resolve)
  167 + // },
  168 + // })
  169 + // } else {
  170 + // CustomPullToRefresh({
  171 + // alldata: this.attentionList,
  172 + // scroller: this.listScroller,
  173 + // hasMore: this.hasMore,
  174 + // customList: () => {
  175 + // this.ListAttentionLayout()
  176 + // },
  177 + // onRefresh: (resolve) => {
  178 + // this.currentPage = 1
  179 + // this.getData(resolve)
  180 + // },
  181 + // onLoadMore: (resolve) => {
  182 + // if (this.hasMore === false) {
  183 + // if (resolve) {
  184 + // resolve('')
  185 + // }
  186 + // return
  187 + // }
  188 + // if (!this.isLoading && this.hasMore) {
  189 + // //加载分页数据
  190 + // this.currentPage++;
  191 + // this.getAttentionContentListData(resolve)
  192 + // } else {
  193 + // if (resolve) {
  194 + // resolve('')
  195 + // }
  196 + // }
  197 + // },
  198 + // })
  199 + // }
  200 + // }
136 } 201 }
137 202
138 @Builder 203 @Builder
@@ -145,6 +210,14 @@ export struct PeopleShipMainComponent { @@ -145,6 +210,14 @@ export struct PeopleShipMainComponent {
145 ListLayout() { 210 ListLayout() {
146 211
147 List({ scroller: this.listScroller }) { 212 List({ scroller: this.listScroller }) {
  213 + ListItem() {
  214 + RefreshLayout({
  215 + refreshBean: new RefreshLayoutBean(this.pageModel.isVisiblePullDown, this.pageModel.load,
  216 + this.pageModel.offsetY)
  217 + })
  218 + }
  219 + .grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
  220 +
148 // 头部关注列表 221 // 头部关注列表
149 ListItem() { 222 ListItem() {
150 PeopleShipRecommendComponent({ 223 PeopleShipRecommendComponent({
@@ -164,7 +237,15 @@ export struct PeopleShipMainComponent { @@ -164,7 +237,15 @@ export struct PeopleShipMainComponent {
164 @Builder 237 @Builder
165 ListAttentionLayout() { 238 ListAttentionLayout() {
166 List({ scroller: this.listScroller }) { 239 List({ scroller: this.listScroller }) {
167 - // 头部关注列表 240 + ListItem() {
  241 + RefreshLayout({
  242 + refreshBean: new RefreshLayoutBean(this.pageModel.isVisiblePullDown, this.pageModel.load,
  243 + this.pageModel.offsetY)
  244 + })
  245 + }
  246 + .grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
  247 +
  248 + // // 头部关注列表
168 ListItem() { 249 ListItem() {
169 PeopleShipAttentionContentListTopComponent({ 250 PeopleShipAttentionContentListTopComponent({
170 followList: this.followList 251 followList: this.followList
@@ -185,10 +266,18 @@ export struct PeopleShipMainComponent { @@ -185,10 +266,18 @@ export struct PeopleShipMainComponent {
185 266
186 }, (item: ContentDTO, index: number) => item.objectId + index.toString()) 267 }, (item: ContentDTO, index: number) => item.objectId + index.toString())
187 268
  269 + // // 加载更多
  270 + // ListItem() {
  271 + // if (!this.hasMore && !this.isLoading) {
  272 + // PeopleShipNoMoreData()
  273 + // }
  274 + // }
188 // 加载更多 275 // 加载更多
189 ListItem() { 276 ListItem() {
190 - if (!this.hasMore && !this.isLoading) {  
191 - PeopleShipNoMoreData() 277 + if (this.pageModel.hasMore) {
  278 + LoadMoreLayout({ isVisible: this.pageModel.isVisiblePullUpLoad })
  279 + } else {
  280 + PageNoMoreLayout({ noMoreBean: new NoMoreBean(this.pageModel.pageInfo.baselineCopywriting) })
192 } 281 }
193 } 282 }
194 .grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0) 283 .grayscale(this.GrayManage.get().isRmhMourning(`${this.channelId}`) ? 1 : 0)
@@ -197,6 +286,12 @@ export struct PeopleShipMainComponent { @@ -197,6 +286,12 @@ export struct PeopleShipMainComponent {
197 .scrollBar(BarState.Off) 286 .scrollBar(BarState.Off)
198 .width('100%') 287 .width('100%')
199 .height('100%') 288 .height('100%')
  289 + .onScrollIndex((start: number, end: number) => {
  290 + // Listen to the first index of the current list.
  291 + this.pageModel.startIndex = start;
  292 + // 包含了 头尾item,判断时需要考虑+3
  293 + this.pageModel.endIndex = end - 2;
  294 + })
200 } 295 }
201 296
202 aboutToAppear() { 297 aboutToAppear() {
@@ -271,10 +366,12 @@ export struct PeopleShipMainComponent { @@ -271,10 +366,12 @@ export struct PeopleShipMainComponent {
271 if (resolve) { 366 if (resolve) {
272 resolve('已更新至最新') 367 resolve('已更新至最新')
273 } 368 }
  369 + this.closeRefresh(true)
274 } catch (exception) { 370 } catch (exception) {
275 if (resolve) { 371 if (resolve) {
276 resolve('') 372 resolve('')
277 } 373 }
  374 + this.closeRefresh(false)
278 this.viewType = ViewType.ERROR 375 this.viewType = ViewType.ERROR
279 this.changeButton = false 376 this.changeButton = false
280 this.isLoading = false 377 this.isLoading = false
@@ -297,14 +394,17 @@ export struct PeopleShipMainComponent { @@ -297,14 +394,17 @@ export struct PeopleShipMainComponent {
297 if (listData && listData.list && listData.list.length > 0) { 394 if (listData && listData.list && listData.list.length > 0) {
298 if (listData.list.length === 20) { 395 if (listData.list.length === 20) {
299 this.hasMore = true; 396 this.hasMore = true;
  397 + this.pageModel.hasMore = true
300 } else { 398 } else {
301 this.hasMore = false; 399 this.hasMore = false;
  400 + this.pageModel.hasMore = false
302 } 401 }
303 402
304 //批量查询各类型内容动态数据接口 403 //批量查询各类型内容动态数据接口
305 this.checkContentInteractData(listData.list, resolve,myFollowInfor) 404 this.checkContentInteractData(listData.list, resolve,myFollowInfor)
306 } else { 405 } else {
307 this.hasMore = false; 406 this.hasMore = false;
  407 + this.pageModel.hasMore = false
308 this.resolveEnd(true, resolve) 408 this.resolveEnd(true, resolve)
309 } 409 }
310 410
@@ -362,8 +462,11 @@ export struct PeopleShipMainComponent { @@ -362,8 +462,11 @@ export struct PeopleShipMainComponent {
362 this.attentionList[i].isMourning = true; 462 this.attentionList[i].isMourning = true;
363 } 463 }
364 } 464 }
365 - 465 + this.pageModel.compList.clear()
  466 + this.pageModel.compList.push(...this.attentionList)
  467 + this.closeRefresh(true)
366 } catch (exception) { 468 } catch (exception) {
  469 + this.closeRefresh(false)
367 this.resolveEnd(false, resolve) 470 this.resolveEnd(false, resolve)
368 } 471 }
369 } 472 }
@@ -455,7 +558,11 @@ export struct PeopleShipMainComponent { @@ -455,7 +558,11 @@ export struct PeopleShipMainComponent {
455 // 当前页面,自动刷新数据 558 // 当前页面,自动刷新数据
456 Logger.debug(TAG, 'page onAutoRefresh ' + this.autoRefresh) 559 Logger.debug(TAG, 'page onAutoRefresh ' + this.autoRefresh)
457 this.listScroller.scrollToIndex(0) 560 this.listScroller.scrollToIndex(0)
458 - this.currentPage = 1  
459 - this.getData() 561 + autoRefresh(this.pageModel,this.onRefresh)
460 } 562 }
  563 +
  564 + closeRefresh(isRefreshSuccess:boolean){
  565 + closeRefresh(this.pageModel,isRefreshSuccess)
  566 + }
  567 +
461 } 568 }
  1 +import { RefreshConstants as Const, RefreshState } from './RefreshConstants';
  2 +import { touchMoveLoadMore, touchUpLoadMore } from './NewPullUpLoadMore';
  3 +import PageModel from '../viewmodel/PageModel';
  4 +import newPageHelper from '../viewmodel/NewPageHelper';
  5 +import { LoadStatus } from '../components/refresh/RefreshLayoutBean';
  6 +import { Logger } from 'wdKit/Index';
  7 +
  8 +const TAG = 'NewPullDownRefresh'
  9 +/***********新的下拉、上拉手势 start **********/
  10 +export function onActionStart(pageModel: PageModel, event?: GestureEvent) {
  11 + if (event === undefined) {
  12 + return
  13 + }
  14 + pageModel.downY = event.offsetY;
  15 + pageModel.lastMoveY = event.offsetY;
  16 +}
  17 +
  18 +export function onActionUpdate(pageModel: PageModel, event?: GestureEvent,onRefreshMore: () => void = () => {
  19 +}) {
  20 + if (event === undefined) {
  21 + return
  22 + }
  23 + if ((pageModel.isRefreshing === true) || (pageModel.isLoading === true)) {
  24 + return;
  25 + }
  26 + let isDownPull = event.offsetY - pageModel.lastMoveY > 0;
  27 + if (((isDownPull === true) || (pageModel.isPullRefreshOperation === true)) &&
  28 + (pageModel.isCanLoadMore === false)) {
  29 + actionUpdatePullRefresh(pageModel, event);
  30 + } else {
  31 + actionUpdateLoadMore(pageModel, event,onRefreshMore);
  32 + }
  33 + pageModel.lastMoveY = event.offsetY;
  34 +}
  35 +
  36 +export function onActionEnd(pageModel: PageModel,onRefresh: () => void = () => {
  37 +}) {
  38 + if ((pageModel.isRefreshing === true) || (pageModel.isLoading === true)) {
  39 + return;
  40 + }
  41 + if ((pageModel.isPullRefreshOperation === true)) {
  42 + touchUpPullRefresh(pageModel,onRefresh);
  43 + } else {
  44 + // touchUpLoadMore(pageModel);
  45 + }
  46 +}
  47 +
  48 +export function actionUpdatePullRefresh(pageModel: PageModel, event: GestureEvent) {
  49 + if (pageModel.startIndex === 0) {
  50 + pageModel.isPullRefreshOperation = true;
  51 + let height = vp2px(Const.CUSTOM_REFRESH_DECIDE_HEIGHT);
  52 + pageModel.offsetY = event.offsetY - pageModel.downY;
  53 + if (pageModel.offsetY >= height) {
  54 + pullRefreshState(pageModel, RefreshState.Release);
  55 + pageModel.offsetY = height + pageModel.offsetY * Const.Y_OFF_SET_COEFFICIENT;
  56 + } else {
  57 + pullRefreshState(pageModel, RefreshState.DropDown);
  58 + }
  59 + if (pageModel.offsetY < 0) {
  60 + pageModel.offsetY = 0;
  61 + pageModel.isPullRefreshOperation = false;
  62 + }
  63 + }
  64 +}
  65 +
  66 +export function actionUpdateLoadMore(model: PageModel, event: GestureEvent,onRefreshMore: () => void = () => {
  67 +}) {
  68 + // list size +1
  69 + if (model.endIndex >= model.compList.totalCount() - 3 && model.endIndex <= model.compList.totalCount()) {
  70 + // 不用分页动画,直接预加载
  71 + model.isCanLoadMore = true;
  72 + model.isVisiblePullUpLoad = true;
  73 + touchUpLoadMore(model,onRefreshMore);
  74 + }
  75 +}
  76 +
  77 +/***********新的下拉、上拉手势 end **********/
  78 +
  79 +
  80 +//下拉刷新上拉加载更多组件
  81 +/**
  82 + * @deprecated
  83 + */
  84 +export function listTouchEvent(pageModel: PageModel, event: TouchEvent) {
  85 + switch (event.type) {
  86 + case TouchType.Down:
  87 + pageModel.downY = event.touches[0].y;
  88 + pageModel.lastMoveY = event.touches[0].y;
  89 + break;
  90 + case TouchType.Move:
  91 + if ((pageModel.isRefreshing === true) || (pageModel.isLoading === true)) {
  92 + return;
  93 + }
  94 + let isDownPull = event.touches[0].y - pageModel.lastMoveY > 0;
  95 + if (((isDownPull === true) || (pageModel.isPullRefreshOperation === true)) &&
  96 + (pageModel.isCanLoadMore === false)) {
  97 + // Finger movement, processing pull-down refresh.
  98 + touchMovePullRefresh(pageModel, event);
  99 + } else {
  100 + // Finger movement, processing load more.
  101 + touchMoveLoadMore(pageModel, event);
  102 + }
  103 + pageModel.lastMoveY = event.touches[0].y;
  104 + break;
  105 + case TouchType.Cancel:
  106 + break;
  107 + case TouchType.Up:
  108 + if ((pageModel.isRefreshing === true) || (pageModel.isLoading === true)) {
  109 + return;
  110 + }
  111 + if ((pageModel.isPullRefreshOperation === true)) {
  112 + // Lift your finger and pull down to refresh.
  113 + touchUpPullRefresh(pageModel);
  114 + } else {
  115 + // Fingers up, handle loading more.
  116 + // touchUpLoadMore(pageModel);
  117 + }
  118 + break;
  119 + default:
  120 + break;
  121 + }
  122 +}
  123 +
  124 +/**
  125 + * @deprecated
  126 + */
  127 +export function touchMovePullRefresh(pageModel: PageModel, event: TouchEvent) {
  128 + if (pageModel.startIndex === 0) {
  129 + pageModel.isPullRefreshOperation = true;
  130 + let height = vp2px(Const.CUSTOM_REFRESH_DECIDE_HEIGHT);
  131 + pageModel.offsetY = event.touches[0].y - pageModel.downY;
  132 + // The sliding offset is greater than the pull-down refresh layout height, and the refresh condition is met.
  133 + if (pageModel.offsetY >= height) {
  134 + pullRefreshState(pageModel, RefreshState.Release);
  135 + pageModel.offsetY = height + pageModel.offsetY * Const.Y_OFF_SET_COEFFICIENT;
  136 + } else {
  137 + pullRefreshState(pageModel, RefreshState.DropDown);
  138 + }
  139 + if (pageModel.offsetY < 0) {
  140 + pageModel.offsetY = 0;
  141 + pageModel.isPullRefreshOperation = false;
  142 + }
  143 + }
  144 +}
  145 +
  146 +export function touchUpPullRefresh(pageModel: PageModel,onRefresh: () => void = () => {
  147 +}) {
  148 + if (pageModel.isCanRefresh === true) {
  149 + pageModel.offsetY = vp2px(pageModel.pullDownRefreshHeight);
  150 + pullRefreshState(pageModel, RefreshState.Refreshing);
  151 + pageModel.currentPage = 1;
  152 + setTimeout(() => {
  153 + let self: PageModel = pageModel;
  154 + newPageHelper.refreshUI(self,onRefresh)
  155 + }, Const.DELAY_TIME);
  156 + setRefreshTimeoutTimer(pageModel)
  157 + } else {
  158 + closeRefresh(pageModel, false);
  159 + }
  160 +}
  161 +
  162 +export function setRefreshTimeoutTimer(pageModel: PageModel) {
  163 + let timeoutId = setTimeout(() => {
  164 + closeRefresh(pageModel, false);
  165 + Logger.error(TAG, 'closeRefresh by timeout')
  166 + }, Const.REFRESH_TIMEOUT__TIME);
  167 + // 取消超时关闭定时器
  168 + clearTimeout(pageModel.refreshTimeoutTimerId)
  169 + pageModel.refreshTimeoutTimerId = timeoutId
  170 +}
  171 +
  172 +/**
  173 + * 自动刷新接口,如首页底导,双击按钮自动刷新
  174 + * @param pageModel 页面数据
  175 + * @param pageAdvModel 广告数据
  176 + */
  177 +export function autoRefresh(pageModel: PageModel,onRefresh: () => void = () => {
  178 +}) {
  179 + if (pageModel.isRefreshing === true) {
  180 + // 拦截多次刷新
  181 + return
  182 + }
  183 + pageModel.isVisiblePullDown = true;
  184 + pageModel.offsetY = vp2px(pageModel.pullDownRefreshHeight);
  185 + pullRefreshState(pageModel, RefreshState.Refreshing);
  186 + pageModel.currentPage = 1;
  187 + newPageHelper.refreshUI(pageModel,onRefresh)
  188 + setRefreshTimeoutTimer(pageModel)
  189 +}
  190 +
  191 +export function pullRefreshState(pageModel: PageModel, state: number) {
  192 + switch (state) {
  193 + case RefreshState.DropDown:
  194 + pageModel.pullDownRefreshText = $r('app.string.pull_down_refresh_text');
  195 + pageModel.pullDownRefreshImage = $r('app.media.ic_pull_down_refresh');
  196 + pageModel.isCanRefresh = false;
  197 + pageModel.isRefreshing = false;
  198 + pageModel.isVisiblePullDown = true;
  199 + pageModel.load = LoadStatus.PRELOAD
  200 + break;
  201 + case RefreshState.Release:
  202 + pageModel.pullDownRefreshText = $r('app.string.release_refresh_text');
  203 + pageModel.pullDownRefreshImage = $r('app.media.ic_pull_up_refresh');
  204 + pageModel.isCanRefresh = true;
  205 + pageModel.isRefreshing = false;
  206 + pageModel.load = LoadStatus.PRELOAD
  207 + break;
  208 + case RefreshState.Refreshing:
  209 + pageModel.offsetY = vp2px(pageModel.pullDownRefreshHeight);
  210 + pageModel.pullDownRefreshText = $r('app.string.refreshing_text');
  211 + pageModel.pullDownRefreshImage = $r('app.media.ic_pull_up_load');
  212 + pageModel.isCanRefresh = true;
  213 + pageModel.isRefreshing = true;
  214 + pageModel.load = LoadStatus.LOADING
  215 + break;
  216 + case RefreshState.Success:
  217 + pageModel.pullDownRefreshText = $r('app.string.refresh_success_text');
  218 + pageModel.pullDownRefreshImage = $r('app.media.ic_succeed_refresh');
  219 + pageModel.isCanRefresh = true;
  220 + pageModel.isRefreshing = true;
  221 + pageModel.load = LoadStatus.LOADED
  222 + break;
  223 + case RefreshState.Fail:
  224 + pageModel.pullDownRefreshText = $r('app.string.refresh_fail_text');
  225 + pageModel.pullDownRefreshImage = $r('app.media.ic_fail_refresh');
  226 + pageModel.isCanRefresh = true;
  227 + pageModel.isRefreshing = true;
  228 + pageModel.load = LoadStatus.LOADED
  229 + break;
  230 + default:
  231 + break;
  232 + }
  233 +}
  234 +
  235 +export function closeRefresh(pageModel: PageModel, isRefreshSuccess: boolean) {
  236 + let self = pageModel;
  237 + // 取消超时关闭定时器
  238 + clearTimeout(self.refreshTimeoutTimerId)
  239 + setTimeout(() => {
  240 + let delay = Const.RefreshConstant_DELAY_PULL_DOWN_REFRESH;
  241 + if (self.isCanRefresh === true) {
  242 + pullRefreshState(pageModel, isRefreshSuccess ? RefreshState.Success : RefreshState.Fail);
  243 + delay = Const.RefreshConstant_DELAY_SHRINK_ANIMATION_TIME;
  244 + }
  245 + animateTo({
  246 + duration: Const.RefreshConstant_CLOSE_PULL_DOWN_REFRESH_TIME,
  247 + delay: delay,
  248 + onFinish: () => {
  249 + pullRefreshState(pageModel, RefreshState.DropDown);
  250 + self.isVisiblePullDown = false;
  251 + self.isPullRefreshOperation = false;
  252 + }
  253 + }, () => {
  254 + self.offsetY = 0;
  255 + })
  256 + }, self.isCanRefresh ? Const.DELAY_ANIMATION_DURATION : 0);
  257 +}
  1 +import PageModel from '../viewmodel/PageModel';
  2 +import { RefreshConstants as Const } from './RefreshConstants';
  3 +import newPageHelper from '../viewmodel/NewPageHelper';
  4 +import { Logger } from 'wdKit/Index';
  5 +
  6 +const TAG = 'NewPullUpLoadMore'
  7 +
  8 +export function touchMoveLoadMore(model: PageModel, event: TouchEvent) {
  9 + // list size +1
  10 + if (model.endIndex >= model.compList.totalCount() - 3 && model.endIndex <= model.compList.totalCount()) {
  11 + // model.offsetY = event.touches[0].y - model.downY;
  12 + // if (Math.abs(model.offsetY) > vp2px(model.pullUpLoadHeight) / 2) {
  13 + // model.isCanLoadMore = true;
  14 + // model.isVisiblePullUpLoad = true;
  15 + // model.offsetY = -vp2px(model.pullUpLoadHeight) + model.offsetY * Const.Y_OFF_SET_COEFFICIENT;
  16 + // }
  17 +
  18 + // 不用分页动画,直接预加载
  19 + model.isCanLoadMore = true;
  20 + model.isVisiblePullUpLoad = true;
  21 + touchUpLoadMore(model);
  22 + }
  23 +}
  24 +
  25 +export function touchUpLoadMore(model: PageModel,onRefreshMore: () => void = () => {
  26 +}) {
  27 + let self: PageModel = model;
  28 + animateTo({
  29 + duration: Const.ANIMATION_DURATION,
  30 + }, () => {
  31 + self.offsetY = 0;
  32 + })
  33 + if ((self.isCanLoadMore === true) && (self.hasMore === true) && (self.isLoading === false)) {
  34 + self.isLoading = true;
  35 + setTimeout(() => {
  36 + // closeLoadMore(model);
  37 + // newPageHelper.loadMore(self)
  38 + onRefreshMore()
  39 + }, Const.DELAY_TIME);
  40 + setLoadMoreTimeoutTimer(self)
  41 + } else {
  42 + closeLoadMore(self);
  43 + }
  44 +}
  45 +
  46 +export function closeLoadMore(model: PageModel) {
  47 + model.isCanLoadMore = false;
  48 + model.isLoading = false;
  49 + model.isVisiblePullUpLoad = false;
  50 +}
  51 +
  52 +export function setLoadMoreTimeoutTimer(pageModel: PageModel) {
  53 + let timeoutId = setTimeout(() => {
  54 + closeLoadMore(pageModel);
  55 + Logger.error(TAG, 'closeLoadMore by timeout')
  56 + }, Const.REFRESH_TIMEOUT__TIME);
  57 + // 取消超时关闭定时器
  58 + clearTimeout(pageModel.loadMoreTimeoutTimerId)
  59 + pageModel.loadMoreTimeoutTimerId = timeoutId
  60 +}
  1 +import { CompDTO, ContentDTO, InteractDataDTO, LiveReviewDTO, LiveRoomDataBean, PageDTO, PageInfoDTO } from 'wdBean';
  2 +import { CompStyle, ViewType } from 'wdConstant/Index';
  3 +import { CollectionUtils, DateTimeUtils, LazyDataSource, Logger, NetworkUtil, StringUtils, ToastUtils } from 'wdKit';
  4 +import { closeRefresh } from '../utils/NewPullDownRefresh';
  5 +import PageModel from './PageModel';
  6 +import PageViewModel from './PageViewModel';
  7 +import { promptAction } from '@kit.ArkUI';
  8 +import { CompAdvBean } from 'wdBean/src/main/ets/bean/adv/AdvsRuleBean';
  9 +// import PageAdModel from './PageAdvModel';
  10 +import { ArrayList } from '@kit.ArkTS';
  11 +import { WDViewDefaultType } from '../components/view/EmptyComponent';
  12 +import { CompAdvMatInfoBean } from 'wdBean/src/main/ets/bean/adv/CompAdvInfoBean';
  13 +import { BaseDTO } from 'wdBean/src/main/ets/bean/component/BaseDTO';
  14 +import { viewBlogInsightIntentShare, ActionMode } from '../utils/InsightIntentShare'
  15 +import { common } from '@kit.AbilityKit';
  16 +import { CacheData } from 'wdNetwork/Index';
  17 +import { closeLoadMore } from '../utils/PullUpLoadMore';
  18 +
  19 +const TAG = 'PageHelper';
  20 +
  21 +// 本地的一行两图卡 style值
  22 +const OneRowDoubleColumnStyle = CompStyle.Card_Comp_Zh_Grid_Layout_02
  23 +
  24 +const Normal_Page_Size = 20 // 常规每页数量
  25 +
  26 +const Rec_Page_Size = 10 // 推荐每页数量
  27 +
  28 +const SpecialComp: string[] = [CompStyle.Zh_Single_Column_03.toString()]
  29 +
  30 +/**
  31 + * 处理返回后的数据
  32 + */
  33 +export class NewPageHelper {
  34 + /**
  35 + * 刷新数据
  36 + */
  37 + async refreshUI(pageModel: PageModel, onRefresh: () => void = () => {
  38 + }) {
  39 + let netStatus = NetworkUtil.isNetConnected()
  40 + if (!netStatus) {
  41 + ToastUtils.showToast('网络出小差了,请检查网络后重试', 1000)
  42 + setTimeout(() => {
  43 + this.refreshUIEnd(pageModel, false)
  44 + }, 500)
  45 + return
  46 + }
  47 + pageModel.loadStrategy = 2
  48 + pageModel.pageTotalCompSize = 0;
  49 + onRefresh()
  50 + }
  51 +
  52 + private refreshUIEnd(pageModel: PageModel, isRefreshSuccess: boolean) {
  53 + if (pageModel.loadStrategy != 2) {
  54 + return
  55 + }
  56 + closeRefresh(pageModel, isRefreshSuccess)
  57 + }
  58 +
  59 + }
  60 +
  61 +let newPageHelper = new NewPageHelper();
  62 +
  63 +export default newPageHelper as NewPageHelper;