useBarcodeModule.js 831 B

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