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