更新记录

1.1.0(2026-08-17)

  • Android 蓝牙搜索/连接前运行时申请 SCAN/CONNECT 与定位权限
  • 连接态补充 busy;demo 补 cancelPrinting / printTemplate / printPDF
  • 文档:模板说明与扫描/连接超时默认数值化(15000 / 10000 ms)
  • 平台插件版本号对齐本版;不开启源码授权
  • 不升级 Print SDK(保持 4.13.0);扩端本期不做

1.0.1(2026-08-17)

  • readme 加深模板打印与替换字段说明、补充可运行示例路径
  • 平台插件版本号对齐本版
  • 功能与行为与上一版一致;扩端本期不做

平台兼容性

uni-app(4.11)

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

uni-app x(4.11)

Chrome Safari Android Android插件版本 iOS iOS插件版本 鸿蒙 微信小程序
× × 5.0 1.0.1 12 1.0.1 × ×

breao-brotherprint 使用说明

兄弟 Brother 标签 / 便携打印插件,封装官方 Print SDK v4,适用于 QL / PT 系列图像、PDF 与模板打印。

当前版本:1.1.0

  • Android:Wi-Fi、经典蓝牙、BLE、USB Host
  • iOS:Wi-Fi、MFi 蓝牙、BLE
  • 能力:printImage / printPDF / printTemplate、状态与取消、序列号与电量;连接态含 busy
  • 不做鸿蒙 / 微信、固件大批量 transfer、Scanner SDK

建议调用顺序:initopenChannel(或先 startSearch)→ printImage / printPDF / printTemplatecloseChannel / destroy。各异步方法均支持 success / fail / completefailerrCode / errMsg。插件为单例通道语义:再次 initopenChannel 会关闭上一通道。


1. 环境要求

  • HBuilderX 4.11 及以上
  • uni-app Vue3(App-vue / App-nvue)或 uni-app x(App)
  • 支持:App-Android、App-iOS
  • 不支持:鸿蒙、微信及其它小程序、H5
  • Android 最低 API:21;iOS 最低 12
  • App 真机调试须制作自定义基座;正式发版须购买授权后走云端传统打包
  • 授权绑定唯一 appid + 包名

2. 安装与引入

将插件目录放入工程的 uni_modules/breao-brotherprint,或从插件市场导入后同步。

import {
  init,
  destroy,
  openChannel,
  closeChannel,
  startSearch,
  stopSearch,
  updatePrintSettings,
  printImage,
  printPDF,
  printTemplate,
  getPrinterStatus,
  cancelPrinting,
  requestSerialNumber,
  requestBatteryInfo,
  getConnectionState,
} from '@/uni_modules/breao-brotherprint'

3. API

3.1 init / destroy

init({
  series: 'QL',
  printerModel: 'QL_820NWB',
  labelSize: 'RollW62',
  autoCut: true,
  success() {},
  fail(err) {
    console.error(err.errCode, err.errMsg)
  },
})

destroy({ success() {}, fail() {} })

3.2 打开 / 关闭通道

openChannel({
  type: 'wifi',
  address: '192.168.1.100',
  success(res) {
    // res.state / res.address / res.channelType
  },
  fail(err) {},
})

openChannel({ type: 'bluetooth', address: 'XX:XX:XX:XX:XX:XX' })
openChannel({ type: 'ble', address: 'XX:XX:XX:XX:XX:XX' })
openChannel({ type: 'usb' }) // 仅 Android

closeChannel({ success() {}, fail() {} })
字段 说明
state connected / connecting / disconnected / busy
address 当前通道地址信息
channelType wifi / bluetooth / ble / usb

3.3 搜索

startSearch({
  type: 'bluetooth',
  success(res) {
    // res.devices: [{ name, address, channelType, modelName? }]
  },
  fail(err) {},
})

stopSearch({ success() {}, fail() {} })

说明:Android 的 bluetooth / usb 搜索可用;wifi / ble 异步搜索在 1.0.0 引导用已知 address 直连。参数见 §4。

3.4 打印设置

updatePrintSettings({
  series: 'PT',
  printerModel: 'PT_P910BT',
  labelSize: 'Width24mm',
  autoCut: true,
})

3.5 printImage / printPDF / printTemplate

printImage({ path: '/path/to/label.png', success() {}, fail(err) {} })
printImage({ paths: ['/a.png', '/b.png'], success() {}, fail(err) {} })

printPDF({ path: '/path/to/doc.pdf', success() {}, fail(err) {} })
printPDF({ path: '/path/to/doc.pdf', pages: [1, 2], success() {}, fail(err) {} })

