MyCollectionViewModel.ets
1.78 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
import { MyCollectionListModel } from '../model/MyCollectionModel';
import HashMap from '@ohos.util.HashMap';
import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
import { Logger } from 'wdKit';
const TAG = "MyCollectionViewModel"
class MyCollectionViewModel {
private static instance:MyCollectionViewModel
/**
* 单例模式
* @returns
*/
public static getInstance(): MyCollectionViewModel {
if (!MyCollectionViewModel.instance) {
MyCollectionViewModel.instance = new MyCollectionViewModel();
}
return MyCollectionViewModel.instance;
}
BaseGetRequest(type:number,tagId:string,pageNum:string){
let url = HttpUrlUtils.getMyCollectionListDataUrl()+ `?type=${type}&operateTag=${1}&pageSize=${20}&pageNum=${pageNum}`
if (tagId.length > 0) {
url = url + `&tagId=${tagId}`
}
let headers: HashMap<string, string> = HttpUrlUtils.getCommonHeaders()
return WDHttp.get<ResponseDTO<MyCollectionListModel>>(url, headers)
}
//Type 1 收藏 2 浏览历史
//tagId 收藏界面 标签筛选
fetchMyCollectList(type:number,tagId:string,pageNum:string):Promise<MyCollectionListModel>{
return new Promise<MyCollectionListModel>((success,error) => {
this.BaseGetRequest(type,tagId,pageNum).then((navResDTO: ResponseDTO<MyCollectionListModel>) => {
if (navResDTO) {
let listData = navResDTO.data as MyCollectionListModel
success(listData)
}else{
Logger.info(TAG, "getAppointmentList then,AppointmentResDTO.timeStamp:" + navResDTO.timestamp);
error("page data invalid");
}
}).catch((err: Error) => {
Logger.error(TAG, `fetchAppointmentListDataApi catch, error.name : ${err.name}, error.message:${err.message}`);
error("page data invalid");
})
})
}
}