Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
zhangbo1_wd
2024-04-09 18:25:29 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2bc66fdf1e1de90c23a9c45ac5f409217d3f0566
2bc66fdf
1 parent
c9902c8e
首页请求互动数据,优化为异步加载
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
38 additions
and
12 deletions
PeopleDaily_Harmony/wdComponent/src/main/ets/components/page/PageComponent.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/components/view/BigPicCardComponent.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/repository/bean/InteractDataDTO.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/utils/PullDownRefresh.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/utils/PullUpLoadMore.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/viewmodel/PageModel.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/viewmodel/PageViewModel.ets
PeopleDaily_Harmony/wdKit/src/main/ets/utils/LazyDataSource.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/components/page/PageComponent.ets
View file @
2bc66fd
import { CommonConstants, ViewType } from 'wdConstant';
import { CollectionUtils, Logger } from 'wdKit';
import { CollectionUtils,
DateTimeUtils,
Logger } from 'wdKit';
import { CompDTO } from '../../repository/bean/CompDTO';
import PageViewModel from '../../viewmodel/PageViewModel';
import { EmptyComponent } from '../view/EmptyComponent';
...
...
@@ -65,7 +65,9 @@ export struct PageComponent {
CompParser({ compDTO: compDTO, compIndex: compIndex });
}
}
})
},
(compDTO: CompDTO, compIndex: number) => compDTO.id + compIndex.toString() + this.pageModel.timestamp
)
// 加载更多
ListItem() {
...
...
@@ -136,6 +138,11 @@ export struct PageComponent {
} else {
this.pageModel.hasMore = false;
}
PageViewModel.getInteractData(pageDto.compList).then((data: CompDTO[]) => {
// 刷新,替换所有数据
this.pageModel.compList.replaceAll(...data)
this.pageModel.timestamp = DateTimeUtils.getCurrentTimeMillis().toString()
})
} else {
Logger.debug(TAG, 'aboutToAppear, data response page ' + this.pageId + ', comp list is empty.');
this.pageModel.viewType = ViewType.EMPTY;
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/components/view/BigPicCardComponent.ets
View file @
2bc66fd
...
...
@@ -35,6 +35,8 @@ export struct BigPicCardComponent {
Column() {
Column() {
// TODO 测试代码
Text("likeNum " + this.contentDTO?.interactData?.likeNum)
//新闻标题
Text(this.compDTO.operDataList[0].newsTitle)
.fontSize(17)
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/repository/bean/InteractDataDTO.ets
View file @
2bc66fd
/**
* 批查接口查询互动相关数据,返回数据bean
*/
export
interface
InteractDataDTO {
export
class
InteractDataDTO {
collectNum: number;
commentNum: number;
contentId: string;
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/utils/PullDownRefresh.ets
View file @
2bc66fd
...
...
@@ -4,6 +4,8 @@ import { RefreshConstants as Const, RefreshState } from './RefreshConstants';
import PageViewModel from '../viewmodel/PageViewModel';
import { PageDTO } from '../repository/bean/PageDTO';
import { touchMoveLoadMore, touchUpLoadMore } from './PullUpLoadMore';
import { CompDTO } from '../repository/bean/CompDTO';
import { DateTimeUtils } from 'wdKit/src/main/ets/utils/DateTimeUtils';
export function listTouchEvent(pageModel: PageModel, event: TouchEvent) {
switch (event.type) {
...
...
@@ -73,6 +75,7 @@ export function touchUpPullRefresh(pageModel: PageModel) {
PageViewModel.getPageData(self)
.then((data: PageDTO) => {
self.timestamp = DateTimeUtils.getCurrentTimeMillis().toString()
if (data == null || data.compList == null || data.compList.length == 0) {
self.hasMore = false;
} else {
...
...
@@ -84,6 +87,11 @@ export function touchUpPullRefresh(pageModel: PageModel) {
}
// 刷新,替换所有数据
self.compList.replaceAll(...data.compList)
PageViewModel.getInteractData(data.compList).then((data: CompDTO[]) => {
// 刷新,替换所有数据
self.compList.replaceAll(...data)
self.timestamp = DateTimeUtils.getCurrentTimeMillis().toString()
})
}
closeRefresh(self, true);
}).catch((err: string | Resource) => {
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/utils/PullUpLoadMore.ets
View file @
2bc66fd
...
...
@@ -3,6 +3,8 @@ import PageModel from '../viewmodel/PageModel';
import { RefreshConstants as Const } from './RefreshConstants';
import PageViewModel from '../viewmodel/PageViewModel';
import { PageDTO } from '../repository/bean/PageDTO';
import { CompDTO } from '../repository/bean/CompDTO';
import { DateTimeUtils } from 'wdKit';
export function touchMoveLoadMore(model: PageModel, event: TouchEvent) {
// list size +1
...
...
@@ -38,7 +40,13 @@ export function touchUpLoadMore(model: PageModel) {
} else {
self.hasMore = false;
}
let sizeBefore = self.compList.size();
self.compList.push(...data.compList)
PageViewModel.getInteractData(data.compList).then((data: CompDTO[]) => {
// 刷新,替换所有数据
self.compList.updateItems(sizeBefore, data)
self.timestamp = DateTimeUtils.getCurrentTimeMillis().toString()
})
}
}).catch((err: string | Resource) => {
promptAction.showToast({ message: err });
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/viewmodel/PageModel.ets
View file @
2bc66fd
...
...
@@ -34,4 +34,6 @@ export default class PageModel {
isPullRefreshOperation = false;
isLoading: boolean = false;
isCanLoadMore: boolean = false;
// keyGenerator相关字符串,用于刷新list布局
timestamp: String = '1';
}
\ No newline at end of file
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/viewmodel/PageViewModel.ets
View file @
2bc66fd
...
...
@@ -147,14 +147,6 @@ export class PageViewModel extends BaseViewModel {
return;
}
success(resDTO.data);
// TODO 打开同步请求互动数据,待优化为异步加载
if (CollectionUtils.isEmpty(resDTO.data.compList)) {
success(resDTO.data);
} else {
this.getInteractData(resDTO.data.compList).then(() => {
success(resDTO.data);
})
}
})
.catch((err: Error) => {
Logger.error(TAG, `getPageData catch, error.name : ${err.name}, error.message:${err.message}`);
...
...
@@ -249,7 +241,8 @@ export class PageViewModel extends BaseViewModel {
}
if (id == content.objectId) {
content.interactData = interactData;
content.interactData.likeNum = 109;
// TODO 测试代码,待删除
// content.interactData.likeNum = Math.floor(Math.random() * Math.floor(999));;
break outer;
}
}
...
...
PeopleDaily_Harmony/wdKit/src/main/ets/utils/LazyDataSource.ets
View file @
2bc66fd
...
...
@@ -254,4 +254,10 @@ export class LazyDataSource<T> extends BasicDataSource<T> {
sort(comparator: (firstValue: T, secondValue: T) => number): void {
this.dataArray.sort(comparator)
}
public updateItems(start: number, data: T[]): void {
// 从数组中的start位置开始删除dataArray.length个元素,并在同一位置插入((1个或多个))新元素。
this.dataArray.splice(start, this.dataArray.length, ...data);
this.notifyDataReload()
}
}
\ No newline at end of file
...
...
Please
register
or
login
to post a comment