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-03-07 10:46:23 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
9e607a62df89386de4e7a82fa747b3c48b5f9989
9e607a62
1 parent
95fadde0
添加推荐page接口
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
125 additions
and
12 deletions
PeopleDaily_Harmony/wdComponent/src/main/ets/components/page/PageComponent.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/network/HttpUrlUtils.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/repository/PageRepository.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/repository/bean/PageDTO.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/repository/bean/PageInfoDTO.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/wdComponent/src/main/ets/components/page/PageComponent.ets
View file @
9e607a6
import { CommonConstants, ViewType } from 'wdConstant';
import { Logger } from 'wdKit';
import {
CollectionUtils,
Logger } from 'wdKit';
import { CompDTO } from '../../repository/bean/CompDTO';
import PageViewModel from '../../viewmodel/PageViewModel';
import { EmptyComponent } from '../view/EmptyComponent';
...
...
@@ -12,6 +12,7 @@ import NoMoreLayout from './NoMoreLayout';
import LoadMoreLayout from './LoadMoreLayout';
import CustomRefreshLoadLayout from './CustomRefreshLoadLayout';
import { CompParser } from '../CompParser';
import { GroupInfoDTO } from '../../repository/bean/PageInfoDTO';
const TAG = 'PageComponent';
...
...
@@ -112,8 +113,20 @@ export struct PageComponent {
this.pageModel.groupId = this.pageId;
this.pageModel.channelId = this.channelId;
this.pageModel.currentPage = 1;
let pageDto = await PageViewModel.getPageData(this.pageModel.pageId, this.pageModel.pageId, this.pageModel.channelId
, this.pageModel.currentPage, this.pageModel.pageSize, getContext(this))
let pageInfo = await PageViewModel.getPageInfo(this.pageModel.pageId);
if (pageInfo == null) {
this.pageModel.viewType = ViewType.EMPTY;
return;
}
// TODO group是个列表,可以配多个楼层,需要适配 多个group数据请求,后续优化
let groupInfo: GroupInfoDTO = CollectionUtils.getElement(pageInfo.groups, 0);
if (groupInfo != null) {
this.pageModel.groupStrategy = groupInfo.groupStrategy;
this.pageModel.isRecGroup = groupInfo.groupStrategy === 1;
this.pageModel.groupId = groupInfo.id;
}
let pageDto = await PageViewModel.getPageData(this.pageModel, getContext(this))
if (pageDto && pageDto.compList && pageDto.compList.length > 0) {
this.pageModel.viewType = ViewType.LOADED;
this.pageModel.compList.push(...pageDto.compList)
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/network/HttpUrlUtils.ets
View file @
9e607a6
...
...
@@ -28,10 +28,18 @@ export class HttpUrlUtils {
*/
static readonly BOTTOM_NAV_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/bottomNavGroup";
/**
* 展现page接口
*/
static readonly PAGE_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/pageInfo";
/**
* 展现comp接口
*/
static readonly COMP_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/compInfo";
/**
* 推荐内容的展现comp接口
*/
static readonly COMP_REC_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/rec/compInfo";
/**
* 详情页面详情接口
*/
static readonly DETAIL_PATH: string = "/api/rmrb-bff-display-zh/content/zh/c/content/detail";
...
...
@@ -87,6 +95,10 @@ export class HttpUrlUtils {
return this.hostUrl + this.BOTTOM_NAV_PATH;
}
static getPageUrl(pageId: string) {
return this.hostUrl + this.PAGE_PATH + "?pageId=" + pageId;
}
static getCompInfoUrl(pageId: string, groupId: string, channelId: string, currentPage: number
, pageSize: number) {
let url = this.hostUrl + this.COMP_PATH;
...
...
@@ -105,6 +117,24 @@ export class HttpUrlUtils {
return url;
}
static getRecCompInfoUrl(pageId: string, groupId: string, channelId: string, currentPage: number
, pageSize: number) {
let url = this.hostUrl + this.COMP_REC_PATH;
// TODO 暂定只请求第一页,后续对接分页加载,参数再调整 first_load?
url = url + "?channelStrategy=1&loadStrategy=first_load"
+ "&districtCode=" + this.getDistrictCode()
+ "&provinceCode=" + this.getProvinceCode()
+ "&cityCode=" + this.getCityCode()
+ "&refreshTime=" + DateTimeUtils.getCurrentTimeMillis()
+ "&pageId=" + pageId
+ "&groupId=" + groupId
+ "&channelId=" + channelId
+ "&pageSize=" + pageSize
+ "&pageNum=" + currentPage;
// Logger.debug("TAG", 'getCompInfoUrl url: '+url);
return url;
}
static getDetailInfoUrl(relId: string, contentId: string, relType: string) {
let url = this.hostUrl + this.DETAIL_PATH;
url = url + "?relId=" + relId
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/repository/PageRepository.ets
View file @
9e607a6
...
...
@@ -4,6 +4,7 @@ import { PageDTO } from './bean/PageDTO';
import HashMap from '@ohos.util.HashMap';
import { HttpUrlUtils } from '../network/HttpUrlUtils';
import { InteractDataDTO } from './bean/InteractDataDTO';
import { PageInfoDTO } from './bean/PageInfoDTO';
export class PageRepository {
static fetchNavigationDataApi() {
...
...
@@ -12,13 +13,26 @@ export class PageRepository {
return WDHttp.get<ResponseDTO<NavigationBodyDTO>>(url, headers)
};
static fetchPageData(pageId: string, groupId: string, channelId: string, currentPage: number
static fetchPageData(pageId: string) {
let url = HttpUrlUtils.getPageUrl(pageId)
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return WDHttp.get<ResponseDTO<PageInfoDTO>>(url, headers)
};
static fetchCompData(pageId: string, groupId: string, channelId: string, currentPage: number
, pageSize: number) {
let url = HttpUrlUtils.getCompInfoUrl(pageId, groupId, channelId, currentPage, pageSize)
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return WDHttp.get<ResponseDTO<PageDTO>>(url, headers)
};
static fetchRecCompData(pageId: string, groupId: string, channelId: string, currentPage: number
, pageSize: number) {
let url = HttpUrlUtils.getRecCompInfoUrl(pageId, groupId, channelId, currentPage, pageSize)
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return WDHttp.get<ResponseDTO<PageDTO>>(url, headers)
};
static fetchDetailData(relId: string, contentId: string, relType: string) {
let url = HttpUrlUtils.getDetailInfoUrl(relId, contentId, relType)
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/repository/bean/PageDTO.ets
View file @
9e607a6
import { CompDTO } from './CompDTO';
/**
* Page数据DTO
*
compInfo接口返回的
Page数据DTO
*/
export interface PageDTO {
pageId: string; // 页面id
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/repository/bean/PageInfoDTO.ets
0 → 100644
View file @
9e607a6
/**
* page接口返回的Page数据DTO
*/
export interface PageInfoDTO {
pageId: string; // 页面id
id: number; // 楼层id
name: string; // 名称
hasAdInfo: number;
hasPopUp: number;
baselineShow: number;
groups: GroupInfoDTO[];
channelInfo: ChannelInfoDTO;
}
export interface ChannelInfoDTO {
channelId: string;
channelLevel: string;
channelName: string;
channelStrategy: string;
channelStyle: string;
pageId: string;
}
export interface GroupInfoDTO {
blockDesc: string;
groupStrategy: number;
id: string;
showType: number;
sortValue: number;
}
\ No newline at end of file
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/utils/PullDownRefresh.ets
View file @
9e607a6
...
...
@@ -71,7 +71,7 @@ export function touchUpPullRefresh(pageModel: PageModel) {
setTimeout(() => {
let self: PageModel = pageModel;
PageViewModel.getPageData(self
.pageId, self.groupId, self.channelId, self.currentPage, self.pageSize
)
PageViewModel.getPageData(self)
.then((data: PageDTO) => {
if (data == null || data.compList == null || data.compList.length == 0) {
self.hasMore = false;
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/utils/PullUpLoadMore.ets
View file @
9e607a6
...
...
@@ -27,7 +27,7 @@ export function touchUpLoadMore(model: PageModel) {
self.isLoading = true;
setTimeout(() => {
closeLoadMore(model);
PageViewModel.getPageData(self
.pageId, self.groupId, self.channelId, self.currentPage, self.pageSize
)
PageViewModel.getPageData(self)
.then((data: PageDTO) => {
if (data == null || data.compList == null || data.compList.length == 0) {
self.hasMore = false;
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/viewmodel/PageModel.ets
View file @
9e607a6
...
...
@@ -8,6 +8,8 @@ export default class PageModel {
pageId: string = "";
groupId: string = "";
channelId: string = "";
groupStrategy: number = 0;
isRecGroup: boolean = false;
compList: LazyDataSource<CompDTO> = new LazyDataSource();
// 页面状态,刷新、加载更多等
currentPage: number = 1;
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/viewmodel/PageViewModel.ets
View file @
9e607a6
...
...
@@ -7,6 +7,8 @@ import { BaseViewModel } from './BaseViewModel';
import { InteractDataDTO } from '../repository/bean/InteractDataDTO';
import { ContentBean, InteractParam } from '../repository/bean/InteractParam';
import { CompDTO } from '../repository/bean/CompDTO';
import { PageInfoDTO } from '../repository/bean/PageInfoDTO';
import PageModel from './PageModel';
const TAG = 'PageViewModel';
/**
...
...
@@ -106,14 +108,34 @@ export class PageViewModel extends BaseViewModel {
return compRes.data
}
async getPageData(pageId: string, groupId: string, channelId: string, currentPage: number
, pageSize: number, context?: Context): Promise<PageDTO> {
Logger.debug(TAG, 'getPageData pageId: ' + pageId);
async getPageInfo(pageId: string): Promise<PageInfoDTO> {
return new Promise<PageInfoDTO>((success, error) => {
PageRepository.fetchPageData(pageId).then((resDTO: ResponseDTO<PageInfoDTO>) => {
if (this.isRespondsInvalid(resDTO, 'getPageInfo')) {
error("getPageInfo data invalid");
return
}
Logger.info(TAG, "getPageInfo then,resDTO.timeStamp:" + resDTO.timestamp);
success(resDTO.data);
});
});
}
async getPageData(pageModel: PageModel, context?: Context): Promise<PageDTO> {
Logger.debug(TAG, 'getPageData pageId: ' + pageModel.pageId);
if (mock_switch) {
return this.getPageData1(currentPage, context);
return this.getPageData1(pageModel.currentPage, context);
}
if (pageModel.isRecGroup) {
return this.parseComp(PageRepository.fetchRecCompData(pageModel.pageId, pageModel.groupId, pageModel.channelId, pageModel.currentPage, pageModel.pageSize))
} else {
return this.parseComp(PageRepository.fetchCompData(pageModel.pageId, pageModel.groupId, pageModel.channelId, pageModel.currentPage, pageModel.pageSize))
}
}
private parseComp(getData: Promise<ResponseDTO<PageDTO>>): Promise<PageDTO> {
return new Promise<PageDTO>((success, error) => {
PageRepository.fetchPageData(pageId, groupId, channelId, currentPage, pageSize)
getData
.then((resDTO: ResponseDTO<PageDTO>) => {
if (this.isRespondsInvalid(resDTO, 'getPageData')) {
error("page data invalid");
...
...
@@ -124,6 +146,7 @@ export class PageViewModel extends BaseViewModel {
success(resDTO.data);
return;
}
success(resDTO.data);
// TODO 打开同步请求互动数据,待优化为异步加载
if (CollectionUtils.isEmpty(resDTO.data.compList)) {
success(resDTO.data);
...
...
@@ -226,6 +249,7 @@ export class PageViewModel extends BaseViewModel {
}
if (id == content.objectId) {
content.interactData = interactData;
content.interactData.likeNum = 109;
break outer;
}
}
...
...
Please
register
or
login
to post a comment