zhangbo1_wd

新增详情接口合并到4.0

@@ -26,6 +26,15 @@ export class PageRepository { @@ -26,6 +26,15 @@ export class PageRepository {
26 return url; 26 return url;
27 } 27 }
28 28
  29 + static getDetailInfoUrl(relId: string, contentId: string, relType: string) {
  30 + let url = this.HOST + this.DETAIL_PATH;
  31 + url = url + "?relId=" + relId
  32 + + "&contentId=" + contentId
  33 + + "&relType=" + relType;
  34 + // Logger.debug("TAG", 'getCompInfoUrl url: '+url);
  35 + return url;
  36 + }
  37 +
29 static fetchNavigationDataApi() { 38 static fetchNavigationDataApi() {
30 let url = PageRepository.getBottomNavGroupUrl(); 39 let url = PageRepository.getBottomNavGroupUrl();
31 let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); 40 let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
@@ -37,4 +46,10 @@ export class PageRepository { @@ -37,4 +46,10 @@ export class PageRepository {
37 let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); 46 let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
38 return WDHttp.get<ResponseDTO<PageDTO>>(url, headers) 47 return WDHttp.get<ResponseDTO<PageDTO>>(url, headers)
39 }; 48 };
  49 +
  50 + static fetchDetailData(relId: string, contentId: string, relType: string) {
  51 + let url = PageRepository.getDetailInfoUrl(relId, contentId, relType)
  52 + let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
  53 + return WDHttp.get<ResponseDTO<string>>(url, headers)
  54 + };
40 } 55 }
  1 +import { Logger, StringUtils } from 'wdKit';
  2 +import { ResponseDTO, } from 'wdNetwork';
  3 +import { ContentDetailDTO } from '../repository/bean/ContentDetailDTO';
  4 +import { PageRepository } from '../repository/PageRepository';
  5 +import { BaseViewModel } from './BaseViewModel';
  6 +
  7 +const TAG = 'DetailViewModel';
  8 +
  9 +/**
  10 + * 处理返回后的数据
  11 + */
  12 +export class DetailViewModel extends BaseViewModel {
  13 + getLogTag() {
  14 + return TAG;
  15 + }
  16 +
  17 + /**
  18 + * 获取详情数据.
  19 + * 例:https://pd-apis-uat.pdnews.cn/api/rmrb-bff-display-zh/content/zh/c/content/detail?relId=500000008738&contentId=30001373964&relType=1
  20 + * @return {string} resDTO.data
  21 + */
  22 + async getDetailPageData(relId: string, contentId: string, relType: string): Promise<string> {
  23 + Logger.debug(TAG, 'getDetailPageData contentId: ' + contentId);
  24 + return new Promise<string>((success, error) => {
  25 + PageRepository.fetchDetailData(relId, contentId, relType)
  26 + .then((resDTO: ResponseDTO<string>) => {
  27 + if (this.isRespondsInvalid(resDTO, 'getDetailPageData')) {
  28 + error("detail data invalid");
  29 + return
  30 + }
  31 + Logger.info(TAG, "getDetailPageData then,resDTO.timeStamp:" + resDTO.timestamp);
  32 + success(JSON.stringify(resDTO.data));
  33 + })
  34 + .catch((err: Error) => {
  35 + Logger.error(TAG, `getDetailPageData catch, error.name : ${err.name}, error.message:${err.message}`);
  36 + error(err);
  37 + })
  38 + })
  39 + }
  40 +
  41 + private dataTranslate(json: string): ContentDetailDTO {
  42 + if (StringUtils.isEmpty(json)) {
  43 + return null;
  44 + }
  45 + try {
  46 + let data: ContentDetailDTO = JSON.parse(json)
  47 + return data;
  48 + } catch (err) {
  49 + // json解析异常
  50 + Logger.error(TAG, `dataTranslate catch parse failed.: ${err}`);
  51 + }
  52 + return null;
  53 + }
  54 +}
  55 +
  56 +let detailViewModel = new DetailViewModel();
  57 +
  58 +export default detailViewModel as DetailViewModel;
@@ -18,6 +18,10 @@ export class HttpUrlUtils { @@ -18,6 +18,10 @@ export class HttpUrlUtils {
18 * 展现comp接口 18 * 展现comp接口
19 */ 19 */
20 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";
  21 + /**
  22 + * 详情页面详情接口
  23 + */
  24 + static readonly DETAIL_PATH: string = "/api/rmrb-bff-display-zh/content/zh/c/content/detail";
21 25
22 static getCommonHeaders(): HashMap<string, string> { 26 static getCommonHeaders(): HashMap<string, string> {
23 let headers: HashMap<string, string> = new HashMap<string, string>() 27 let headers: HashMap<string, string> = new HashMap<string, string>()