@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.js CHANGED
@@ -1341,6 +1341,449 @@ async function logout() {
1341
1341
  }
1342
1342
  }
1343
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: typeof uni !== 'undefined' ? uni.chooseImage : null,
1576
+ pathToBase64: null
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
+
1344
1787
  /**
1345
1788
  * JSBridge SDK
1346
1789
  * 统一的原生能力封装
@@ -1649,8 +2092,11 @@ const Debug = {
1649
2092
 
1650
2093
  exports.Debug = Debug;
1651
2094
  exports.JSBridge = JSBridge;
2095
+ exports.JsBridgeHandlers = JsBridgeHandlers;
1652
2096
  exports.Monitor = Monitor;
2097
+ exports.UniProxy = UniProxy;
1653
2098
  exports.getPlatform = getPlatform;
2099
+ exports.hdH5Adapter = hdH5Adapter;
1654
2100
  exports.inApp = inApp;
1655
2101
  exports.init = init;
1656
2102
  exports.isReady = isReady;