mo-h5-bridge 0.0.36 → 0.0.39

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/dist/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export declare const Bridge: {
6
6
  getLocation: any;
7
7
  openLocation: any;
8
8
  postMessage: any;
9
+ onMessage: any;
9
10
  getToken: any;
10
11
  gotoOrderDetail: any;
11
12
  getAreas: any;
@@ -1,12 +1,12 @@
1
- function m(t) {
2
- return new Promise((i) => {
3
- const n = document.createElement("script");
4
- n.type = "text/javascript", n.src = t, n.onload = function() {
5
- i();
6
- }, document.head.appendChild(n);
1
+ function w(t) {
2
+ return new Promise((e) => {
3
+ const i = document.createElement("script");
4
+ i.type = "text/javascript", i.src = t, i.onload = function() {
5
+ e();
6
+ }, document.head.appendChild(i);
7
7
  });
8
8
  }
9
- const c = navigator.userAgent, p = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(c), w = /Windows|Macintosh|Linux/i.test(c) && !p, a = {
9
+ const r = navigator.userAgent, h = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(r), y = /Windows|Macintosh|Linux/i.test(r) && !h, c = {
10
10
  WeChatMini: "WeChatMini",
11
11
  // 微信小程序
12
12
  AlipayMini: "AlipayMini",
@@ -19,53 +19,53 @@ const c = navigator.userAgent, p = /Android|webOS|iPhone|iPad|iPod|BlackBerry|IE
19
19
  // 移动端
20
20
  Pc: "Pc"
21
21
  // pc端
22
- }, f = {
23
- ["is" + a.WeChatMini]: /miniProgram/i.test(c),
22
+ }, l = {
23
+ ["is" + c.WeChatMini]: /miniProgram/i.test(r),
24
24
  // 微信小程序
25
- ["is" + a.AlipayMini]: /AlipayClient.*miniProgram/i.test(c),
25
+ ["is" + c.AlipayMini]: /AlipayClient.*miniProgram/i.test(r),
26
26
  // 支付宝小程序
27
- ["is" + a.Android]: /Android/i.test(c),
27
+ ["is" + c.Android]: /Android/i.test(r),
28
28
  // andorid
29
- ["is" + a.Ios]: /iPhone|iPad|iPod/i.test(c),
29
+ ["is" + c.Ios]: /iPhone|iPad|iPod/i.test(r),
30
30
  // ios
31
- ["is" + a.Mobile]: p,
32
- ["is" + a.Pc]: w
33
- }, h = "https://appx/web-view.min.js", v = {
31
+ ["is" + c.Mobile]: h,
32
+ ["is" + c.Pc]: y
33
+ }, P = "https://appx/web-view.min.js", M = {
34
34
  // 用于在外勤app中,app返回到库存管理页面中,刷新库存管理页面
35
35
  refreshCar: void 0
36
36
  };
37
- class y {
37
+ class T {
38
38
  constructor() {
39
- this.map = /* @__PURE__ */ new Map(), Object.keys(v).forEach((i) => {
40
- this.map.set(i, /* @__PURE__ */ new Set());
39
+ this.map = /* @__PURE__ */ new Map(), Object.keys(M).forEach((e) => {
40
+ this.map.set(e, /* @__PURE__ */ new Set());
41
41
  });
42
42
  }
43
43
  // 添加元素到指定键的集合
44
- add(i, n) {
45
- return this.map.has(i) || this.map.set(i, /* @__PURE__ */ new Set()), this.map.get(i).add(n), this;
44
+ add(e, i) {
45
+ return this.map.has(e) || this.map.set(e, /* @__PURE__ */ new Set()), this.map.get(e).add(i), this;
46
46
  }
47
47
  // 从指定键的集合中删除元素
48
- delete(i, n) {
49
- if (!this.map.has(i))
48
+ delete(e, i) {
49
+ if (!this.map.has(e))
50
50
  return !1;
51
- const e = this.map.get(i), s = e.delete(n);
52
- return e.size === 0 && this.map.delete(i), s;
51
+ const n = this.map.get(e), o = n.delete(i);
52
+ return n.size === 0 && this.map.delete(e), o;
53
53
  }
54
54
  // 检查指定键的集合是否包含元素
55
- has(i, n) {
56
- return this.map.has(i) && this.map.get(i).has(n);
55
+ has(e, i) {
56
+ return this.map.has(e) && this.map.get(e).has(i);
57
57
  }
58
58
  // 获取指定键的集合
59
- get(i) {
60
- return this.map.get(i) || /* @__PURE__ */ new Set();
59
+ get(e) {
60
+ return this.map.get(e) || /* @__PURE__ */ new Set();
61
61
  }
62
62
  // 删除整个键及其集合
63
- deleteKey(i) {
64
- return this.map.delete(i);
63
+ deleteKey(e) {
64
+ return this.map.delete(e);
65
65
  }
66
66
  // 检查键是否存在
67
- hasKey(i) {
68
- return this.map.has(i);
67
+ hasKey(e) {
68
+ return this.map.has(e);
69
69
  }
70
70
  // 获取所有键
71
71
  keys() {
@@ -84,234 +84,246 @@ class y {
84
84
  this.map.clear();
85
85
  }
86
86
  // 遍历每个键的集合
87
- forEach(i) {
88
- this.map.forEach((n, e) => {
89
- i(n, e, this.map);
87
+ forEach(e) {
88
+ this.map.forEach((i, n) => {
89
+ e(i, n, this.map);
90
90
  });
91
91
  }
92
92
  }
93
- const P = new y(), o = {
94
- navigateTo: void 0,
95
- navigateBack: void 0,
96
- switchTab: void 0,
97
- getLocation: void 0,
98
- openLocation: void 0,
99
- postMessage: void 0,
100
- authorize: void 0,
101
- getToken: void 0,
102
- gotoOrderDetail: void 0,
103
- getAreas: void 0,
104
- updateAppMessageShareData: void 0,
105
- updateTimelineShareData: void 0,
106
- getArea: void 0
93
+ const B = new T(), d = [];
94
+ function a(t) {
95
+ return (...e) => (console.warn(`Bridge:${t} not init`), new Promise((i, n) => {
96
+ d.push({ name: t, args: e, resolve: i, reject: n });
97
+ }));
98
+ }
99
+ function p() {
100
+ if (d.length === 0)
101
+ return;
102
+ d.splice(0).forEach(({ name: e, args: i, resolve: n, reject: o }) => {
103
+ s[e](...i).then(n).catch(o);
104
+ });
105
+ }
106
+ const s = {
107
+ navigateTo: a("navigateTo"),
108
+ navigateBack: a("navigateBack"),
109
+ switchTab: a("switchTab"),
110
+ getLocation: a("getLocation"),
111
+ openLocation: a("openLocation"),
112
+ postMessage: a("postMessage"),
113
+ onMessage: a("onMessage"),
114
+ getToken: a("getToken"),
115
+ gotoOrderDetail: a("gotoOrderDetail"),
116
+ getAreas: a("getAreas"),
117
+ updateAppMessageShareData: a("updateAppMessageShareData"),
118
+ updateTimelineShareData: a("updateTimelineShareData"),
119
+ getArea: a("getArea")
107
120
  };
108
- async function B(t) {
109
- return new Promise((i, n) => {
121
+ async function b(t) {
122
+ return new Promise((e) => {
110
123
  my.postMessage({
111
- ...t,
112
- success: function(e) {
113
- i(e);
114
- },
115
- fail: function(e) {
116
- n(e);
117
- }
118
- });
124
+ ...t
125
+ }), e();
126
+ });
127
+ }
128
+ async function L(t) {
129
+ return new Promise((e) => {
130
+ my.onMessage = t, e();
119
131
  });
120
132
  }
121
- async function T(t) {
122
- return new Promise((i, n) => {
133
+ async function A(t) {
134
+ return new Promise((e, i) => {
123
135
  my.getLocation({
124
136
  ...t,
125
- success: function(e) {
126
- i(e);
137
+ success: function(n) {
138
+ e(n);
127
139
  },
128
- fail: function(e) {
129
- n(e);
140
+ fail: function(n) {
141
+ i(n);
130
142
  }
131
143
  });
132
144
  });
133
145
  }
134
- async function b(t) {
135
- return new Promise((i, n) => {
146
+ async function C(t) {
147
+ return new Promise((e, i) => {
136
148
  my.openLocation({
137
149
  ...t,
138
- success: function(e) {
139
- i(e);
150
+ success: function(n) {
151
+ e(n);
140
152
  },
141
- fail: function(e) {
142
- n(e);
153
+ fail: function(n) {
154
+ i(n);
143
155
  }
144
156
  });
145
157
  });
146
158
  }
147
- async function M(t) {
148
- return new Promise((i, n) => {
159
+ async function W(t) {
160
+ return new Promise((e, i) => {
149
161
  my.navigateTo({
150
162
  ...t,
151
- success: function(e) {
152
- i(e);
163
+ success: function(n) {
164
+ e(n);
153
165
  },
154
- fail: function(e) {
155
- n(e);
166
+ fail: function(n) {
167
+ i(n);
156
168
  }
157
169
  });
158
170
  });
159
171
  }
160
- async function L(t) {
161
- return new Promise((i, n) => {
172
+ async function J(t) {
173
+ return new Promise((e, i) => {
162
174
  my.navigateBack({
163
175
  ...t,
164
- success: function(e) {
165
- i(e);
176
+ success: function(n) {
177
+ e(n);
166
178
  },
167
- fail: function(e) {
168
- n(e);
179
+ fail: function(n) {
180
+ i(n);
169
181
  }
170
182
  });
171
183
  });
172
184
  }
173
- async function A(t) {
174
- return new Promise((i, n) => {
185
+ async function S(t) {
186
+ return new Promise((e, i) => {
175
187
  my.redirectTo({
176
188
  ...t,
177
- success: function(e) {
178
- i(e);
189
+ success: function(n) {
190
+ e(n);
179
191
  },
180
- fail: function(e) {
181
- n(e);
192
+ fail: function(n) {
193
+ i(n);
182
194
  }
183
195
  });
184
196
  });
185
197
  }
186
- function W(t) {
187
- return new Promise((i, n) => {
198
+ function x(t) {
199
+ return new Promise((e, i) => {
188
200
  my.switchTab({
189
201
  ...t,
190
- success: function(e) {
191
- i(e);
202
+ success: function(n) {
203
+ e(n);
192
204
  },
193
- fail: function(e) {
194
- n(e);
205
+ fail: function(n) {
206
+ i(n);
195
207
  }
196
208
  });
197
209
  });
198
210
  }
199
- function C() {
200
- o.postMessage = B, o.getLocation = T, o.openLocation = b, o.navigateTo = M, o.navigateBack = L, o.redirectTo = A, o.switchTab = W;
211
+ function E() {
212
+ s.postMessage = b, s.onMessage = L, s.getLocation = A, s.openLocation = C, s.navigateTo = W, s.navigateBack = J, s.redirectTo = S, s.switchTab = x, p();
201
213
  }
202
- async function x() {
203
- await m(h), C();
214
+ async function $() {
215
+ await w(P), E();
204
216
  }
205
- const J = "https://res.wx.qq.com/open/js/jweixin-1.6.0.js";
206
- async function E(t = {}) {
207
- return new Promise((i, n) => {
217
+ const V = "https://res.wx.qq.com/open/js/jweixin-1.6.0.js";
218
+ async function I(t = {}) {
219
+ return new Promise((e, i) => {
208
220
  wx.getLocation({
209
221
  ...t,
210
- success: function(e) {
211
- console.log("success", e), i(e);
222
+ success: function(n) {
223
+ console.log("success", n), e(n);
212
224
  },
213
- fail: function(e) {
214
- console.log("fail", e), n(e);
225
+ fail: function(n) {
226
+ console.log("fail", n), i(n);
215
227
  }
216
228
  });
217
229
  });
218
230
  }
219
- async function V(t) {
220
- return new Promise((i, n) => {
231
+ async function j(t) {
232
+ return new Promise((e, i) => {
221
233
  wx.openLocation({
222
234
  ...t,
223
- success: function(e) {
224
- i(e);
235
+ success: function(n) {
236
+ e(n);
225
237
  },
226
- fail: function(e) {
227
- n(e);
238
+ fail: function(n) {
239
+ i(n);
228
240
  }
229
241
  });
230
242
  });
231
243
  }
232
- async function $(t) {
233
- return new Promise((i, n) => {
244
+ async function k(t) {
245
+ return new Promise((e, i) => {
234
246
  wx.miniProgram.postMessage({
235
247
  ...t,
236
- success: function(e) {
237
- i(e);
248
+ success: function(n) {
249
+ e(n);
238
250
  },
239
- fail: function(e) {
240
- n(e);
251
+ fail: function(n) {
252
+ i(n);
241
253
  }
242
254
  });
243
255
  });
244
256
  }
245
- async function j(t) {
246
- return new Promise((i, n) => {
257
+ async function R(t) {
258
+ return new Promise((e, i) => {
247
259
  wx.miniProgram.navigateTo({
248
260
  ...t,
249
- success: function(e) {
250
- i(e);
261
+ success: function(n) {
262
+ e(n);
251
263
  },
252
- fail: function(e) {
253
- n(e);
264
+ fail: function(n) {
265
+ i(n);
254
266
  }
255
267
  });
256
268
  });
257
269
  }
258
- async function S(t) {
259
- return new Promise((i, n) => {
270
+ async function D(t) {
271
+ return new Promise((e, i) => {
260
272
  wx.miniProgram.navigateBack({
261
273
  ...t,
262
- success: function(e) {
263
- i(e);
274
+ success: function(n) {
275
+ e(n);
264
276
  },
265
- fail: function(e) {
266
- n(e);
277
+ fail: function(n) {
278
+ i(n);
267
279
  }
268
280
  });
269
281
  });
270
282
  }
271
- async function I(t) {
272
- return new Promise((i, n) => {
283
+ async function O(t) {
284
+ return new Promise((e, i) => {
273
285
  wx.miniProgram.switchTab({
274
286
  ...t,
275
- success: function(e) {
276
- i(e);
287
+ success: function(n) {
288
+ e(n);
277
289
  },
278
- fail: function(e) {
279
- n(e);
290
+ fail: function(n) {
291
+ i(n);
280
292
  }
281
293
  });
282
294
  });
283
295
  }
284
- async function k(t) {
285
- return new Promise((i, n) => {
296
+ async function N(t) {
297
+ return new Promise((e, i) => {
286
298
  wx.miniProgram.redirectTo({
287
299
  ...t,
288
- success: function(e) {
289
- i(e);
300
+ success: function(n) {
301
+ e(n);
290
302
  },
291
- fail: function(e) {
292
- n(e);
303
+ fail: function(n) {
304
+ i(n);
293
305
  }
294
306
  });
295
307
  });
296
308
  }
297
- function l() {
298
- o.navigateTo = j, o.navigateBack = S, o.redirectTo = k, o.switchTab = I, o.postMessage = $, o.getLocation = E, o.openLocation = V;
309
+ function m() {
310
+ s.navigateTo = R, s.navigateBack = D, s.redirectTo = N, s.switchTab = O, s.postMessage = k, s.getLocation = I, s.openLocation = j, p();
299
311
  }
300
- async function R(t) {
301
- const i = location.href.split("#")[0];
302
- return await fetch(`${t.requestUrl}?url=${i}`, {
312
+ async function _(t) {
313
+ const e = location.href.split("#")[0];
314
+ return await fetch(`${t.requestUrl}?url=${e}`, {
303
315
  method: "GET"
304
- }).then((n) => n.json());
316
+ }).then((i) => i.json());
305
317
  }
306
- function N(t) {
307
- async function i() {
308
- const n = await R(t);
309
- wx.config({
318
+ function q(t) {
319
+ async function e() {
320
+ const i = await _(t);
321
+ console.log({
310
322
  debug: !1,
311
- appId: n.data.appId,
312
- timestamp: n.data.timestamp,
313
- nonceStr: n.data.nonceStr,
314
- signature: n.data.signature,
323
+ appId: i.data.appId,
324
+ timestamp: i.data.timestamp,
325
+ nonceStr: i.data.nonceStr,
326
+ signature: i.data.signature,
315
327
  jsApiList: [
316
328
  // 获取当前的地理位置、速度:
317
329
  // 微信小程序与支付宝同名
@@ -322,23 +334,34 @@ function N(t) {
322
334
  "startRecord",
323
335
  "chooseImage",
324
336
  "scanQRCode"
325
- ],
326
- openTagList: ["wx-open-launch-weapp"]
337
+ ]
338
+ }), wx.config({
339
+ debug: !1,
340
+ appId: i.data.appId,
341
+ timestamp: i.data.timestamp,
342
+ nonceStr: i.data.nonceStr,
343
+ signature: i.data.signature,
344
+ jsApiList: [
345
+ // 获取当前的地理位置、速度:
346
+ // 微信小程序与支付宝同名
347
+ "getLocation",
348
+ // 使用微信内置地图查看位置:
349
+ // 微信小程序与支付宝同名
350
+ "openLocation",
351
+ "startRecord",
352
+ "chooseImage",
353
+ "scanQRCode"
354
+ ]
327
355
  });
328
356
  }
329
- return i(), setInterval(
330
- async (n) => {
331
- console.log("js-sdk 重新初始化", n), i();
332
- },
333
- 1e3 * 60 * 4
334
- ), Promise.resolve();
357
+ return e(), Promise.resolve();
335
358
  }
336
- async function O(t) {
337
- await m(J), t.requestUrl ? (await N(t), wx.ready(function() {
338
- l();
339
- })) : l();
359
+ async function H(t) {
360
+ await w(V), t.requestUrl ? (await q(t), wx.ready(function() {
361
+ m();
362
+ })) : m();
340
363
  }
341
- const g = f.isAndroid, D = (t) => {
364
+ const v = l.isAndroid, U = (t) => {
342
365
  window.WebViewJavascriptBridge ? t(window.WebViewJavascriptBridge) : document.addEventListener(
343
366
  "WebViewJavascriptBridgeReady",
344
367
  function() {
@@ -346,63 +369,63 @@ const g = f.isAndroid, D = (t) => {
346
369
  },
347
370
  !1
348
371
  );
349
- }, _ = (t) => {
372
+ }, F = (t) => {
350
373
  if (window.WebViewJavascriptBridge)
351
374
  return t(window.WebViewJavascriptBridge);
352
375
  if (window.WVJBCallbacks)
353
376
  return window.WVJBCallbacks.push(t);
354
377
  window.WVJBCallbacks = [t];
355
- const i = document.createElement("iframe");
356
- i.style.display = "none", i.src = "wvjbscheme://__BRIDGE_LOADED__", document.documentElement.appendChild(i), setTimeout(function() {
357
- document.documentElement.removeChild(i);
378
+ const e = document.createElement("iframe");
379
+ e.style.display = "none", e.src = "wvjbscheme://__BRIDGE_LOADED__", document.documentElement.appendChild(e), setTimeout(function() {
380
+ document.documentElement.removeChild(e);
358
381
  }, 0);
359
382
  };
360
- window.setupWebViewJavascriptBridge = g ? D : _;
361
- g && window.setupWebViewJavascriptBridge(function(t) {
362
- t.init(function(i, n) {
363
- alert(i), n("JS 返回给原生的消息内容");
383
+ window.setupWebViewJavascriptBridge = v ? U : F;
384
+ v && window.setupWebViewJavascriptBridge(function(t) {
385
+ t.init(function(e, i) {
386
+ i("JS 返回给原生的消息内容");
364
387
  });
365
388
  });
366
- async function q() {
389
+ async function G() {
367
390
  return new Promise((t) => {
368
- window.setupWebViewJavascriptBridge((i) => {
369
- Object.keys(o).forEach((n) => {
370
- o[n] = function(e) {
371
- return new Promise((s, d) => {
372
- i.callHandler(
391
+ window.setupWebViewJavascriptBridge((e) => {
392
+ Object.keys(s).forEach((i) => {
393
+ s[i] = function(n) {
394
+ return new Promise((o, g) => {
395
+ e.callHandler(
373
396
  "sendToNative",
374
397
  // 传递给原生的参数
375
398
  {
376
- type: n,
377
- value: e
399
+ type: i,
400
+ value: n
378
401
  },
379
- (u) => {
380
- console.log("fromNativeParams 1", u);
381
- const r = typeof u == "string" ? JSON.parse(u) : u;
382
- console.log("fromNativeParams 2", r), r.type === "success" ? (console.log("fromNativeParams 3", r.value), s(r.value)) : d(r.value);
402
+ (f) => {
403
+ console.log("fromNativeParams 1", f);
404
+ const u = typeof f == "string" ? JSON.parse(f) : f;
405
+ console.log("fromNativeParams 2", u), u.type === "success" ? (console.log("fromNativeParams 3", u.value), o(u.value)) : g(u.value);
383
406
  }
384
407
  );
385
408
  });
386
409
  };
387
- }), i.registerHandler(
410
+ }), e.registerHandler(
388
411
  "receiveFromNative",
389
- (n, e) => {
390
- console.log(1111, n);
391
- const s = typeof n == "string" ? JSON.parse(n) : n;
392
- console.log(2222, s), P.get(s.type).forEach((d) => {
393
- console.log(3333, s.value), d(s.value);
394
- }), e();
412
+ (i, n) => {
413
+ console.log(1111, i);
414
+ const o = typeof i == "string" ? JSON.parse(i) : i;
415
+ console.log(2222, o), B.get(o.type).forEach((g) => {
416
+ console.log(3333, o.value), g(o.value);
417
+ }), n();
395
418
  }
396
- ), t();
419
+ ), p(), t();
397
420
  });
398
421
  });
399
422
  }
400
- async function H(t) {
401
- f.isAlipayMini ? await x() : f.isWeChatMini ? await O(t) : f.isMobile && await q();
423
+ async function K(t) {
424
+ l.isAlipayMini ? await $() : l.isWeChatMini ? await H(t) : l.isMobile && await G();
402
425
  }
403
426
  export {
404
- o as Bridge,
405
- P as BridgeReceive,
406
- H as initBridge
427
+ s as Bridge,
428
+ B as BridgeReceive,
429
+ K as initBridge
407
430
  };
408
431
  //# sourceMappingURL=mo-h5-bridge.js.map