Showing
5 changed files
with
45 additions
and
32 deletions
| 1 | import { BottomNavi, CommonConstants } from 'wdConstant'; | 1 | import { BottomNavi, CommonConstants } from 'wdConstant'; |
| 2 | -import { LazyDataSource, Logger } from 'wdKit'; | 2 | +import { Logger } from 'wdKit'; |
| 3 | import { TopNavigationComponent } from './TopNavigationComponent'; | 3 | import { TopNavigationComponent } from './TopNavigationComponent'; |
| 4 | -import { PageComponent } from './PageComponent'; | ||
| 5 | import { BottomNavDTO } from '../repository/bean/BottomNavDTO'; | 4 | import { BottomNavDTO } from '../repository/bean/BottomNavDTO'; |
| 6 | -import { PageViewModel } from '../Index'; | ||
| 7 | import { UIUtils } from '../repository/UIUtils'; | 5 | import { UIUtils } from '../repository/UIUtils'; |
| 8 | import { MinePageComponent } from './MinePageComponent'; | 6 | import { MinePageComponent } from './MinePageComponent'; |
| 7 | +import PageViewModel from '../viewmodel/PageViewModel'; | ||
| 9 | 8 | ||
| 10 | const TAG = 'BottomNavigationComponent'; | 9 | const TAG = 'BottomNavigationComponent'; |
| 11 | 10 | ||
| @@ -33,9 +32,9 @@ export struct BottomNavigationComponent { | @@ -33,9 +32,9 @@ export struct BottomNavigationComponent { | ||
| 33 | async aboutToAppear() { | 32 | async aboutToAppear() { |
| 34 | Logger.info(TAG, `aboutToAppear currentNavIndex: ${this.currentNavIndex}`); | 33 | Logger.info(TAG, `aboutToAppear currentNavIndex: ${this.currentNavIndex}`); |
| 35 | let bottomNav = await PageViewModel.getBottomNavData() | 34 | let bottomNav = await PageViewModel.getBottomNavData() |
| 36 | - if (bottomNav) { | ||
| 37 | - Logger.info(TAG, `aboutToAppear, bottomNav.length: ${bottomNav.length}`); | ||
| 38 | - this.bottomNavList = bottomNav | 35 | + if (bottomNav && bottomNav.bottomNavList != null) { |
| 36 | + Logger.info(TAG, `aboutToAppear, bottomNav.length: ${bottomNav.bottomNavList.length}`); | ||
| 37 | + this.bottomNavList = bottomNav.bottomNavList | ||
| 39 | } | 38 | } |
| 40 | } | 39 | } |
| 41 | 40 |
| @@ -11,6 +11,10 @@ export class HttpUrlUtils { | @@ -11,6 +11,10 @@ export class HttpUrlUtils { | ||
| 11 | */ | 11 | */ |
| 12 | static readonly HOST: string = "https://pd-apis-uat.pdnews.cn"; | 12 | static readonly HOST: string = "https://pd-apis-uat.pdnews.cn"; |
| 13 | /** | 13 | /** |
| 14 | + * 启动接口(底导接口) | ||
| 15 | + */ | ||
| 16 | + static readonly BOTTOM_NAV_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/bottomNavGroup"; | ||
| 17 | + /** | ||
| 14 | * 展现comp接口 | 18 | * 展现comp接口 |
| 15 | */ | 19 | */ |
| 16 | static readonly COMP_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/compInfo"; | 20 | static readonly COMP_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/compInfo"; |
| @@ -46,6 +50,11 @@ export class HttpUrlUtils { | @@ -46,6 +50,11 @@ export class HttpUrlUtils { | ||
| 46 | return headers; | 50 | return headers; |
| 47 | } | 51 | } |
| 48 | 52 | ||
| 53 | + static getBottomNavGroupUrl() { | ||
| 54 | + // https: //pd-apis-uat.pdnews.cn/api/rmrb-bff-display-zh/display/zh/c/bottomNavGroup | ||
| 55 | + return this.HOST + this.BOTTOM_NAV_PATH; | ||
| 56 | + } | ||
| 57 | + | ||
| 49 | static getCompInfoUrl(pageId: string, groupId: string, channelId: string) { | 58 | static getCompInfoUrl(pageId: string, groupId: string, channelId: string) { |
| 50 | let url = this.HOST + this.COMP_PATH; | 59 | let url = this.HOST + this.COMP_PATH; |
| 51 | // TODO 暂定只请求第一页,后续对接分页加载,参数再调整 | 60 | // TODO 暂定只请求第一页,后续对接分页加载,参数再调整 |
| @@ -5,7 +5,8 @@ import HashMap from '@ohos.util.HashMap'; | @@ -5,7 +5,8 @@ import HashMap from '@ohos.util.HashMap'; | ||
| 5 | import { HttpUrlUtils } from '../network/HttpUrlUtils'; | 5 | import { HttpUrlUtils } from '../network/HttpUrlUtils'; |
| 6 | 6 | ||
| 7 | export class PageRepository { | 7 | export class PageRepository { |
| 8 | - static fetchNavigationDataApi(url: string) { | 8 | + static fetchNavigationDataApi() { |
| 9 | + let url = HttpUrlUtils.getBottomNavGroupUrl(); | ||
| 9 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | 10 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); |
| 10 | return WDHttp.get<ResponseDTO<NavigationBodyDTO>>(url, headers) | 11 | return WDHttp.get<ResponseDTO<NavigationBodyDTO>>(url, headers) |
| 11 | }; | 12 | }; |
| @@ -6,13 +6,15 @@ import { NavigationBodyDTO } from '../repository/bean/NavigationBodyDTO'; | @@ -6,13 +6,15 @@ import { NavigationBodyDTO } from '../repository/bean/NavigationBodyDTO'; | ||
| 6 | import { BottomNavDTO } from '../repository/bean/BottomNavDTO'; | 6 | import { BottomNavDTO } from '../repository/bean/BottomNavDTO'; |
| 7 | import { PageDTO } from '../repository/bean/PageDTO'; | 7 | import { PageDTO } from '../repository/bean/PageDTO'; |
| 8 | import { BaseViewModel } from './BaseViewModel'; | 8 | import { BaseViewModel } from './BaseViewModel'; |
| 9 | +import Router from '@system.router'; | ||
| 10 | +import router from '@ohos.router'; | ||
| 9 | 11 | ||
| 10 | const TAG = 'PageViewModel'; | 12 | const TAG = 'PageViewModel'; |
| 11 | /** | 13 | /** |
| 12 | * mock数据开关,默认关。 | 14 | * mock数据开关,默认关。 |
| 13 | * mock数据是本地json数据,可自行修改内容(‘entry\src\main\resources\rawfile\’目录) | 15 | * mock数据是本地json数据,可自行修改内容(‘entry\src\main\resources\rawfile\’目录) |
| 14 | */ | 16 | */ |
| 15 | -const mock_switch = false; | 17 | +const mock_switch = true; |
| 16 | 18 | ||
| 17 | /** | 19 | /** |
| 18 | * 处理返回后的数据 | 20 | * 处理返回后的数据 |
| @@ -27,36 +29,33 @@ export class PageViewModel extends BaseViewModel { | @@ -27,36 +29,33 @@ export class PageViewModel extends BaseViewModel { | ||
| 27 | * | 29 | * |
| 28 | * @return BottomNavBean[] Nav Data List | 30 | * @return BottomNavBean[] Nav Data List |
| 29 | */ | 31 | */ |
| 30 | - static async getBottomNavData(): Promise<BottomNavDTO[]> { | 32 | + async getBottomNavData(): Promise<NavigationBodyDTO> { |
| 31 | Logger.info(TAG, `getBottomNavData start`); | 33 | Logger.info(TAG, `getBottomNavData start`); |
| 34 | + if (mock_switch) { | ||
| 35 | + return this.getBottomNavDataMock(); | ||
| 36 | + } | ||
| 37 | + return this.getNavData(); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + async getBottomNavDataMock(): Promise<NavigationBodyDTO> { | ||
| 41 | + Logger.info(TAG, `getBottomNavDataMock start`); | ||
| 32 | let compRes: ResponseDTO<NavigationBodyDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<NavigationBodyDTO>>('bottom_nav.json'); | 42 | let compRes: ResponseDTO<NavigationBodyDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<NavigationBodyDTO>>('bottom_nav.json'); |
| 33 | - if (!compRes || !compRes.data || !compRes.data.bottomNavList) { | ||
| 34 | - Logger.info(TAG, `getBottomNavData compRes bottomNavList is empty`); | ||
| 35 | - return [] | 43 | + if (!compRes || !compRes.data) { |
| 44 | + Logger.info(TAG, `getBottomNavDataMock compRes bottomNavList is empty`); | ||
| 45 | + return null | ||
| 36 | } | 46 | } |
| 37 | - Logger.info(TAG, `getBottomNavData getResourcesJsonSync compRes : ${JSON.stringify(compRes)}`); | ||
| 38 | - return compRes.data.bottomNavList | 47 | + Logger.info(TAG, `getBottomNavDataMock getResourcesJsonSync compRes : ${JSON.stringify(compRes)}`); |
| 48 | + return compRes.data | ||
| 39 | } | 49 | } |
| 40 | 50 | ||
| 41 | - static getNavData(url: string): Promise<NavigationBodyDTO> { | 51 | + private getNavData(): Promise<NavigationBodyDTO> { |
| 42 | return new Promise<NavigationBodyDTO>((success, error) => { | 52 | return new Promise<NavigationBodyDTO>((success, error) => { |
| 43 | Logger.info(TAG, `getNavData start`); | 53 | Logger.info(TAG, `getNavData start`); |
| 44 | - PageRepository.fetchNavigationDataApi(url).then((navResDTO: ResponseDTO<NavigationBodyDTO>) => { | ||
| 45 | - if (!navResDTO) { | ||
| 46 | - Logger.error(TAG, 'getNavData then navResDTO is empty'); | ||
| 47 | - error('navResDTO is empty'); | ||
| 48 | - return | ||
| 49 | - } | ||
| 50 | - if (navResDTO.code != http.ResponseCode.OK) { | ||
| 51 | - Logger.error(TAG, `getNavData then code:${navResDTO.code}, message:${navResDTO.message}`); | ||
| 52 | - error('navResDTO Response Code is failure'); | ||
| 53 | - return | ||
| 54 | - } | ||
| 55 | - if (!navResDTO.data?.bottomNavList) { | ||
| 56 | - error('navResDTO list is empty'); | 54 | + PageRepository.fetchNavigationDataApi().then((navResDTO: ResponseDTO<NavigationBodyDTO>) => { |
| 55 | + if (this.isRespondsInvalid(navResDTO, 'getNavData')) { | ||
| 56 | + error("page data invalid"); | ||
| 57 | return | 57 | return |
| 58 | } | 58 | } |
| 59 | - // let navResStr = JSON.stringify(navResDTO); | ||
| 60 | Logger.info(TAG, "getNavData then,navResDTO.timeStamp:" + navResDTO.timestamp); | 59 | Logger.info(TAG, "getNavData then,navResDTO.timeStamp:" + navResDTO.timestamp); |
| 61 | let navigationBean = navResDTO.data | 60 | let navigationBean = navResDTO.data |
| 62 | success(navigationBean); | 61 | success(navigationBean); |
| @@ -72,7 +71,7 @@ export class PageViewModel extends BaseViewModel { | @@ -72,7 +71,7 @@ export class PageViewModel extends BaseViewModel { | ||
| 72 | * | 71 | * |
| 73 | * @return {GroupDTO} compRes.data | 72 | * @return {GroupDTO} compRes.data |
| 74 | */ | 73 | */ |
| 75 | - static async getPageData1(): Promise<PageDTO> { | 74 | + private async getPageData1(): Promise<PageDTO> { |
| 76 | let compRes: ResponseDTO<PageDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>('comp_list0.json'); | 75 | let compRes: ResponseDTO<PageDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>('comp_list0.json'); |
| 77 | if (!compRes || !compRes.data) { | 76 | if (!compRes || !compRes.data) { |
| 78 | Logger.info(TAG, `getCompList compRes is empty`); | 77 | Logger.info(TAG, `getCompList compRes is empty`); |
| @@ -86,19 +85,24 @@ export class PageViewModel extends BaseViewModel { | @@ -86,19 +85,24 @@ export class PageViewModel extends BaseViewModel { | ||
| 86 | * Get Group data. | 85 | * Get Group data. |
| 87 | * | 86 | * |
| 88 | * @return {GroupDTO} compRes.data | 87 | * @return {GroupDTO} compRes.data |
| 88 | + * @deprecated | ||
| 89 | */ | 89 | */ |
| 90 | - async getPageData2(): Promise<PageDTO> { | 90 | + private async getPageData2(): Promise<PageDTO> { |
| 91 | let compRes: ResponseDTO<PageDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>('comp_list2.json'); | 91 | let compRes: ResponseDTO<PageDTO> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<PageDTO>>('comp_list2.json'); |
| 92 | if (!compRes || !compRes.data) { | 92 | if (!compRes || !compRes.data) { |
| 93 | Logger.info(TAG, `getCompList compRes is empty`); | 93 | Logger.info(TAG, `getCompList compRes is empty`); |
| 94 | return {} as PageDTO | 94 | return {} as PageDTO |
| 95 | } | 95 | } |
| 96 | + // router.push('') | ||
| 96 | Logger.info(TAG, `getCompList getResourcesJson compRes : ${JSON.stringify(compRes)}`); | 97 | Logger.info(TAG, `getCompList getResourcesJson compRes : ${JSON.stringify(compRes)}`); |
| 97 | return compRes.data | 98 | return compRes.data |
| 98 | } | 99 | } |
| 99 | 100 | ||
| 100 | async getPageData(pageId: string, groupId: string, channelId: string): Promise<PageDTO> { | 101 | async getPageData(pageId: string, groupId: string, channelId: string): Promise<PageDTO> { |
| 101 | Logger.error(TAG, 'getPageData pageId: ' + pageId); | 102 | Logger.error(TAG, 'getPageData pageId: ' + pageId); |
| 103 | + if (mock_switch) { | ||
| 104 | + return this.getPageData1(); | ||
| 105 | + } | ||
| 102 | return new Promise<PageDTO>((success, error) => { | 106 | return new Promise<PageDTO>((success, error) => { |
| 103 | PageRepository.fetchPageData(pageId, groupId, channelId).then((resDTO: ResponseDTO<PageDTO>) => { | 107 | PageRepository.fetchPageData(pageId, groupId, channelId).then((resDTO: ResponseDTO<PageDTO>) => { |
| 104 | if (this.isRespondsInvalid(resDTO, 'getPageData')) { | 108 | if (this.isRespondsInvalid(resDTO, 'getPageData')) { |
| @@ -23,7 +23,7 @@ export class HttpRequest { | @@ -23,7 +23,7 @@ export class HttpRequest { | ||
| 23 | 23 | ||
| 24 | static get<T = any>(url: string, headers?: HashMap<string, string>): Promise<T> { | 24 | static get<T = any>(url: string, headers?: HashMap<string, string>): Promise<T> { |
| 25 | let requestHeaders: AxiosHeaders = new AxiosHeaders() | 25 | let requestHeaders: AxiosHeaders = new AxiosHeaders() |
| 26 | - headers.forEach((v, k) => { | 26 | + headers?.forEach((v, k) => { |
| 27 | requestHeaders.set(k, v); | 27 | requestHeaders.set(k, v); |
| 28 | }); | 28 | }); |
| 29 | let config: AxiosRequestConfig = { | 29 | let config: AxiosRequestConfig = { |
-
Please register or login to post a comment