@hd-front-end/jsbridge-sdk 1.0.2 → 1.0.4

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 +201 -2
  3. package/dist/index.esm.js +444 -1
  4. package/dist/index.esm.js.map +1 -1
  5. package/dist/index.js +446 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.umd.js +446 -0
  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/README.md CHANGED
@@ -29,7 +29,7 @@ npm install @hd-front-end/jsbridge-sdk
29
29
  ### 基础使用
30
30
 
31
31
  ```typescript
32
- import { init, JSBridge } from '@hd/jsbridge-sdk'
32
+ import { init, JSBridge } from '@hd-front-end/jsbridge-sdk'
33
33
 
34
34
  // 初始化
35
35
  await init({
@@ -83,6 +83,7 @@ if (process.env.NODE_ENV === 'development') {
83
83
 
84
84
  - [平台兼容性说明.md](./docs/平台兼容性说明.md) - Android/iOS 兼容
85
85
  - [监控指南.md](./docs/监控指南.md) - 监控使用指南
86
+ - [新增桥接能力扩展说明.md](./docs/07-新桥接方法扩展说明.md) - **新集成的业务级桥接能力及 UniApp 适配方法说明**
86
87
  - [更新日志.md](./docs/更新日志.md) - 版本演进历史
87
88
  - [关键问题解答.md](./docs/关键问题解答.md) - 核心问题解答
88
89
 
@@ -101,7 +102,7 @@ if (process.env.NODE_ENV === 'development') {
101
102
  └─────────────────────────────────────┘
102
103
 
103
104
  ┌─────────────────────────────────────┐
104
- │ @hd/jsbridge-sdk │
105
+ │ @hd-front-end/jsbridge-sdk │
105
106
  │ ├── 核心通信(Android/iOS) │
106
107
  │ ├── API 层(device/media/log...) │
107
108
  │ ├── 监控层(通过 log 上报) │
@@ -141,3 +142,4 @@ const info = await JSBridge.getDeviceInfo()
141
142
  await JSBridge.log.info('操作成功', 'Business')
142
143
  await JSBridge.log.error('接口异常', 'Network', { status: 500 })
143
144
  ```
145
+
package/dist/index.d.ts CHANGED
@@ -148,6 +148,7 @@ declare global {
148
148
  };
149
149
  }
150
150
  }
151
+ type Nullable$1<T> = T | null | undefined;
151
152
 
152
153
  /**
153
154
  * 日志 API
@@ -398,6 +399,204 @@ declare function onPdaScan(handler: (data: any, callback: (response: any) => voi
398
399
  */
399
400
  declare function logout(): Promise<void>;
400
401
 
