Skip to content

taro-bluetooth-printTaro 蓝牙打印方案

零依赖 · 多平台 · 多协议 · TypeScript 严格模式 · 开箱即用

npm versiondownloadslicensebuild statusstarsTypeScriptzero dependency

⚡ 快速开始

安装依赖:

bash
# 使用 pnpm(推荐)
pnpm add taro-bluetooth-print

# 或使用 npm
npm install taro-bluetooth-print

仅需几行代码即可完成蓝牙打印:

typescript
import { BluetoothPrinter, DeviceManager } from 'taro-bluetooth-print';

async function printReceipt() {
  // 1️⃣ 扫描并发现打印机
  const deviceManager = new DeviceManager();
  deviceManager.on('device-found', (device) => {
    console.log('发现设备:', device.name);
  });
  await deviceManager.startScan({ timeout: 10000 });

  // 2️⃣ 连接目标打印机
  const printer = new BluetoothPrinter();
  const devices = deviceManager.getDiscoveredDevices();
  await printer.connect(devices[0].deviceId);

  // 3️⃣ 链式调用构建并打印内容
  await printer
    .text('=== 欢迎光临 ===', 'GBK')
    .feed()
    .text('商品A     x1    ¥10.00', 'GBK')
    .text('商品B     x2    ¥20.00', 'GBK')
    .feed()
    .text('------------------------', 'GBK')
    .text('合计:            ¥30.00', 'GBK')
    .feed(2)
    .qr('https://example.com', { size: 6 })
    .feed(2)
    .cut()
    .print();

  // 4️⃣ 断开连接
  await printer.disconnect();
}

📋 支持的驱动

驱动协议适用场景典型品牌 / 型号
EscPosDriverESC/POS热敏小票佳博、芯烨、商米、汉印
TsplDriverTSPL条码标签TSC ME240、TA210、TTP-244
ZplDriverZPL工业标签Zebra ZD420、GT800、ZM400
CpclDriverCPCL便携标签HP IR3222、霍尼韦尔移动打印机
StarPrinterDriverSTAR餐饮收银STAR TSP100、TSP700、TSP800
GPrinterDriver佳博自定义热敏小票佳博 GP-5890X 系列
XprinterDriverESC/POS热敏小票芯烨 XP-58 系列
SprtDriverESC/POS热敏小票思普瑞特 SP 系列

🌐 平台支持

平台适配层状态
微信小程序wx.writeBLECharacteristicValue✅ 已适配
支付宝小程序my.writeBLECharacteristicValue✅ 已适配
百度小程序swan.writeBLECharacteristicValue✅ 已适配
字节跳动小程序tt.writeBLECharacteristicValue✅ 已适配
QQ 小程序qq.writeBLECharacteristicValue✅ 已适配
H5WebBluetooth API✅ 已适配
React Native@react-native-ble-plx✅ 已适配

💡 为什么选择 taro-bluetooth-print?

  • 极致轻量 — gzip 后仅 ~15KB,零外部依赖,不增加包体积负担
  • 生产可靠 — TypeScript 严格模式 + 100% 类型覆盖,编译期消灭潜在错误
  • 多端统一 — 一套 API 适配 7 大平台,无需关心底层蓝牙差异
  • 工业级驱动 — 8 大打印机驱动覆盖市面主流品牌,即插即用
  • 离线容灾 — 断网自动缓存、来网智能同步,确保零打印任务丢失
  • GBK 编码 — 内置 GBK 编码支持,完美显示中文内容
  • 企业级管理 — 打印统计、定时重试、批量队列,满足复杂业务场景
MIT License · Made with ❤️ by agions

基于 MIT 许可发布