WebApp快捷打包
扫一扫 - 将摄像头扫码 UI 嵌入网页

敬告:此 DEMO 演示为开放测试页面,仅用于开发者快速测试体验应用功能,请严格遵守开发者协议,了解更多

JS-SDK 引用方式:

♦ 普通网页 script 方式加载:下载最新版 jsBridge-v20240326.zip,请在页面上调用 jsBridge 接口之前引用 jsbridge-mini.js 库;

♦ js module 方式引用:npm install ym-jsbridge 具体请参考 npm package

识别结果:

scan 添加摄像头 UI - top

//如果已添加,需移除后再添加
jsBridge.scan({
  needResult: true,
  //嵌入式扫码
  embed: {
    //位置,top 或 bottom
    //iOS 平台上始终为 top
    position: "top",
    //高度
    height  : parseInt($(window).height() * 0.45),
    //连续扫码时,两次成功识别之间的最小时间间隔(毫秒),最小 200
    interval: 1000
  }
}, function(code) {
  if (code) {
    //震动提示
    jsBridge.vibrate();
    //处理结果
    $("#result").val(code);
  }
});

scan 添加摄像头 UI - bottom

//如果已添加,需移除后再添加
jsBridge.scan({
  needResult: true,
  embed: {
    //iOS 平台上始终为 top
    position: "bottom",
    height  : parseInt($(window).height() * 0.45),
    interval: 1000
  }
}, function(code) {
  if (code) {
    //震动提示
    jsBridge.vibrate();
    //处理结果
    $("#result").val(code);
  }
});

暂停识别

jsBridge.scan({
  embed: {
    action: "pause"
  }
});

恢复识别

jsBridge.scan({
  embed: {
    action: "resume"
  }
});

开/关 灯光

jsBridge.scan({
  embed: {
    //switch light
    action: "light"
  }
});

获取当前状态

jsBridge.scan({
  needResult: true,
  embed: {
    action: "status"
  }
}, function(status) {
  if (status) {
    status = JSON.parse(status);
    alert(JSON.stringify(status));
  }
});

/*
回调参数 status 是 json 字符串,请转换
{
  scanning: boolean  //是否正在识别
  light   : boolean  //是否已开启灯光
}
*/

移除摄像头

jsBridge.scan({
  embed: {
    action: "remove"
  }
});