Showing
3 changed files
with
76 additions
and
0 deletions
| @@ -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>() |
| @@ -78,6 +82,14 @@ export class HttpUrlUtils { | @@ -78,6 +82,14 @@ export class HttpUrlUtils { | ||
| 78 | return url; | 82 | return url; |
| 79 | } | 83 | } |
| 80 | 84 | ||
| 85 | + static getDetailInfoUrl(relId: string, contentId: string, relType: string) { | ||
| 86 | + let url = this.HOST + this.DETAIL_PATH; | ||
| 87 | + url = url + "?relId=" + relId | ||
| 88 | + + "&contentId=" + contentId | ||
| 89 | + + "&relType=" + relType; | ||
| 90 | + // Logger.debug("TAG", 'getCompInfoUrl url: '+url); | ||
| 91 | + return url; | ||
| 92 | + } | ||
| 81 | 93 | ||
| 82 | private static getCity() { | 94 | private static getCity() { |
| 83 | // TODO 对接定位 | 95 | // TODO 对接定位 |
| @@ -17,4 +17,10 @@ export class PageRepository { | @@ -17,4 +17,10 @@ export class PageRepository { | ||
| 17 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | 17 | let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); |
| 18 | return WDHttp.get<ResponseDTO<PageDTO>>(url, headers) | 18 | return WDHttp.get<ResponseDTO<PageDTO>>(url, headers) |
| 19 | }; | 19 | }; |
| 20 | + | ||
| 21 | + static fetchDetailData(relId: string, contentId: string, relType: string) { | ||
| 22 | + let url = HttpUrlUtils.getDetailInfoUrl(relId, contentId, relType) | ||
| 23 | + let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders(); | ||
| 24 | + return WDHttp.get<ResponseDTO<string>>(url, headers) | ||
| 25 | + }; | ||
| 20 | } | 26 | } |
| 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; |
-
Please register or login to post a comment