useBarcodeModule.js 694 B

1234567891011121314151617181920212223242526
  1. const modal = uni.requireNativePlugin('modal');
  2. /**
  3. * 初始化idata扫描模块
  4. */
  5. export function useInit() {
  6. //获取module
  7. var barcodeModel = uni.requireNativePlugin("iData-BarcodePlugin-BarcodeModule")
  8. //使用示例
  9. barcodeModel.initScan((ret) => {
  10. console.log('初始化扫描', ret)
  11. });
  12. }
  13. /**
  14. * 全局监听扫描后结果
  15. * @param onChange 回调函数
  16. */
  17. export function useGlobalEvent(onChange) {
  18. //页面监听event事件,建议在页面onLoad方法里调用
  19. var globalEvent = uni.requireNativePlugin('globalEvent');
  20. globalEvent.addEventListener('iDataBarcodeEvent', function(e) {
  21. onChange && onChange(e)
  22. //条码结果示例:{"barcode","条码数据"}
  23. });
  24. }