@cc-component/cc-core 1.8.8 → 1.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -132,6 +132,7 @@ export class App {
|
|
|
132
132
|
static OnProgess(param: { open: (param: ISceneParam, finish: () => void) => void, close: (param: ISceneParam) => void, progess: (param: ISceneParam, progress: number, time?: number) => void }) { App.gui.progess = param; }
|
|
133
133
|
static OnWindow(param: { willOpen: (comp: IBundleConfig) => void, open: (comp: IBundleConfig) => void, willClose: (comp: IBundleConfig) => void, close: (comp: IBundleConfig) => void }) { App.gui.window = param; }
|
|
134
134
|
static async Requst<T>(config: IHttpConfig, params?: any, ext?: IExtData): Promise<{ code: number, data: T, msg: string }> { return App.http.Requst<T>(config, params, ext); }
|
|
135
|
+
static OnReadyState<T>(param: { error: (xhr: XMLHttpRequest, ret: HttpReturn<T>) => void }): void { App.http.OnReadyState<T>(param); }
|
|
135
136
|
/**重置网络配置 */
|
|
136
137
|
static ResetHttpServer(config: EnvironmentConfig) {
|
|
137
138
|
let httpServer = config.httpServer!;
|
|
@@ -62,6 +62,9 @@ declare global {
|
|
|
62
62
|
/**=====================================✅✅Http请求======================= */
|
|
63
63
|
/**网络接口 */
|
|
64
64
|
function Requst<T>(config: IHttpConfig, params?: any, ext?: { is_show_alert?: boolean }): Promise<{ code: number, data: T, msg: string }>;
|
|
65
|
+
/**监听网络失败时数据处理 */
|
|
66
|
+
function OnReadyState(param: { error: (xhr: XMLHttpRequest, ret: HttpReturn<any>) => void }): void;
|
|
67
|
+
|
|
65
68
|
/**重置网络配置 */
|
|
66
69
|
function ResetHttpServer(config: EnvironmentConfig)
|
|
67
70
|
/**=====================================✅✅消息发送======================= */
|
|
@@ -68,6 +68,18 @@ export class HttpManager {
|
|
|
68
68
|
timeout: number = 10000;
|
|
69
69
|
/**内部使用 */
|
|
70
70
|
param: any;
|
|
71
|
+
|
|
72
|
+
/** 自定义请求头信息 */
|
|
73
|
+
public headers: Map<string, string> = new Map<string, string>();
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 添加自定义请求头信息
|
|
77
|
+
* @param name 信息名
|
|
78
|
+
* @param value 信息值
|
|
79
|
+
*/
|
|
80
|
+
addHeader(name: string, value: string) {
|
|
81
|
+
this.headers.set(name, value);
|
|
82
|
+
}
|
|
71
83
|
/**
|
|
72
84
|
* GET请求获取文本格式数据
|
|
73
85
|
* @param name 协议名
|
|
@@ -75,9 +87,8 @@ export class HttpManager {
|
|
|
75
87
|
* @returns HTTP请求返回值
|
|
76
88
|
*/
|
|
77
89
|
getText(name: string, params: BodyInit | null = null): Promise<HttpReturn<any>> {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
return this.request(name, params, HttpMethod.GET, HttpResponseType.Text, headers);
|
|
90
|
+
this.headers.set(HeaderName, HeaderValueText);
|
|
91
|
+
return this.request(name, params, HttpMethod.GET, HttpResponseType.Text, this.headers);
|
|
81
92
|
}
|
|
82
93
|
|
|
83
94
|
/**
|
|
@@ -87,9 +98,8 @@ export class HttpManager {
|
|
|
87
98
|
* @returns HTTP请求返回值
|
|
88
99
|
*/
|
|
89
100
|
getJson(name: string, params: BodyInit | null = null): Promise<HttpReturn<any>> {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
return this.request(name, params, HttpMethod.GET, HttpResponseType.Json, headers);
|
|
101
|
+
this.headers.set(HeaderName, HeaderValueJson);
|
|
102
|
+
return this.request(name, params, HttpMethod.GET, HttpResponseType.Json, this.headers);
|
|
93
103
|
}
|
|
94
104
|
|
|
95
105
|
/**
|
|
@@ -99,9 +109,8 @@ export class HttpManager {
|
|
|
99
109
|
* @returns HTTP请求返回值
|
|
100
110
|
*/
|
|
101
111
|
postJson(name: string, params: BodyInit | null = null, ext?: IExtData): Promise<HttpReturn<any>> {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return this.request(name, params, HttpMethod.POST, HttpResponseType.Json, headers, ext);
|
|
112
|
+
this.headers.set(HeaderName, HeaderValueJson);
|
|
113
|
+
return this.request(name, params, HttpMethod.POST, HttpResponseType.Json, this.headers, ext);
|
|
105
114
|
}
|
|
106
115
|
|
|
107
116
|
/**
|
|
@@ -123,10 +132,8 @@ export class HttpManager {
|
|
|
123
132
|
pb = null;
|
|
124
133
|
}
|
|
125
134
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
let r = await this.request<T>(cmd.toString(), pb, HttpMethod.POST, HttpResponseType.ArrayBuffer, headers);
|
|
135
|
+
this.headers.set(HeaderName, HeaderValuePb);
|
|
136
|
+
let r = await this.request<T>(cmd.toString(), pb, HttpMethod.POST, HttpResponseType.ArrayBuffer, this.headers);
|
|
130
137
|
if (r.isSucc) {
|
|
131
138
|
let u8a = new Uint8Array(r.res as any);
|
|
132
139
|
let decode = pc[res].decode(u8a);
|
|
@@ -246,6 +253,11 @@ export class HttpManager {
|
|
|
246
253
|
|
|
247
254
|
ret.isSucc = true;
|
|
248
255
|
resolve(ret);
|
|
256
|
+
} else {
|
|
257
|
+
// ret.res = { code: xhr.status, msg: xhr.statusText, data: xhr.response } as any
|
|
258
|
+
// ret.isSucc = true;
|
|
259
|
+
this.paramReady.error?.(xhr, ret)
|
|
260
|
+
resolve(ret);
|
|
249
261
|
}
|
|
250
262
|
};
|
|
251
263
|
|
|
@@ -254,6 +266,7 @@ export class HttpManager {
|
|
|
254
266
|
xhr.send();
|
|
255
267
|
}
|
|
256
268
|
else {
|
|
269
|
+
|
|
257
270
|
xhr.send(pss);
|
|
258
271
|
}
|
|
259
272
|
});
|
|
@@ -376,4 +389,8 @@ export class HttpManager {
|
|
|
376
389
|
});
|
|
377
390
|
}
|
|
378
391
|
|
|
392
|
+
paramReady: { error: (xhr: XMLHttpRequest, ret: HttpReturn<any>) => void }
|
|
393
|
+
OnReadyState<T>(param: { error: (xhr: XMLHttpRequest, ret: HttpReturn<any>) => void }): void {
|
|
394
|
+
this.paramReady = param;
|
|
395
|
+
}
|
|
379
396
|
}
|