402
+ declare function hdH5Adapter(): void;
403
+
404
+ declare const UniProxy: any;
405
+
406
+ declare class PageLifeCycle {
407
+ state: string;
408
+ route: any;
409
+ constructor(state: string, route: any);
410
+ }
411
+
412
+ declare class UniScanRequest {
413
+ scanType: string[];
414
+ hideAlbum: boolean;
415
+ language: string;
416
+ failedMsg: string;
417
+ screenType: string;
418
+ timeoutInterval: string;
419
+ timeoutText: string;
420
+ viewText: string;
421
+ }
422
+
423
+ declare class UniScanResult {
424
+ resp_result: Nullable<string>;
425
+ resp_code: number;
426
+ resp_message: Nullable<string>;
427
+ }
428
+
429
+ declare class UniChooseMediaRequest {
430
+ extension: string[];
431
+ sourceType: string[];
432
+ camera: string;
433
+ mediaType: string[];
434
+ count: number;
435
+ maxDuration: number;
436
+ sizeType: string[];
437
+ }
438
+
439
+ declare class UniMediaFile {
440
+ tempFilePath: string;
441
+ name: string;
442
+ fileType: string;
443
+ size: number;
444
+ width: number;
445
+ height: number;
446
+ duration: number;
447
+ thumbTempFilePath?: string;
448
+ }
449
+
450
+ declare class UniChooseMediaResult {
451
+ tempFiles: UniMediaFile[];
452
+ tempFilePaths: string[];
453
+ }
454
+
455
+ declare class ImageInfoRequest {
456
+ src: string;
457
+ }
458
+
459
+ declare class UniUploadFileResult {
460
+ code: number;
461
+ errMsg: Nullable<string>;
462
+ data: Nullable<string>;
463
+ statusCode: Nullable<number>;
464
+ }
465
+
466
+ declare class UniPhoneCall {
467
+ phoneNumber: string;
468
+ }
469
+
470
+ declare class UniNavigationBarStyle {
471
+ title: Nullable<string>;
472
+ frontColor: Nullable<string>;
473
+ backgroundColor: Nullable<string>;
474
+ }
475
+
476
+ declare class UniLog {
477
+ tag: Nullable<string>;
478
+ level: string;
479
+ message: string;
480
+ }
481
+
482
+ interface UniUrlScheme {
483
+ url: string;
484
+ openType?: 'APP' | 'SYSTEM';
485
+ style?: any;
486
+ }
487
+
488
+ interface UniReloadModule {
489
+ appId: string;
490
+ }
491
+
492
+ declare class JsBridgeHandlers {
493
+ /**
494
+ * 路由变化通知原生
495
+ * @param to
496
+ * @param from
497
+ */
498
+ static handleRouterAfterEach(to: any, from: any): Promise<any>;
499
+ /**
500
+ * 获取app端信息
501
+ */
502
+ static handleGetAppInfo(): Promise<any>;
503
+ /**
504
+ * 页面生命周期通知原生
505
+ * @param lifecycle
506
+ */
507
+ static handlePageLifeCycle(lifecycle: PageLifeCycle): Promise<any>;
508
+ /**
509
+ * 注册路由跳转调用
510
+ * @param handler
511
+ */
512
+ static registerOnRoute(handler: (data: any, responseCallback: any) => void): Promise<void>;
513
+ /**
514
+ * 注册获取路由信息调用
515
+ */
516
+ static registerOnGetRouteInfo(handler: (data: any, responseCallback: any) => void): Promise<void>;
517
+ /**
518
+ * 注册刷新store数据
519
+ * @param handler
520
+ */
521
+ static registerOnRefreshStore(handler: (data: any, responseCallback: any) => void): Promise<void>;
522
+ /**
523
+ * 注册PDA扫码回调
524
+ * @param handler
525
+ */
526
+ static registerOnPdaScan(handler: (data: any, responseCallback: any) => void): Promise<void>;
527
+ /**
528
+ * 调用原生扫码
529
+ * @param request
530
+ */
531
+ static handleScan(request?: UniScanRequest): Promise<UniScanResult>;
532
+ /**
533
+ * 调用原生选择图片/视频
534
+ * @param request
535
+ */
536
+ static handleChooseMedia(request: UniChooseMediaRequest): Promise<Nullable<UniChooseMediaResult>>;
537
+ /**
538
+ * 获取图片信息
539
+ * @param request
540
+ */
541
+ static handleGetImageInfo(request: ImageInfoRequest): Promise<UniMediaFile>;
542
+ /**
543
+ * 上传文件
544
+ * @param request
545
+ */
546
+ static handleUploadFile(request: UniApp.UploadFileOption): Promise<UniUploadFileResult>;
547
+ /**
548
+ * 关闭当前WebView
549
+ * @param request
550
+ */
551
+ static handleCloseWebView(): Promise<void>;
552
+ /**
553
+ * 打电话
554
+ * @param request
555
+ */
556
+ static handleMakePhoneCall(request: UniPhoneCall): Promise<any>;
557
+ /**
558
+ * 动态设置标题
559
+ * @param request
560
+ */
561
+ static handleSetNavigationBar(request: UniNavigationBarStyle): Promise<void>;
562
+ /**
563
+ * 打日志
564
+ * @param request
565
+ */
566
+ static handleLog(request: UniLog): Promise<void>;
567
+ /**
568
+ * 通知原生APP已加载完成
569
+ * @param data
570
+ */
571
+ static handleAppOnload(data: any): Promise<void>;
572
+ /**
573
+ * 通知原生APP退出登录
574
+ * @param data
575
+ */
576
+ static handleLogout(): Promise<void>;
577
+ /**
578
+ * 通知原生APP打开链接
579
+ * @param data
580
+ */
581
+ static handleOpenSchemeUrl(request: UniUrlScheme): Promise<string>;
582
+ /**
583
+ * 图片路径转换成base64格式
584
+ * @param path
585
+ */
586
+ static handlePathToBase64(request: ImageInfoRequest): Promise<string>;
587
+ static handleBluetoothPrintImage(request: any): Promise<any>;
588
+ /**
589
+ * 蓝牙打印
590
+ * @param data
591
+ */
592
+ static handleBluetoothPrint(request: any): Promise<any>;
593
+ /**
594
+ * 通知原生APP重新加载子应用
595
+ * @param request
596
+ */
597
+ static handleReloadModule(request: UniReloadModule): Promise<void>;
598
+ }
599
+
401
600
  /**
402
601
  * 初始化 JSBridge SDK
403
602
  *
@@ -641,5 +840,5 @@ declare const Debug: {
641
840
  clearLogs: () => void;
642
841
  };
643
842
 
644
- export { Debug, JSBridge, LogLevel, Monitor, getPlatform, inApp, init, isReady };
645
- export type { AppInfo, ChooseMediaRequest, ChooseMediaResult, DebugConfig, DebugLog, DeviceInfo, ImageInfo, JSBridgeConfig, LogRequest, MediaFile, MonitorConfig, MonitorRecord, MonitorStats, NavigationBarStyle, NetworkInfo, PhoneCallRequest, Platform, PrintRequest, RouteInfo, ScanRequest, ScanResult, StorageData, UploadFileRequest, UploadFileResult };
843
+ export { Debug, JSBridge, JsBridgeHandlers, LogLevel, Monitor, UniProxy, getPlatform, hdH5Adapter, inApp, init, isReady };
844
+ export type { AppInfo, ChooseMediaRequest, ChooseMediaResult, DebugConfig, DebugLog, DeviceInfo, ImageInfo, JSBridgeConfig, LogRequest, MediaFile, MonitorConfig, MonitorRecord, MonitorStats, NavigationBarStyle, NetworkInfo, Nullable$1 as Nullable, PhoneCallRequest, Platform, PrintRequest, RouteInfo, ScanRequest, ScanResult, StorageData, UploadFileRequest, UploadFileResult };
package/dist/index.esm.js CHANGED
@@ -1339,6 +1339,449 @@ async function logout() {
1339
1339
  }
1340
1340
  }
1341
1341
 
1342
+ class PageLifeCycle {
1343
+ constructor(state, route) {
1344
+ this.state = state;
1345
+ this.route = route;
1346
+ }
1347
+ }
1348
+
1349
+ class UniScanRequest {
1350
+ constructor() {
1351
+ this.scanType = ['qrCode', 'barCode']; // 扫码识别类型,参数可多选,qrCode、barCode,不设置,默认识别所有
1352
+ this.hideAlbum = false; // 是否隐藏相册,默认false不隐藏
1353
+ this.language = 'zh-Hans'; // ios需要设置这个参数,只支持中英文 zh-Hans、en,默认中文
1354
+ this.failedMsg = '未识别到二维码,请重试'; // 相册选择照片识别错误提示(ios)
1355
+ this.screenType = 'full'; // Android支持全屏需要设置此参数
1356
+ this.timeoutInterval = '10'; // 设置超时时间,单位秒,默认10秒
1357
+ this.timeoutText = '未识别到二维码?'; // 超时提醒文本,默认未识别到二维码?
1358
+ this.viewText = '扫二维码/条码'; // 扫码提示文字,设置null时显示sdk默认文案
1359
+ }
1360
+ }
1361
+
1362
+ class UniScanResult {
1363
+ }
1364
+
1365
+ class JsBridgeHandlers {
1366
+ /**
1367
+ * 路由变化通知原生
1368
+ * @param to
1369
+ * @param from
1370
+ */
1371
+ static handleRouterAfterEach(to, from) {
1372
+ return bridge.call('routerAfterEach', { to, from });
1373
+ }
1374
+ /**
1375
+ * 获取app端信息
1376
+ */
1377
+ static handleGetAppInfo() {
1378
+ return bridge.call('getAppInfo');
1379
+ }
1380
+ /**
1381
+ * 页面生命周期通知原生
1382
+ * @param lifecycle
1383
+ */
1384
+ static handlePageLifeCycle(lifecycle) {
1385
+ return bridge.call('uniPageLifeCycle', lifecycle);
1386
+ }
1387
+ /**
1388
+ * 注册路由跳转调用
1389
+ * @param handler
1390
+ */
1391
+ static registerOnRoute(handler) {
1392
+ return bridge.register('route', handler);
1393
+ }
1394
+ /**
1395
+ * 注册获取路由信息调用
1396
+ */
1397
+ static registerOnGetRouteInfo(handler) {
1398
+ return bridge.register('getRouteInfo', handler);
1399
+ }
1400
+ /**
1401
+ * 注册刷新store数据
1402
+ * @param handler
1403
+ */
1404
+ static registerOnRefreshStore(handler) {
1405
+ return bridge.register('refreshStore', handler);
1406
+ }
1407
+ /**
1408
+ * 注册PDA扫码回调
1409
+ * @param handler
1410
+ */
1411
+ static registerOnPdaScan(handler) {
1412
+ return bridge.register('pdaScan', handler);
1413
+ }
1414
+ /**
1415
+ * 调用原生扫码
1416
+ * @param request
1417
+ */
1418
+ static handleScan(request = new UniScanRequest()) {
1419
+ return bridge.call('scan', request).then((res) => {
1420
+ const json = JSON.parse(res);
1421
+ const result = new UniScanResult();
1422
+ // eslint-disable-next-line @typescript-eslint/camelcase
1423
+ result.resp_code = json.resp_code;
1424
+ // eslint-disable-next-line @typescript-eslint/camelcase
1425
+ result.resp_result = json.resp_result;
1426
+ // eslint-disable-next-line @typescript-eslint/camelcase
1427
+ result.resp_message = json.resp_message;
1428
+ return result;
1429
+ });
1430
+ }
1431
+ /**
1432
+ * 调用原生选择图片/视频
1433
+ * @param request
1434
+ */
1435
+ static handleChooseMedia(request) {
1436
+ return bridge.call('chooseMedia', request).then((res) => {
1437
+ if (res) {
1438
+ const result = JSON.parse(res);
1439
+ return result;
1440
+ }
1441
+ else
1442
+ return null;
1443
+ });
1444
+ }
1445
+ /**
1446
+ * 获取图片信息
1447
+ * @param request
1448
+ */
1449
+ static handleGetImageInfo(request) {
1450
+ return bridge.call('getImageInfo', request).then((res) => {
1451
+ const result = JSON.parse(res);
1452
+ return result;
1453
+ });
1454
+ }
1455
+ /**
1456
+ * 上传文件
1457
+ * @param request
1458
+ */
1459
+ static handleUploadFile(request) {
1460
+ return bridge.call('uploadFile', request).then((res) => {
1461
+ const result = JSON.parse(res);
1462
+ return result;
1463
+ });
1464
+ }
1465
+ /**
1466
+ * 关闭当前WebView
1467
+ * @param request
1468
+ */
1469
+ static handleCloseWebView() {
1470
+ return bridge.call('closeWebView');
1471
+ }
1472
+ /**
1473
+ * 打电话
1474
+ * @param request
1475
+ */
1476
+ static handleMakePhoneCall(request) {
1477
+ return bridge.call('makePhoneCall', request);
1478
+ }
1479
+ /**
1480
+ * 动态设置标题
1481
+ * @param request
1482
+ */
1483
+ static handleSetNavigationBar(request) {
1484
+ return bridge.call('setNavigationBar', request);
1485
+ }
1486
+ /**
1487
+ * 打日志
1488
+ * @param request
1489
+ */
1490
+ static handleLog(request) {
1491
+ return bridge.call('log', request);
1492
+ }
1493
+ /**
1494
+ * 通知原生APP已加载完成
1495
+ * @param data
1496
+ */
1497
+ static handleAppOnload(data) {
1498
+ return JsBridgeHandlers.handlePageLifeCycle(new PageLifeCycle('appOnLaunch', data));
1499
+ }
1500
+ /**
1501
+ * 通知原生APP退出登录
1502
+ * @param data
1503
+ */
1504
+ static handleLogout() {
1505
+ return bridge.call('logout');
1506
+ }
1507
+ /**
1508
+ * 通知原生APP打开链接
1509
+ * @param data
1510
+ */
1511
+ static handleOpenSchemeUrl(request) {
1512
+ return bridge.call('openSchemeUrl', request);
1513
+ }
1514
+ /**
1515
+ * 图片路径转换成base64格式
1516
+ * @param path
1517
+ */
1518
+ static handlePathToBase64(request) {
1519
+ return bridge.call('pathToBase64', request).then((res) => {
1520
+ const result = JSON.parse(res);
1521
+ return result;
1522
+ });
1523
+ }
1524
+ static handleBluetoothPrintImage(request) {
1525
+ console.log(request);
1526
+ return bridge.call('printImage', request).then((res) => {
1527
+ if (!res)
1528
+ return res;
1529
+ if (typeof res === 'string') {
1530
+ try {
1531
+ return JSON.parse(res);
1532
+ }
1533
+ catch (e) {
1534
+ return res;
1535
+ }
1536
+ }
1537
+ return res;
1538
+ });
1539
+ }
1540
+ /**
1541
+ * 蓝牙打印
1542
+ * @param data
1543
+ */
1544
+ static handleBluetoothPrint(request) {
1545
+ return bridge.call('bluetoothPrint', request).then((res) => {
1546
+ if (!res)
1547
+ return res;
1548
+ if (typeof res === 'string') {
1549
+ try {
1550
+ return JSON.parse(res);
1551
+ }
1552
+ catch (e) {
1553
+ return res;
1554
+ }
1555
+ }
1556
+ return res;
1557
+ });
1558
+ }
1559
+ /**
1560
+ * 通知原生APP重新加载子应用
1561
+ * @param request
1562
+ */
1563
+ static handleReloadModule(request) {
1564
+ return bridge.call('reloadModule', request);
1565
+ }
1566
+ }
1567
+
1568
+ // 为什么会有这个类?
1569
+ //uni.chooseImage = chooseImage
1570
+ //Cannot assign to read only property 'chooseImage' of object '[object Object]'
1571
+ // chooseImage是只读的,无法替换,只能用代理模式,如果有好方法替换可以删除这个类
1572
+ const UniProxy = {
1573
+ chooseImage: typeof uni !== 'undefined' ? uni.chooseImage : null,
1574
+ pathToBase64: null
1575
+ };
1576
+
1577
+ function hdH5Adapter() {
1578
+ uni.scanCode = (options) => {
1579
+ const mpaasScanOptions = {
1580
+ scanType: options.scanType || ['qrCode', 'barCode'],
1581
+ hideAlbum: options.onlyFromCamera || false,
1582
+ viewText: '扫二维码/条码',
1583
+ language: 'zh-Hans',
1584
+ failedMsg: '未识别到二维码,请重试',
1585
+ screenType: 'full',
1586
+ timeoutInterval: '10',
1587
+ timeoutText: '未识别到二维码?'
1588
+ };
1589
+ JsBridgeHandlers.handleScan(mpaasScanOptions).then((ret) => {
1590
+ var _a, _b, _c, _d;
1591
+ if (ret.resp_code === 1000) {
1592
+ (_a = options.success) === null || _a === void 0 ? void 0 : _a.call(options, {
1593
+ result: ret.resp_result || '',
1594
+ scanType: mpaasScanOptions.scanType[0],
1595
+ charSet: 'utf-8',
1596
+ path: ''
1597
+ });
1598
+ }
1599
+ else if (ret.resp_code === 10) {
1600
+ (_b = options.fail) === null || _b === void 0 ? void 0 : _b.call(options, { errMsg: '用户取消扫码' });
1601
+ }
1602
+ else {
1603
+ (_c = options.fail) === null || _c === void 0 ? void 0 : _c.call(options, { errMsg: ret.resp_message || '扫码失败' });
1604
+ }
1605
+ (_d = options.complete) === null || _d === void 0 ? void 0 : _d.call(options, ret);
1606
+ });
1607
+ };
1608
+ // uni.chooseImage = chooseImage 会报错: Cannot assign to read only property 'chooseImage' of object '[object Object]'
1609
+ UniProxy.chooseImage = (options) => {
1610
+ const request = {
1611
+ extension: options.extension || [], //TODO 未实现
1612
+ sourceType: options.sourceType || ['album', 'camera'],
1613
+ camera: 'back',
1614
+ mediaType: ['image'],
1615
+ count: options.count || 9,
1616
+ maxDuration: 30, // 图片忽略
1617
+ sizeType: ['original', 'compressed'] //TODO 未实现
1618
+ };
1619
+ JsBridgeHandlers.handleChooseMedia(request).then((ret) => {
1620
+ var _a, _b, _c;
1621
+ if (ret == null) {
1622
+ (_a = options.fail) === null || _a === void 0 ? void 0 : _a.call(options, { errMsg: '用户取消' });
1623
+ }
1624
+ else {
1625
+ const result = {
1626
+ tempFiles: ret.tempFiles.map((item) => {
1627
+ return {
1628
+ path: item.tempFilePath,
1629
+ size: item.size,
1630
+ type: item.fileType,
1631
+ name: item.name,
1632
+ width: item.width,
1633
+ height: item.height
1634
+ };
1635
+ }),
1636
+ tempFilePaths: ret.tempFilePaths
1637
+ };
1638
+ (_b = options.success) === null || _b === void 0 ? void 0 : _b.call(options, result);
1639
+ }
1640
+ (_c = options.complete) === null || _c === void 0 ? void 0 : _c.call(options, ret);
1641
+ });
1642
+ };
1643
+ uni.chooseVideo = (options) => {
1644
+ const request = {
1645
+ extension: options.extension || [], //TODO 未实现
1646
+ sourceType: options.sourceType || ['album', 'camera'],
1647
+ camera: options.camera || 'back',
1648
+ mediaType: ['video'],
1649
+ count: 1,
1650
+ maxDuration: options.maxDuration || 30, // 图片忽略
1651
+ sizeType: ['original', 'compressed'] //TODO 未实现
1652
+ };
1653
+ JsBridgeHandlers.handleChooseMedia(request).then((ret) => {
1654
+ var _a, _b, _c;
1655
+ if (ret == null) {
1656
+ (_a = options.fail) === null || _a === void 0 ? void 0 : _a.call(options, { errMsg: '用户取消' });
1657
+ }
1658
+ else {
1659
+ const first = ret.tempFiles[0];
1660
+ // eslint-disable-next-line @typescript-eslint/ban-ts-ignore
1661
+ // @ts-ignore
1662
+ const result = {
1663
+ tempFilePath: first.tempFilePath,
1664
+ size: first.size,
1665
+ duration: first.duration / 1000,
1666
+ height: first.height,
1667
+ width: first.width,
1668
+ name: first.name
1669
+ };
1670
+ (_b = options.success) === null || _b === void 0 ? void 0 : _b.call(options, result);
1671
+ }
1672
+ (_c = options.complete) === null || _c === void 0 ? void 0 : _c.call(options, ret);
1673
+ });
1674
+ };
1675
+ uni.getImageInfo = (options) => {
1676
+ const request = {
1677
+ src: options.src
1678
+ };
1679
+ JsBridgeHandlers.handleGetImageInfo(request).then((ret) => {
1680
+ var _a;
1681
+ const result = {
1682
+ width: ret.width,
1683
+ height: ret.height,
1684
+ path: ret.tempFilePath,
1685
+ type: ret.fileType,
1686
+ orientation: ''
1687
+ };
1688
+ (_a = options.success) === null || _a === void 0 ? void 0 : _a.call(options, result);
1689
+ });
1690
+ };
1691
+ UniProxy.pathToBase64 = function (path) {
1692
+ return new Promise((resolve, reject) => {
1693
+ JsBridgeHandlers.handlePathToBase64({ src: path }).then((result) => {
1694
+ if (result && result.startsWith('data:'))
1695
+ resolve(result);
1696
+ else
1697
+ reject(result);
1698
+ });
1699
+ });
1700
+ };
1701
+ uni.uploadFile = (options) => {
1702
+ // 核心修复:防止 DataCloneError
1703
+ // iOS 的 postMessage 无法克隆包含 success/fail 等函数的对象
1704
+ // 我们必须提取出纯数据字段发送给原生
1705
+ const request = {
1706
+ url: options.url,
1707
+ filePath: options.filePath,
1708
+ name: options.name,
1709
+ formData: options.formData,
1710
+ header: options.header,
1711
+ timeout: options.timeout
1712
+ };
1713
+ JsBridgeHandlers.handleUploadFile(request).then((ret) => {
1714
+ var _a, _b, _c;
1715
+ if (ret.code === 200) {
1716
+ (_a = options.success) === null || _a === void 0 ? void 0 : _a.call(options, {
1717
+ data: ret.data || '',
1718
+ statusCode: ret.statusCode || 200
1719
+ });
1720
+ }
1721
+ else {
1722
+ (_b = options.fail) === null || _b === void 0 ? void 0 : _b.call(options, { errMsg: ret.errMsg || '上传失败' });
1723
+ }
1724
+ (_c = options.complete) === null || _c === void 0 ? void 0 : _c.call(options, { errMsg: ret.errMsg || '' });
1725
+ });
1726
+ //TODO 假的,不支持
1727
+ return {
1728
+ abort: () => { },
1729
+ onHeadersReceived: () => { },
1730
+ offHeadersReceived: () => { },
1731
+ onProgressUpdate: () => { },
1732
+ offProgressUpdate: () => { }
1733
+ };
1734
+ };
1735
+ // 这里不能直接赋值,后面uni-simple-router会重写uni.navigateBack,导致此处赋值失效,所以用setTimeout延时赋值就ok了
1736
+ setTimeout(() => {
1737
+ // 原始的navigateBack
1738
+ const navigateBack = uni.navigateBack;
1739
+ uni.navigateBack = (options) => {
1740
+ const pages = getCurrentPages();
1741
+ if (pages && pages.length > 1) {
1742
+ navigateBack(options);
1743
+ }
1744
+ else {
1745
+ JsBridgeHandlers.handleCloseWebView();
1746
+ }
1747
+ };
1748
+ }, 100);
1749
+ uni.makePhoneCall = (options) => {
1750
+ const request = {
1751
+ phoneNumber: options.phoneNumber
1752
+ };
1753
+ JsBridgeHandlers.handleMakePhoneCall(request).then((ret) => {
1754
+ var _a, _b, _c;
1755
+ if (ret)
1756
+ (_a = options.fail) === null || _a === void 0 ? void 0 : _a.call(options, ret);
1757
+ else
1758
+ (_b = options.success) === null || _b === void 0 ? void 0 : _b.call(options, null);
1759
+ (_c = options.complete) === null || _c === void 0 ? void 0 : _c.call(options, null);
1760
+ });
1761
+ };
1762
+ uni.setNavigationBarTitle = (options) => {
1763
+ const request = {
1764
+ title: options.title
1765
+ };
1766
+ JsBridgeHandlers.handleSetNavigationBar(request).then((ret) => {
1767
+ var _a, _b;
1768
+ (_a = options.success) === null || _a === void 0 ? void 0 : _a.call(options, null);
1769
+ (_b = options.complete) === null || _b === void 0 ? void 0 : _b.call(options, null);
1770
+ });
1771
+ };
1772
+ uni.setNavigationBarColor = (options) => {
1773
+ const request = {
1774
+ frontColor: options.frontColor,
1775
+ backgroundColor: options.backgroundColor
1776
+ };
1777
+ JsBridgeHandlers.handleSetNavigationBar(request).then((ret) => {
1778
+ var _a, _b;
1779
+ (_a = options.success) === null || _a === void 0 ? void 0 : _a.call(options, null);
1780
+ (_b = options.complete) === null || _b === void 0 ? void 0 : _b.call(options, null);
1781
+ });
1782
+ };
1783
+ }
1784
+
1342
1785
  /**
1343
1786
  * JSBridge SDK
1344
1787
  * 统一的原生能力封装
@@ -1645,5 +2088,5 @@ const Debug = {
1645
2088
  clearLogs: debug.clearLogs.bind(debug)
1646
2089
  };
1647
2090
 
1648
- export { Debug, JSBridge, LogLevel, Monitor, getPlatform, inApp, init, isReady };
2091
+ export { Debug, JSBridge, JsBridgeHandlers, LogLevel, Monitor, UniProxy, getPlatform, hdH5Adapter, inApp, init, isReady };
1649
2092
  //# sourceMappingURL=index.esm.js.map