@kkarum/framework 2.3.17 → 2.3.18
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.
- package/package.json +1 -1
- package/service/http/FWHttp.ts +80 -1
- package/types/FW.d.ts +32 -18
package/package.json
CHANGED
package/service/http/FWHttp.ts
CHANGED
|
@@ -34,7 +34,22 @@ export class FWHttp extends FW.Service {
|
|
|
34
34
|
FW.SystemDefine.FWHttpRequestType.POST,
|
|
35
35
|
);
|
|
36
36
|
}
|
|
37
|
-
|
|
37
|
+
protected async postApiMessage(
|
|
38
|
+
url: string,
|
|
39
|
+
params?: string,
|
|
40
|
+
headers?: string,
|
|
41
|
+
cb?: (response: string) => void,
|
|
42
|
+
tag?: string,
|
|
43
|
+
): Promise<string> {
|
|
44
|
+
return this.processApi(
|
|
45
|
+
url,
|
|
46
|
+
params,
|
|
47
|
+
headers,
|
|
48
|
+
cb,
|
|
49
|
+
tag,
|
|
50
|
+
FW.SystemDefine.FWHttpRequestType.POST,
|
|
51
|
+
);
|
|
52
|
+
}
|
|
38
53
|
private async process(
|
|
39
54
|
url: string,
|
|
40
55
|
params: string,
|
|
@@ -97,7 +112,71 @@ export class FWHttp extends FW.Service {
|
|
|
97
112
|
tag ? `http request ->${tag}` : "",
|
|
98
113
|
);
|
|
99
114
|
}
|
|
115
|
+
private async processApi(
|
|
116
|
+
url: string,
|
|
117
|
+
params: string,
|
|
118
|
+
headers: string,
|
|
119
|
+
cb: (response: any) => void,
|
|
120
|
+
tag: string,
|
|
121
|
+
type: FW.SystemDefine.FWHttpRequestType,
|
|
122
|
+
): Promise<string> {
|
|
123
|
+
let xhr: XMLHttpRequest;
|
|
124
|
+
|
|
125
|
+
const promiseProxy: FW.PromiseProxy<string> =
|
|
126
|
+
FW.Entry.promiseMgr.execute<string>(
|
|
127
|
+
(resolve, reject, signal, reason) => {
|
|
128
|
+
xhr = new XMLHttpRequest();
|
|
129
|
+
|
|
130
|
+
xhr.onreadystatechange = () => {
|
|
131
|
+
if (xhr.readyState !== 4) return;
|
|
100
132
|
|
|
133
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
134
|
+
cb?.(xhr.response);
|
|
135
|
+
resolve(xhr.response);
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const errMsg = `http request failed, status: ${xhr.status}, url: ${url}`;
|
|
140
|
+
FW.Log.warn(errMsg);
|
|
141
|
+
reject(errMsg);
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
xhr.onerror = (err: any) => {
|
|
145
|
+
FW.Log.error("http request error:", err);
|
|
146
|
+
this.onError?.(err);
|
|
147
|
+
reject(`http request error:${err}`);
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
xhr.ontimeout = () => {
|
|
151
|
+
this.onTimeout?.();
|
|
152
|
+
reject(`http request timeout!`);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
xhr.open(type as string, url, true);
|
|
156
|
+
xhr.setRequestHeader("Content-Type", "application/json");
|
|
157
|
+
xhr.setRequestHeader("sign", headers);
|
|
158
|
+
xhr.send(params);
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
...FWSystemConfig.PromiseConfig.http,
|
|
162
|
+
retryCondition(error, retryCount) {
|
|
163
|
+
return (
|
|
164
|
+
!!error &&
|
|
165
|
+
retryCount < (FWSystemConfig.PromiseConfig.http.retryCount || 0)
|
|
166
|
+
);
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
promiseProxy.addAbortEventListener(() => {
|
|
172
|
+
xhr.abort();
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
return await this.invoke(
|
|
176
|
+
promiseProxy.promise,
|
|
177
|
+
tag ? `http request ->${tag}` : "",
|
|
178
|
+
);
|
|
179
|
+
}
|
|
101
180
|
onError?(err: any);
|
|
102
181
|
onTimeout?();
|
|
103
182
|
}
|
package/types/FW.d.ts
CHANGED
|
@@ -96,7 +96,7 @@ declare namespace FW {
|
|
|
96
96
|
* @param bundleName - bundle名称
|
|
97
97
|
* @param forceRelease - 是否强制释放当前包资源
|
|
98
98
|
*/
|
|
99
|
-
launchScene(bundleName: string,forceRelease?:boolean): void;
|
|
99
|
+
launchScene(bundleName: string, forceRelease?: boolean): void;
|
|
100
100
|
|
|
101
101
|
/**
|
|
102
102
|
* 注册框架组件
|
|
@@ -314,7 +314,7 @@ declare namespace FW {
|
|
|
314
314
|
getEnableObjectMap();
|
|
315
315
|
getDisableObjectMap();
|
|
316
316
|
getAllObjectMap();
|
|
317
|
-
isEmpty():boolean;
|
|
317
|
+
isEmpty(): boolean;
|
|
318
318
|
findObjectProperty(node: cc.Node);
|
|
319
319
|
findObjectProperty(component: FW.Object);
|
|
320
320
|
findObjectProperty(uniqueId: number);
|
|
@@ -359,7 +359,7 @@ declare namespace FW {
|
|
|
359
359
|
*/
|
|
360
360
|
getSocketMap(): Map<string, Socket>;
|
|
361
361
|
/** 关闭所有Socket连接 */
|
|
362
|
-
closeAll():void;
|
|
362
|
+
closeAll(): void;
|
|
363
363
|
/** 暂停消息处理 */
|
|
364
364
|
pauseMessageHandle(): void;
|
|
365
365
|
/** 恢复消息处理 */
|
|
@@ -901,9 +901,9 @@ declare namespace FW {
|
|
|
901
901
|
/** 清理方法 */
|
|
902
902
|
clear(): void;
|
|
903
903
|
/** 开启调试 */
|
|
904
|
-
openDebug():void;
|
|
904
|
+
openDebug(): void;
|
|
905
905
|
/** 是否开启调试 */
|
|
906
|
-
isDebug():boolean;
|
|
906
|
+
isDebug(): boolean;
|
|
907
907
|
|
|
908
908
|
/**
|
|
909
909
|
* 异步打开layer
|
|
@@ -1016,8 +1016,8 @@ declare namespace FW {
|
|
|
1016
1016
|
};
|
|
1017
1017
|
|
|
1018
1018
|
type ResRejectHandlerListener = {
|
|
1019
|
-
loadResHandler:(err: Error | null, asset: AssetProperty | string | null) => void;
|
|
1020
|
-
loadBundleHandler:(err: Error | null, bundle: string | null) => void;
|
|
1019
|
+
loadResHandler: (err: Error | null, asset: AssetProperty | string | null) => void;
|
|
1020
|
+
loadBundleHandler: (err: Error | null, bundle: string | null) => void;
|
|
1021
1021
|
}
|
|
1022
1022
|
/**
|
|
1023
1023
|
* 资源管理器 - 负责游戏资源的加载、获取和释放等操作
|
|
@@ -1080,7 +1080,7 @@ declare namespace FW {
|
|
|
1080
1080
|
ext?: string;
|
|
1081
1081
|
enableCache?: boolean;
|
|
1082
1082
|
maxRetryCount?: number;
|
|
1083
|
-
texture?:boolean;
|
|
1083
|
+
texture?: boolean;
|
|
1084
1084
|
cb?: (asset: T) => void;
|
|
1085
1085
|
},): Promise<T>;
|
|
1086
1086
|
|
|
@@ -1886,7 +1886,7 @@ declare namespace FW {
|
|
|
1886
1886
|
/**
|
|
1887
1887
|
* 状态构造类
|
|
1888
1888
|
*/
|
|
1889
|
-
stateConstructor: { new
|
|
1889
|
+
stateConstructor: { new(): T };
|
|
1890
1890
|
};
|
|
1891
1891
|
|
|
1892
1892
|
/**
|
|
@@ -2060,11 +2060,11 @@ declare namespace FW {
|
|
|
2060
2060
|
};
|
|
2061
2061
|
|
|
2062
2062
|
|
|
2063
|
-
type VirtualScrollViewListener =
|
|
2064
|
-
|
|
2065
|
-
|
|
2066
|
-
|
|
2067
|
-
|
|
2063
|
+
type VirtualScrollViewListener =
|
|
2064
|
+
{
|
|
2065
|
+
onRender(element: ObjectProperty, index: number, ...args: any);
|
|
2066
|
+
onTouchElement(element: ObjectProperty, index: number, ...args: any);
|
|
2067
|
+
}
|
|
2068
2068
|
|
|
2069
2069
|
type VirtualScrollViewConfig = {
|
|
2070
2070
|
/**
|
|
@@ -2079,7 +2079,7 @@ declare namespace FW {
|
|
|
2079
2079
|
/**
|
|
2080
2080
|
* 列表容器
|
|
2081
2081
|
*/
|
|
2082
|
-
container:cc.Node;
|
|
2082
|
+
container: cc.Node;
|
|
2083
2083
|
}
|
|
2084
2084
|
|
|
2085
2085
|
|
|
@@ -2491,7 +2491,7 @@ declare namespace FW {
|
|
|
2491
2491
|
static SUB_LOGIC = 5;
|
|
2492
2492
|
}
|
|
2493
2493
|
|
|
2494
|
-
export class FWVirtualScrollViewDirection{
|
|
2494
|
+
export class FWVirtualScrollViewDirection {
|
|
2495
2495
|
static VERTICAL = 0;
|
|
2496
2496
|
static HORIZONTAL = 1;
|
|
2497
2497
|
}
|
|
@@ -2949,8 +2949,8 @@ declare namespace FW {
|
|
|
2949
2949
|
* http服务
|
|
2950
2950
|
*/
|
|
2951
2951
|
export class Http extends Service {
|
|
2952
|
-
public initialize() {}
|
|
2953
|
-
public onDestroy(): void {}
|
|
2952
|
+
public initialize() { }
|
|
2953
|
+
public onDestroy(): void { }
|
|
2954
2954
|
/**
|
|
2955
2955
|
* get请求
|
|
2956
2956
|
* @param url
|
|
@@ -2977,6 +2977,20 @@ declare namespace FW {
|
|
|
2977
2977
|
cb?: (response: string) => void,
|
|
2978
2978
|
tag?: string,
|
|
2979
2979
|
): Promise<string>;
|
|
2980
|
+
/**
|
|
2981
|
+
* post请求
|
|
2982
|
+
* @param url
|
|
2983
|
+
* @param params
|
|
2984
|
+
* @param cb
|
|
2985
|
+
* @param tag
|
|
2986
|
+
*/
|
|
2987
|
+
async postApiMessage(
|
|
2988
|
+
url: string,
|
|
2989
|
+
params?: string,
|
|
2990
|
+
headers?: string,
|
|
2991
|
+
cb?: (response: string) => void,
|
|
2992
|
+
tag?: string,
|
|
2993
|
+
): Promise<string>;
|
|
2980
2994
|
/**
|
|
2981
2995
|
* 请求错误
|
|
2982
2996
|
* @param err
|