mo-h5-bridge 0.0.36 → 0.0.38

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