@pisell/utils 1.0.41 → 1.0.43
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.js
CHANGED
|
@@ -6,7 +6,7 @@ import regDeviceApi from "./regDeviceApi";
|
|
|
6
6
|
* @param callback
|
|
7
7
|
*/
|
|
8
8
|
export function webPrint(params, _callback, onError) {
|
|
9
|
-
regDeviceApi().then(function (jsBridge) {
|
|
9
|
+
regDeviceApi(true).then(function (jsBridge) {
|
|
10
10
|
jsBridge.callDeviceApi({
|
|
11
11
|
apiName: "webPrint",
|
|
12
12
|
params: params,
|
|
@@ -10,6 +10,6 @@ type ComposedJSBridge = {
|
|
|
10
10
|
calledByDevice: (a: { apiName: string; callback: Functon }) => void;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
const regDeviceApi: () => Promise<ComposedJSBridge>;
|
|
13
|
+
const regDeviceApi: (isWebPrint?: boolean) => Promise<ComposedJSBridge>;
|
|
14
14
|
|
|
15
15
|
export default regDeviceApi;
|
|
@@ -4,10 +4,12 @@ var iosRegStatus = false;
|
|
|
4
4
|
var androidBridge;
|
|
5
5
|
var iosBridge;
|
|
6
6
|
var composedBridge;
|
|
7
|
-
function regIosJsBridge(callback) {
|
|
7
|
+
function regIosJsBridge(callback, reject) {
|
|
8
8
|
if (window.WebViewJavascriptBridge) {
|
|
9
9
|
callback(window.WebViewJavascriptBridge);
|
|
10
10
|
return;
|
|
11
|
+
} else {
|
|
12
|
+
reject();
|
|
11
13
|
}
|
|
12
14
|
if (window.WVJBCallbacks) {
|
|
13
15
|
window.WVJBCallbacks.push(callback);
|
|
@@ -99,12 +101,8 @@ function getComposedBridge(deviceType) {
|
|
|
99
101
|
onError === null || onError === void 0 ? void 0 : onError();
|
|
100
102
|
return;
|
|
101
103
|
}
|
|
102
|
-
androidBridge.callHandler(apiName, params
|
|
103
|
-
|
|
104
|
-
if (onError) {
|
|
105
|
-
onError === null || onError === void 0 ? void 0 : onError(e);
|
|
106
|
-
}
|
|
107
|
-
});
|
|
104
|
+
var res = androidBridge.callHandler(apiName, JSON.stringify(params));
|
|
105
|
+
callback(res);
|
|
108
106
|
} else {
|
|
109
107
|
onError === null || onError === void 0 ? void 0 : onError();
|
|
110
108
|
console.log('--- 没获取到js bridge ---');
|
|
@@ -123,15 +121,23 @@ function getComposedBridge(deviceType) {
|
|
|
123
121
|
};
|
|
124
122
|
return composedBridge;
|
|
125
123
|
}
|
|
126
|
-
export default function regDeviceApi() {
|
|
124
|
+
export default function regDeviceApi(isWebPrint) {
|
|
127
125
|
return new Promise(function (resolve, reject) {
|
|
126
|
+
// 旧版本只能用WebPrint
|
|
127
|
+
var isOld = !navigator.userAgent.includes('jsBridge');
|
|
128
|
+
if (isOld) {
|
|
129
|
+
if (!isWebPrint) {
|
|
130
|
+
reject();
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
128
134
|
if (isIos() && !iosRegStatus) {
|
|
129
135
|
regIosJsBridge(function (bridge) {
|
|
130
136
|
iosRegStatus = true;
|
|
131
137
|
iosBridge = bridge;
|
|
132
138
|
var realBridge = getComposedBridge('iphone');
|
|
133
139
|
resolve(realBridge);
|
|
134
|
-
});
|
|
140
|
+
}, reject);
|
|
135
141
|
} else if (isIos() && iosRegStatus) {
|
|
136
142
|
var realBridge = getComposedBridge('iphone');
|
|
137
143
|
resolve(realBridge);
|
package/lib/jsBridge/index.js
CHANGED
|
@@ -35,7 +35,7 @@ __export(jsBridge_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(jsBridge_exports);
|
|
36
36
|
var import_regDeviceApi = __toESM(require("./regDeviceApi"));
|
|
37
37
|
function webPrint(params, callback, onError) {
|
|
38
|
-
(0, import_regDeviceApi.default)().then((jsBridge) => {
|
|
38
|
+
(0, import_regDeviceApi.default)(true).then((jsBridge) => {
|
|
39
39
|
jsBridge.callDeviceApi({
|
|
40
40
|
apiName: "webPrint",
|
|
41
41
|
params,
|
|
@@ -10,6 +10,6 @@ type ComposedJSBridge = {
|
|
|
10
10
|
calledByDevice: (a: { apiName: string; callback: Functon }) => void;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
const regDeviceApi: () => Promise<ComposedJSBridge>;
|
|
13
|
+
const regDeviceApi: (isWebPrint?: boolean) => Promise<ComposedJSBridge>;
|
|
14
14
|
|
|
15
15
|
export default regDeviceApi;
|
|
@@ -28,10 +28,12 @@ var iosRegStatus = false;
|
|
|
28
28
|
var androidBridge;
|
|
29
29
|
var iosBridge;
|
|
30
30
|
var composedBridge;
|
|
31
|
-
function regIosJsBridge(callback) {
|
|
31
|
+
function regIosJsBridge(callback, reject) {
|
|
32
32
|
if (window.WebViewJavascriptBridge) {
|
|
33
33
|
callback(window.WebViewJavascriptBridge);
|
|
34
34
|
return;
|
|
35
|
+
} else {
|
|
36
|
+
reject();
|
|
35
37
|
}
|
|
36
38
|
if (window.WVJBCallbacks) {
|
|
37
39
|
window.WVJBCallbacks.push(callback);
|
|
@@ -111,12 +113,8 @@ function getComposedBridge(deviceType) {
|
|
|
111
113
|
onError == null ? void 0 : onError();
|
|
112
114
|
return;
|
|
113
115
|
}
|
|
114
|
-
androidBridge.callHandler(apiName, params
|
|
115
|
-
|
|
116
|
-
if (onError) {
|
|
117
|
-
onError == null ? void 0 : onError(e);
|
|
118
|
-
}
|
|
119
|
-
});
|
|
116
|
+
const res = androidBridge.callHandler(apiName, JSON.stringify(params));
|
|
117
|
+
callback(res);
|
|
120
118
|
} else {
|
|
121
119
|
onError == null ? void 0 : onError();
|
|
122
120
|
console.log("--- \u6CA1\u83B7\u53D6\u5230js bridge ---");
|
|
@@ -133,15 +131,22 @@ function getComposedBridge(deviceType) {
|
|
|
133
131
|
};
|
|
134
132
|
return composedBridge;
|
|
135
133
|
}
|
|
136
|
-
function regDeviceApi() {
|
|
134
|
+
function regDeviceApi(isWebPrint) {
|
|
137
135
|
return new Promise((resolve, reject) => {
|
|
136
|
+
const isOld = !navigator.userAgent.includes("jsBridge");
|
|
137
|
+
if (isOld) {
|
|
138
|
+
if (!isWebPrint) {
|
|
139
|
+
reject();
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
138
143
|
if ((0, import_platform.isIos)() && !iosRegStatus) {
|
|
139
144
|
regIosJsBridge((bridge) => {
|
|
140
145
|
iosRegStatus = true;
|
|
141
146
|
iosBridge = bridge;
|
|
142
147
|
const realBridge = getComposedBridge("iphone");
|
|
143
148
|
resolve(realBridge);
|
|
144
|
-
});
|
|
149
|
+
}, reject);
|
|
145
150
|
} else if ((0, import_platform.isIos)() && iosRegStatus) {
|
|
146
151
|
const realBridge = getComposedBridge("iphone");
|
|
147
152
|
resolve(realBridge);
|