mo-h5-bridge 0.0.24 → 0.0.26

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