更新记录
1.0.0(2024-07-05)
平台兼容性
App |
快应用 |
微信小程序 |
支付宝小程序 |
百度小程序 |
字节小程序 |
QQ小程序 |
HBuilderX 3.6.8,Android:5.0,iOS:不支持,HarmonyNext:不确定 |
× |
× |
× |
× |
× |
× |
钉钉小程序 |
快手小程序 |
飞书小程序 |
京东小程序 |
鸿蒙元服务 |
× |
× |
× |
× |
× |
H5-Safari |
Android Browser |
微信浏览器(Android) |
QQ浏览器(Android) |
Chrome |
IE |
Edge |
Firefox |
PC-Safari |
× |
× |
× |
× |
× |
× |
× |
× |
× |
达普电子科技有限公司打印机
- 下载demo示例,拷贝demo里的AndroidManifest.xml文件到uniapp项目根目录下
- 点击插件页面右上角的"试用"按钮,按照提示集成到uniapp项目
- 删除本地基座和手机app
- 重新自定义基座运行
- 集成插件步骤请参考https://www.cnblogs.com/wenrisheng/p/18323027
import {
UTSDaPuPrinter
} from "@/uni_modules/wrs-uts-dapuprinter"
// 注册USB插拔监听
UTSDaPuPrinter.registerReceiver(this.action, (resp) => {
let action = resp.action;
switch (action) {
// USB授权结果
case this.action: {
let granted = resp.granted
let action = resp.action
let device = resp.device
this.showMsg("有USB设备授权结果:" + JSON.stringify(resp));
if (granted) {
this.showMsg("有USB设备授权成功");
} else {
this.showMsg("有USB设备授权失败");
}
}
break;
// 监测到有USB拔出
case "android.hardware.usb.action.USB_DEVICE_DETACHED": {
this.showMsg("有USB设备拔出:" + JSON.stringify(resp));
}
break;
// 检测到有USB插入
case "android.hardware.usb.action.USB_DEVICE_ATTACHED": {
// USB插入时,有些设备会监听到USB插入-USB设备拔出-USB设备插入这么个过程,可能是系统或USB设备的bug
this.showMsg("有USB设备插入:" + JSON.stringify(resp));
}
break;
default:
break;
}
})
UTSDaPuPrinter.unregisterReceiver()
UTSDaPuPrinter.getDeviceList((resp) => {
this.showMsg(JSON.stringify(resp))
// {"devices":[{"deviceName":"/dev/bus/usb/001/017","interfaceCount":2,"interfaces":[{"id":0,"name":"Espressif CDC Device","interfaceProtocol":0,"interfaceClass":2},{"id":1,"interfaceProtocol":0,"interfaceClass":10}],"deviceId":1017,"deviceProtocol":0}]}
});
权限结果在registerReceiver里回调
let device = devices[index];
let deviceId = device.deviceId;
let requestCode = this.requestCode;
let action = this.action;
// FLAG_IMMUTABLE = 67108864
// FLAG_ONE_SHOT = 1073741824
// FLAG_MUTABLE = 33554432
let flags = 67108864;
UTSDaPuPrinter.requestPermission(deviceId, requestCode, action, flags);
// 打印机的USB一般是PID:22336,VID:1155
let params = {}
params.deviceId = deviceId
let suc = UTSDaPuPrinter.connectUsb(params)
UTSDaPuPrinter.CloseUSB()
UTSDaPuPrinter.Check_Paper()
let params = {}
params.width = 560
params.height = 380
UTSDaPuPrinter.LabelBegin(params)
UTSDaPuPrinter.Labelend()
UTSDaPuPrinter.PaperCut()
// 1: 标签模式,2: 小票打印模式
let model = 1
UTSDaPuPrinter.setprintmode(model)
UTSDaPuPrinter.LableText({
startx: 80,
starty: 20,
fontsize: 2, // 设置字体大小,有效值范围为{1, 2, 3, 4, 5, 6}
rotate: 0,// 旋转角度(0-1) 0不旋转,1旋转90°
bold: 0,// 字体加粗
text: "深圳市第二高级中学"
});
UTSDaPuPrinter.LabelQRCode({
startx: 70,
starty: 70,
unitwidth: 14, // 设置字体大小,有效值范围为{1, 2, 3, 4, 5, 6}
text: "abc123"
});
UTSDaPuPrinter.LableBarcode({
startx: 70,
starty: 70,
height: 20,
unitwidth: 14, // unitwidth条码线条宽度,1-4
rotate: 0, // 0不旋转,1旋转90°
barodetext: "abc123"
});
UTSDaPuPrinter.LableImage({
startx: 70,
starty: 70,
mwidth: 100,// 图片大小最大范围不能超过标签纸的宽度,最大不能超过576,如果图片是800*400打印机会做等比例缩放处理到要打印图片的大小
photo: "/aaa/bbb/xx.png" // 本地图片绝对地址
});
UTSDaPuPrinter.LableTextImage({
startx: 70,
starty: 70,
mwidth: 100,
size: 2,
text: "5545454"
});