liujian1_wd

编排底层能力

@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 "wdConstant": "file:../wdConstant", 10 "wdConstant": "file:../wdConstant",
11 "wdKit": "file:../wdKit", 11 "wdKit": "file:../wdKit",
12 "wdBean": "file:../wdBean", 12 "wdBean": "file:../wdBean",
  13 + "wdNetwork": "file:../wdNetwork",
13 "wdRouter": "file:../wdRouter" 14 "wdRouter": "file:../wdRouter"
14 } 15 }
15 } 16 }
  1 +import { GroupDTO, NavigationBody } from 'wdBean';
  2 +import { WDHttp } from 'wdNetwork';
  3 +
  4 +export class PageRepository {
  5 +
  6 + static fetchNavigationDataApi(url: string) {
  7 + return WDHttp.Request.get<WDHttp.ResponseDTO<NavigationBody>>(url)
  8 + };
  9 +
  10 + static fetchPageData(url: string) {
  11 + return WDHttp.Request.get<WDHttp.ResponseDTO<GroupDTO>>(url)
  12 + };
  13 +
  14 +}
1 import { BottomNavBean, GroupDTO, NavigationBody } from 'wdBean'; 1 import { BottomNavBean, GroupDTO, NavigationBody } from 'wdBean';
2 import { Logger, ResourcesUtils } from 'wdKit'; 2 import { Logger, ResourcesUtils } from 'wdKit';
3 -import { ResponseDTO } from 'wdNetwork'; 3 +import { ResponseDTO, WDHttp } from 'wdNetwork';
  4 +import { PageRepository } from '../repository/PageRepository';
  5 +import http from '@ohos.net.http';
  6 +import { BusinessError } from '@ohos.base';
4 7
5 const TAG = 'PageViewModel'; 8 const TAG = 'PageViewModel';
6 9
@@ -24,6 +27,35 @@ export class PageViewModel { @@ -24,6 +27,35 @@ export class PageViewModel {
24 return compRes.data.bottomNavList 27 return compRes.data.bottomNavList
25 } 28 }
26 29
  30 + static getNavData(url: string): Promise<NavigationBody> {
  31 + return new Promise<NavigationBody>((success, error) => {
  32 + Logger.info(TAG, `getNavData start`);
  33 + PageRepository.fetchNavigationDataApi(url).then((navResDTO: WDHttp.ResponseDTO<NavigationBody>) => {
  34 + if (!navResDTO) {
  35 + Logger.error(TAG, 'getNavData then navResDTO is empty');
  36 + error('navResDTO is empty');
  37 + return
  38 + }
  39 + if (navResDTO.code != http.ResponseCode.OK) {
  40 + Logger.error(TAG, `getNavData then code:${navResDTO.code}, message:${navResDTO.message}`);
  41 + error('navResDTO Response Code is failure');
  42 + return
  43 + }
  44 + if (!navResDTO.body?.bottomNavList) {
  45 + error('navResDTO list is empty');
  46 + return
  47 + }
  48 + // let navResStr = JSON.stringify(navResDTO);
  49 + Logger.info(TAG, "getNavData then,navResDTO.timeStamp:" + navResDTO.timeStamp);
  50 + let navigationBean = navResDTO.body
  51 + success(navigationBean);
  52 + }).catch((err: BusinessError) => {
  53 + Logger.error(TAG, `fetchNavigationDataApi catch, error.code : ${err.code}, error.message:${err.message}`);
  54 + error(err);
  55 + })
  56 + })
  57 + }
  58 +
27 /** 59 /**
28 * Get Group data. 60 * Get Group data.
29 * 61 *
@@ -38,8 +70,33 @@ export class PageViewModel { @@ -38,8 +70,33 @@ export class PageViewModel {
38 Logger.info(TAG, `getCompList getResourcesJson compRes : ${JSON.stringify(compRes)}`); 70 Logger.info(TAG, `getCompList getResourcesJson compRes : ${JSON.stringify(compRes)}`);
39 return compRes.data 71 return compRes.data
40 } 72 }
  73 +
  74 +
  75 + static getPageData(url: string): Promise<GroupDTO> {
  76 + return new Promise<GroupDTO>((success, error) => {
  77 + PageRepository.fetchPageData(url).then((resDTO: WDHttp.ResponseDTO<GroupDTO>) => {
  78 + if (!resDTO) {
  79 + Logger.error(TAG, 'getPageData then resDTO is empty');
  80 + error("page data is empty");
  81 + return
  82 + }
  83 + if (resDTO.code != http.ResponseCode.OK || !resDTO.body) {
  84 + Logger.error(TAG, `getPageData then code:${resDTO.code}, message:${resDTO.message}`);
  85 + error(`get page data error code:${resDTO.code}, message:${resDTO.message}`);
  86 + return
  87 + }
  88 + Logger.info(TAG, "getPageData then,resDTO.timeStamp:" + resDTO.timeStamp);
  89 + success(resDTO.body);
  90 + }).catch((err: BusinessError) => {
  91 + Logger.error(TAG, `getPageData catch, error.code : ${err.code}, error.message:${err.message}`);
  92 + error(err);
  93 + })
  94 + })
  95 + }
41 } 96 }
42 97
  98 +
  99 +
43 let pageViewModel = new PageViewModel(); 100 let pageViewModel = new PageViewModel();
44 101
45 export default pageViewModel as PageViewModel; 102 export default pageViewModel as PageViewModel;