printTemplate({
  key: 1,
  replacers: [
    { name: 'title', value: '货架A' },
    { index: 2, value: 'SN001', encode: 'UTF_8' },
  ],
  numCopies: 1,
  success() {},
  fail(err) {},
})

3.6 状态与设备信息

getPrinterStatus({
  success(res) {
    // errorCode / model / statusError
  },
  fail(err) {},
})

cancelPrinting({ success() {}, fail() {} })

requestSerialNumber({
  success(res) {
    // serialNumber
  },
  fail(err) {},
})

requestBatteryInfo({
  success(res) {
    // batteryChargeLevel / batteryHealthLevel / batteryHealthStatus
  },
  fail(err) {},
})

getConnectionState({
  success(res) {
    // state: disconnected | connecting | connected | busy
    // address / channelType / inited / busy
  },
  fail(err) {},
})

4. 可配置项

字段 位置 默认 说明
series init / updatePrintSettings QL 打印系列:QL 或 PT;决定 LabelSize / TemplateSettings
printerModel init / updatePrintSettings QL_820NWB SDK PrinterModel 枚举名,如 QL_820NWB、PT_P910BT;须与实机一致
labelSize init / updatePrintSettings RollW62(QL)/ Width24mm(PT) 标签尺寸枚举名;须与装入介质一致
autoCut init / updatePrintSettings true 是否自动切纸
workPath init / updatePrintSettings Android 外部文件目录 Android SDK 工作目录;iOS 可忽略
debug init false 调试日志
onDisconnected init 被动断开回调(预留)
type openChannel / startSearch wifi / bluetooth 通道:wifi、bluetooth、ble;Android 另支持 usb
address openChannel 必填(usb 可空) wifi=IP;Android 蓝牙/BLE=MAC;iOS 蓝牙=MFi 序列号;iOS BLE=广播 localName
timeout openChannel 15000 连接超时毫秒(尽力传递;部分通道由 SDK 内部决定)
timeout startSearch 10000 搜索超时毫秒(蓝牙/USB 同步搜索侧尽力使用)
nameHints startSearch Brother/QL-/PT- 等 名称过滤关键字;空数组表示不过滤
path printImage / printPDF 见 API 本地文件路径(绝对路径或 file://)
paths printImage 多图路径数组;与 path 二选一,优先 paths
pages printPDF 全页 页码列表,从 1 起
key printTemplate 必填 机内已安装 P-touch 模板编号,从 1 起
replacers printTemplate [] 模板替换项数组,见 4.2
numCopies printTemplate 1 打印份数
encode replacer UTF_8 UTF_8 / SHIFT_JIS / GB_18030_2000

不传参即用默认值。

4.1 常用 labelSize

系列 示例
QL RollW62、RollW29、DieCutW62H100、DieCutW62H29 等(与 SDK QLPrintSettings.LabelSize 同名)
PT Width12mm、Width18mm、Width24mm、Width36mm 等(与 SDK PTPrintSettings.LabelSize 同名)

4.2 replacer 字段

字段 位置 默认 说明
name replacer 模板对象名;与 index 二选一,优先 name
index replacer 模板对象索引
value replacer 必填 替换文本
encode replacer UTF_8 UTF_8 / SHIFT_JIS / GB_18030_2000

4.3 模板打印上手

  1. 用 Brother P-touch Editor(或机型配套工具)制作模板,并预先传输/安装到打印机;本插件只按 key 调机内模板,不负责上传 .lbx 等模板文件。
  2. 模板内可编辑对象须命名(如 titlebarcode);replacers 用同名 name 替换,或用 index(从 0 起,与 SDK 对象顺序一致)。nameindex 同时给时优先 name
  3. key 为机内模板编号(从 1 起),与打印机菜单/SDK 文档中的 Template Key 一致;找不到 key 时 SDK 返回打印错误(9090010)。
  4. 中文内容优先 encode: 'UTF_8';部分旧机型/地区模板可能需要 SHIFT_JISGB_18030_2000
  5. 建议流程:init(确认 series / printerModel / labelSize)→ openChannelprintTemplategetPrinterStatus(可选)→ closeChannel

模板最小示例:

printTemplate({
  key: 1,
  numCopies: 1,
  replacers: [
    { name: 'title', value: '货架A-01', encode: 'UTF_8' },
    { name: 'sku', value: 'SKU-10086' },
  ],
  success() {},
  fail(err) { console.error(err.errCode, err.errMsg) },
})

5. 完整示例

import {
  init,
  openChannel,
  printImage,
  getPrinterStatus,
  closeChannel,
  destroy,
} from '@/uni_modules/breao-brotherprint'

init({
  series: 'QL',
  printerModel: 'QL_820NWB',
  labelSize: 'RollW62',
  autoCut: true,
  success() {
    openChannel({
      type: 'wifi',
      address: '192.168.1.100',
      success() {
        printImage({
          path: '/path/to/label.png',
          success() {
            getPrinterStatus({
              success() {
                closeChannel({ success() { destroy({}) } })
              },
            })
          },
          fail(err) {
            console.error(err.errCode, err.errMsg)
          },
        })
      },
      fail(err) {
        console.error(err.errCode, err.errMsg)
      },
    })
  },
})

5.1 模板打印完整路径

import {
  init,
  openChannel,
  printTemplate,
  closeChannel,
  destroy,
} from '@/uni_modules/breao-brotherprint'

init({
  series: 'QL',
  printerModel: 'QL_820NWB',
  labelSize: 'RollW62',
  success() {
    openChannel({
      type: 'wifi',
      address: '192.168.1.100',
      success() {
        printTemplate({
          key: 1,
          replacers: [
            { name: 'title', value: '示例标签' },
            { index: 1, value: '第二对象' },
          ],
          success() {
            closeChannel({ success() { destroy({}) } })
          },
          fail(err) {
            console.error(err.errCode, err.errMsg)
          },
        })
      },
    })
  },
})

6. 权限

请在应用 manifest / 隐私弹窗中声明上述用途为连接并打印至附近的兄弟打印机。

平台 权限 说明
Android android.permission.BLUETOOTH、android.permission.BLUETOOTH_ADMIN API≤30 蓝牙连接
Android android.permission.BLUETOOTH_SCAN、android.permission.BLUETOOTH_CONNECT Android 12+ 蓝牙扫描与连接;搜索/连接前插件会运行时申请
Android android.permission.ACCESS_FINE_LOCATION、android.permission.ACCESS_COARSE_LOCATION 蓝牙扫描常见要求
Android android.permission.INTERNET、android.permission.ACCESS_NETWORK_STATE、android.permission.ACCESS_WIFI_STATE Wi-Fi 打印
Android USB Host 系统授权 openChannel({ type: 'usb' }) 时由系统弹窗
iOS NSBluetoothAlwaysUsageDescription、NSBluetoothPeripheralUsageDescription 蓝牙连接说明
iOS NSLocalNetworkUsageDescription 局域网 Wi-Fi 打印机
iOS UISupportedExternalAccessoryProtocols:com.brother.ptcbp MFi 兄弟打印机协议

7. 错误码(909)

含义
9090001 成功
9090002 通用失败
9090003 SDK 未配置或未正确打包
9090004 蓝牙未开启或不可用
9090005 未打开通道(未连接)
9090006 参数无效(缺 address、路径、机型等)
9090007 当前平台不支持
9090008 打开通道失败
9090009 通道类型不支持(如 iOS USB)
9090010 打印失败(SDK PrintError)

8. 平台注意

  • Android 打印图像/PDF 前请确保 workPath 可写;默认使用应用外部文件目录
  • iOS 经典蓝牙打印机通常需 MFi;address 使用 External Accessory 序列号,不是 BLE MAC
  • iOS BLE 使用打印机广播 localName 作为 address
  • printerModel / labelSize 必须与实机及装入标签一致,否则 SDK 返回打印错误
  • RJ / TD / PJ 等机型可将 printerModel 透传 Android 枚举名,但不承诺全测
  • 模板打印要求打印机内已安装对应 key 的 P-touch 模板;本插件不做模板文件大批量传输(详见 §4.3)
  • wifi / ble 搜索建议已知 IP、MFi 序列号或 BLE localName 后直连

隐私、权限声明

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

Android: android.permission.BLUETOOTH、android.permission.BLUETOOTH_ADMIN(API≤30); android.permission.BLUETOOTH_SCAN、android.permission.BLUETOOTH_CONNECT(Android 12+); android.permission.ACCESS_FINE_LOCATION、android.permission.ACCESS_COARSE_LOCATION; android.permission.INTERNET、android.permission.ACCESS_NETWORK_STATE、android.permission.ACCESS_WIFI_STATE。 USB Host 打印需系统 USB 权限授权。 iOS: NSBluetoothAlwaysUsageDescription、NSBluetoothPeripheralUsageDescription、NSLocalNetworkUsageDescription; UISupportedExternalAccessoryProtocols(com.brother.ptcbp,MFi 蓝牙打印机)。 用途:兄弟打印机扫描、连接与标签/便携打印。

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

不采集、不上传任何数据;打印内容仅经本机蓝牙、USB 或局域网发至已连接的兄弟打印机。集成 Brother 官方 Print SDK 仅用于本地设备通信

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

暂无用户评论。