@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/dist/index.umd.js CHANGED
@@ -1345,6 +1345,449 @@
1345
1345
  }
1346
1346
  }
1347
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: typeof uni !== 'undefined' ? uni.chooseImage : null,
1580
+ pathToBase64: null
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
+
1348
1791
  /**
1349
1792
  * JSBridge SDK
1350
1793
  * 统一的原生能力封装
@@ -1653,8 +2096,11 @@
1653
2096
 
1654
2097
  exports.Debug = Debug;
1655
2098
  exports.JSBridge = JSBridge;
2099
+ exports.JsBridgeHandlers = JsBridgeHandlers;
1656
2100
  exports.Monitor = Monitor;
2101
+ exports.UniProxy = UniProxy;
1657
2102
  exports.getPlatform = getPlatform;
2103
+ exports.hdH5Adapter = hdH5Adapter;
1658
2104
  exports.inApp = inApp;
1659
2105
  exports.init = init;
1660
2106
  exports.isReady = isReady;