@hylid/call 0.0.90011477778-dev.2 → 0.0.90011477778-dev.3
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 +98 -26
- package/package.json +3 -3
package/lib/webCall.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { CLIENT, client } from '@hylid/env';
|
|
1
2
|
export var alipayJSBridge = function alipayJSBridge(cb) {
|
|
2
3
|
if (window.AlipayJSBridge) return cb();
|
|
3
4
|
document.addEventListener('AlipayJSBridgeReady', function () {
|
|
@@ -9,19 +10,49 @@ export function webCall(apiName, options, config) {
|
|
|
9
10
|
var _a = (config || {}).type,
|
|
10
11
|
type = _a === void 0 ? 'async' : _a;
|
|
11
12
|
if (type === 'async') {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
if (client === CLIENT.HUAWEI_ATOMIC) {
|
|
14
|
+
// TDOO: 华为元服务“出境服务”通信实现
|
|
15
|
+
// 对通信数据包装一层
|
|
16
|
+
var atomicsdkParams = {
|
|
17
|
+
code: 0,
|
|
18
|
+
data: options.data && JSON.stringify(options.data),
|
|
19
|
+
msg: 'success'
|
|
20
|
+
};
|
|
21
|
+
// @ts-ignore
|
|
22
|
+
var isAtomicFn = window.atomicsdk.invokeMethod({
|
|
23
|
+
appMethod: 'canIUse',
|
|
24
|
+
data: apiName
|
|
25
|
+
});
|
|
26
|
+
if (isAtomicFn) {
|
|
27
|
+
// 出境服务存在此通信方法再调用
|
|
28
|
+
// @ts-ignore
|
|
29
|
+
window.atomicsdk.invokeMethod({
|
|
30
|
+
appMethod: apiName,
|
|
31
|
+
jsMethod: options.jsMethod,
|
|
32
|
+
data: atomicsdkParams // 参数对象
|
|
33
|
+
});
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
} else if (window[apiName]) {
|
|
36
|
+
// @ts-ignore
|
|
37
|
+
window[apiName](options);
|
|
20
38
|
} else {
|
|
21
|
-
|
|
39
|
+
throw new Error('webCall Error: apiName not found');
|
|
22
40
|
}
|
|
23
|
-
|
|
24
|
-
|
|
41
|
+
} else {
|
|
42
|
+
window.AlipayJSBridge.call(apiName, options, function (res) {
|
|
43
|
+
var _a = options || {},
|
|
44
|
+
success = _a.success,
|
|
45
|
+
fail = _a.fail,
|
|
46
|
+
complete = _a.complete;
|
|
47
|
+
// 兼容 worldfirst 安卓端报错,后续客户端统一字段后删除
|
|
48
|
+
if (res.error || res.errorCode) {
|
|
49
|
+
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
50
|
+
} else {
|
|
51
|
+
success === null || success === void 0 ? void 0 : success(res);
|
|
52
|
+
}
|
|
53
|
+
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
25
56
|
}
|
|
26
57
|
if (type === 'callback') {
|
|
27
58
|
window.AlipayJSBridge.call(apiName, options);
|
|
@@ -47,22 +78,63 @@ export function webCallAsync(apiName, options, config) {
|
|
|
47
78
|
fail === null || fail === void 0 ? void 0 : fail(err);
|
|
48
79
|
}, timeout);
|
|
49
80
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
81
|
+
if (client === CLIENT.HUAWEI_ATOMIC) {
|
|
82
|
+
// TDOO: 华为元服务“出境服务”通信实现
|
|
83
|
+
// 对通信数据包装一层
|
|
84
|
+
var atomicsdkParams = {
|
|
85
|
+
code: 0,
|
|
86
|
+
data: options.data && JSON.stringify(options.data),
|
|
87
|
+
msg: 'success'
|
|
88
|
+
};
|
|
89
|
+
// @ts-ignore
|
|
90
|
+
var isAtomicFn = window.atomicsdk.invokeMethod({
|
|
91
|
+
appMethod: 'canIUse',
|
|
92
|
+
data: apiName
|
|
93
|
+
});
|
|
94
|
+
if (isAtomicFn) {
|
|
95
|
+
// 出境服务存在此通信方法再调用
|
|
96
|
+
// @ts-ignore
|
|
97
|
+
window.atomicsdk.invokeMethod({
|
|
98
|
+
appMethod: apiName,
|
|
99
|
+
jsMethod: options.jsMethod,
|
|
100
|
+
data: atomicsdkParams // 参数对象
|
|
101
|
+
});
|
|
102
|
+
if (options === null || options === void 0 ? void 0 : options.jsMethod) {
|
|
103
|
+
// 生成一次性回调 id,防止并发冲突
|
|
104
|
+
var cbId = 'cb_' + Date.now() + '_' + Math.random().toString(36).slice(2, 8);
|
|
105
|
+
var cbName_1 = 'jsMethod' + cbId;
|
|
106
|
+
// @ts-ignore
|
|
107
|
+
window[cbName_1] = function (result) {
|
|
108
|
+
// @ts-ignore
|
|
109
|
+
delete window[cbName_1];
|
|
110
|
+
resolve(result);
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
// @ts-ignore
|
|
114
|
+
} else if (window[apiName]) {
|
|
115
|
+
// @ts-ignore
|
|
116
|
+
window[apiName](options);
|
|
61
117
|
} else {
|
|
62
|
-
|
|
63
|
-
success === null || success === void 0 ? void 0 : success(res);
|
|
118
|
+
throw new Error('webCallAsync Error: apiName not found');
|
|
64
119
|
}
|
|
65
|
-
|
|
66
|
-
|
|
120
|
+
} else {
|
|
121
|
+
window.AlipayJSBridge.call(apiName, options, function (res) {
|
|
122
|
+
var _a = options || {},
|
|
123
|
+
success = _a.success,
|
|
124
|
+
fail = _a.fail,
|
|
125
|
+
complete = _a.complete;
|
|
126
|
+
if (timer) {
|
|
127
|
+
clearTimeout(timer);
|
|
128
|
+
}
|
|
129
|
+
if (res === null || res === void 0 ? void 0 : res.error) {
|
|
130
|
+
reject(res);
|
|
131
|
+
fail === null || fail === void 0 ? void 0 : fail(res);
|
|
132
|
+
} else {
|
|
133
|
+
resolve(res);
|
|
134
|
+
success === null || success === void 0 ? void 0 : success(res);
|
|
135
|
+
}
|
|
136
|
+
complete === null || complete === void 0 ? void 0 : complete(res);
|
|
137
|
+
});
|
|
138
|
+
}
|
|
67
139
|
});
|
|
68
140
|
}
|
package/package.json
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hylid/call",
|
|
3
|
-
"version": "0.0.90011477778-dev.
|
|
3
|
+
"version": "0.0.90011477778-dev.3",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"files": [
|
|
6
6
|
"lib"
|
|
7
7
|
],
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@hylid/env": "^0.0.90011477778-dev.
|
|
10
|
-
"@hylid/types": "^0.0.90011477778-dev.
|
|
9
|
+
"@hylid/env": "^0.0.90011477778-dev.3",
|
|
10
|
+
"@hylid/types": "^0.0.90011477778-dev.3"
|
|
11
11
|
},
|
|
12
12
|
"publishConfig": {
|
|
13
13
|
"access": "public"
|