更新记录

1.0.3(2026-09-06)

  • 优化;

1.0.2(2026-09-03)

  • demo;

1.0.1(2026-09-03)

  • demo;
查看更多

平台兼容性

uni-app(5.25)

Vue2 Vue3 Chrome Safari app-vue app-vue插件版本 app-nvue app-nvue插件版本 Android Android插件版本 iOS iOS插件版本 鸿蒙
√ √ - - √ 1.0.0 √ 1.0.0 5.0 1.0.0 13 1.0.0 -
微信小程序 支付宝小程序 抖音小程序 百度小程序 快手小程序 京东小程序 鸿蒙元服务 QQ小程序 飞书小程序 小红书小程序 快应用-华为 快应用-联盟
- - - - - - - - - - - -

uni-app x(5.25)

Chrome Safari Android Android插件版本 iOS iOS插件版本 鸿蒙 微信小程序
- - 5.0 1.0.0 13 1.0.0 - -

其他

多语言 暗黑模式 宽屏模式 蒸汽模式
× × × √

xl-qqPrinter

以下示例中的 qqPrinter 为插件导入后的接口对象。

import * as qqPrinter from '@/uni_modules/xl-qqPrinter'

基础流程

qqPrinter.onDisconnect(() => {
  console.log('设备已断开')
})

qqPrinter.startScan({
  duration: 15000,
  onScanResult: (device) => {
    console.log('发现设备', device)
  }
})

qqPrinter.connect({
  deviceId: deviceId,
  onConnectSuccess: (id) => {
    console.log('连接成功', id)
  },
  onConnectFail: (message) => {
    console.error('连接失败', message)
  }
})

qqPrinter.preparePrint((code, result) => {
  if (code === 'OK' && (result === 'ALL_READY' || result === 'LOW_POWER')) {
    qqPrinter.print({
      base64: imageBase64,
      widthMm: 50,
      heightMm: 30,
      density: 13,
      count: 1,
      paperType: 'Continuous',
      walkStep: 100
    })
  }
})

接口说明

onDisconnect

监听设备断开事件。

qqPrinter.onDisconnect(callback: () => void): void

onPrinterMessage

监听打印机主动上报的消息。

qqPrinter.onPrinterMessage((event) => {
  console.log(event.message, event.instruction, event.content, event.otherMsg)
})

event 字段:

字段 类型 说明
instruction number 指令编号
message string 消息内容
content string \| null 附加内容
otherMsg string \| null 其他信息

startScan

开始扫描打印机。

qqPrinter.startScan({
  duration?: number,
  onScanResult?: (device) => void
}): void
  • duration:扫描时长,单位为毫秒,默认值为 15000。
  • onScanResult:发现设备时触发。

扫描结果字段:

字段 类型 说明
name string 设备名称
deviceId string 设备标识,连接时使用
rssi number \| null 蓝牙信号强度,单位为 dBm
mark string 设备标记

stopScan

停止扫描。

qqPrinter.stopScan(): void

connect

连接扫描结果中的设备。

qqPrinter.connect({
  deviceId: string,
  onConnectSuccess?: (deviceId: string) => void,
  onConnectFail?: (message: string) => void
}): void

disconnect

断开当前设备连接。

qqPrinter.disconnect(): void

preparePrint

打印前检查设备状态。

qqPrinter.preparePrint((code, result) => {
  console.log(code, result)
})
  • code:请求状态,例如 OK、TIMEOUT、BUSY、NOT_CONNECTED。
  • result:设备状态,例如 ALL_READY、LOW_POWER、NO_PAPER、DEVICE_OPEN、TOO_HOT;请求失败时可能为 null。

查询设备信息

查询接口均应在设备连接后调用,回调第一个参数为请求状态,第二个参数为查询结果;请求失败时结果可能为 null。

qqPrinter.getBattery((code, battery) => {
  // battery:电量百分比
})

qqPrinter.getFirmwareVersion((code, version) => {
  // version:固件版本
})

qqPrinter.getSnCode((code, sn) => {
  // sn:打印机序列号
})

// getSNNumber 与 getSnCode 等价
qqPrinter.getSNNumber((code, sn) => {})

print

提交打印任务。

qqPrinter.print(options, callback?)

options 参数:

参数 类型 必填 说明
base64 string 是 待打印图片的 Base64 字符串
widthMm number 是 输出宽度,单位为毫米
heightMm number 是 输出高度,单位为毫米
density number 否 打印浓度,范围为 1-15
count number 否 打印份数
paperType QPaperType 否 纸张类型
walkStep number 否 走纸步长

paperType 可选值:

值 说明
Continuous 连续纸
Gap 间隙纸
Fold 折叠纸
Black 黑标纸
Tattoo 纹身纸
BlackOrRransparent 黑标透明纸或纹身纸

打印回调参数:

qqPrinter.print(options, (result) => {
  console.log(result.code, result.message, result.currentIndex, result.totalCount)
})
字段 类型 说明
code string 提交状态、打印进度或结束状态
message string \| null 状态说明
currentIndex number 当前进度
totalCount number 总任务数

cancelPrint

取消当前正在进行的打印任务。没有正在打印时调用不会产生影响。

qqPrinter.cancelPrint(): void

隐私、权限声明

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

无

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

无

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

无