Showing
9 changed files
with
125 additions
and
12 deletions
| 1 | import { CommonConstants, ViewType } from 'wdConstant'; | 1 | import { CommonConstants, ViewType } from 'wdConstant'; |
| 2 | -import { Logger } from 'wdKit'; | 2 | +import { CollectionUtils, Logger } from 'wdKit'; |
| 3 | import { CompDTO } from '../../repository/bean/CompDTO'; | 3 | import { CompDTO } from '../../repository/bean/CompDTO'; |
| 4 | import PageViewModel from '../../viewmodel/PageViewModel'; | 4 | import PageViewModel from '../../viewmodel/PageViewModel'; |
| 5 | import { EmptyComponent } from '../view/EmptyComponent'; | 5 | import { EmptyComponent } from '../view/EmptyComponent'; |
| @@ -12,6 +12,7 @@ import NoMoreLayout from './NoMoreLayout'; | @@ -12,6 +12,7 @@ import NoMoreLayout from './NoMoreLayout'; | ||
| 12 | import LoadMoreLayout from './LoadMoreLayout'; | 12 | import LoadMoreLayout from './LoadMoreLayout'; |
| 13 | import CustomRefreshLoadLayout from './CustomRefreshLoadLayout'; | 13 | import CustomRefreshLoadLayout from './CustomRefreshLoadLayout'; |
| 14 | import { CompParser } from '../CompParser'; | 14 | import { CompParser } from '../CompParser'; |
| 15 | +import { GroupInfoDTO } from '../../repository/bean/PageInfoDTO'; | ||
| 15 | 16 | ||
| 16 | const TAG = 'PageComponent'; | 17 | const TAG = 'PageComponent'; |
| 17 | 18 | ||
| @@ -112,8 +113,20 @@ export struct PageComponent { | @@ -112,8 +113,20 @@ export struct PageComponent { | ||
| 112 | this.pageModel.groupId = this.pageId; | 113 | this.pageModel.groupId = this.pageId; |
| 113 | this.pageModel.channelId = this.channelId; | 114 | this.pageModel.channelId = this.channelId; |
| 114 | this.pageModel.currentPage = 1; | 115 | this.pageModel.currentPage = 1; |
| 115 | - let pageDto = await PageViewModel.getPageData(this.pageModel.pageId, this.pageModel.pageId, this.pageModel.channelId | ||
| 116 | - , this.pageModel.currentPage, this.pageModel.pageSize, getContext(this)) | 116 | + let pageInfo = await PageViewModel.getPageInfo(this.pageModel.pageId); |
| 117 | + if (pageInfo == null) { | ||
| 118 | + this.pageModel.viewType = ViewType.EMPTY; | ||
| 119 | + return; | ||
| 120 | + } | ||
| 121 | + | ||
| 122 | + // TODO group是个列表,可以配多个楼层,需要适配 多个group数据请求,后续优化 | ||
| 123 | + let groupInfo: GroupInfoDTO = CollectionUtils.getElement(pageInfo.groups, 0); | ||
| 124 | + if (groupInfo != null) { | ||
| 125 | + this.pageModel.groupStrategy = groupInfo.groupStrategy; | ||
| 126 | + this.pageModel.isRecGroup = groupInfo.groupStrategy === 1; | ||
| 127 | + this.pageModel.groupId = groupInfo.id; | ||
| 128 | + } | ||
| 129 | + let pageDto = await PageViewModel.getPageData(this.pageModel, getContext(this)) | ||
| 117 | if (pageDto && pageDto.compList && pageDto.compList.length > 0) { | 130 | if (pageDto && pageDto.compList && pageDto.compList.length > 0) { |
| 118 | this.pageModel.viewType = ViewType.LOADED; | 131 | this.pageModel.viewType = ViewType.LOADED; |
| 119 | this.pageModel.compList.push(...pageDto.compList) | 132 | this.pageModel.compList.push(...pageDto.compList) |
| @@ -28,10 +28,18 @@ export class HttpUrlUtils { | @@ -28,10 +28,18 @@ export class HttpUrlUtils { | ||
| 28 | */ | 28 | */ |
| 29 | static readonly BOTTOM_NAV_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/bottomNavGroup"; | 29 | static readonly BOTTOM_NAV_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/bottomNavGroup"; |
| 30 | /** | 30 | /** |
| 31 | + * 展现page接口 | ||
| 32 | + */ | ||
| 33 | + static readonly PAGE_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/pageInfo"; | ||
| 34 | + /** | ||
| 31 | * 展现comp接口 | 35 | * 展现comp接口 |
| 32 | */ | 36 | */ |
| 33 | static readonly COMP_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/compInfo"; | 37 | static readonly COMP_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/compInfo"; |
| 34 | /** | 38 | /** |
| 39 | + * 推荐内容的展现comp接口 | ||
| 40 | + */ | ||
| 41 | + static readonly COMP_REC_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/rec/compInfo"; | ||
| 42 | + /** | ||
| 35 | * 详情页面详情接口 | 43 | * 详情页面详情接口 |
| 36 | */ | 44 | */ |
| 37 | static readonly DETAIL_PATH: string = "/api/rmrb-bff-display-zh/content/zh/c/content/detail"; | 45 | static readonly DETAIL_PATH: string = "/api/rmrb-bff-display-zh/content/zh/c/content/detail"; |
| @@ -87,6 +95,10 @@ export class HttpUrlUtils { | @@ -87,6 +95,10 @@ export class HttpUrlUtils { | ||
| 87 | return this.hostUrl + this.BOTTOM_NAV_PATH; | 95 | return this.hostUrl + this.BOTTOM_NAV_PATH; |
| 88 | } | 96 | } |
| 89 | 97 | ||
| 98 | + static getPageUrl(pageId: string) { | ||
| 99 | + return this.hostUrl + this.PAGE_PATH + "?pageId=" + pageId; | ||
| 100 | + } | ||
| 101 | + | ||
| 90 | static getCompInfoUrl(pageId: string, groupId: string, channelId: string, currentPage: number | 102 | static getCompInfoUrl(pageId: string, groupId: string, channelId: string, currentPage: number |
| 91 | , pageSize: number) { | 103 | , pageSize: number) { |
| 92 | let url = this.hostUrl + this.COMP_PATH; | 104 | let url = this.hostUrl + this.COMP_PATH; |
| @@ -105,6 +117,24 @@ export class HttpUrlUtils { | @@ -105,6 +117,24 @@ export class HttpUrlUtils { | ||
| 105 | return url; | 117 | return url; |
| 106 | } | 118 | } |
| 107 | 119 | ||
| 120 | + static getRecCompInfoUrl(pageId: string, groupId: string, channelId: string, currentPage: number | ||
| 121 | + , pageSize: number) { | ||
| 122 | + let url = this.hostUrl + this.COMP_REC_PATH; | ||
| 123 | + // TODO 暂定只请求第一页,后续对接分页加载,参数再调整 first_load? | ||
| 124 | + url = url + "?channelStrategy=1&loadStrategy=first_load" | ||
| 125 | + + "&districtCode=" + this.getDistrictCode() | ||
| 126 | + + "&provinceCode=" + this.getProvinceCode() | ||
| 127 | + + "&cityCode=" + this.getCityCode() | ||
| 128 | + + "&refreshTime=" + DateTimeUtils.getCurrentTimeMillis() | ||
| 129 | + + "&pageId=" + pageId | ||
| 130 | + + "&groupId=" + groupId | ||
| 131 | + + "&channelId=" + channelId | ||
| 132 | + + "&pageSize=" + pageSize | ||
| 133 | + + "&pageNum=" + currentPage; | ||
| 134 | + // Logger.debug("TAG", 'getCompInfoUrl url: '+url); | ||
| 135 | + return url; | ||
| 136 | + } | ||
| 137 | + | ||
| 108 | static getDetailInfoUrl(relId: string, contentId: string, relType: string) { | 138 | static getDetailInfoUrl(relId: string, contentId: string, relType: string) { |
| 109 | let url = this.hostUrl + this.DETAIL_PATH; | 139 | let url = this.hostUrl + this.DETAIL_PATH; |
| 110 | url = url + "?relId=" + relId | 140 | url = url + "?relId=" + relId |
| @@ -4,6 +4,7 @@ import { PageDTO } from './bean/PageDTO'; | @@ -4,6 +4,7 @@ import { PageDTO } from './bean/PageDTO'; | ||
| 4 | import HashMap from '@ohos.util.HashMap'; | 4 | import HashMap from '@ohos.util.HashMap'; |
| 5 | import { HttpUrlUtils } from '../network/HttpUrlUtils'; | 5 | import { HttpUrlUtils } from '../network/HttpUrlUtils'; |
| 6 | import { InteractDataDTO } from './bean/InteractDataDTO'; | 6 | import { InteractDataDTO } from './bean/InteractDataDTO'; |
| 7 | +import { PageInfoDTO } from './bean/PageInfoDTO'; | ||
| 7 | 8 | ||
| 8 | export class PageRepository { | 9 | export class PageRepository { |
| 9 | static fetchNavigationDataApi() { | 10 | static fetchNavigationDataApi() { |
| @@ -12,13 +13,26 @@ export class PageRepository { | @@ -12,13 +13,26 @@ export class PageRepository { | ||
| 12 | return WDHttp.get<ResponseDTO<NavigationBodyDTO>>(url, headers) | 13 | return WDHttp.get<ResponseDTO<NavigationBodyDTO>>(url, headers) |
| 13 | }; | 14 | }; |
| 14 | 15 | ||
| 15 | - static fetchPageData(pageId: string, groupId: string, channelId: string, currentPage: number | 16 | + static fetchPageData(pageId: string) { |
| 17 | + let url = HttpUrlUtils.getPageUrl(pageId) | ||
| 18 | + let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | ||
| 19 | + return WDHttp.get<ResponseDTO<PageInfoDTO>>(url, headers) | ||
| 20 | + }; | ||
| 21 | + | ||
| 22 | + static fetchCompData(pageId: string, groupId: string, channelId: string, currentPage: number | ||
| 16 | , pageSize: number) { | 23 | , pageSize: number) { |
| 17 | let url = HttpUrlUtils.getCompInfoUrl(pageId, groupId, channelId, currentPage, pageSize) | 24 | let url = HttpUrlUtils.getCompInfoUrl(pageId, groupId, channelId, currentPage, pageSize) |
| 18 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | 25 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); |
| 19 | return WDHttp.get<ResponseDTO<PageDTO>>(url, headers) | 26 | return WDHttp.get<ResponseDTO<PageDTO>>(url, headers) |
| 20 | }; | 27 | }; |
| 21 | 28 | ||
| 29 | + static fetchRecCompData(pageId: string, groupId: string, channelId: string, currentPage: number | ||
| 30 | + , pageSize: number) { | ||
| 31 | + let url = HttpUrlUtils.getRecCompInfoUrl(pageId, groupId, channelId, currentPage, pageSize) | ||
| 32 | + let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | ||
| 33 | + return WDHttp.get<ResponseDTO<PageDTO>>(url, headers) | ||
| 34 | + }; | ||
| 35 | + | ||
| 22 | static fetchDetailData(relId: string, contentId: string, relType: string) { | 36 | static fetchDetailData(relId: string, contentId: string, relType: string) { |
| 23 | let url = HttpUrlUtils.getDetailInfoUrl(relId, contentId, relType) | 37 | let url = HttpUrlUtils.getDetailInfoUrl(relId, contentId, relType) |
| 24 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | 38 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); |
| 1 | +/** | ||
| 2 | + * page接口返回的Page数据DTO | ||
| 3 | + */ | ||
| 4 | +export interface PageInfoDTO { | ||
| 5 | + pageId: string; // 页面id | ||
| 6 | + id: number; // 楼层id | ||
| 7 | + name: string; // 名称 | ||
| 8 | + hasAdInfo: number; | ||
| 9 | + hasPopUp: number; | ||
| 10 | + baselineShow: number; | ||
| 11 | + groups: GroupInfoDTO[]; | ||
| 12 | + channelInfo: ChannelInfoDTO; | ||
| 13 | +} | ||
| 14 | + | ||
| 15 | +export interface ChannelInfoDTO { | ||
| 16 | + channelId: string; | ||
| 17 | + channelLevel: string; | ||
| 18 | + channelName: string; | ||
| 19 | + channelStrategy: string; | ||
| 20 | + channelStyle: string; | ||
| 21 | + pageId: string; | ||
| 22 | +} | ||
| 23 | + | ||
| 24 | +export interface GroupInfoDTO { | ||
| 25 | + blockDesc: string; | ||
| 26 | + groupStrategy: number; | ||
| 27 | + id: string; | ||
| 28 | + showType: number; | ||
| 29 | + sortValue: number; | ||
| 30 | +} |
| @@ -71,7 +71,7 @@ export function touchUpPullRefresh(pageModel: PageModel) { | @@ -71,7 +71,7 @@ export function touchUpPullRefresh(pageModel: PageModel) { | ||
| 71 | setTimeout(() => { | 71 | setTimeout(() => { |
| 72 | let self: PageModel = pageModel; | 72 | let self: PageModel = pageModel; |
| 73 | 73 | ||
| 74 | - PageViewModel.getPageData(self.pageId, self.groupId, self.channelId, self.currentPage, self.pageSize) | 74 | + PageViewModel.getPageData(self) |
| 75 | .then((data: PageDTO) => { | 75 | .then((data: PageDTO) => { |
| 76 | if (data == null || data.compList == null || data.compList.length == 0) { | 76 | if (data == null || data.compList == null || data.compList.length == 0) { |
| 77 | self.hasMore = false; | 77 | self.hasMore = false; |
| @@ -27,7 +27,7 @@ export function touchUpLoadMore(model: PageModel) { | @@ -27,7 +27,7 @@ export function touchUpLoadMore(model: PageModel) { | ||
| 27 | self.isLoading = true; | 27 | self.isLoading = true; |
| 28 | setTimeout(() => { | 28 | setTimeout(() => { |
| 29 | closeLoadMore(model); | 29 | closeLoadMore(model); |
| 30 | - PageViewModel.getPageData(self.pageId, self.groupId, self.channelId, self.currentPage, self.pageSize) | 30 | + PageViewModel.getPageData(self) |
| 31 | .then((data: PageDTO) => { | 31 | .then((data: PageDTO) => { |
| 32 | if (data == null || data.compList == null || data.compList.length == 0) { | 32 | if (data == null || data.compList == null || data.compList.length == 0) { |
| 33 | self.hasMore = false; | 33 | self.hasMore = false; |
| @@ -8,6 +8,8 @@ export default class PageModel { | @@ -8,6 +8,8 @@ export default class PageModel { | ||
| 8 | pageId: string = ""; | 8 | pageId: string = ""; |
| 9 | groupId: string = ""; | 9 | groupId: string = ""; |
| 10 | channelId: string = ""; | 10 | channelId: string = ""; |
| 11 | + groupStrategy: number = 0; | ||
| 12 | + isRecGroup: boolean = false; | ||
| 11 | compList: LazyDataSource<CompDTO> = new LazyDataSource(); | 13 | compList: LazyDataSource<CompDTO> = new LazyDataSource(); |
| 12 | // 页面状态,刷新、加载更多等 | 14 | // 页面状态,刷新、加载更多等 |
| 13 | currentPage: number = 1; | 15 | currentPage: number = 1; |
| @@ -7,6 +7,8 @@ import { BaseViewModel } from './BaseViewModel'; | @@ -7,6 +7,8 @@ import { BaseViewModel } from './BaseViewModel'; | ||
| 7 | import { InteractDataDTO } from '../repository/bean/InteractDataDTO'; | 7 | import { InteractDataDTO } from '../repository/bean/InteractDataDTO'; |
| 8 | import { ContentBean, InteractParam } from '../repository/bean/InteractParam'; | 8 | import { ContentBean, InteractParam } from '../repository/bean/InteractParam'; |
| 9 | import { CompDTO } from '../repository/bean/CompDTO'; | 9 | import { CompDTO } from '../repository/bean/CompDTO'; |
| 10 | +import { PageInfoDTO } from '../repository/bean/PageInfoDTO'; | ||
| 11 | +import PageModel from './PageModel'; | ||
| 10 | 12 | ||
| 11 | const TAG = 'PageViewModel'; | 13 | const TAG = 'PageViewModel'; |
| 12 | /** | 14 | /** |
| @@ -106,14 +108,34 @@ export class PageViewModel extends BaseViewModel { | @@ -106,14 +108,34 @@ export class PageViewModel extends BaseViewModel { | ||
| 106 | return compRes.data | 108 | return compRes.data |
| 107 | } | 109 | } |
| 108 | 110 | ||
| 109 | - async getPageData(pageId: string, groupId: string, channelId: string, currentPage: number | ||
| 110 | - , pageSize: number, context?: Context): Promise<PageDTO> { | ||
| 111 | - Logger.debug(TAG, 'getPageData pageId: ' + pageId); | 111 | + async getPageInfo(pageId: string): Promise<PageInfoDTO> { |
| 112 | + return new Promise<PageInfoDTO>((success, error) => { | ||
| 113 | + PageRepository.fetchPageData(pageId).then((resDTO: ResponseDTO<PageInfoDTO>) => { | ||
| 114 | + if (this.isRespondsInvalid(resDTO, 'getPageInfo')) { | ||
| 115 | + error("getPageInfo data invalid"); | ||
| 116 | + return | ||
| 117 | + } | ||
| 118 | + Logger.info(TAG, "getPageInfo then,resDTO.timeStamp:" + resDTO.timestamp); | ||
| 119 | + success(resDTO.data); | ||
| 120 | + }); | ||
| 121 | + }); | ||
| 122 | + } | ||
| 123 | + | ||
| 124 | + async getPageData(pageModel: PageModel, context?: Context): Promise<PageDTO> { | ||
| 125 | + Logger.debug(TAG, 'getPageData pageId: ' + pageModel.pageId); | ||
| 112 | if (mock_switch) { | 126 | if (mock_switch) { |
| 113 | - return this.getPageData1(currentPage, context); | 127 | + return this.getPageData1(pageModel.currentPage, context); |
| 128 | + } | ||
| 129 | + if (pageModel.isRecGroup) { | ||
| 130 | + return this.parseComp(PageRepository.fetchRecCompData(pageModel.pageId, pageModel.groupId, pageModel.channelId, pageModel.currentPage, pageModel.pageSize)) | ||
| 131 | + } else { | ||
| 132 | + return this.parseComp(PageRepository.fetchCompData(pageModel.pageId, pageModel.groupId, pageModel.channelId, pageModel.currentPage, pageModel.pageSize)) | ||
| 114 | } | 133 | } |
| 134 | + } | ||
| 135 | + | ||
| 136 | + private parseComp(getData: Promise<ResponseDTO<PageDTO>>): Promise<PageDTO> { | ||
| 115 | return new Promise<PageDTO>((success, error) => { | 137 | return new Promise<PageDTO>((success, error) => { |
| 116 | - PageRepository.fetchPageData(pageId, groupId, channelId, currentPage, pageSize) | 138 | + getData |
| 117 | .then((resDTO: ResponseDTO<PageDTO>) => { | 139 | .then((resDTO: ResponseDTO<PageDTO>) => { |
| 118 | if (this.isRespondsInvalid(resDTO, 'getPageData')) { | 140 | if (this.isRespondsInvalid(resDTO, 'getPageData')) { |
| 119 | error("page data invalid"); | 141 | error("page data invalid"); |
| @@ -124,6 +146,7 @@ export class PageViewModel extends BaseViewModel { | @@ -124,6 +146,7 @@ export class PageViewModel extends BaseViewModel { | ||
| 124 | success(resDTO.data); | 146 | success(resDTO.data); |
| 125 | return; | 147 | return; |
| 126 | } | 148 | } |
| 149 | + success(resDTO.data); | ||
| 127 | // TODO 打开同步请求互动数据,待优化为异步加载 | 150 | // TODO 打开同步请求互动数据,待优化为异步加载 |
| 128 | if (CollectionUtils.isEmpty(resDTO.data.compList)) { | 151 | if (CollectionUtils.isEmpty(resDTO.data.compList)) { |
| 129 | success(resDTO.data); | 152 | success(resDTO.data); |
| @@ -226,6 +249,7 @@ export class PageViewModel extends BaseViewModel { | @@ -226,6 +249,7 @@ export class PageViewModel extends BaseViewModel { | ||
| 226 | } | 249 | } |
| 227 | if (id == content.objectId) { | 250 | if (id == content.objectId) { |
| 228 | content.interactData = interactData; | 251 | content.interactData = interactData; |
| 252 | + content.interactData.likeNum = 109; | ||
| 229 | break outer; | 253 | break outer; |
| 230 | } | 254 | } |
| 231 | } | 255 | } |
-
Please register or login to post a comment