@hd-front-end/jsbridge-sdk 1.0.1 → 1.0.3

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.
Files changed (26) hide show
  1. package/README.md +4 -2
  2. package/dist/index.d.ts +204 -2
  3. package/dist/index.esm.js +556 -9
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +558 -8
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.umd.js +560 -12
  8. package/dist/index.umd.js.map +1 -1
  9. package/docs/00-/351/241/271/347/233/256/346/246/202/350/247/210.md +282 -0
  10. package/docs/01-/346/236/266/346/236/204/350/256/276/350/256/241.md +623 -0
  11. package/docs/02-/346/212/200/346/234/257/345/256/236/347/216/260.md +867 -0
  12. package/docs/03-API/344/275/277/347/224/250/346/226/207/346/241/243.md +1104 -0
  13. package/docs/04-/346/265/213/350/257/225/346/226/271/346/241/210.md +360 -0
  14. package/docs/05-/350/277/201/347/247/273/346/214/207/345/215/227.md +181 -0
  15. package/docs/06-/346/236/266/346/236/204/345/233/276/351/233/206.md +738 -0
  16. package/docs/07-/346/226/260/346/241/245/346/216/245/346/226/271/346/263/225/346/211/251/345/261/225/350/257/264/346/230/216.md +139 -0
  17. package/docs/CODE_REVIEW.md +65 -0
  18. package/docs/EVALUATION.md +72 -0
  19. package/docs/README.md +258 -0
  20. package/docs//345/205/263/351/224/256/351/227/256/351/242/230/350/247/243/347/255/224.md +495 -0
  21. package/docs//346/226/207/346/241/243/346/225/264/345/220/210/350/257/264/346/230/216.md +265 -0
  22. package/docs//346/233/264/346/226/260/346/227/245/345/277/227.md +669 -0
  23. package/docs//347/224/237/344/272/247/347/272/247-/345/277/253/351/200/237/345/274/200/345/247/213-v2.md +673 -0
  24. package/docs//347/224/237/344/272/247/347/272/247-/346/236/266/346/236/204/350/256/276/350/256/241-v2.md +730 -0
  25. package/docs//350/256/276/350/256/241/347/220/206/345/277/265/350/257/264/346/230/216.md +438 -0
  26. package/package.json +3 -2
package/dist/index.esm.js CHANGED
@@ -1,3 +1,5 @@
1
+ import { pathToBase64 } from 'image-tools';
2
+
1
3
  /**
2
4
  * JSBridge 核心通信层
3
5
  *
@@ -10,7 +12,38 @@ class Bridge {
10
12
  this.isInitialized = false;
11
13
  this.platform = 'unknown';
12
14
  this.initPromise = null;
15
+ // iOS 回调相关
16
+ this.callbacks = {};
17
+ this.seq = 1;
13
18
  this.detectPlatform();
19
+ this.exposeGlobal();
20
+ }
21
+ /**
22
+ * 暴露全局对象供原生回调 (特别是 iOS)
23
+ */
24
+ exposeGlobal() {
25
+ if (typeof window !== 'undefined') {
26
+ window.JsBridge = {
27
+ _invokeCallback: (callbackId, result, error) => {
28
+ const entry = this.callbacks[callbackId];
29
+ if (!entry)
30
+ return;
31
+ delete this.callbacks[callbackId];
32
+ if (error) {
33
+ entry.reject(error);
34
+ }
35
+ else {
36
+ entry.resolve(result);
37
+ }
38
+ },
39
+ _handleMessageFromNative: (messageJSON) => {
40
+ const w = window;
41
+ if (w.WebViewJavascriptBridge && typeof w.WebViewJavascriptBridge._handleMessageFromNative === 'function') {
42
+ w.WebViewJavascriptBridge._handleMessageFromNative(messageJSON);
43
+ }
44
+ }
45
+ };
46
+ }
14
47
  }
