Toggle navigation
Toggle navigation
This project
Loading...
Sign in
developOne
/
harmonyPool
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
zhangbo1_wd
2024-01-31 11:11:52 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
16f3631faa2d92958b86512333a21d6e9feac072
16f3631f
1 parent
ac0eedcb
新增详情接口请求
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
76 additions
and
0 deletions
PeopleDaily_Harmony/wdComponent/src/main/ets/network/HttpUrlUtils.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/repository/PageRepository.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/viewmodel/DetailViewModel.ets
PeopleDaily_Harmony/wdComponent/src/main/ets/network/HttpUrlUtils.ets
View file @
16f3631
...
...
@@ -18,6 +18,10 @@ export class HttpUrlUtils {
* 展现comp接口
*/
static readonly COMP_PATH: string = "/api/rmrb-bff-display-zh/display/zh/c/compInfo";
/**
* 详情页面详情接口
*/
static readonly DETAIL_PATH: string = "/api/rmrb-bff-display-zh/content/zh/c/content/detail";
static getCommonHeaders(): HashMap<string, string> {
let headers: HashMap<string, string> = new HashMap<string, string>()
...
...
@@ -78,6 +82,14 @@ export class HttpUrlUtils {
return url;
}
static getDetailInfoUrl(relId: string, contentId: string, relType: string) {
let url = this.HOST + this.DETAIL_PATH;
url = url + "?relId=" + relId
+ "&contentId=" + contentId
+ "&relType=" + relType;
// Logger.debug("TAG", 'getCompInfoUrl url: '+url);
return url;
}
private static getCity() {
// TODO 对接定位
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/repository/PageRepository.ets
View file @
16f3631
...
...
@@ -17,4 +17,10 @@ export class PageRepository {
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return WDHttp.get<ResponseDTO<PageDTO>>(url, headers)
};
static fetchDetailData(relId: string, contentId: string, relType: string) {
let url = HttpUrlUtils.getDetailInfoUrl(relId, contentId, relType)
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders();
return WDHttp.get<ResponseDTO<string>>(url, headers)
};
}
\ No newline at end of file
...
...
PeopleDaily_Harmony/wdComponent/src/main/ets/viewmodel/DetailViewModel.ets
0 → 100644
View file @
16f3631
import { Logger, StringUtils } from 'wdKit';
import { ResponseDTO, } from 'wdNetwork';
import { ContentDetailDTO } from '../repository/bean/ContentDetailDTO';
import { PageRepository } from '../repository/PageRepository';
import { BaseViewModel } from './BaseViewModel';
const TAG = 'DetailViewModel';
/**
* 处理返回后的数据
*/
export class DetailViewModel extends BaseViewModel {
getLogTag() {
return TAG;
}
/**
* 获取详情数据.
* 例:https://pd-apis-uat.pdnews.cn/api/rmrb-bff-display-zh/content/zh/c/content/detail?relId=500000008738&contentId=30001373964&relType=1
* @return {string} resDTO.data
*/
async getDetailPageData(relId: string, contentId: string, relType: string): Promise<string> {
Logger.debug(TAG, 'getDetailPageData contentId: ' + contentId);
return new Promise<string>((success, error) => {
PageRepository.fetchDetailData(relId, contentId, relType)
.then((resDTO: ResponseDTO<string>) => {
if (this.isRespondsInvalid(resDTO, 'getDetailPageData')) {
error("detail data invalid");
return
}
Logger.info(TAG, "getDetailPageData then,resDTO.timeStamp:" + resDTO.timestamp);
success(JSON.stringify(resDTO.data));
})
.catch((err: Error) => {
Logger.error(TAG, `getDetailPageData catch, error.name : ${err.name}, error.message:${err.message}`);
error(err);
})
})
}
private dataTranslate(json: string): ContentDetailDTO {
if (StringUtils.isEmpty(json)) {
return null;
}
try {
let data: ContentDetailDTO = JSON.parse(json)
return data;
} catch (err) {
// json解析异常
Logger.error(TAG, `dataTranslate catch parse failed.: ${err}`);
}
return null;
}
}
let detailViewModel = new DetailViewModel();
export default detailViewModel as DetailViewModel;
\ No newline at end of file
...
...
Please
register
or
login
to post a comment