PeopleShipMainViewModel.ets
4.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
import { Logger } from 'wdKit';
import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
import HashMap from '@ohos.util.HashMap';
import {
RmhRecommendDTO,
PeopleShipContentListDTO,
AttentionBatchDTO
} from 'wdBean';
const TAG = 'PeopleShipMainViewModel'
export class PeopleShipMainViewModel {
/*人民号号主推荐*/
static fetchPeopleRemRecommendData() {
let url = HttpUrlUtils.getRmhRecommendUrl()
let bean: Record<string, string> = {};
return WDHttp.post<ResponseDTO<RmhRecommendDTO[]>>(url, bean)
}
static async getPeopleRemRecommendInfo(): Promise<RmhRecommendDTO[]> {
return new Promise<RmhRecommendDTO[]>((success, error) => {
Logger.debug(TAG, `getMorningEveningCompInfo pageInfo start`);
PeopleShipMainViewModel.fetchPeopleRemRecommendData()
.then((resDTO: ResponseDTO<RmhRecommendDTO[]>) => {
if (!resDTO || !resDTO.data) {
Logger.error(TAG, 'getPeopleRemRecommendInfo then navResDTO is empty');
error('resDTO is empty');
return
}
if (resDTO.code != 0) {
Logger.error(TAG, `getPeopleRemRecommendInfo then code:${resDTO.code}, message:${resDTO.message}`);
error('resDTO Response Code is failure');
return
}
Logger.debug(TAG, "getPeopleRemRecommendInfo then,navResDTO.timestamp:" + resDTO.timestamp);
success(resDTO.data);
})
.catch((err: Error) => {
Logger.error(TAG, `getPeopleRemRecommendInfo catch, error.name : ${err.name}, error.message:${err.message}`);
error(err);
})
})
}
/*关注号主发布内容接口*/
static fetchAttentionContentListData(pageNum: number, pageSize: number, time: string) {
let url = HttpUrlUtils.getAttentionContentListUrl()
let params: Record<string, Object> = {};
params['pageNum'] = pageNum
params['pageSize'] = pageSize
params['time'] = time
return WDHttp.post<ResponseDTO<PeopleShipContentListDTO>>(url, params)
}
static async getAttentionContentListInfo(pageNum:number, pageSize: number, time: string): Promise<PeopleShipContentListDTO> {
return new Promise<PeopleShipContentListDTO>((success, error) => {
Logger.debug(TAG, `getAttentionContentListInfo pageInfo start`);
PeopleShipMainViewModel.fetchAttentionContentListData(pageNum, pageSize, time)
.then((resDTO: ResponseDTO<PeopleShipContentListDTO>) => {
if (!resDTO || !resDTO.data) {
Logger.error(TAG, 'getAttentionContentListInfo then navResDTO is empty');
error('resDTO is empty');
return
}
if (resDTO.code != 0) {
Logger.error(TAG, `getAttentionContentListInfo then code:${resDTO.code}, message:${resDTO.message}`);
error('resDTO Response Code is failure');
return
}
Logger.debug(TAG, "getAttentionContentListInfo then,navResDTO.timestamp:" + resDTO.timestamp);
success(resDTO.data);
})
.catch((err: Error) => {
Logger.error(TAG, `getAttentionContentListInfo catch, error.name : ${err.name}, error.message:${err.message}`);
error(err);
})
})
}
/*一键关注接口*/
static fetchAttentionBatchData(params: AttentionBatchDTO) {
let url = HttpUrlUtils.getAttentionBatchUrl()
return WDHttp.post<ResponseDTO>(url, params)
}
static async getAttentionBatchInfo(params: AttentionBatchDTO): Promise<ResponseDTO> {
return new Promise<ResponseDTO>((success, error) => {
Logger.debug(TAG, `getAttentionBatchInfo pageInfo start`);
PeopleShipMainViewModel.fetchAttentionBatchData(params)
.then((resDTO: ResponseDTO) => {
if (!resDTO || resDTO.code != 0) {
error(resDTO.message)
return
}
Logger.debug(TAG, "getAttentionBatchInfo then,navResDTO.timestamp:" + resDTO.timestamp);
success(resDTO);
})
.catch((err: Error) => {
Logger.error(TAG, `getAttentionBatchInfo catch, error.name : ${err.name}, error.message:${err.message}`);
error(err);
})
})
}
}