LayoutService.ets
4.96 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
128
129
130
131
132
133
134
135
136
137
138
/**
* 用于请求乐高数据,对外提供服务。
*/
import { PageDTO } from '../bean/PageDTO';
import { LayoutCallback } from './LayoutCallback';
import {Logger} from 'wdKit';
import { WDHttp } from 'wdNetwork';
import http from '@ohos.net.http';
import { BusinessError } from '@ohos.base';
import { CompDTO } from '../bean/CompDTO';
import { CompDataDTO } from '../bean/CompDataDTO';
import { GroupDataDTO } from '../bean/GroupDataDTO';
import { StaticPageRequest } from '../request/StaticPageRequest';
import { StaticGroupRequest } from '../request/StaticGroupRequest';
import { CompRequest } from '../request/CompRequest';
export class LayoutService {
static readonly TAG: string = 'LayoutService';
/**
* 获取Page数据
* @param pageId Page ID
* @param isRefresh 是否为刷新
* @param callback 回调
*/
public getPage(pageId: string, isRefresh: boolean, callback: LayoutCallback<PageDTO>) {
// TODO: 调用StaticPageRequest请求数据
StaticPageRequest.fetch(pageId).then((resDTO: WDHttp.ResponseDTO<PageDTO>) => {
if (!resDTO) {
Logger.error(LayoutService.TAG, 'then pageResDTO is empty');
if (callback) {
callback.onFailed(WDHttp.ErrorCode.FAILED, 'Empty response');
}
return
}
if (resDTO.code != http.ResponseCode.OK || !resDTO.body) {
Logger.error(LayoutService.TAG, `then code:${resDTO.code}, message:${resDTO.message}`);
if (callback) {
callback.onFailed(resDTO.code, resDTO.message)
}
return
}
Logger.info(LayoutService.TAG, "then,resDTO.timeStamp:" + resDTO.timeStamp);
if (callback) {
callback.onSuccess(resDTO.body);
}
}).catch((error: BusinessError) => {
Logger.error(LayoutService.TAG, `getPage catch, error.code : ${error.code}, error.message:${error.message}`);
if (callback) {
callback.onFailed(WDHttp.ErrorCode.FAILED, error.message);
}
})
}
/**
* 获取Group数据
* @param pageId Page ID
* @param groupId Group ID
* @param isRefresh 是否为刷新
* @param callback 回调
*/
public getGroup(pageId: string, groupId: string, isRefresh: boolean, callback: LayoutCallback<GroupDataDTO>) {
// TODO: 调用StaticGroupRequest请求数据
StaticGroupRequest.fetch(pageId, groupId).then((resDTO: WDHttp.ResponseDTO<GroupDataDTO>) => {
if (!resDTO) {
Logger.error(LayoutService.TAG, 'getGroup then resDTO is empty');
if (callback) {
callback.onFailed(WDHttp.ErrorCode.FAILED, 'Empty response');
}
return
}
if (resDTO.code != http.ResponseCode.OK || !resDTO.body) {
Logger.error(LayoutService.TAG, `getGroup then code:${resDTO.code}, message:${resDTO.message}`);
if (callback) {
callback.onFailed(resDTO.code, resDTO.message)
}
return
}
Logger.info(LayoutService.TAG, "getGroup then,resDTO.timeStamp:" + resDTO.timeStamp);
if (callback) {
callback.onSuccess(resDTO.body);
}
}).catch((error: BusinessError) => {
Logger.error(LayoutService.TAG, `getGroup catch, error.code : ${error.code}, error.message:${error.message}`);
if (callback) {
callback.onFailed(WDHttp.ErrorCode.FAILED, error.message);
}
})
}
/**
* 获取Comp数据
* @param pageId Page ID
* @param groupId Group ID
* @param compId Comp ID
* @param isRefresh 是否为刷新
* @param callback 回调
*/
public getComp(pageId: string, groupId: string, compId: string, isRefresh: boolean, callback: LayoutCallback<CompDataDTO>) {
// TODO: 调用CompDataRequest请求数据
CompRequest.fetch(pageId, groupId, compId, -1, 10, isRefresh).then((resDTO: WDHttp.ResponseDTO<CompDataDTO>) => {
if (!resDTO) {
Logger.error(LayoutService.TAG, 'getComp then resDTO is empty');
if (callback) {
callback.onFailed(WDHttp.ErrorCode.FAILED, 'Empty response');
}
return
}
if (resDTO.code != http.ResponseCode.OK || !resDTO.body) {
Logger.error(LayoutService.TAG, `getComp then code:${resDTO.code}, message:${resDTO.message}`);
if (callback) {
callback.onFailed(resDTO.code, resDTO.message)
}
return
}
Logger.info(LayoutService.TAG, "getComp then,resDTO.timeStamp:" + resDTO.timeStamp);
if (callback) {
callback.onSuccess(resDTO.body);
}
}).catch((error: BusinessError) => {
Logger.error(LayoutService.TAG, `getComp catch, error.code : ${error.code}, error.message:${error.message}`);
if (callback) {
callback.onFailed(WDHttp.ErrorCode.FAILED, error.message);
}
})
}
/**
* 获取动态Group数据
* @param pageId Page ID
* @param groupId Group ID
* @param isRefresh 是否为刷新
* @param callback 回调
*/
public getDynamicGroup(pageId: string, groupId: string, isRefresh: boolean, callback: LayoutCallback<CompDTO>) {
// TODO: 调用DynamicGroupRequest请求数据
}
}