@hylid/call 4.0.28-alpha.0 → 4.0.28-alpha.1
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/lib/webCall.js +36 -15
- package/package.json +3 -3
package/lib/webCall.js
CHANGED
|
@@ -6,22 +6,43 @@ export var alipayJSBridge = function alipayJSBridge(cb) {
|
|
|
6
6
|
};
|
|
7
7
|
export function webCall(apiName, options, config) {
|
|
8
8
|
alipayJSBridge(function () {
|
|
9
|
-
var _a =
|
|
10
|
-
|
|
9
|
+
var _a = config || {},
|
|
10
|
+
_b = _a.type,
|
|
11
|
+
type = _b === void 0 ? 'async' : _b,
|
|
12
|
+
_c = _a.timeout,
|
|
13
|
+
timeout = _c === void 0 ? 0 : _c;
|
|
14
|
+
var timer;
|
|
15
|
+
var isHandled = false; // 添加标志位,防止重复触发回调
|
|
16
|
+
var handleResponse = function handleResponse(res) {
|
|
17
|
+
if (isHandled) return; // 如果已经处理过,直接返回
|
|
18
|
+
isHandled = true;
|
|
19
|
+
if (timer) {
|
|
20
|
+
clearTimeout(timer);
|
|
21
|
+
}
|
|
22
|
+
var _a = options || {},
|
|
23
|
+
success = _a.success,
|
|
24
|
+
fail = _a.fail,
|
|
25
|
+
complete = _a.complete;
|
|
26
|
+
// 兼容 worldfirst 安卓端报错,后续客户端统一字段后删除
|
|
27
|
+
if (res.error || res.errorCode) {
|
|
28
|
+
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
29
|
+
} else {
|
|
30
|
+
success === null || success === void 0 ? void 0 : success(res);
|
|
31
|
+
}
|
|
32
|
+
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
33
|
+
};
|
|
11
34
|
if (type === 'async') {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
24
|
-
});
|
|
35
|
+
// 设置超时
|
|
36
|
+
if (timeout > 0) {
|
|
37
|
+
timer = setTimeout(function () {
|
|
38
|
+
var timeoutError = {
|
|
39
|
+
error: -101,
|
|
40
|
+
errorMessage: "[".concat(apiName, "]: Timeout")
|
|
41
|
+
};
|
|
42
|
+
handleResponse(timeoutError);
|
|
43
|
+
}, timeout);
|
|
44
|
+
}
|
|
45
|
+
window.AlipayJSBridge.call(apiName, options, handleResponse);
|
|
25
46
|
}
|
|
26
47
|
if (type === 'callback') {
|
|
27
48
|
window.AlipayJSBridge.call(apiName, options);
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hylid/call",
|
|
3
|
-
"version": "4.0.28-alpha.
|
|
3
|
+
"version": "4.0.28-alpha.1",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib"
|
|
7
7
|
],
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@hylid/env": "^4.0.28-alpha.
|
|
10
|
-
"@hylid/types": "^4.0.28-alpha.
|
|
9
|
+
"@hylid/env": "^4.0.28-alpha.1",
|
|
10
|
+
"@hylid/types": "^4.0.28-alpha.1"
|
|
11
11
|
},
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|