15
48
  /**
16
49
  * 检测平台
@@ -85,8 +118,15 @@ class Bridge {
85
118
  // 不 reject,依赖下方的 setTimeout 超时机制或原生主动调用 WKWVJBCallbacks
86
119
  }
87
120
  }
88
- // iOS 平台:使用 iframe 触发
121
+ // iOS 平台:直接检查或使用 iframe 触发
89
122
  if (this.platform === 'ios') {
123
+ const w = window;
124
+ if (w.webkit && w.webkit.messageHandlers && w.webkit.messageHandlers.JsBridge) {
125
+ this.isInitialized = true;
126
+ resolve(true);
127
+ return;
128
+ }
129
+ // 回退:如果还未注入,尝试 iframe 触发或等待
90
130
  const iframe = document.createElement('iframe');
91
131
  iframe.style.display = 'none';
92
132
  iframe.src = 'https://__bridge_loaded__';
@@ -118,8 +158,11 @@ class Bridge {
118
158
  * 轮询检查 Bridge 实例是否存在
119
159
  */
120
160
  async waitForReady() {
161
+ var _a, _b;
121
162
  if (this.bridge)
122
163
  return;
164
+ if (this.platform === 'ios' && ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.JsBridge))
165
+ return;
123
166
  return new Promise((resolve, reject) => {
124
167
  let retryCount = 0;
125
168
  const maxRetries = 20; // 最多重试 20 次 (4秒)
@@ -133,6 +176,15 @@ class Bridge {
133
176
  resolve();
134
177
  return;
135
178
  }
179
+ // iOS 再次检查
180
+ if (this.platform === 'ios') {
181
+ const w = window;
182
+ if (w.webkit && w.webkit.messageHandlers && w.webkit.messageHandlers.JsBridge) {
183
+ this.isInitialized = true;
184
+ resolve();
185
+ return;
186
+ }
187
+ }
136
188
  // Android 再次尝试触发注入
137
189
  if (this.platform === 'android' && ((_a = window.InjectJavascript) === null || _a === void 0 ? void 0 : _a.init)) {
138
190
  window.InjectJavascript.init();
@@ -153,12 +205,13 @@ class Bridge {
153
205
  * 优化:自动初始化、增强错误处理、支持泛型返回值
154
206
  */
155
207
  async call(method, data) {
208
+ var _a, _b;
156
209
  // 自动初始化
157
210
  if (!this.isInitialized) {
158
211
  await this.init();
159
212
  }
160
213
  // 确保 bridge 实例就绪
161
- if (!this.bridge) {
214
+ if (!this.bridge && !(this.platform === 'ios' && ((_b = (_a = window.webkit) === null || _a === void 0 ? void 0 : _a.messageHandlers) === null || _b === void 0 ? void 0 : _b.JsBridge))) {
162
215
  try {
163
216
  await this.waitForReady();
164
217
  }
@@ -172,11 +225,51 @@ class Bridge {
172
225
  const timeoutId = setTimeout(() => {
173
226
  reject(new Error(`${method} 调用超时`));
174
227
  }, 10000);
175
- // 调用原生方法
176
- this.bridge.callHandler(method, data, (result) => {
177
- clearTimeout(timeoutId);
178
- resolve(result);
179
- });
228
+ // Android 调用
229
+ if (this.platform === 'android' && this.bridge) {
230
+ this.bridge.callHandler(method, data, (result) => {
231
+ clearTimeout(timeoutId);
232
+ resolve(result);
233
+ });
234
+ return;
235
+ }
236
+ // iOS 调用
237
+ if (this.platform === 'ios') {
238
+ const w = window;
239
+ const handler = w.webkit && w.webkit.messageHandlers && w.webkit.messageHandlers.JsBridge;
240
+ if (handler && typeof handler.postMessage === 'function') {
241
+ const callbackId = 'cb_' + this.seq++;
242
+ this.callbacks[callbackId] = {
243
+ resolve: (res) => {
244
+ clearTimeout(timeoutId);
245
+ resolve(res);
246
+ },
247
+ reject: (err) => {
248
+ clearTimeout(timeoutId);
249
+ reject(err);
250
+ }
251
+ };
252
+ // 核心防御:防止 DataCloneError
253
+ // 剥离可能存在的不可序列化对象(如 success/fail 回调函数)
254
+ let safeData = data;
255
+ if (data && typeof data === 'object') {
256
+ try {
257
+ safeData = JSON.parse(JSON.stringify(data));
258
+ }
259
+ catch (e) {
260
+ // 忽略异常,保留原数据
261
+ }
262
+ }
263
+ handler.postMessage({
264
+ handlerName: method,
265
+ data: safeData,
266
+ callbackId
267
+ });
268
+ return;
269
+ }
270
+ }
271
+ clearTimeout(timeoutId);
272
+ reject(new Error(`调用 ${method} 失败: 当前环境不支持`));
180
273
  }
181
274
  catch (error) {
182
275
  console.error(`[JSBridge] ${method} 调用异常:`, error);
@@ -197,7 +290,18 @@ class Bridge {
197
290
  }
198
291
  }
199
292
  try {
200
- this.bridge.registerHandler(method, handler);
293
+ if (this.platform === 'android' && this.bridge) {
294
+ this.bridge.registerHandler(method, handler);
295
+ }
296
+ else if (this.platform === 'ios') {
297
+ const w = window;
298
+ if (w.WebViewJavascriptBridge) {
299
+ w.WebViewJavascriptBridge.registerHandler(method, handler);
300
+ }
301
+ else {
302
+ console.warn(`[JSBridge] iOS WebViewJavascriptBridge 未就绪,注册方法 ${method} 可能失败`);
303
+ }
304
+ }
201
305
  }
202
306
  catch (error) {
203
307
  console.error(`[JSBridge] 注册方法失败: ${method}`, error);
@@ -1237,6 +1341,449 @@ async function logout() {
1237
1341
  }
1238
1342
  }
1239
1343
 
1344
+ class PageLifeCycle {
1345
+ constructor(state, route) {
1346
+ this.state = state;
1347
+ this.route = route;
1348
+ }
1349
+ }
1350
+
1351
+ class UniScanRequest {
1352
+ constructor() {
1353
+ this.scanType = ['qrCode', 'barCode']; // 扫码识别类型,参数可多选,qrCode、barCode,不设置,默认识别所有
1354
+ this.hideAlbum = false; // 是否隐藏相册,默认false不隐藏
1355
+ this.language = 'zh-Hans'; // ios需要设置这个参数,只支持中英文 zh-Hans、en,默认中文
1356
+ this.failedMsg = '未识别到二维码,请重试'; // 相册选择照片识别错误提示(ios)
1357
+ this.screenType = 'full'; // Android支持全屏需要设置此参数
1358
+ this.timeoutInterval = '10'; // 设置超时时间,单位秒,默认10秒
1359
+ this.timeoutText = '未识别到二维码?'; // 超时提醒文本,默认未识别到二维码?
1360
+ this.viewText = '扫二维码/条码'; // 扫码提示文字,设置null时显示sdk默认文案
1361
+ }
1362
+ }
1363
+
1364
+ class UniScanResult {
1365
+ }
1366
+
1367
+ class JsBridgeHandlers {
1368
+ /**
1369
+ * 路由变化通知原生
1370
+ * @param to
1371
+ * @param from
1372
+ */
1373
+ static handleRouterAfterEach(to, from) {
1374
+ return bridge.call('routerAfterEach', { to, from });
1375
+ }
1376
+ /**
1377
+ * 获取app端信息
1378
+ */
1379
+ static handleGetAppInfo() {
1380
+ return bridge.call('getAppInfo');
1381
+ }
1382
+ /**
1383
+ * 页面生命周期通知原生
1384
+ * @param lifecycle
1385
+ */
1386
+ static handlePageLifeCycle(lifecycle) {
1387
+ return bridge.call('uniPageLifeCycle', lifecycle);
1388
+ }
1389
+ /**
1390
+ * 注册路由跳转调用
1391
+ * @param handler
1392
+ */
1393
+ static registerOnRoute(handler) {
1394
+ return bridge.register('route', handler);
1395
+ }
1396
+ /**
1397
+ * 注册获取路由信息调用
1398
+ */
1399
+ static registerOnGetRouteInfo(handler) {
1400
+ return bridge.register('getRouteInfo', handler);
1401
+ }
1402
+ /**
1403
+ * 注册刷新store数据
1404
+ * @param handler
1405
+ */
1406
+ static registerOnRefreshStore(handler) {
1407
+ return bridge.register('refreshStore', handler);
1408
+ }
1409
+ /**
1410
+ * 注册PDA扫码回调
1411
+ * @param handler
1412
+ */
1413
+ static registerOnPdaScan(handler) {
1414
+ return bridge.register('pdaScan', handler);
1415
+ }
1416
+ /**
1417
+ * 调用原生扫码
1418
+ * @param request
1419
+ */
1420
+ static handleScan(request = new UniScanRequest()) {
1421
+ return bridge.call('scan', request).then((res) => {
1422
+ const json = JSON.parse(res);
1423
+ const result = new UniScanResult();
1424
+ // eslint-disable-next-line @typescript-eslint/camelcase
1425
+ result.resp_code = json.resp_code;
1426
+ // eslint-disable-next-line @typescript-eslint/camelcase
1427
+ result.resp_result = json.resp_result;
1428
+ // eslint-disable-next-line @typescript-eslint/camelcase
1429
+ result.resp_message = json.resp_message;
1430
+ return result;
1431
+ });
1432
+ }
1433
+ /**
1434
+ * 调用原生选择图片/视频
1435
+ * @param request
1436
+ */
1437
+ static handleChooseMedia(request) {
1438
+ return bridge.call('chooseMedia', request).then((res) => {
1439
+ if (res) {
1440
+ const result = JSON.parse(res);
1441
+ return result;
1442
+ }
1443
+ else
1444
+ return null;
1445
+ });
1446
+ }
1447
+ /**
1448
+ * 获取图片信息
1449
+ * @param request
1450
+ */
1451
+ static handleGetImageInfo(request) {
1452
+ return bridge.call('getImageInfo', request).then((res) => {
1453
+ const result = JSON.parse(res);
1454
+ return result;
1455
+ });
1456
+ }
1457
+ /**
1458
+ * 上传文件
1459
+ * @param request
1460
+ */
1461
+ static handleUploadFile(request) {
1462
+ return bridge.call('uploadFile', request).then((res) => {
1463
+ const result = JSON.parse(res);
1464
+ return result;
1465
+ });
1466
+ }
1467
+ /**
1468
+ * 关闭当前WebView
1469
+ * @param request
1470
+ */
1471
+ static handleCloseWebView() {
1472
+ return bridge.call('closeWebView');
1473
+ }
1474
+ /**
1475
+ * 打电话
1476
+ * @param request
1477
+ */
1478
+ static handleMakePhoneCall(request) {
1479
+ return bridge.call('makePhoneCall', request);
1480
+ }
1481
+ /**
1482
+ * 动态设置标题
1483
+ * @param request
1484
+ */
1485
+ static handleSetNavigationBar(request) {
1486
+ return bridge.call('setNavigationBar', request);
1487
+ }
1488
+ /**
1489
+ * 打日志
1490
+ * @param request
1491
+ */
1492
+ static handleLog(request) {
1493
+ return bridge.call('log', request);
1494
+ }
1495
+ /**
1496
+ * 通知原生APP已加载完成
1497
+ * @param data
1498
+ */
1499
+ static handleAppOnload(data) {
1500
+ return JsBridgeHandlers.handlePageLifeCycle(new PageLifeCycle('appOnLaunch', data));
1501
+ }
1502
+ /**
1503
+ * 通知原生APP退出登录
1504
+ * @param data
1505
+ */
1506
+ static handleLogout() {
1507
+ return bridge.call('logout');
1508
+ }
1509
+ /**
1510
+ * 通知原生APP打开链接
1511
+ * @param data
1512
+ */
1513
+ static handleOpenSchemeUrl(request) {
1514
+ return bridge.call('openSchemeUrl', request);
1515
+ }
1516
+ /**
1517
+ * 图片路径转换成base64格式
1518
+ * @param path
1519
+ */
1520
+ static handlePathToBase64(request) {
1521
+ return bridge.call('pathToBase64', request).then((res) => {
1522
+ const result = JSON.parse(res);
1523
+ return result;
1524
+ });
1525
+ }
1526
+ static handleBluetoothPrintImage(request) {
1527
+ console.log(request);
1528
+ return bridge.call('printImage', request).then((res) => {
1529
+ if (!res)
1530
+ return res;
1531
+ if (typeof res === 'string') {
1532
+ try {
1533
+ return JSON.parse(res);
1534
+ }
1535
+ catch (e) {
1536
+ return res;
1537
+ }
1538
+ }
1539
+ return res;
1540
+ });
1541
+ }
1542
+ /**
1543
+ * 蓝牙打印
1544
+ * @param data
1545
+ */
1546
+ static handleBluetoothPrint(request) {
1547
+ return bridge.call('bluetoothPrint', request).then((res) => {
1548
+ if (!res)
1549
+ return res;
1550
+ if (typeof res === 'string') {
1551
+ try {
1552
+ return JSON.parse(res);
1553
+ }
1554
+ catch (e) {
1555
+ return res;
1556
+ }
1557
+ }
1558
+ return res;
1559
+ });
1560
+ }
1561
+ /**
1562
+ * 通知原生APP重新加载子应用
1563
+ * @param request
1564
+ */
1565
+ static handleReloadModule(request) {
1566
+ return bridge.call('reloadModule', request);
1567
+ }
1568
+ }
1569
+
1570
+ // 为什么会有这个类?
1571
+ //uni.chooseImage = chooseImage
1572
+ //Cannot assign to read only property 'chooseImage' of object '[object Object]'
1573
+ // chooseImage是只读的,无法替换,只能用代理模式,如果有好方法替换可以删除这个类
1574
+ const UniProxy = {
1575
+ chooseImage: uni.chooseImage,
1576
+ pathToBase64: pathToBase64
1577
+ };
1578
+
1579
+ function hdH5Adapter() {
1580
+ uni.scanCode = (options) => {
1581
+ const mpaasScanOptions = {
1582
+ scanType: options.scanType || ['qrCode', 'barCode'],
1583
+ hideAlbum: options.onlyFromCamera || false,
1584
+ viewText: '扫二维码/条码',
1585
+ language: 'zh-Hans',
1586
+ failedMsg: '未识别到二维码,请重试',
1587
+ screenType: 'full',
1588
+ timeoutInterval: '10',
1589
+ timeoutText: '未识别到二维码?'
1590
+ };
1591
+ JsBridgeHandlers.handleScan(mpaasScanOptions).then((ret) => {
1592
+ var _a, _b, _c, _d;
1593
+ if (ret.resp_code === 1000) {
1594
+ (_a = options.success) === null || _a === void 0 ? void 0 : _a.call(options, {
1595
+ result: ret.resp_result || '',
1596
+ scanType: mpaasScanOptions.scanType[0],
1597
+ charSet: 'utf-8',
1598
+ path: ''
1599
+ });
1600
+ }
1601
+ else if (ret.resp_code === 10) {
1602
+ (_b = options.fail) === null || _b === void 0 ? void 0 : _b.call(options, { errMsg: '用户取消扫码' });
1603
+ }
1604
+ else {
1605
+ (_c = options.fail) === null || _c === void 0 ? void 0 : _c.call(options, { errMsg: ret.resp_message || '扫码失败' });
1606
+ }
1607
+ (_d = options.complete) === null || _d === void 0 ? void 0 : _d.call(options, ret);
1608
+ });
1609
+ };
1610
+ // uni.chooseImage = chooseImage 会报错: Cannot assign to read only property 'chooseImage' of object '[object Object]'
1611
+ UniProxy.chooseImage = (options) => {
1612
+ const request = {
1613
+ extension: options.extension || [], //TODO 未实现
1614
+ sourceType: options.sourceType || ['album', 'camera'],
1615
+ camera: 'back',
1616
+ mediaType: ['image'],
1617
+ count: options.count || 9,
1618
+ maxDuration: 30, // 图片忽略
1619
+ sizeType: ['original', 'compressed'] //TODO 未实现
1620
+ };
1621
+ JsBridgeHandlers.handleChooseMedia(request).then((ret) => {
1622
+ var _a, _b, _c;
1623
+ if (ret == null) {
1624
+ (_a = options.fail) === null || _a === void 0 ? void 0 : _a.call(options, { errMsg: '用户取消' });
1625
+ }
1626
+ else {
1627
+ const result = {
1628
+ tempFiles: ret.tempFiles.map((item) => {
1629
+ return {
1630
+ path: item.tempFilePath,
1631
+ size: item.size,
1632
+ type: item.fileType,
1633
+ name: item.name,
1634
+ width: item.width,
1635
+ height: item.height
1636
+ };
1637
+ }),
1638
+ tempFilePaths: ret.tempFilePaths
1639
+ };
1640
+ (_b = options.success) === null || _b === void 0 ? void 0 : _b.call(options, result);
1641
+ }
1642
+ (_c = options.complete) === null || _c === void 0 ? void 0 : _c.call(options, ret);
1643
+ });
1644
+ };
1645
+ uni.chooseVideo = (options) => {
1646
+ const request = {
1647
+ extension: options.extension || [], //TODO 未实现
1648
+ sourceType: options.sourceType || ['album', 'camera'],
1649
+ camera: options.camera || 'back',
1650
+ mediaType: ['video'],
1651
+ count: 1,
1652
+ maxDuration: options.maxDuration || 30, // 图片忽略
1653
+ sizeType: ['original', 'compressed'] //TODO 未实现
1654
+ };
1655
+ JsBridgeHandlers.handleChooseMedia(request).then((ret) => {
1656
+ var _a, _b, _c;
1657
+ if (ret == null) {
1658
+ (_a = options.fail) === null || _a === void 0 ? void 0 : _a.call(options, { errMsg: '用户取消' });
1659
+ }
1660
+ else {
1661
+ const first = ret.tempFiles[0];
1662
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
1663
+ // @ts-ignore
1664
+ const result = {
1665
+ tempFilePath: first.tempFilePath,
1666
+ size: first.size,
1667
+ duration: first.duration / 1000,
1668
+ height: first.height,
1669
+ width: first.width,
1670
+ name: first.name
1671
+ };
1672
+ (_b = options.success) === null || _b === void 0 ? void 0 : _b.call(options, result);
1673
+ }
1674
+ (_c = options.complete) === null || _c === void 0 ? void 0 : _c.call(options, ret);
1675
+ });
1676
+ };
1677
+ uni.getImageInfo = (options) => {
1678
+ const request = {
1679
+ src: options.src
1680
+ };
1681
+ JsBridgeHandlers.handleGetImageInfo(request).then((ret) => {
1682
+ var _a;
1683
+ const result = {
1684
+ width: ret.width,
1685
+ height: ret.height,
1686
+ path: ret.tempFilePath,
1687
+ type: ret.fileType,
1688
+ orientation: ''
1689
+ };
1690
+ (_a = options.success) === null || _a === void 0 ? void 0 : _a.call(options, result);
1691
+ });
1692
+ };
1693
+ UniProxy.pathToBase64 = function (path) {
1694
+ return new Promise((resolve, reject) => {
1695
+ JsBridgeHandlers.handlePathToBase64({ src: path }).then((result) => {
1696
+ if (result && result.startsWith('data:'))
1697
+ resolve(result);
1698
+ else
1699
+ reject(result);
1700
+ });
1701
+ });
1702
+ };
1703
+ uni.uploadFile = (options) => {
1704
+ // 核心修复:防止 DataCloneError
1705
+ // iOS 的 postMessage 无法克隆包含 success/fail 等函数的对象
1706
+ // 我们必须提取出纯数据字段发送给原生
1707
+ const request = {
1708
+ url: options.url,
1709
+ filePath: options.filePath,
1710
+ name: options.name,
1711
+ formData: options.formData,
1712
+ header: options.header,
1713
+ timeout: options.timeout
1714
+ };
1715
+ JsBridgeHandlers.handleUploadFile(request).then((ret) => {
1716
+ var _a, _b, _c;
1717
+ if (ret.code === 200) {
1718
+ (_a = options.success) === null || _a === void 0 ? void 0 : _a.call(options, {
1719
+ data: ret.data || '',
1720
+ statusCode: ret.statusCode || 200
1721
+ });
1722
+ }
1723
+ else {
1724
+ (_b = options.fail) === null || _b === void 0 ? void 0 : _b.call(options, { errMsg: ret.errMsg || '上传失败' });
1725
+ }
1726
+ (_c = options.complete) === null || _c === void 0 ? void 0 : _c.call(options, { errMsg: ret.errMsg || '' });
1727
+ });
1728
+ //TODO 假的,不支持
1729
+ return {
1730
+ abort: () => { },
1731
+ onHeadersReceived: () => { },
1732
+ offHeadersReceived: () => { },
1733
+ onProgressUpdate: () => { },
1734
+ offProgressUpdate: () => { }
1735
+ };
1736
+ };
1737
+ // 这里不能直接赋值,后面uni-simple-router会重写uni.navigateBack,导致此处赋值失效,所以用setTimeout延时赋值就ok了
1738
+ setTimeout(() => {
1739
+ // 原始的navigateBack
1740
+ const navigateBack = uni.navigateBack;
1741
+ uni.navigateBack = (options) => {
1742
+ const pages = getCurrentPages();
1743
+ if (pages && pages.length > 1) {
1744
+ navigateBack(options);
1745
+ }
1746
+ else {
1747
+ JsBridgeHandlers.handleCloseWebView();
1748
+ }
1749
+ };
1750
+ }, 100);
1751
+ uni.makePhoneCall = (options) => {
1752
+ const request = {
1753
+ phoneNumber: options.phoneNumber
1754
+ };
1755
+ JsBridgeHandlers.handleMakePhoneCall(request).then((ret) => {
1756
+ var _a, _b, _c;
1757
+ if (ret)
1758
+ (_a = options.fail) === null || _a === void 0 ? void 0 : _a.call(options, ret);
1759
+ else
1760
+ (_b = options.success) === null || _b === void 0 ? void 0 : _b.call(options, null);
1761
+ (_c = options.complete) === null || _c === void 0 ? void 0 : _c.call(options, null);
1762
+ });
1763
+ };
1764
+ uni.setNavigationBarTitle = (options) => {
1765
+ const request = {
1766
+ title: options.title
1767
+ };
1768
+ JsBridgeHandlers.handleSetNavigationBar(request).then((ret) => {
1769
+ var _a, _b;
1770
+ (_a = options.success) === null || _a === void 0 ? void 0 : _a.call(options, null);
1771
+ (_b = options.complete) === null || _b === void 0 ? void 0 : _b.call(options, null);
1772
+ });
1773
+ };
1774
+ uni.setNavigationBarColor = (options) => {
1775
+ const request = {
1776
+ frontColor: options.frontColor,
1777
+ backgroundColor: options.backgroundColor
1778
+ };
1779
+ JsBridgeHandlers.handleSetNavigationBar(request).then((ret) => {
1780
+ var _a, _b;
1781
+ (_a = options.success) === null || _a === void 0 ? void 0 : _a.call(options, null);
1782
+ (_b = options.complete) === null || _b === void 0 ? void 0 : _b.call(options, null);
1783
+ });
1784
+ };
1785
+ }
1786
+
1240
1787
  /**
1241
1788
  * JSBridge SDK
1242
1789
  * 统一的原生能力封装
@@ -1543,5 +2090,5 @@ const Debug = {
1543
2090
  clearLogs: debug.clearLogs.bind(debug)
1544
2091
  };
1545
2092
 
1546
- export { Debug, JSBridge, LogLevel, Monitor, getPlatform, inApp, init, isReady };
2093
+ export { Debug, JSBridge, JsBridgeHandlers, LogLevel, Monitor, UniProxy, getPlatform, hdH5Adapter, inApp, init, isReady };
1547
2094
  //# sourceMappingURL=index.esm.js.map