更新记录
1.0.9(2026-05-12) 下载此版本
示例插件
平台兼容性
ZPL 原生插件使用说明
1.复制nativeplugins文件夹到自己的项目中,在manifest中添加本地插件HPRTHelper。
2.根据文档在代码中调用插件功能。
3.制作自定义调试基座,运行基座选择自定义基座,然后再运行调试。
ZPL 插件接口文档
1.注册插件
const printModule = uni.requireNativePlugin('PrintModule');
2.连接蓝牙
注意:该接口需要蓝牙权限,要去manifest中配置。
printModule.connectBT({address}, result => {const msg = JSON.stringify(result);
modal.toast({message: msg,duration: 6});
})
mac:蓝牙地址,例如:"address":"00:15:83:EA:52:2E"。
result:运行结果。
3.断开连接
printModule.closePort();
4.连接wifi
注意:该接口需要网络权限,要去manifest中配置。
printModule.connectWifi({'IP':'192.168.1.1'},(ret) =>{})
IP:打印机IP地址。
ret:运行结果。
5.打印自检页
printModule.printSelf()
6.标签开头
printModule.labelStart()
7.标签结尾
printModule.labelEnd()
8.打印图片
注意:该接口需要读写权限,要去manifest中配置。
printModule.printBitmapPath({'x':'0','y':'0','path':'','halftoneType':1},(ret) => {});
x:横坐标。
y:纵坐标。
path:图片本地路径。
halftoneType:图片算法类型。
0:二值算法。
1:抖动算法。
ret:运行结果。
另一种打印图片方式
printModule.printBitmapBase64({'x':'0','y':'0','base64':'','halftoneType':1},(ret) => {});
x:横坐标。
y:纵坐标。
base64:图片Base64字符串。
halftoneType:图片算法类型。
0:二值算法。
1:抖动算法。
2:聚集算法。
ret:运行结果。
9.发送数据
printModule.writeData({'bData':data},(ret) =>{})
bData:数据。例如 var data = [0x0D,0x0A]
ret:运行结果。
10.读取数据
printModule.readData({'time':2},(ret) =>{})
time:超时时间(秒)。
ret:运行结果。
11.打印文本
printModule.printText({'x':'0','y':'0','type':7,'orientation':'N','size':3,'data': '打印测试'},(ret) => {});
x:横坐标。
y:纵坐标。
type:字体(0~6:中文无效,7:中文)。
orientation:方向。
N = normal
R = rotate 90 degrees clockwise
I = invert 180 degrees
B = read from bottom up-270 degrees
size:字体大小。 1:10px。 2:20px。 3:30px。 4:40px。 5:50px。 6:60px。
data:文本数据。
另一种打印文本的方式
printModule.printTextAutoSize({'x':'0','y':'0','type':7,'orientation':'N','textWidth':20,'textHeight':20,'data': '打印测试'},(ret) => {});
x:横坐标。
y:纵坐标。
type:字体(0~6:中文无效,7:中文)。
orientation:方向。
N = normal
R = rotate 90 degrees clockwise
I = invert 180 degrees
B = read from bottom up-270 degrees
textWidth:字体宽度(单位点)。
textHeight:字体高度(单位点)。
data:文本数据。
12.打印条码
printModule.printBarCode({'x':'0','y':'50','type':4,'ratio':'2','orientation':'N','height':80,'visible':'Y','data':'123456789'},(ret) => {});
x:横坐标。
y:从坐标。
Type:条码类型: 0=39,1=EAN-8,2=UPC-E,3=93,4=128,5=EAN-13。
ratio:宽窄条码比例(1-3)
orientation:方向:
N = normal
R = rotated 90 degrees (clockwise)
I = inverted 180 degrees
B = read from bottom up, 270 degrees
Height:条码高度(1-32000)。
visible:条码内容是否见(默认 Y):
Y = yes
N = no
data:内容。
13.打印二维码
printModule.printQRCode({'x':'0','y':'300','orientation':'N','magnification':'2','size':'6','data':'test QR code'},(ret) => {});
x:横坐标。
y:从坐标。
orientation:方向(N)。
magnification:模式: 1=普通模式。 2=加强模式。 默认(2)。
size :尺寸(1~10)。
data:二维码的内容。
14.发送文本数据
printModule.writeTextData({'text':data},(ret) =>{})
text:数据。例如 var data = 'test\r\n'
ret:运行结果。
15.设置字符集
printModule.setLanguageEncode({'language':data)
language:字符集,例如 var data = 'GBK'
15.设置打印宽度
printModule.setPrintWidth({'printWidth':'576'},(ret) => {});
printWidth:打印宽度(单位)

收藏人数:
下载插件并导入HBuilderX
下载插件ZIP
赞赏(0)
下载 4
赞赏 0
下载 11881163
赞赏 1912
赞赏
京公网安备:11010802035340号