@pisell/utils 1.0.53 → 2.0.2
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 +22 -0
- package/es/jsBridge/index.js +1 -2
- package/es/jsBridge/regDeviceApi.d.ts +1 -1
- package/es/jsBridge/regDeviceApi.js +4 -29
- package/lib/jsBridge/index.d.ts +22 -0
- package/lib/jsBridge/index.js +1 -2
- package/lib/jsBridge/regDeviceApi.d.ts +1 -1
- package/lib/jsBridge/regDeviceApi.js +4 -26
- package/package.json +5 -5
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { WebPrintParams, DataManagerParams, WebPaymentParams } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* webView页面中调用打印机打印
|
|
4
|
+
* 此api暂时只支持native app平台下ios手机
|
|
5
|
+
* @param params
|
|
6
|
+
* @param callback
|
|
7
|
+
*/
|
|
8
|
+
export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
|
|
9
|
+
/**
|
|
10
|
+
* webView页面中调用APP内的数据
|
|
11
|
+
* 此api暂时只支持native app平台下ios手机
|
|
12
|
+
* @param params
|
|
13
|
+
* @param callback
|
|
14
|
+
*/
|
|
15
|
+
export declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void, onError: () => void): void;
|
|
16
|
+
/**
|
|
17
|
+
* webView页面中调用APP内的支付
|
|
18
|
+
* 此api暂时只支持native app平台下ios
|
|
19
|
+
* @param params
|
|
20
|
+
* @param callback
|
|
21
|
+
*/
|
|
22
|
+
export declare function webPayment(params: WebPaymentParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
|
package/es/jsBridge/index.js
CHANGED
|
@@ -10,6 +10,6 @@ type ComposedJSBridge = {
|
|
|
10
10
|
calledByDevice: (a: { apiName: string; callback: Functon }) => void;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
const regDeviceApi: (
|
|
13
|
+
const regDeviceApi: () => Promise<ComposedJSBridge>;
|
|
14
14
|
|
|
15
15
|
export default regDeviceApi;
|
|
@@ -4,12 +4,10 @@ var iosRegStatus = false;
|
|
|
4
4
|
var androidBridge;
|
|
5
5
|
var iosBridge;
|
|
6
6
|
var composedBridge;
|
|
7
|
-
function regIosJsBridge(callback
|
|
7
|
+
function regIosJsBridge(callback) {
|
|
8
8
|
if (window.WebViewJavascriptBridge) {
|
|
9
9
|
callback(window.WebViewJavascriptBridge);
|
|
10
10
|
return;
|
|
11
|
-
} else {
|
|
12
|
-
reject();
|
|
13
11
|
}
|
|
14
12
|
if (window.WVJBCallbacks) {
|
|
15
13
|
window.WVJBCallbacks.push(callback);
|
|
@@ -46,10 +44,6 @@ function regAndroidJsBridge(extraInit) {
|
|
|
46
44
|
extraInit(bridge);
|
|
47
45
|
}, false);
|
|
48
46
|
}
|
|
49
|
-
function checkApiName(apiNames, apiName) {
|
|
50
|
-
var _apiNames = apiNames || ['webPrint'];
|
|
51
|
-
return _apiNames.includes(apiName);
|
|
52
|
-
}
|
|
53
47
|
|
|
54
48
|
/**
|
|
55
49
|
* 通用jsBridge
|
|
@@ -84,27 +78,16 @@ function getComposedBridge(deviceType) {
|
|
|
84
78
|
inCb.apply(void 0, [result].concat(args));
|
|
85
79
|
};
|
|
86
80
|
if (deviceType === 'iphone') {
|
|
87
|
-
var _iosBridge;
|
|
88
|
-
if (!checkApiName((_iosBridge = iosBridge) === null || _iosBridge === void 0 ? void 0 : _iosBridge.apiNames, apiName)) {
|
|
89
|
-
onError === null || onError === void 0 || onError();
|
|
90
|
-
return;
|
|
91
|
-
}
|
|
92
81
|
iosBridge.callHandler(apiName, params, callback, function (e) {
|
|
93
82
|
console.log(e, '--- 调用ios api报错:', apiName);
|
|
94
83
|
if (onError) {
|
|
95
|
-
onError
|
|
84
|
+
onError(e);
|
|
96
85
|
}
|
|
97
86
|
});
|
|
98
87
|
} else if (deviceType === 'android') {
|
|
99
|
-
var _androidBridge;
|
|
100
|
-
if (!checkApiName((_androidBridge = androidBridge) === null || _androidBridge === void 0 ? void 0 : _androidBridge.apiNames, apiName)) {
|
|
101
|
-
onError === null || onError === void 0 || onError();
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
88
|
var res = androidBridge.callHandler(apiName, JSON.stringify(params));
|
|
105
89
|
callback(res);
|
|
106
90
|
} else {
|
|
107
|
-
onError === null || onError === void 0 || onError();
|
|
108
91
|
console.log('--- 没获取到js bridge ---');
|
|
109
92
|
}
|
|
110
93
|
},
|
|
@@ -121,23 +104,15 @@ function getComposedBridge(deviceType) {
|
|
|
121
104
|
};
|
|
122
105
|
return composedBridge;
|
|
123
106
|
}
|
|
124
|
-
export default function regDeviceApi(
|
|
107
|
+
export default function regDeviceApi() {
|
|
125
108
|
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
|
-
}
|
|
134
109
|
if (isIos() && !iosRegStatus) {
|
|
135
110
|
regIosJsBridge(function (bridge) {
|
|
136
111
|
iosRegStatus = true;
|
|
137
112
|
iosBridge = bridge;
|
|
138
113
|
var realBridge = getComposedBridge('iphone');
|
|
139
114
|
resolve(realBridge);
|
|
140
|
-
}
|
|
115
|
+
});
|
|
141
116
|
} else if (isIos() && iosRegStatus) {
|
|
142
117
|
var realBridge = getComposedBridge('iphone');
|
|
143
118
|
resolve(realBridge);
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { WebPrintParams, DataManagerParams, WebPaymentParams } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* webView页面中调用打印机打印
|
|
4
|
+
* 此api暂时只支持native app平台下ios手机
|
|
5
|
+
* @param params
|
|
6
|
+
* @param callback
|
|
7
|
+
*/
|
|
8
|
+
export declare function webPrint(params: WebPrintParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
|
|
9
|
+
/**
|
|
10
|
+
* webView页面中调用APP内的数据
|
|
11
|
+
* 此api暂时只支持native app平台下ios手机
|
|
12
|
+
* @param params
|
|
13
|
+
* @param callback
|
|
14
|
+
*/
|
|
15
|
+
export declare function dataManager(params: DataManagerParams, callback: (...arg: any) => void, onError: () => void): void;
|
|
16
|
+
/**
|
|
17
|
+
* webView页面中调用APP内的支付
|
|
18
|
+
* 此api暂时只支持native app平台下ios
|
|
19
|
+
* @param params
|
|
20
|
+
* @param callback
|
|
21
|
+
*/
|
|
22
|
+
export declare function webPayment(params: WebPaymentParams, callback: (...arg: any) => void, onError?: (error: any) => void): void;
|
package/lib/jsBridge/index.js
CHANGED
|
@@ -10,6 +10,6 @@ type ComposedJSBridge = {
|
|
|
10
10
|
calledByDevice: (a: { apiName: string; callback: Functon }) => void;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
const regDeviceApi: (
|
|
13
|
+
const regDeviceApi: () => Promise<ComposedJSBridge>;
|
|
14
14
|
|
|
15
15
|
export default regDeviceApi;
|
|
@@ -28,12 +28,10 @@ var iosRegStatus = false;
|
|
|
28
28
|
var androidBridge;
|
|
29
29
|
var iosBridge;
|
|
30
30
|
var composedBridge;
|
|
31
|
-
function regIosJsBridge(callback
|
|
31
|
+
function regIosJsBridge(callback) {
|
|
32
32
|
if (window.WebViewJavascriptBridge) {
|
|
33
33
|
callback(window.WebViewJavascriptBridge);
|
|
34
34
|
return;
|
|
35
|
-
} else {
|
|
36
|
-
reject();
|
|
37
35
|
}
|
|
38
36
|
if (window.WVJBCallbacks) {
|
|
39
37
|
window.WVJBCallbacks.push(callback);
|
|
@@ -73,10 +71,6 @@ function regAndroidJsBridge(extraInit) {
|
|
|
73
71
|
false
|
|
74
72
|
);
|
|
75
73
|
}
|
|
76
|
-
function checkApiName(apiNames, apiName) {
|
|
77
|
-
let _apiNames = apiNames || ["webPrint"];
|
|
78
|
-
return _apiNames.includes(apiName);
|
|
79
|
-
}
|
|
80
74
|
function getComposedBridge(deviceType) {
|
|
81
75
|
if (composedBridge) {
|
|
82
76
|
return composedBridge;
|
|
@@ -94,25 +88,16 @@ function getComposedBridge(deviceType) {
|
|
|
94
88
|
inCb(result, ...args);
|
|
95
89
|
};
|
|
96
90
|
if (deviceType === "iphone") {
|
|
97
|
-
if (!checkApiName(iosBridge == null ? void 0 : iosBridge.apiNames, apiName)) {
|
|
98
|
-
onError == null ? void 0 : onError();
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
91
|
iosBridge.callHandler(apiName, params, callback, (e) => {
|
|
102
92
|
console.log(e, "--- 调用ios api报错:", apiName);
|
|
103
93
|
if (onError) {
|
|
104
|
-
onError
|
|
94
|
+
onError(e);
|
|
105
95
|
}
|
|
106
96
|
});
|
|
107
97
|
} else if (deviceType === "android") {
|
|
108
|
-
if (!checkApiName(androidBridge == null ? void 0 : androidBridge.apiNames, apiName)) {
|
|
109
|
-
onError == null ? void 0 : onError();
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
98
|
const res = androidBridge.callHandler(apiName, JSON.stringify(params));
|
|
113
99
|
callback(res);
|
|
114
100
|
} else {
|
|
115
|
-
onError == null ? void 0 : onError();
|
|
116
101
|
console.log("--- 没获取到js bridge ---");
|
|
117
102
|
}
|
|
118
103
|
},
|
|
@@ -127,22 +112,15 @@ function getComposedBridge(deviceType) {
|
|
|
127
112
|
};
|
|
128
113
|
return composedBridge;
|
|
129
114
|
}
|
|
130
|
-
function regDeviceApi(
|
|
115
|
+
function regDeviceApi() {
|
|
131
116
|
return new Promise((resolve, reject) => {
|
|
132
|
-
const isOld = !navigator.userAgent.includes("jsBridge");
|
|
133
|
-
if (isOld) {
|
|
134
|
-
if (!isWebPrint) {
|
|
135
|
-
reject();
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
117
|
if ((0, import_platform.isIos)() && !iosRegStatus) {
|
|
140
118
|
regIosJsBridge((bridge) => {
|
|
141
119
|
iosRegStatus = true;
|
|
142
120
|
iosBridge = bridge;
|
|
143
121
|
const realBridge = getComposedBridge("iphone");
|
|
144
122
|
resolve(realBridge);
|
|
145
|
-
}
|
|
123
|
+
});
|
|
146
124
|
} else if ((0, import_platform.isIos)() && iosRegStatus) {
|
|
147
125
|
const realBridge = getComposedBridge("iphone");
|
|
148
126
|
resolve(realBridge);
|
package/package.json
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pisell/utils",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.2",
|
|
4
|
+
"scripts": {
|
|
5
|
+
"build": "father build",
|
|
6
|
+
"dev": "father dev"
|
|
7
|
+
},
|
|
4
8
|
"sideEffects": false,
|
|
5
9
|
"main": "./lib/index.js",
|
|
6
10
|
"module": "./es/index.js",
|
|
@@ -24,9 +28,5 @@
|
|
|
24
28
|
],
|
|
25
29
|
"publishConfig": {
|
|
26
30
|
"access": "public"
|
|
27
|
-
},
|
|
28
|
-
"scripts": {
|
|
29
|
-
"build": "father build",
|
|
30
|
-
"dev": "father dev"
|
|
31
31
|
}
|
|
32
32
|
}
|