MinePageDatasModel.ets
5.39 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import MinePagePersonalFunctionsItem from '../viewmodel/MinePagePersonalFunctionsItem'
import MinePageCreatorFunctionsItem from '../viewmodel/MinePageCreatorFunctionsItem'
import MinePageMoreFunctionModel from '../viewmodel/MinePageMoreFunctionModel';
import HashMap from '@ohos.util.HashMap';
import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork';
import { MineAppointmentListItem } from '../viewmodel/MineAppointmentListItem';
import { Logger, ResourcesUtils } from 'wdKit';
const TAG = "MinePageDatasModel"
/**
* 我的页面 所有数据 获取封装类
*/
class MinePageDatasModel{
private static instance: MinePageDatasModel;
personalData:MinePagePersonalFunctionsItem[] = []
creatorData:MinePageCreatorFunctionsItem[] = []
moreData:MinePageMoreFunctionModel[] = []
private constructor() { }
/**
* 单例模式
* @returns
*/
public static getInstance(): MinePageDatasModel {
if (!MinePageDatasModel.instance) {
MinePageDatasModel.instance = new MinePageDatasModel();
}
return MinePageDatasModel.instance;
}
/**
* 评论 关注 收藏 等7个数据
* 包含名字和图标
*/
getPersonalFunctionsData():MinePagePersonalFunctionsItem[]{
if(this.personalData.length === 7){
return this.personalData
}
this.personalData.push(new MinePagePersonalFunctionsItem("评论",$r('app.media.mine_comment_icon')))
this.personalData.push(new MinePagePersonalFunctionsItem("关注",$r('app.media.mine_order_icon')))
this.personalData.push(new MinePagePersonalFunctionsItem("收藏",$r('app.media.mine_collect_icon')))
this.personalData.push(new MinePagePersonalFunctionsItem("历史",$r('app.media.mine_history_icon')))
this.personalData.push(new MinePagePersonalFunctionsItem("消息",$r('app.media.mine_msg_icon')))
this.personalData.push(new MinePagePersonalFunctionsItem("留言板",$r('app.media.mine_msgboard_icon')))
this.personalData.push(new MinePagePersonalFunctionsItem("预约",$r('app.media.mine_order_icon')))
return this.personalData
}
/**
* 发布文章 发布视频 等4个数据
* 包含名字和图标
*/
getCreatorFunctionsData():MinePageCreatorFunctionsItem[]{
if(this.creatorData.length === 4){
return this.creatorData
}
this.creatorData.push(new MinePageCreatorFunctionsItem("发布文章",$r('app.media.mine_active_create_article')))
this.creatorData.push(new MinePageCreatorFunctionsItem("发布视频",$r('app.media.mine_active_create_video')))
this.creatorData.push(new MinePageCreatorFunctionsItem("发布动态",$r('app.media.mine_active_create_video')))
this.creatorData.push(new MinePageCreatorFunctionsItem("发布图集",$r('app.media.mine_active_create_pics')))
return this.creatorData
}
/**
* 扫一扫 我的奖品 等5个数据
* 包含名字和图标
*/
getMoreFunctionsData():MinePageCreatorFunctionsItem[]{
if(this.moreData.length === 5){
return this.moreData
}
this.moreData.push(new MinePageMoreFunctionModel("扫一扫",$r('app.media.mine_scan')))
this.moreData.push(new MinePageMoreFunctionModel("我的奖品",$r('app.media.mine_mygift')))
this.moreData.push(new MinePageMoreFunctionModel("意见反馈",$r('app.media.mine_suggest')))
this.moreData.push(new MinePageMoreFunctionModel("设置",$r('app.media.mine_setting')))
this.moreData.push(new MinePageMoreFunctionModel("关于",$r('app.media.mine_about')))
return this.moreData
}
fetchAppointmentListData(pageSize:string,pageNum:string) {
let url = HttpUrlUtils.getAppointmentListDataUrl()+ `?pageSize=${pageSize}&pageNum=${pageNum}`
let headers: HashMap<string, string> = HttpUrlUtils.getYcgCommonHeaders();
return WDHttp.get<ResponseDTO<MineAppointmentListItem>>(url, headers)
};
getAppointmentListData(pageSize:string,pageNum:string,context: Context): Promise<MineAppointmentListItem> {
return new Promise<MineAppointmentListItem>((success, error) => {
Logger.info(TAG, `getAppointmentList start`);
this.fetchAppointmentListData(pageSize,pageNum).then((navResDTO: ResponseDTO<MineAppointmentListItem>) => {
if (!navResDTO) {
error("page data invalid");
success(this.getAppointmentListDataLocal(context))
return
}
Logger.info(TAG, "getAppointmentList then,AppointmentResDTO.timeStamp:" + navResDTO.timestamp);
let navigationBean = navResDTO.data as MineAppointmentListItem
success(navigationBean);
}).catch((err: Error) => {
Logger.error(TAG, `fetchAppointmentListDataApi catch, error.name : ${err.name}, error.message:${err.message}`);
// error(err);
success(this.getAppointmentListDataLocal(context))
})
})
}
async getAppointmentListDataLocal(context: Context): Promise<MineAppointmentListItem> {
Logger.info(TAG, `getBottomNavDataMock start`);
let compRes: ResponseDTO<MineAppointmentListItem> | null = await ResourcesUtils.getResourcesJson<ResponseDTO<MineAppointmentListItem>>(context,'appointment_list_data.json' );
if (!compRes || !compRes.data) {
Logger.info(TAG, `getAppointmentListDataLocal compRes is empty`);
return new MineAppointmentListItem()
}
Logger.info(TAG, `getAppointmentListDataLocal getResourcesJsonSync compRes : ${JSON.stringify(compRes)}`);
return compRes.data
}
}
const minePageDatasModel = MinePageDatasModel.getInstance()
export default minePageDatasModel as MinePageDatasModel