敬告:此 DEMO 演示为开放测试页面,仅用于开发者快速测试体验应用功能,请严格遵守开发者协议。
♦ JS-SDK 引用方式:
♦ 普通网页 script 方式加载:下载最新版 jsBridge-v20261013.zip,请在页面上调用 jsBridge 接口之前引用 jsbridge-mini.js 库;
♦ js module 方式引用:npm install ym-jsbridge 具体请参考 npm package
事件监听
• 如需接口调用事件,请设置此监听器;
jsBridge.dstp.setListener(function(event, data) {
switch (event) {
//扫描到蓝牙设备
case "discoverBluetoothDevice": {
//data.macAddress: string 设备 mac 地址
//data.name: string 设备名称
break;
}
}
//此函数仅用于显示回调参数在本 DEMO 页面上
showResult({
event: event,
data: data
});
});
//请拉到页面底部查看回调数据信息
$('html,body').animate({ scrollTop: $('#view').offset().top }, 500);
//移除监听器,不会再收到回调通知 //在需要时可重新调用 setListener jsBridge.omni.removeListener();
打印机
jsBridge.dstp.requestPermission(function(success, res) {
alert(success && res.granted ? "已获得全部权限" : JSON.stringify(res));
});
//在 setListener 中监听获取扫描到的设备信息
jsBridge.dstp.startDiscoverBluetoothDevice(function(success, res) {
alert(success ? "已开始扫描" : JSON.stringify(res));
});
jsBridge.dstp.stopDiscoverBluetoothDevice(function(success, res) {
alert(success ? "已停止扫描" : JSON.stringify(res));
});
macAddress:
needBond:
pin:
sender:
jsBridge.progress({ visible: true });
jsBridge.dstp.connectBluetooth({
//蓝牙打印机 mac 地址
macAddress: "{{connectBluetooth.macAddress}}",
//是否需要配对
needBond: {{connectBluetooth.needBond}},
//配对 pin 码
pin: "{{connectBluetooth.pin}}",
//仿真操作,可选值 ESCPOS, ZPL, TSPL, CPCL,默认 ESCPOS
sender: "{{connectBluetooth.sender}}"
}, function(success, res) {
jsBridge.progress({ visible: false });
alert(success ? "连接成功" : JSON.stringify(res));
});
jsBridge.dstp.disconnect(function(success, res) {
alert(success ? "已断开" : JSON.stringify(res));
});
x:
y:
scale:
base64Image:
jsBridge.dstp.printImage({
//x 坐标
x: {{printImage.x}},
//y 坐标
y: {{printImage.y}},
//仅用于 ZPL 仿真,缩放比例 1~10,默认 1 即不缩放
scale:{{printImage.scale}},
//Base64 编码的图片
base64Image: "{{printImage.base64Image}}"
}, function(success, res) {
alert(success ? "成功" : JSON.stringify(res));
});
监听回调数据: