@kbapp/js-bridge 1.0.8-alpha.0 → 1.0.10-alpha.0
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/README.md +7 -4
- package/dist/es/core/index.js +30 -29
- package/dist/es/core/lib/flutter-ds-bridge.js +1 -1
- package/dist/es/lib/app-version-support.js +31 -13
- package/dist/es/lib/generate-kb-sign.js +35 -8
- package/dist/es/lib/open-post-editor.js +56 -17
- package/dist/es/lib/share-model.js +36 -20
- package/dist/es/lib/subscribe-notify.js +24 -8
- package/dist/es/lib/trigger-login.js +49 -31
- package/dist/es/utils/wrap-async.js +44 -15
- package/dist/umd/index.js +2 -1
- package/package.json +7 -1
- package/.claude/settings.local.json +0 -6
- package/LOGIN.MD +0 -79
- package/tsconfig.json +0 -20
- package/vitest.config.ts +0 -18
package/README.md
CHANGED
|
@@ -15,13 +15,13 @@ npm i @kbapp/js-bridge
|
|
|
15
15
|
使用 unpkg CDN:
|
|
16
16
|
|
|
17
17
|
```html
|
|
18
|
-
<script src="https://unpkg.com/@kbapp/js-bridge@latest/dist/index.
|
|
18
|
+
<script src="https://unpkg.com/@kbapp/js-bridge@latest/dist/umd/index.js"></script>
|
|
19
19
|
```
|
|
20
20
|
|
|
21
21
|
使用 jsdelivr CDN:
|
|
22
22
|
|
|
23
23
|
```html
|
|
24
|
-
<script src="https://cdn.jsdelivr.net/npm/@kbapp/js-bridge@latest/dist/index.
|
|
24
|
+
<script src="https://cdn.jsdelivr.net/npm/@kbapp/js-bridge@latest/dist/umd/index.js"></script>
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
> 通过 script 标签引入后,SDK 将作为全局变量 `kbBridge` 挂载在 window 对象上
|
|
@@ -47,9 +47,11 @@ function saveImageHandle() {
|
|
|
47
47
|
|
|
48
48
|
### 通过 script 标签引入的使用示例
|
|
49
49
|
|
|
50
|
-
```
|
|
51
|
-
|
|
50
|
+
```html
|
|
51
|
+
<script src="https://unpkg.com/@kbapp/js-bridge@latest/dist/umd/index.js"></script>
|
|
52
|
+
<script>
|
|
52
53
|
async function saveImageHandle() {
|
|
54
|
+
// 通过全局变量kbBridge访问SDK功能
|
|
53
55
|
kbBridge.saveImageToLocal({
|
|
54
56
|
imageUrl: 'https://static.kaiba315.com.cn/kaiba-logo.png',
|
|
55
57
|
success() {
|
|
@@ -60,6 +62,7 @@ async function saveImageHandle() {
|
|
|
60
62
|
},
|
|
61
63
|
})
|
|
62
64
|
}
|
|
65
|
+
</script>
|
|
63
66
|
```
|
|
64
67
|
|
|
65
68
|
## API
|
package/dist/es/core/index.js
CHANGED
|
@@ -1,73 +1,74 @@
|
|
|
1
|
-
import { filterUndefinedAndNullProperties as
|
|
1
|
+
import { filterUndefinedAndNullProperties as b } from "../utils/filter-undefined-properties.js";
|
|
2
2
|
import { BridgeCode as d } from "../lib/bridge-code.js";
|
|
3
|
-
import
|
|
3
|
+
import k from "./lib/flutter-ds-bridge.js";
|
|
4
4
|
var g;
|
|
5
|
-
const
|
|
5
|
+
const r = ((e) => /(kb)/i.test(e) ? k() : {
|
|
6
6
|
registerHandler(u, n) {
|
|
7
7
|
throw d.UNSUPPORTED_BRIDGE_ENV;
|
|
8
8
|
},
|
|
9
9
|
callHandler(u, n, i) {
|
|
10
10
|
throw d.UNSUPPORTED_BRIDGE_ENV;
|
|
11
11
|
}
|
|
12
|
-
})((g = window == null ? void 0 : window.navigator) == null ? void 0 : g.userAgent),
|
|
13
|
-
var i,
|
|
12
|
+
})((g = window == null ? void 0 : window.navigator) == null ? void 0 : g.userAgent), B = (e) => new Promise((u, n) => {
|
|
13
|
+
var i, c, o;
|
|
14
14
|
try {
|
|
15
|
-
|
|
15
|
+
r.registerHandler(e.name, e.handler), (i = e.success) == null || i.call(e), u();
|
|
16
16
|
} catch (t) {
|
|
17
|
-
(
|
|
17
|
+
(c = e.fail) == null || c.call(e, t), n(t);
|
|
18
18
|
} finally {
|
|
19
|
-
(
|
|
19
|
+
(o = e.complete) == null || o.call(e);
|
|
20
20
|
}
|
|
21
21
|
});
|
|
22
|
-
function
|
|
22
|
+
function N(e) {
|
|
23
23
|
const u = (n) => {
|
|
24
24
|
let i;
|
|
25
|
-
const
|
|
25
|
+
const c = (t) => {
|
|
26
26
|
var l;
|
|
27
27
|
(!i || i === "success") && (i = "success", (l = n.success) == null || l.call(n, t));
|
|
28
|
-
},
|
|
28
|
+
}, o = (t) => {
|
|
29
29
|
var l;
|
|
30
30
|
i || (i = "error", (l = n.fail) == null || l.call(n, t));
|
|
31
31
|
};
|
|
32
32
|
n.timeout && setTimeout(() => {
|
|
33
|
-
|
|
33
|
+
o(d.TIMEOUT);
|
|
34
34
|
}, n.timeout);
|
|
35
35
|
try {
|
|
36
|
-
|
|
36
|
+
r.callHandler(n.name, n.params, (t) => {
|
|
37
37
|
let l;
|
|
38
38
|
try {
|
|
39
|
-
typeof t == "string" && /^\s*(\{|\[).*(\}|\])\s*$/.test(t) ? l = JSON.parse(t.
|
|
40
|
-
|
|
39
|
+
typeof t == "string" && /^\s*(\{|\[).*(\}|\])\s*$/.test(t) ? l = JSON.parse(t.trim().replace(/[\u0000-\u001F\u007F-\u009F]/g, (f) => f === `
|
|
40
|
+
` ? "\\n" : f === "\r" ? "\\r" : f === " " ? "\\t" : "")) : l = t;
|
|
41
|
+
} catch (f) {
|
|
41
42
|
l = t;
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
+
c(l);
|
|
44
45
|
});
|
|
45
46
|
} catch (t) {
|
|
46
|
-
|
|
47
|
+
o(t);
|
|
47
48
|
}
|
|
48
49
|
};
|
|
49
50
|
return new Promise((n, i) => {
|
|
50
51
|
u({
|
|
51
52
|
name: e.name,
|
|
52
|
-
params:
|
|
53
|
+
params: b(e.params),
|
|
53
54
|
timeout: e.timeout,
|
|
54
|
-
success: (
|
|
55
|
-
var
|
|
56
|
-
(
|
|
55
|
+
success: (c) => {
|
|
56
|
+
var o, t;
|
|
57
|
+
(o = e.success) == null || o.call(e, c), (t = e.complete) == null || t.call(e), n(c);
|
|
57
58
|
},
|
|
58
|
-
fail: (
|
|
59
|
-
var
|
|
60
|
-
(
|
|
59
|
+
fail: (c) => {
|
|
60
|
+
var o, t;
|
|
61
|
+
(o = e.fail) == null || o.call(e, c), (t = e.complete) == null || t.call(e), i(c);
|
|
61
62
|
}
|
|
62
63
|
});
|
|
63
64
|
});
|
|
64
65
|
}
|
|
65
|
-
function
|
|
66
|
-
|
|
66
|
+
function U(e) {
|
|
67
|
+
r.callHandler(e.name, e.params, (u) => {
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
70
|
export {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
71
|
+
B as defineBridgeCallback,
|
|
72
|
+
U as runBridgeApi,
|
|
73
|
+
N as runBridgeApiResponse
|
|
73
74
|
};
|
|
@@ -11,7 +11,7 @@ const S = () => {
|
|
|
11
11
|
return n;
|
|
12
12
|
try {
|
|
13
13
|
return JSON.parse(n || "{}").data;
|
|
14
|
-
} catch {
|
|
14
|
+
} catch (f) {
|
|
15
15
|
console.error("callHandle异常,JSON.parse错误");
|
|
16
16
|
}
|
|
17
17
|
}, _ = () => window.navigator.userAgent.includes("Android") ? window.flutter_inappwebview && window.flutter_inappwebview._platformReady : !0, y = (() => {
|
|
@@ -1,18 +1,36 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
1
|
+
var m = (e, n, o) => new Promise((i, s) => {
|
|
2
|
+
var V = (r) => {
|
|
3
|
+
try {
|
|
4
|
+
t(o.next(r));
|
|
5
|
+
} catch (p) {
|
|
6
|
+
s(p);
|
|
7
|
+
}
|
|
8
|
+
}, a = (r) => {
|
|
9
|
+
try {
|
|
10
|
+
t(o.throw(r));
|
|
11
|
+
} catch (p) {
|
|
12
|
+
s(p);
|
|
13
|
+
}
|
|
14
|
+
}, t = (r) => r.done ? i(r.value) : Promise.resolve(r.value).then(V, a);
|
|
15
|
+
t((o = o.apply(e, n)).next());
|
|
16
|
+
});
|
|
17
|
+
import { wrapAsync as c } from "../utils/wrap-async.js";
|
|
18
|
+
import { getAppBaseInfo as d } from "./get-app-base-info.js";
|
|
19
|
+
import { BridgeCode as u } from "./bridge-code.js";
|
|
20
|
+
const f = c((e) => m(void 0, null, function* () {
|
|
21
|
+
return (yield d()).vcode >= e.minVersion;
|
|
22
|
+
}));
|
|
23
|
+
function P(e, n) {
|
|
24
|
+
return (...o) => f({
|
|
25
|
+
minVersion: e.minVersion
|
|
26
|
+
}).then((i) => i ? n(...o) : Promise.reject(
|
|
27
|
+
new u({
|
|
28
|
+
errorCode: u.UNSUPPORTED_VERSION.errorCode,
|
|
29
|
+
errorMsg: `最低版本要求${e.minVersion}`
|
|
12
30
|
})
|
|
13
31
|
));
|
|
14
32
|
}
|
|
15
33
|
export {
|
|
16
|
-
|
|
17
|
-
|
|
34
|
+
P as decorateAppVersionSupport,
|
|
35
|
+
f as isAppVersionSupport
|
|
18
36
|
};
|
|
@@ -1,16 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var m = Object.getOwnPropertySymbols;
|
|
2
|
+
var d = Object.prototype.hasOwnProperty, g = Object.prototype.propertyIsEnumerable;
|
|
3
|
+
var i = (e, r) => {
|
|
4
|
+
var a = {};
|
|
5
|
+
for (var t in e)
|
|
6
|
+
d.call(e, t) && r.indexOf(t) < 0 && (a[t] = e[t]);
|
|
7
|
+
if (e != null && m)
|
|
8
|
+
for (var t of m(e))
|
|
9
|
+
r.indexOf(t) < 0 && g.call(e, t) && (a[t] = e[t]);
|
|
10
|
+
return a;
|
|
11
|
+
};
|
|
12
|
+
var c = (e, r, a) => new Promise((t, o) => {
|
|
13
|
+
var u = (n) => {
|
|
14
|
+
try {
|
|
15
|
+
p(a.next(n));
|
|
16
|
+
} catch (s) {
|
|
17
|
+
o(s);
|
|
18
|
+
}
|
|
19
|
+
}, y = (n) => {
|
|
20
|
+
try {
|
|
21
|
+
p(a.throw(n));
|
|
22
|
+
} catch (s) {
|
|
23
|
+
o(s);
|
|
24
|
+
}
|
|
25
|
+
}, p = (n) => n.done ? t(n.value) : Promise.resolve(n.value).then(u, y);
|
|
26
|
+
p((a = a.apply(e, r)).next());
|
|
27
|
+
});
|
|
28
|
+
import { wrapAsync as A } from "../utils/wrap-async.js";
|
|
29
|
+
import { runBridgeApiResponse as f } from "../core/index.js";
|
|
30
|
+
const R = A((e) => c(void 0, null, function* () {
|
|
31
|
+
const o = e, { kbKey: r } = o, a = i(o, ["kbKey"]), { data: t } = yield f({
|
|
5
32
|
name: "OpenActRequest",
|
|
6
33
|
timeout: 5e3,
|
|
7
34
|
params: {
|
|
8
35
|
type: 51,
|
|
9
|
-
data:
|
|
36
|
+
data: a
|
|
10
37
|
}
|
|
11
38
|
});
|
|
12
|
-
return
|
|
13
|
-
});
|
|
39
|
+
return t;
|
|
40
|
+
}));
|
|
14
41
|
export {
|
|
15
|
-
|
|
42
|
+
R as generateKBSign
|
|
16
43
|
};
|
|
@@ -1,13 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var
|
|
4
|
-
|
|
1
|
+
var E = Object.defineProperty;
|
|
2
|
+
var r = Object.getOwnPropertySymbols;
|
|
3
|
+
var h = Object.prototype.hasOwnProperty, x = Object.prototype.propertyIsEnumerable;
|
|
4
|
+
var c = (t, e, i) => e in t ? E(t, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : t[e] = i, a = (t, e) => {
|
|
5
|
+
for (var i in e || (e = {}))
|
|
6
|
+
h.call(e, i) && c(t, i, e[i]);
|
|
7
|
+
if (r)
|
|
8
|
+
for (var i of r(e))
|
|
9
|
+
x.call(e, i) && c(t, i, e[i]);
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
var g = (t, e) => {
|
|
13
|
+
var i = {};
|
|
14
|
+
for (var o in t)
|
|
15
|
+
h.call(t, o) && e.indexOf(o) < 0 && (i[o] = t[o]);
|
|
16
|
+
if (t != null && r)
|
|
17
|
+
for (var o of r(t))
|
|
18
|
+
e.indexOf(o) < 0 && x.call(t, o) && (i[o] = t[o]);
|
|
19
|
+
return i;
|
|
20
|
+
};
|
|
21
|
+
var _ = (t, e, i) => new Promise((o, s) => {
|
|
22
|
+
var d = (n) => {
|
|
23
|
+
try {
|
|
24
|
+
R(i.next(n));
|
|
25
|
+
} catch (u) {
|
|
26
|
+
s(u);
|
|
27
|
+
}
|
|
28
|
+
}, l = (n) => {
|
|
29
|
+
try {
|
|
30
|
+
R(i.throw(n));
|
|
31
|
+
} catch (u) {
|
|
32
|
+
s(u);
|
|
33
|
+
}
|
|
34
|
+
}, R = (n) => n.done ? o(n.value) : Promise.resolve(n.value).then(d, l);
|
|
35
|
+
R((i = i.apply(t, e)).next());
|
|
36
|
+
});
|
|
37
|
+
import { runBridgeApiResponse as M } from "../core/index.js";
|
|
38
|
+
import { wrapAsync as m } from "../utils/wrap-async.js";
|
|
39
|
+
var v = /* @__PURE__ */ ((t) => (t[t.FREE = 1] = "FREE", t[t.FORBID = 2] = "FORBID", t[t.REQUIRED = 3] = "REQUIRED", t))(v || {});
|
|
40
|
+
class q {
|
|
5
41
|
constructor() {
|
|
6
42
|
this.textMin = 0, this.textMax = 1e3, this.imageMax = 9, this.imageMin = 0, this.audioRqr = 1, this.videoRqr = 1, this.mediaRqr = 2, this.streetRqr = 1;
|
|
7
43
|
}
|
|
8
44
|
}
|
|
9
|
-
function
|
|
10
|
-
const e = new
|
|
45
|
+
function B(t) {
|
|
46
|
+
const e = new q();
|
|
11
47
|
return t && Object.keys(t).forEach((i) => {
|
|
12
48
|
e[i] = t[i];
|
|
13
49
|
}), {
|
|
@@ -29,18 +65,21 @@ function c(t) {
|
|
|
29
65
|
content_min_length: e.textMin
|
|
30
66
|
};
|
|
31
67
|
}
|
|
32
|
-
const
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
68
|
+
const D = m(
|
|
69
|
+
(t) => _(void 0, null, function* () {
|
|
70
|
+
var e;
|
|
71
|
+
return M({
|
|
72
|
+
name: "OpenActRequest",
|
|
73
|
+
params: { type: 13, data: (e = t == null ? void 0 : t.postRule) != null ? e : {} }
|
|
74
|
+
}).then(({ data: i }) => {
|
|
75
|
+
const d = i, { pic: o } = d, s = g(d, ["pic"]);
|
|
76
|
+
return a({ images: o }, s);
|
|
77
|
+
});
|
|
39
78
|
})
|
|
40
79
|
);
|
|
41
80
|
export {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
81
|
+
v as KbRequirement,
|
|
82
|
+
q as NoteThreadPostRule,
|
|
83
|
+
B as generatePostEditorParamsByThreadPostRule,
|
|
84
|
+
D as openPostEditor
|
|
46
85
|
};
|
|
@@ -1,30 +1,46 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var A = (e, d, n) => new Promise((s, i) => {
|
|
2
|
+
var w = (t) => {
|
|
3
|
+
try {
|
|
4
|
+
p(n.next(t));
|
|
5
|
+
} catch (a) {
|
|
6
|
+
i(a);
|
|
7
|
+
}
|
|
8
|
+
}, E = (t) => {
|
|
9
|
+
try {
|
|
10
|
+
p(n.throw(t));
|
|
11
|
+
} catch (a) {
|
|
12
|
+
i(a);
|
|
13
|
+
}
|
|
14
|
+
}, p = (t) => t.done ? s(t.value) : Promise.resolve(t.value).then(w, E);
|
|
15
|
+
p((n = n.apply(e, d)).next());
|
|
16
|
+
});
|
|
17
|
+
import { defineBridgeCallback as S, runBridgeApi as h } from "../core/index.js";
|
|
18
|
+
import { wrapAsync as r } from "../utils/wrap-async.js";
|
|
19
|
+
const o = "SHARE_EVENT_NAME";
|
|
20
|
+
class f {
|
|
5
21
|
}
|
|
6
|
-
const
|
|
22
|
+
const u = r((e) => S({
|
|
7
23
|
name: "CommonShare",
|
|
8
|
-
handler(
|
|
9
|
-
window.dispatchEvent(new Event(
|
|
24
|
+
handler(d, n) {
|
|
25
|
+
window.dispatchEvent(new Event(o)), "onShareApp" in e && e.onShareApp ? n({ type: 12, data: e.onShareApp() }) : n({ type: 12, data: e });
|
|
10
26
|
}
|
|
11
|
-
})),
|
|
12
|
-
window.dispatchEvent(new Event(
|
|
27
|
+
})), v = r((e) => A(void 0, null, function* () {
|
|
28
|
+
window.dispatchEvent(new Event(o)), h({
|
|
13
29
|
name: "OpenActRequest",
|
|
14
30
|
params: {
|
|
15
31
|
type: 58,
|
|
16
32
|
data: e
|
|
17
33
|
}
|
|
18
34
|
});
|
|
19
|
-
});
|
|
20
|
-
function
|
|
21
|
-
return window.addEventListener(
|
|
22
|
-
window.removeEventListener(
|
|
35
|
+
}));
|
|
36
|
+
function y(e) {
|
|
37
|
+
return window.addEventListener(o, e), () => {
|
|
38
|
+
window.removeEventListener(o, e);
|
|
23
39
|
};
|
|
24
40
|
}
|
|
25
|
-
const
|
|
41
|
+
const M = r(
|
|
26
42
|
(e) => {
|
|
27
|
-
|
|
43
|
+
h({
|
|
28
44
|
name: "OpenActRequest",
|
|
29
45
|
params: {
|
|
30
46
|
type: 68,
|
|
@@ -37,9 +53,9 @@ const E = t(
|
|
|
37
53
|
}
|
|
38
54
|
);
|
|
39
55
|
export {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
56
|
+
f as AppShareModel,
|
|
57
|
+
u as defineAppShareModel,
|
|
58
|
+
M as defineAppSharePanelState,
|
|
59
|
+
y as onAppSharePanelShow,
|
|
60
|
+
v as openAppSharePanel
|
|
45
61
|
};
|
|
@@ -1,19 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var s = (o, a, t) => new Promise((c, n) => {
|
|
2
|
+
var m = (e) => {
|
|
3
|
+
try {
|
|
4
|
+
p(t.next(e));
|
|
5
|
+
} catch (r) {
|
|
6
|
+
n(r);
|
|
7
|
+
}
|
|
8
|
+
}, u = (e) => {
|
|
9
|
+
try {
|
|
10
|
+
p(t.throw(e));
|
|
11
|
+
} catch (r) {
|
|
12
|
+
n(r);
|
|
13
|
+
}
|
|
14
|
+
}, p = (e) => e.done ? c(e.value) : Promise.resolve(e.value).then(m, u);
|
|
15
|
+
p((t = t.apply(o, a)).next());
|
|
16
|
+
});
|
|
17
|
+
import { runBridgeApiResponse as A, runBridgeApi as y } from "../core/index.js";
|
|
18
|
+
import { wrapAsync as i } from "../utils/wrap-async.js";
|
|
19
|
+
const S = i(() => A({
|
|
4
20
|
name: "OpenActRequest",
|
|
5
21
|
params: {
|
|
6
22
|
type: 72
|
|
7
23
|
}
|
|
8
|
-
})),
|
|
9
|
-
|
|
24
|
+
})), R = i(() => s(void 0, null, function* () {
|
|
25
|
+
y({
|
|
10
26
|
name: "OpenActRequest",
|
|
11
27
|
params: {
|
|
12
28
|
type: 73
|
|
13
29
|
}
|
|
14
30
|
});
|
|
15
|
-
});
|
|
31
|
+
}));
|
|
16
32
|
export {
|
|
17
|
-
|
|
18
|
-
|
|
33
|
+
S as getAppSubscribeNotifyStatus,
|
|
34
|
+
R as openAppSubscribeNotifySettings
|
|
19
35
|
};
|
|
@@ -1,56 +1,74 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
var c = (t, o, e) => new Promise((i, n) => {
|
|
2
|
+
var u = (a) => {
|
|
3
|
+
try {
|
|
4
|
+
r(e.next(a));
|
|
5
|
+
} catch (g) {
|
|
6
|
+
n(g);
|
|
7
|
+
}
|
|
8
|
+
}, s = (a) => {
|
|
9
|
+
try {
|
|
10
|
+
r(e.throw(a));
|
|
11
|
+
} catch (g) {
|
|
12
|
+
n(g);
|
|
13
|
+
}
|
|
14
|
+
}, r = (a) => a.done ? i(a.value) : Promise.resolve(a.value).then(u, s);
|
|
15
|
+
r((e = e.apply(t, o)).next());
|
|
16
|
+
});
|
|
17
|
+
import { runBridgeApiResponse as T, runBridgeApi as d } from "../core/index.js";
|
|
18
|
+
import { wrapAsync as k } from "../utils/wrap-async.js";
|
|
19
|
+
class A {
|
|
4
20
|
}
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
21
|
+
const l = k(() => c(void 0, null, function* () {
|
|
22
|
+
return (yield T({
|
|
23
|
+
name: "OpenActRequest",
|
|
24
|
+
timeout: 5e3,
|
|
25
|
+
params: { type: 31, data: { requireLogin: !1 } }
|
|
26
|
+
})).data || null;
|
|
27
|
+
})), p = /* @__PURE__ */ (() => {
|
|
28
|
+
const t = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ (() => {
|
|
29
|
+
let e;
|
|
30
|
+
const i = (n) => {
|
|
31
|
+
e = setTimeout(() => c(void 0, null, function* () {
|
|
32
|
+
const s = yield l();
|
|
15
33
|
if (!s)
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
}, ((s) => s === 0 ? 0 : s < 50 ? 600 : s < 80 ? 1e3 : 5e3)(
|
|
34
|
+
return i(++n);
|
|
35
|
+
t.forEach((r) => r(s)), t.clear();
|
|
36
|
+
}), ((s) => s === 0 ? 0 : s < 50 ? 600 : s < 80 ? 1e3 : 5e3)(n));
|
|
19
37
|
};
|
|
20
38
|
return {
|
|
21
39
|
start() {
|
|
22
|
-
|
|
40
|
+
e && clearTimeout(e), t.size > 0 && i(0);
|
|
23
41
|
},
|
|
24
42
|
stop() {
|
|
25
|
-
|
|
43
|
+
e && clearTimeout(e);
|
|
26
44
|
}
|
|
27
45
|
};
|
|
28
46
|
})();
|
|
29
47
|
return {
|
|
30
48
|
/** 注册监听事件(需要通过triggerCheckTask触发检测任务) */
|
|
31
|
-
addTask(
|
|
32
|
-
|
|
49
|
+
addTask(e) {
|
|
50
|
+
t.add(e);
|
|
33
51
|
},
|
|
34
52
|
/** 移除监听 */
|
|
35
|
-
removeTask(
|
|
36
|
-
|
|
53
|
+
removeTask(e) {
|
|
54
|
+
t.delete(e), t.size === 0 && o.stop();
|
|
37
55
|
},
|
|
38
56
|
/** 触发定时检测是否登录成功任务 */
|
|
39
57
|
triggerCheckTask() {
|
|
40
|
-
|
|
58
|
+
o.start();
|
|
41
59
|
}
|
|
42
60
|
};
|
|
43
|
-
})(),
|
|
44
|
-
|
|
61
|
+
})(), y = k(() => c(void 0, null, function* () {
|
|
62
|
+
p.triggerCheckTask(), yield d({
|
|
45
63
|
name: "OpenActRequest",
|
|
46
64
|
params: { type: 31, data: { requireLogin: !0 } }
|
|
47
65
|
});
|
|
48
|
-
}),
|
|
49
|
-
|
|
66
|
+
})), L = (t) => (p.addTask(t), p.triggerCheckTask(), () => {
|
|
67
|
+
p.removeTask(t);
|
|
50
68
|
});
|
|
51
69
|
export {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
70
|
+
A as AppLoginInfo,
|
|
71
|
+
l as getAppLoginInfo,
|
|
72
|
+
L as onLoopCheckAppLogin,
|
|
73
|
+
y as triggerAppLogin
|
|
56
74
|
};
|
|
@@ -1,21 +1,50 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
var u = Object.getOwnPropertySymbols;
|
|
2
|
+
var C = Object.prototype.hasOwnProperty, f = Object.prototype.propertyIsEnumerable;
|
|
3
|
+
var w = (t, a) => {
|
|
4
|
+
var e = {};
|
|
5
|
+
for (var r in t)
|
|
6
|
+
C.call(t, r) && a.indexOf(r) < 0 && (e[r] = t[r]);
|
|
7
|
+
if (t != null && u)
|
|
8
|
+
for (var r of u(t))
|
|
9
|
+
a.indexOf(r) < 0 && f.call(t, r) && (e[r] = t[r]);
|
|
10
|
+
return e;
|
|
11
|
+
};
|
|
12
|
+
var m = (t, a, e) => new Promise((r, s) => {
|
|
13
|
+
var c = (n) => {
|
|
14
|
+
try {
|
|
15
|
+
d(e.next(n));
|
|
16
|
+
} catch (o) {
|
|
17
|
+
s(o);
|
|
18
|
+
}
|
|
19
|
+
}, i = (n) => {
|
|
5
20
|
try {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
const n = r != null && r.errorCode ? r : new s({
|
|
10
|
-
errorCode: s.UNKNOWN.errorCode,
|
|
11
|
-
errorMsg: String(r)
|
|
12
|
-
});
|
|
13
|
-
throw t == null || t(n), n;
|
|
14
|
-
} finally {
|
|
15
|
-
e == null || e();
|
|
21
|
+
d(e.throw(n));
|
|
22
|
+
} catch (o) {
|
|
23
|
+
s(o);
|
|
16
24
|
}
|
|
25
|
+
}, d = (n) => n.done ? r(n.value) : Promise.resolve(n.value).then(c, i);
|
|
26
|
+
d((e = e.apply(t, a)).next());
|
|
27
|
+
});
|
|
28
|
+
import { BridgeCode as y } from "../lib/bridge-code.js";
|
|
29
|
+
function N(t) {
|
|
30
|
+
return function(...e) {
|
|
31
|
+
return m(this, null, function* () {
|
|
32
|
+
const n = e[0] || {}, { success: s, fail: c, complete: i } = n, d = w(n, ["success", "fail", "complete"]);
|
|
33
|
+
try {
|
|
34
|
+
const o = yield Promise.resolve(t(d));
|
|
35
|
+
return s == null || s(o), o;
|
|
36
|
+
} catch (o) {
|
|
37
|
+
const p = o != null && o.errorCode ? o : new y({
|
|
38
|
+
errorCode: y.UNKNOWN.errorCode,
|
|
39
|
+
errorMsg: String(o)
|
|
40
|
+
});
|
|
41
|
+
throw c == null || c(p), p;
|
|
42
|
+
} finally {
|
|
43
|
+
i == null || i();
|
|
44
|
+
}
|
|
45
|
+
});
|
|
17
46
|
};
|
|
18
47
|
}
|
|
19
48
|
export {
|
|
20
|
-
|
|
49
|
+
N as wrapAsync
|
|
21
50
|
};
|
package/dist/umd/index.js
CHANGED
|
@@ -1 +1,2 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(t,l){typeof exports=="object"&&typeof module!="undefined"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(t=typeof globalThis!="undefined"?globalThis:t||self,l(t.kbBridge={}))})(this,function(t){"use strict";var Ee=Object.defineProperty;var b=Object.getOwnPropertySymbols;var Q=Object.prototype.hasOwnProperty,G=Object.prototype.propertyIsEnumerable;var W=(t,l,c)=>l in t?Ee(t,l,{enumerable:!0,configurable:!0,writable:!0,value:c}):t[l]=c,K=(t,l)=>{for(var c in l||(l={}))Q.call(l,c)&&W(t,c,l[c]);if(b)for(var c of b(l))G.call(l,c)&&W(t,c,l[c]);return t};var m=(t,l)=>{var c={};for(var h in t)Q.call(t,h)&&l.indexOf(h)<0&&(c[h]=t[h]);if(t!=null&&b)for(var h of b(t))l.indexOf(h)<0&&G.call(t,h)&&(c[h]=t[h]);return c};var A=(t,l,c)=>new Promise((h,_)=>{var R=d=>{try{p(c.next(d))}catch(E){_(E)}},y=d=>{try{p(c.throw(d))}catch(E){_(E)}},p=d=>d.done?h(d.value):Promise.resolve(d.value).then(R,y);p((c=c.apply(t,l)).next())});var L;function l(e){if(Object.prototype.toString.call(e)!=="[object Object]")return e;const r={};return Object.keys(e).forEach(n=>{const a=e[n];a!=null&&(r[n]=Object.prototype.toString.call(a)==="[object Object]"?l(a):a)}),r}const w=class w{constructor(r){this.errorCode=r.errorCode,this.errorMsg=r.errorMsg}};w.UNKNOWN=new w({errorCode:1e3,errorMsg:"未知错误"}),w.UNSUPPORTED_VERSION=new w({errorCode:1001,errorMsg:"当前开吧版本不支持"}),w.TIMEOUT=new w({errorCode:1002,errorMsg:"执行超时"}),w.UNSUPPORTED_BRIDGE_ENV=new w({errorCode:1003,errorMsg:"请在开吧app内执行"});let c=w;const h=()=>{const e=(o,s,i)=>{var u="";typeof s=="function"&&(i=s,s={});var f={data:s===void 0?null:s};if(typeof i=="function"){var g="dscb"+window.dscb++;window[g]=i,f._dscbstub=g}if(f=JSON.stringify(f),window.flutter_inappwebview?window.flutter_inappwebview.callHandler&&(u=window.flutter_inappwebview.callHandler(""+o,f)):(window._dswk||navigator.userAgent.indexOf("_dsbridge")!=-1)&&(u=prompt("_flutterDsbridge="+o,f)),u instanceof Promise)return u;try{return JSON.parse(u||"{}").data}catch(S){console.error("callHandle异常,JSON.parse错误")}},r=()=>window.navigator.userAgent.includes("Android")?window.flutter_inappwebview&&window.flutter_inappwebview._platformReady:!0,n=(()=>{const o=[],s=setInterval(()=>{r()&&(clearInterval(s),o.forEach(i=>{e.apply(window,i)}),o.length=0)},500);return(...i)=>{o.push(i)}})();var a={default:void 0,callHandler:function(o,s,i){return r()?e(o,s,i):n(o,s,i)},register:function(o,s,i){var u=i?window._dsaf:window._dsf;window._dsInit||(window._dsInit=!0,setTimeout(function(){a.callHandler("_dsb.dsinit")},0)),typeof s=="object"?u._obs[o]=s:u[o]=s},registerHandler:function(o,s){this.register(o,s,!0)}};return function(){if(!window._dsf){var o={_dsf:{_obs:{}},_dsaf:{_obs:{}},dscb:0,jsBridge:a,_handleMessageFromNative:function(i){var u=JSON.parse(i.data),f={id:i.callbackId,complete:!0},g=this._dsf[i.method],S=this._dsaf[i.method],H=function(N,M){f.data=N.apply(M,u),a.callHandler("_dsb.returnValue",f)},j=function(N,M){u.push(function(Se,Re){f.data=Se,f.complete=Re!==!1,a.callHandler("_dsb.returnValue",f)}),N.apply(M,u)};if(g)H(g,this._dsf);else if(S)j(S,this._dsaf);else{var k=i.method.split(".");if(k.length<2)return;var F=k.pop(),J=k.join("."),I=this._dsf._obs,O=I[J]||{},v=O[F];if(v&&typeof v=="function"){H(v,O);return}if(I=this._dsaf._obs,O=I[J]||{},v=O[F],v&&typeof v=="function"){j(v,O);return}}}};for(var s in o)window[s]=o[s]}}(),a},_=(e=>/(kb)/i.test(e)?h():{registerHandler(r,n){throw c.UNSUPPORTED_BRIDGE_ENV},callHandler(r,n,a){throw c.UNSUPPORTED_BRIDGE_ENV}})((L=window==null?void 0:window.navigator)==null?void 0:L.userAgent),R=e=>new Promise((r,n)=>{var a,o,s;try{_.registerHandler(e.name,e.handler),(a=e.success)==null||a.call(e),r()}catch(i){(o=e.fail)==null||o.call(e,i),n(i)}finally{(s=e.complete)==null||s.call(e)}});function y(e){const r=n=>{let a;const o=i=>{var u;(!a||a==="success")&&(a="success",(u=n.success)==null||u.call(n,i))},s=i=>{var u;a||(a="error",(u=n.fail)==null||u.call(n,i))};n.timeout&&setTimeout(()=>{s(c.TIMEOUT)},n.timeout);try{_.callHandler(n.name,n.params,i=>{let u;try{typeof i=="string"&&/^\s*(\{|\[).*(\}|\])\s*$/.test(i)?u=JSON.parse(i.trim().replace(/[\u0000-\u001F\u007F-\u009F]/g,f=>f===`
|
|
2
|
+
`?"\\n":f==="\r"?"\\r":f===" "?"\\t":"")):u=i}catch(f){u=i}o(u)})}catch(i){s(i)}};return new Promise((n,a)=>{r({name:e.name,params:l(e.params),timeout:e.timeout,success:o=>{var s,i;(s=e.success)==null||s.call(e,o),(i=e.complete)==null||i.call(e),n(o)},fail:o=>{var s,i;(s=e.fail)==null||s.call(e,o),(i=e.complete)==null||i.call(e),a(o)}})})}function p(e){_.callHandler(e.name,e.params,r=>{})}function d(e){return function(...n){return A(this,null,function*(){const f=n[0]||{},{success:o,fail:s,complete:i}=f,u=m(f,["success","fail","complete"]);try{const g=yield Promise.resolve(e(u));return o==null||o(g),g}catch(g){const S=g!=null&&g.errorCode?g:new c({errorCode:c.UNKNOWN.errorCode,errorMsg:String(g)});throw s==null||s(S),S}finally{i==null||i()}})}}function E(e){const r=new Map;return function(...n){const a=JSON.stringify(n);if(r.has(a))return r.get(a);const o=e(...n);return r.set(a,o),Promise.resolve(o).catch(()=>{r.delete(a)}),o}}class ${}const q=d(E(()=>y({name:"OpenActRequest",timeout:5e3,params:{type:35,data:{}}}))),V=d(e=>A(this,null,function*(){return(yield q()).vcode>=e.minVersion}));function z(e,r){return(...n)=>V({minVersion:e.minVersion}).then(a=>a?r(...n):Promise.reject(new c({errorCode:c.UNSUPPORTED_VERSION.errorCode,errorMsg:`最低版本要求${e.minVersion}`})))}const X=d(()=>{p({name:"OpenActRequest",params:{type:56,data:null}})}),Y=d(()=>{p({name:"OpenActRequest",params:{type:-1,data:{}}})}),U={microphone:{description:"用于发帖上传音频"},location:{description:"获取你选择的位置信息,用于线下导航服务"},camera:{description:"收集你选中的照片或视频信息 ,用于 发表评论、分享视频"}},Z=d(e=>(Object.assign(U,e),R({name:"getPermissionUsage",handler(r,n){n(U[r.permission])}}))),x=/(kb_flutter|kb_dsbridge_flutter|kb_ios|kb_android|kb_dsbridge_android)/i.test(window.navigator.userAgent),ee=d(e=>A(this,null,function*(){const o=e,{kbKey:r}=o,n=m(o,["kbKey"]),{data:a}=yield y({name:"OpenActRequest",timeout:5e3,params:{type:51,data:n}});return a}));var B=(e=>(e[e.FREE=1]="FREE",e[e.FORBID=2]="FORBID",e[e.REQUIRED=3]="REQUIRED",e))(B||{});class C{constructor(){this.textMin=0,this.textMax=1e3,this.imageMax=9,this.imageMin=0,this.audioRqr=1,this.videoRqr=1,this.mediaRqr=2,this.streetRqr=1}}function te(e){const r=new C;return e&&Object.keys(e).forEach(n=>{r[n]=e[n]}),{hint:e==null?void 0:e.placeholder,initialText:e==null?void 0:e.initialText,audio:r.audioRqr!==2,image:r.imageMax!==0,video:r.videoRqr!==2,address:r.streetRqr!==2,asset_video:r.mediaRqr!==2,audio_must:r.audioRqr===3,image_must:r.imageMin>0,asset_video_must:r.mediaRqr===3,max_image_count:r.imageMax,min_image_count:r.imageMin,video_must:r.videoRqr===3,text_must:r.textMin>0,content_max_length:r.textMax,content_min_length:r.textMin}}const ne=d(e=>A(this,null,function*(){var r;return y({name:"OpenActRequest",params:{type:13,data:(r=e==null?void 0:e.postRule)!=null?r:{}}}).then(({data:n})=>{const s=n,{pic:a}=s,o=m(s,["pic"]);return K({images:a},o)})})),ie=d(e=>{p({name:"OpenActRequest",params:{type:69,data:{eventId:e.eventName,trackParams:e.eventParams,ExtEventType:e.eventType}}})}),re=d(e=>{p({name:"OpenActRequest",params:{type:1001,data:e}})}),oe=d(e=>{p({name:"OpenActRequest",params:{type:62,data:e}})}),se=d(e=>{p({name:"OpenActRequest",params:{type:63,data:e}})}),ae=d(()=>y({name:"OpenActRequest",params:{type:26,data:{}}})),ce=d(e=>{p({name:"OpenActRequest",params:{type:71,data:e}})}),de=d(e=>{p({name:"OpenActRequest",params:{type:64,data:e}})}),ue=d(e=>{p({name:"OpenActRequest",params:{type:58,data:e}})}),P="SHARE_EVENT_NAME";class le{}const fe=d(e=>R({name:"CommonShare",handler(r,n){window.dispatchEvent(new Event(P)),"onShareApp"in e&&e.onShareApp?n({type:12,data:e.onShareApp()}):n({type:12,data:e})}})),pe=d(e=>A(this,null,function*(){window.dispatchEvent(new Event(P)),p({name:"OpenActRequest",params:{type:58,data:e}})}));function ge(e){return window.addEventListener(P,e),()=>{window.removeEventListener(P,e)}}const he=d(e=>{p({name:"OpenActRequest",params:{type:68,data:{show:e.showMenu,showActionMode:e.panelStyle||0}}})}),we=d(()=>y({name:"OpenActRequest",params:{type:72}})),Ae=d(()=>A(this,null,function*(){p({name:"OpenActRequest",params:{type:73}})}));class ye{}const D=d(()=>A(this,null,function*(){return(yield y({name:"OpenActRequest",timeout:5e3,params:{type:31,data:{requireLogin:!1}}})).data||null})),T=(()=>{const e=new Set,r=(()=>{let n;const a=o=>{n=setTimeout(()=>A(this,null,function*(){const i=yield D();if(!i)return a(++o);e.forEach(u=>u(i)),e.clear()}),(i=>i===0?0:i<50?600:i<80?1e3:5e3)(o))};return{start(){n&&clearTimeout(n),e.size>0&&a(0)},stop(){n&&clearTimeout(n)}}})();return{addTask(n){e.add(n)},removeTask(n){e.delete(n),e.size===0&&r.stop()},triggerCheckTask(){r.start()}}})(),ve=d(()=>A(this,null,function*(){T.triggerCheckTask(),yield p({name:"OpenActRequest",params:{type:31,data:{requireLogin:!0}}})})),_e=e=>(T.addTask(e),T.triggerCheckTask(),()=>{T.removeTask(e)});t.AppBaseInfo=$,t.AppLoginInfo=ye,t.AppShareModel=le,t.BridgeCode=c,t.IS_KB_APP_ENV=x,t.KbRequirement=B,t.NoteThreadPostRule=C,t.checkForNewVersion=X,t.closeWebView=Y,t.decorateAppVersionSupport=z,t.defineAppShareModel=fe,t.defineAppSharePanelState=he,t.defineBridgeCallback=R,t.definePermissionUsage=Z,t.generateKBSign=ee,t.generatePostEditorParamsByThreadPostRule=te,t.getAppBaseInfo=q,t.getAppLoginInfo=D,t.getAppSubscribeNotifyStatus=we,t.isAppVersionSupport=V,t.onAppSharePanelShow=ge,t.onLoopCheckAppLogin=_e,t.openAppSharePanel=pe,t.openAppSubscribeNotifySettings=Ae,t.openPostEditor=ne,t.reportDAEvent=ie,t.runAction=re,t.runBridgeApi=p,t.runBridgeApiResponse=y,t.saveImageToLocal=oe,t.saveVideoToLocal=se,t.scanQRCode=ae,t.setScreenOrientation=ce,t.setWebViewTitle=de,t.shareImage=ue,t.triggerAppLogin=ve,Object.defineProperty(t,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"publishConfig": {
|
|
4
4
|
"access": "public"
|
|
5
5
|
},
|
|
6
|
-
"version": "1.0.
|
|
6
|
+
"version": "1.0.10-alpha.0",
|
|
7
7
|
"description": "开吧客户端桥接",
|
|
8
8
|
"author": "along",
|
|
9
9
|
"main": "./dist/umd/index.js",
|
|
@@ -24,6 +24,12 @@
|
|
|
24
24
|
"publish": "npm run build && npm publish",
|
|
25
25
|
"test": "vitest"
|
|
26
26
|
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist",
|
|
29
|
+
"package.json",
|
|
30
|
+
"README.md",
|
|
31
|
+
"examples"
|
|
32
|
+
],
|
|
27
33
|
"devDependencies": {
|
|
28
34
|
"@vitest/ui": "^4.1.2",
|
|
29
35
|
"jsdom": "^29.0.1",
|
package/LOGIN.MD
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
### 登录设计
|
|
3
|
-
|
|
4
|
-
核心提供
|
|
5
|
-
|
|
6
|
-
1. 静默登录方法, 如果用户未注册, 不引导注册
|
|
7
|
-
2. 强制登录, 如果用户未注册, 引导注册
|
|
8
|
-
|
|
9
|
-
页面打开的时候, 默认执行静默登录, 获取用户信息
|
|
10
|
-
|
|
11
|
-
1. 某些点击事件需要登录才能执行, 提供 decorateTryLogin
|
|
12
|
-
|
|
13
|
-
```js
|
|
14
|
-
const onTapSomeButton = decorateTryLogin(() => {
|
|
15
|
-
// Todo someting
|
|
16
|
-
})
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
该装饰器执行逻辑为如果未登录, 则执行登录操作(比如跳转到登录页面), 并直接抛出异常, 不做 _监听登录成功后执行回调函数_ 操作
|
|
20
|
-
|
|
21
|
-
> 那岂不是用户登陆完成后回到当页面还需与再点一下
|
|
22
|
-
|
|
23
|
-
没错, 的确要这么设计, 原因是为了解 如果点击了 2 个通过装饰器包装的按钮, 登陆成功后, 2 个按钮的回调事件将会全部执行(其实也有办法解决, 只是多点代码) 这种情况, 测试较真的话, 真是个问题
|
|
24
|
-
担心一个动作触发累计多个回调事件, 导致逻辑混乱
|
|
25
|
-
|
|
26
|
-
---
|
|
27
|
-
|
|
28
|
-
A 页面 业务逻辑简单, 监听登录成功后, 自身处理重新触发登录请求
|
|
29
|
-
B 页面 业务复杂, 需要登录成功后原地刷新
|
|
30
|
-
C 页面 需要登录成功后才能看
|
|
31
|
-
|
|
32
|
-
---
|
|
33
|
-
|
|
34
|
-
1. uniapp 网页 适配 开吧 app 方案 (不采用中间件)
|
|
35
|
-
|
|
36
|
-
A,B,C 均需要考虑停留一点时间后, 页面登录成功了
|
|
37
|
-
|
|
38
|
-
A 页面 通过 onLoginReady 替代 onMounted
|
|
39
|
-
|
|
40
|
-
```js
|
|
41
|
-
onLoginReady(() => {
|
|
42
|
-
<!-- todo 业务代码 -->
|
|
43
|
-
})
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
B 页面需要
|
|
47
|
-
|
|
48
|
-
监听页面登录成功后执行刷新页面
|
|
49
|
-
|
|
50
|
-
```js
|
|
51
|
-
onLoginIfNotLoggedIn(() => {
|
|
52
|
-
<!-- 当页面登录后, 执行刷新页面 -->
|
|
53
|
-
window.reload()
|
|
54
|
-
})
|
|
55
|
-
```
|
|
56
|
-
|
|
57
|
-
C 页面
|
|
58
|
-
|
|
59
|
-
当页面没有登录的时候, redirectTo 登录页面, 登录页面有个按钮, 点击唤起开吧登录, 页面加载的时候也立刻唤起开吧登录, 登录成功后 redirectTo 回来
|
|
60
|
-
|
|
61
|
-
---
|
|
62
|
-
|
|
63
|
-
2. 纯小程序架构
|
|
64
|
-
|
|
65
|
-
A,B,C 均需要考虑页面加载一段时间后, app 登录完成了或者登录失败, 页面主动点击触发登录
|
|
66
|
-
|
|
67
|
-
A 页面
|
|
68
|
-
监听登录成功执行操作
|
|
69
|
-
|
|
70
|
-
B 页面
|
|
71
|
-
监听登录成功后, 刷新页面
|
|
72
|
-
|
|
73
|
-
C 页面
|
|
74
|
-
页面打开的时候,如果未登录
|
|
75
|
-
redirectTo 登录授权页面, 登录成功后 redirectTo 返回当前页面
|
|
76
|
-
|
|
77
|
-
我建议 B 和 C 的分享链接改为 有个公共的前缀页面, 该页面静默登录或者强制登录成功后再进入 B/C, 这样子可以避免页面刷一下的体验
|
|
78
|
-
|
|
79
|
-
执行登录是前往一个登录页面
|
package/tsconfig.json
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES5",
|
|
4
|
-
"module": "CommonJS",
|
|
5
|
-
"allowJs": true,
|
|
6
|
-
"strict": true,
|
|
7
|
-
"outDir": "./dist",
|
|
8
|
-
"baseUrl": ".",
|
|
9
|
-
"declaration": true,
|
|
10
|
-
"lib": [
|
|
11
|
-
"esnext",
|
|
12
|
-
"dom"
|
|
13
|
-
],
|
|
14
|
-
"sourceMap": false,
|
|
15
|
-
"moduleResolution": "Node"
|
|
16
|
-
},
|
|
17
|
-
"include": [
|
|
18
|
-
"src"
|
|
19
|
-
]
|
|
20
|
-
}
|
package/vitest.config.ts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vitest/config'
|
|
2
|
-
import { resolve } from 'path'
|
|
3
|
-
|
|
4
|
-
export default defineConfig({
|
|
5
|
-
test: {
|
|
6
|
-
globals: true,
|
|
7
|
-
environment: 'jsdom', // 因为代码依赖 window 对象
|
|
8
|
-
setupFiles: ['./test/setup.ts'], // 设置文件用于模拟环境
|
|
9
|
-
coverage: {
|
|
10
|
-
reporter: ['text', 'json', 'html'],
|
|
11
|
-
},
|
|
12
|
-
},
|
|
13
|
-
resolve: {
|
|
14
|
-
alias: {
|
|
15
|
-
'@': resolve(__dirname, './src'),
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
})
|