@lemon-fe/mini-app 0.1.45 → 0.1.50
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/global.d.ts +26 -19
- package/es/global.js +88 -18
- package/package.json +4 -4
package/es/global.d.ts
CHANGED
|
@@ -1,5 +1,14 @@
|
|
|
1
1
|
import { UserInfo } from './typings';
|
|
2
|
-
|
|
2
|
+
declare global {
|
|
3
|
+
interface Window {
|
|
4
|
+
ReactNativeWebView?: {
|
|
5
|
+
postMessage(e: string): void;
|
|
6
|
+
};
|
|
7
|
+
mini?: typeof mini;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
export declare const mini: {
|
|
11
|
+
loaded: boolean;
|
|
3
12
|
getSystemInfoSync(): {
|
|
4
13
|
statusBarHeight: number;
|
|
5
14
|
pixelRatio: number;
|
|
@@ -10,31 +19,29 @@ interface Mini {
|
|
|
10
19
|
left: number;
|
|
11
20
|
};
|
|
12
21
|
};
|
|
13
|
-
addListener(cb: (e: string) => void): void;
|
|
14
22
|
getExtraPayload(): unknown;
|
|
23
|
+
methodRegister(name: string, opts?: {
|
|
24
|
+
success?: ((value: any) => void) | undefined;
|
|
25
|
+
fail?: ((err: Error) => void) | undefined;
|
|
26
|
+
params?: any;
|
|
27
|
+
}): void;
|
|
28
|
+
methodSuccess(id: number, value: unknown): void;
|
|
29
|
+
methodFail(id: number, err: Error): void;
|
|
30
|
+
addListener(cb: (e: string) => void): () => void;
|
|
31
|
+
postMessage(e: string): void;
|
|
15
32
|
scanCode(opts: {
|
|
16
33
|
success: (value: string) => void;
|
|
17
34
|
}): void;
|
|
18
|
-
|
|
35
|
+
exit(): void;
|
|
36
|
+
setStatusBarStyle(opts: {
|
|
19
37
|
success?: () => void;
|
|
20
38
|
params: 'default' | 'light-content' | 'dark-content';
|
|
21
39
|
}): void;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
success?: (user: UserInfo) => void;
|
|
40
|
+
getUserInfo(opts: {
|
|
41
|
+
success?: ((user: UserInfo) => void) | undefined;
|
|
25
42
|
}): void;
|
|
26
|
-
getAccessToken(
|
|
27
|
-
success?: (token: string | null) => void;
|
|
43
|
+
getAccessToken(opts: {
|
|
44
|
+
success?: ((token: string | null) => void) | undefined;
|
|
28
45
|
}): void;
|
|
29
|
-
}
|
|
30
|
-
declare global {
|
|
31
|
-
interface Window {
|
|
32
|
-
ReactNativeWebView?: {
|
|
33
|
-
postMessage(e: string): void;
|
|
34
|
-
};
|
|
35
|
-
mini?: Mini;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
export declare let mini: Mini;
|
|
46
|
+
};
|
|
39
47
|
export declare function createApp(render: () => void): void;
|
|
40
|
-
export {};
|
package/es/global.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
var methodID = 0;
|
|
2
|
+
var methods = {};
|
|
3
|
+
var listeners = [];
|
|
1
4
|
export var mini = {
|
|
5
|
+
loaded: false,
|
|
2
6
|
getSystemInfoSync: function getSystemInfoSync() {
|
|
3
7
|
return {
|
|
4
8
|
statusBarHeight: 0,
|
|
5
|
-
pixelRatio:
|
|
9
|
+
pixelRatio: 1,
|
|
6
10
|
safeArea: {
|
|
7
11
|
top: 0,
|
|
8
12
|
right: 0,
|
|
@@ -11,29 +15,95 @@ export var mini = {
|
|
|
11
15
|
}
|
|
12
16
|
};
|
|
13
17
|
},
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
getExtraPayload: function getExtraPayload() {
|
|
19
|
+
return;
|
|
20
|
+
},
|
|
21
|
+
methodRegister: function methodRegister(name) {
|
|
22
|
+
var _window$ReactNativeWe;
|
|
23
|
+
|
|
24
|
+
var opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
25
|
+
var mOpts = opts || {};
|
|
26
|
+
methods[methodID] = {
|
|
27
|
+
success: mOpts.success,
|
|
28
|
+
fail: mOpts.fail
|
|
29
|
+
};
|
|
30
|
+
(_window$ReactNativeWe = window.ReactNativeWebView) === null || _window$ReactNativeWe === void 0 ? void 0 : _window$ReactNativeWe.postMessage(JSON.stringify({
|
|
31
|
+
type: 'METHOD',
|
|
32
|
+
target: {
|
|
33
|
+
id: methodID,
|
|
34
|
+
name: name,
|
|
35
|
+
params: mOpts.params
|
|
36
|
+
}
|
|
37
|
+
}));
|
|
38
|
+
|
|
39
|
+
if (methodID >= Number.MAX_SAFE_INTEGER) {
|
|
40
|
+
methodID = 0;
|
|
41
|
+
} else {
|
|
42
|
+
methodID += 1;
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
methodSuccess: function methodSuccess(id, value) {
|
|
46
|
+
var method = methods[id];
|
|
47
|
+
|
|
48
|
+
if (method !== undefined) {
|
|
49
|
+
if (method.success !== undefined) {
|
|
50
|
+
method.success(value);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
delete methods[id];
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
methodFail: function methodFail(id, err) {
|
|
57
|
+
var method = methods[id];
|
|
58
|
+
|
|
59
|
+
if (method !== undefined) {
|
|
60
|
+
if (method.fail !== undefined) {
|
|
61
|
+
method.fail(err);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
delete methods[id];
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
addListener: function addListener(cb) {
|
|
68
|
+
listeners.push(cb);
|
|
69
|
+
return function () {
|
|
70
|
+
var index = listeners.findIndex(function (item) {
|
|
71
|
+
return item === cb;
|
|
72
|
+
});
|
|
73
|
+
listeners.splice(index, 1);
|
|
74
|
+
};
|
|
75
|
+
},
|
|
76
|
+
postMessage: function postMessage(e) {
|
|
77
|
+
listeners.forEach(function (item) {
|
|
78
|
+
item(e);
|
|
79
|
+
});
|
|
80
|
+
},
|
|
81
|
+
scanCode: function scanCode(opts) {
|
|
82
|
+
mini.methodRegister('SCAN_CODE', opts);
|
|
83
|
+
},
|
|
84
|
+
exit: function exit() {
|
|
85
|
+
mini.methodRegister('EXIT');
|
|
86
|
+
},
|
|
87
|
+
setStatusBarStyle: function setStatusBarStyle(opts) {
|
|
88
|
+
mini.methodRegister('SET_STATUS_BAR_STYLE', opts);
|
|
89
|
+
},
|
|
90
|
+
getUserInfo: function getUserInfo(opts) {
|
|
91
|
+
mini.methodRegister('GET_USER_INFO', opts);
|
|
92
|
+
},
|
|
93
|
+
getAccessToken: function getAccessToken(opts) {
|
|
94
|
+
mini.methodRegister('GET_ACCESS_TOKEN', opts);
|
|
95
|
+
}
|
|
21
96
|
};
|
|
97
|
+
window.mini = mini;
|
|
22
98
|
export function createApp(render) {
|
|
23
99
|
var count = 0;
|
|
24
100
|
|
|
25
101
|
var check = function check() {
|
|
26
|
-
if (
|
|
27
|
-
count++;
|
|
28
|
-
|
|
29
|
-
if (count <= 10) {
|
|
30
|
-
setTimeout(check, 100);
|
|
31
|
-
} else {
|
|
32
|
-
render();
|
|
33
|
-
}
|
|
34
|
-
} else {
|
|
35
|
-
mini = window.mini;
|
|
102
|
+
if (mini.loaded || count >= 10) {
|
|
36
103
|
render();
|
|
104
|
+
} else {
|
|
105
|
+
count++;
|
|
106
|
+
setTimeout(check, 100);
|
|
37
107
|
}
|
|
38
108
|
};
|
|
39
109
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lemon-fe/mini-app",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.50",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"author": "鲁盛杰 <lusj@cnlemon.net>",
|
|
6
6
|
"homepage": "",
|
|
@@ -23,7 +23,6 @@
|
|
|
23
23
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"react": "^17.0.2",
|
|
27
26
|
"react-transition-group": "^4.4.2"
|
|
28
27
|
},
|
|
29
28
|
"peerDependencies": {
|
|
@@ -32,7 +31,8 @@
|
|
|
32
31
|
},
|
|
33
32
|
"devDependencies": {
|
|
34
33
|
"@types/react-transition-group": "^4.4.4",
|
|
35
|
-
"color-string": "^1.9.0"
|
|
34
|
+
"color-string": "^1.9.0",
|
|
35
|
+
"react": "^17.0.2"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "27699afefdba7171bdc07a5e90a81308d699d1bf"
|
|
38
38
|
}
|