更新记录

1.0.0(2024-07-05)

  • usb连接
  • 打印文本、图片、一维码、二维码等

平台兼容性

Vue2 Vue3
App 快应用 微信小程序 支付宝小程序 百度小程序 字节小程序 QQ小程序
HBuilderX 3.6.8,Android:5.0,iOS:不支持 × × × × × ×
钉钉小程序 快手小程序 飞书小程序 京东小程序
× × × ×
H5-Safari Android Browser 微信浏览器(Android) QQ浏览器(Android) Chrome IE Edge Firefox PC-Safari
× × × × × × × × ×

达普电子科技有限公司打印机

  • usb连接
  • 打印文本、图片、一维码、二维码等
  1. 下载demo示例,拷贝demo里的AndroidManifest.xml文件到uniapp项目根目录下
  2. 点击插件页面右上角的"试用"按钮,按照提示集成到uniapp项目
  3. 删除本地基座和手机app
  4. 重新自定义基座运行
  5. 集成插件步骤请参考https://www.cnblogs.com/wenrisheng/p/18323027

import {
    UTSDaPuPrinter
} from "@/uni_modules/wrs-uts-dapuprinter"
  • 监听USB设备的插拔

                // 注册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;
                    }
                })
  • 取消监听USB设备的插拔

UTSDaPuPrinter.unregisterReceiver()
  • 获取当前连接的所有USB设备

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}]}
});
  • 请求某个USB设备权限

权限结果在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打印机

// 打印机的USB一般是PID:22336,VID:1155
let params = {}
params.deviceId = deviceId
let suc = UTSDaPuPrinter.connectUsb(params)
  • 关闭usb打印机

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"
});

隐私、权限声明

1. 本插件需要申请的系统权限列表:

读写权限

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

暂无用户评论。

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问