@pisell/utils 1.0.39 → 1.0.41
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/es/jsBridge/index.d.ts
CHANGED
|
@@ -102,7 +102,7 @@ declare type WebPrintParams = WebPrint0 | WebPrint1 | WebPrint2;
|
|
|
102
102
|
* @param params
|
|
103
103
|
* @param callback
|
|
104
104
|
*/
|
|
105
|
-
export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void): void;
|
|
105
|
+
export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void, onError: () => void): void;
|
|
106
106
|
declare type DataManagerParams = {
|
|
107
107
|
module: "set" | "get";
|
|
108
108
|
key: string;
|
|
@@ -114,5 +114,5 @@ declare type DataManagerParams = {
|
|
|
114
114
|
* @param params
|
|
115
115
|
* @param callback
|
|
116
116
|
*/
|
|
117
|
-
export declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void): void;
|
|
117
|
+
export declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void, onError: () => void): void;
|
|
118
118
|
export {};
|
package/es/jsBridge/index.js
CHANGED
|
@@ -5,14 +5,15 @@ import regDeviceApi from "./regDeviceApi";
|
|
|
5
5
|
* @param params
|
|
6
6
|
* @param callback
|
|
7
7
|
*/
|
|
8
|
-
export function webPrint(params, _callback) {
|
|
8
|
+
export function webPrint(params, _callback, onError) {
|
|
9
9
|
regDeviceApi().then(function (jsBridge) {
|
|
10
10
|
jsBridge.callDeviceApi({
|
|
11
11
|
apiName: "webPrint",
|
|
12
12
|
params: params,
|
|
13
13
|
callback: function callback() {
|
|
14
14
|
_callback && _callback.apply(void 0, arguments);
|
|
15
|
-
}
|
|
15
|
+
},
|
|
16
|
+
onError: onError
|
|
16
17
|
});
|
|
17
18
|
});
|
|
18
19
|
}
|
|
@@ -22,14 +23,15 @@ export function webPrint(params, _callback) {
|
|
|
22
23
|
* @param params
|
|
23
24
|
* @param callback
|
|
24
25
|
*/
|
|
25
|
-
export function dataManager(params, _callback2) {
|
|
26
|
+
export function dataManager(params, _callback2, onError) {
|
|
26
27
|
regDeviceApi().then(function (jsBridge) {
|
|
27
28
|
jsBridge.callDeviceApi({
|
|
28
29
|
apiName: "dataManager",
|
|
29
30
|
params: params,
|
|
30
31
|
callback: function callback() {
|
|
31
32
|
_callback2 && _callback2.apply(void 0, arguments);
|
|
32
|
-
}
|
|
33
|
+
},
|
|
34
|
+
onError: onError
|
|
33
35
|
});
|
|
34
|
-
});
|
|
36
|
+
}).catch(onError);
|
|
35
37
|
}
|
|
@@ -44,6 +44,10 @@ function regAndroidJsBridge(extraInit) {
|
|
|
44
44
|
extraInit(bridge);
|
|
45
45
|
}, false);
|
|
46
46
|
}
|
|
47
|
+
function checkApiName(apiNames, apiName) {
|
|
48
|
+
var _apiNames = apiNames || ['webPrint'];
|
|
49
|
+
return _apiNames.includes(apiName);
|
|
50
|
+
}
|
|
47
51
|
|
|
48
52
|
/**
|
|
49
53
|
* 通用jsBridge
|
|
@@ -78,20 +82,31 @@ function getComposedBridge(deviceType) {
|
|
|
78
82
|
inCb.apply(void 0, [result].concat(args));
|
|
79
83
|
};
|
|
80
84
|
if (deviceType === 'iphone') {
|
|
85
|
+
var _iosBridge;
|
|
86
|
+
if (!checkApiName((_iosBridge = iosBridge) === null || _iosBridge === void 0 ? void 0 : _iosBridge.apiNames, apiName)) {
|
|
87
|
+
onError === null || onError === void 0 ? void 0 : onError();
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
81
90
|
iosBridge.callHandler(apiName, params, callback, function (e) {
|
|
82
91
|
console.log(e, '--- 调用ios api报错:', apiName);
|
|
83
92
|
if (onError) {
|
|
84
|
-
onError(e);
|
|
93
|
+
onError === null || onError === void 0 ? void 0 : onError(e);
|
|
85
94
|
}
|
|
86
95
|
});
|
|
87
96
|
} else if (deviceType === 'android') {
|
|
97
|
+
var _androidBridge;
|
|
98
|
+
if (!checkApiName((_androidBridge = androidBridge) === null || _androidBridge === void 0 ? void 0 : _androidBridge.apiNames, apiName)) {
|
|
99
|
+
onError === null || onError === void 0 ? void 0 : onError();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
88
102
|
androidBridge.callHandler(apiName, params, callback, function (e) {
|
|
89
103
|
console.log(e, '--- 调用android api报错:', apiName);
|
|
90
104
|
if (onError) {
|
|
91
|
-
onError(e);
|
|
105
|
+
onError === null || onError === void 0 ? void 0 : onError(e);
|
|
92
106
|
}
|
|
93
107
|
});
|
|
94
108
|
} else {
|
|
109
|
+
onError === null || onError === void 0 ? void 0 : onError();
|
|
95
110
|
console.log('--- 没获取到js bridge ---');
|
|
96
111
|
}
|
|
97
112
|
},
|
package/lib/jsBridge/index.d.ts
CHANGED
|
@@ -102,7 +102,7 @@ declare type WebPrintParams = WebPrint0 | WebPrint1 | WebPrint2;
|
|
|
102
102
|
* @param params
|
|
103
103
|
* @param callback
|
|
104
104
|
*/
|
|
105
|
-
export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void): void;
|
|
105
|
+
export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void, onError: () => void): void;
|
|
106
106
|
declare type DataManagerParams = {
|
|
107
107
|
module: "set" | "get";
|
|
108
108
|
key: string;
|
|
@@ -114,5 +114,5 @@ declare type DataManagerParams = {
|
|
|
114
114
|
* @param params
|
|
115
115
|
* @param callback
|
|
116
116
|
*/
|
|
117
|
-
export declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void): void;
|
|
117
|
+
export declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void, onError: () => void): void;
|
|
118
118
|
export {};
|
package/lib/jsBridge/index.js
CHANGED
|
@@ -34,27 +34,29 @@ __export(jsBridge_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(jsBridge_exports);
|
|
36
36
|
var import_regDeviceApi = __toESM(require("./regDeviceApi"));
|
|
37
|
-
function webPrint(params, callback) {
|
|
37
|
+
function webPrint(params, callback, onError) {
|
|
38
38
|
(0, import_regDeviceApi.default)().then((jsBridge) => {
|
|
39
39
|
jsBridge.callDeviceApi({
|
|
40
40
|
apiName: "webPrint",
|
|
41
41
|
params,
|
|
42
42
|
callback: (...arg) => {
|
|
43
43
|
callback && callback(...arg);
|
|
44
|
-
}
|
|
44
|
+
},
|
|
45
|
+
onError
|
|
45
46
|
});
|
|
46
47
|
});
|
|
47
48
|
}
|
|
48
|
-
function dataManager(params, callback) {
|
|
49
|
+
function dataManager(params, callback, onError) {
|
|
49
50
|
(0, import_regDeviceApi.default)().then((jsBridge) => {
|
|
50
51
|
jsBridge.callDeviceApi({
|
|
51
52
|
apiName: "dataManager",
|
|
52
53
|
params,
|
|
53
54
|
callback: (...arg) => {
|
|
54
55
|
callback && callback(...arg);
|
|
55
|
-
}
|
|
56
|
+
},
|
|
57
|
+
onError
|
|
56
58
|
});
|
|
57
|
-
});
|
|
59
|
+
}).catch(onError);
|
|
58
60
|
}
|
|
59
61
|
// Annotate the CommonJS export names for ESM import in node:
|
|
60
62
|
0 && (module.exports = {
|
|
@@ -72,6 +72,10 @@ function regAndroidJsBridge(extraInit) {
|
|
|
72
72
|
false
|
|
73
73
|
);
|
|
74
74
|
}
|
|
75
|
+
function checkApiName(apiNames, apiName) {
|
|
76
|
+
let _apiNames = apiNames || ["webPrint"];
|
|
77
|
+
return _apiNames.includes(apiName);
|
|
78
|
+
}
|
|
75
79
|
function getComposedBridge(deviceType) {
|
|
76
80
|
if (composedBridge) {
|
|
77
81
|
return composedBridge;
|
|
@@ -92,20 +96,29 @@ function getComposedBridge(deviceType) {
|
|
|
92
96
|
inCb(result, ...args);
|
|
93
97
|
};
|
|
94
98
|
if (deviceType === "iphone") {
|
|
99
|
+
if (!checkApiName(iosBridge == null ? void 0 : iosBridge.apiNames, apiName)) {
|
|
100
|
+
onError == null ? void 0 : onError();
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
95
103
|
iosBridge.callHandler(apiName, params, callback, (e) => {
|
|
96
104
|
console.log(e, "--- \u8C03\u7528ios api\u62A5\u9519\uFF1A", apiName);
|
|
97
105
|
if (onError) {
|
|
98
|
-
onError(e);
|
|
106
|
+
onError == null ? void 0 : onError(e);
|
|
99
107
|
}
|
|
100
108
|
});
|
|
101
109
|
} else if (deviceType === "android") {
|
|
110
|
+
if (!checkApiName(androidBridge == null ? void 0 : androidBridge.apiNames, apiName)) {
|
|
111
|
+
onError == null ? void 0 : onError();
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
102
114
|
androidBridge.callHandler(apiName, params, callback, (e) => {
|
|
103
115
|
console.log(e, "--- \u8C03\u7528android api\u62A5\u9519\uFF1A", apiName);
|
|
104
116
|
if (onError) {
|
|
105
|
-
onError(e);
|
|
117
|
+
onError == null ? void 0 : onError(e);
|
|
106
118
|
}
|
|
107
119
|
});
|
|
108
120
|
} else {
|
|
121
|
+
onError == null ? void 0 : onError();
|
|
109
122
|
console.log("--- \u6CA1\u83B7\u53D6\u5230js bridge ---");
|
|
110
123
|
}
|
|
111
124
|
},
|