uniapp原生蓝牙打印插件 | 您所在的位置:网站首页 › uniapp蓝牙打印图片 › uniapp原生蓝牙打印插件 |
蓝牙打印简介 ZJQ-BluetoothUtil 是基于原生手机蓝牙打印的插件,目前支持android蓝牙打印,支持市场上大多蓝牙小票打印机。 下载及使用说明:https://ext.dcloud.net.cn/plugin?id=3406 使用步骤:1、插件安装到uniapp项目中。
2、在相关组件中引用本地插件。 引用方法,在组件中定义 如: const bluetoothUtil = uni.requireNativePlugin('ZJQ-BluetoothUtil'); 3、在uniapp项目中,添加定时器定时读取搜索到的设备 let userTimer = setInterval(() => { bluetoothUtil.getDevices(res => { if (res.isDiscoveryComplete===1) { clearInterval(userTimer ); //搜索完成清除定时器 } else { this.binddevices = res.bindDevice; this.notbinddevices = res.notbindDevice; } }); }, 2000); //每2秒获取一次搜索到的设备 4、在方法中调用相关蓝牙连接、打印API。 API说明 函数名称参数说明enableBlueTooth无启用本机蓝牙。startDiscovery无搜索蓝牙设备,注册蓝牙广播事件。stopDiacovery无停止搜索蓝牙设备,停止蓝牙广播。getDevices无获取蓝牙设备及蓝牙搜索状态,包括搜索到已配对设备、未配对设备。返回jsonobject对象,isDiscoveryComplete是否搜索完成,蓝牙搜索完成返回:1,正在搜索返回为:0;已配对设备列表为:bindDevice,未配对设备列表为:notbindDevicegetBindDevice无获取最近一次搜索到已配对设备列表。参数为:bindDevice。connectbindDevice需连接设备MAC地址:参数为字符串连接蓝牙设备,传入搜索到蓝牙设备地址。intPrint无初始化打印,在开始开始调用此方法。printLine数字:intlineNumber打印空行,传数数字打印多行。printLine无打印空行printTabSpace数字:length打印空格printText字符串:text打印字符printAlignment数字:0、1或2对齐方式:0 : 左对齐,1:居中,2:右对齐printLargeText字符串:text打印大字号标题。printDashLine无打印虚线,样式:------------------------printBitmap传入Bitmap格式图片打印图片printUrlBitmap图片URL:String打印网络图片printQrcode二维码,类型为字符弄打印二维码 例 子: function print(){ bluetoothUtil.intPrint(); //打印前调用初始化方法 bluetoothUtil.printLine(1); 打印1行,传数字打印多行。 bluetoothUtil.printLine();打印空行 bluetoothUtil.printTabSpace() 打印空格 bluetoothUtil.printText("adsf") 打印文本 bluetoothUtil.printLine();打印空行 bluetoothUtil.printText("adsf") 打印文本 bluetoothUtil.printLine();打印空行 bluetoothUtil.printAlignment(0); 设置对齐方式:0 : 左对齐,1:居中,2:右对齐 bluetoothUtil.printLine();打印空行 bluetoothUtil.printLargeText("AAA") 打印大号字体 bluetoothUtil.printLine();打印空行 bluetoothUtil.printDashLine() 打印虚线,样式:------------------------ bluetoothUtil.printLine();打印空行 bluetoothUtil.printQrcode('AAA'); 打印二维码 bluetoothUtil.printLine();打印空行 bluetoothUtil.printUrlBitmap(url); 打印url网络地址 bluetoothUtil.printLine();打印空行 } |
CopyRight 2018-2019 实验室设备网 版权所有 |