🌐
多平台适配
一套代码,七大平台全覆盖。微信 / 支付宝 / 百度 / 字节跳动 / QQ 小程序、H5 WebBluetooth、React Native。零迁移成本,一处编写到处打印。
安装依赖:
# 使用 pnpm(推荐)
pnpm add taro-bluetooth-print
# 或使用 npm
npm install taro-bluetooth-print仅需几行代码即可完成蓝牙打印:
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();
}| 驱动 | 协议 | 适用场景 | 典型品牌 / 型号 |
|---|---|---|---|
| EscPosDriver | ESC/POS | 热敏小票 | 佳博、芯烨、商米、汉印 |
| TsplDriver | TSPL | 条码标签 | TSC ME240、TA210、TTP-244 |
| ZplDriver | ZPL | 工业标签 | Zebra ZD420、GT800、ZM400 |
| CpclDriver | CPCL | 便携标签 | HP IR3222、霍尼韦尔移动打印机 |
| StarPrinterDriver | STAR | 餐饮收银 | STAR TSP100、TSP700、TSP800 |
| GPrinterDriver | 佳博自定义 | 热敏小票 | 佳博 GP-5890X 系列 |
| XprinterDriver | ESC/POS | 热敏小票 | 芯烨 XP-58 系列 |
| SprtDriver | ESC/POS | 热敏小票 | 思普瑞特 SP 系列 |
| 平台 | 适配层 | 状态 |
|---|---|---|
| 微信小程序 | wx.writeBLECharacteristicValue | ✅ 已适配 |
| 支付宝小程序 | my.writeBLECharacteristicValue | ✅ 已适配 |
| 百度小程序 | swan.writeBLECharacteristicValue | ✅ 已适配 |
| 字节跳动小程序 | tt.writeBLECharacteristicValue | ✅ 已适配 |
| QQ 小程序 | qq.writeBLECharacteristicValue | ✅ 已适配 |
| H5 | WebBluetooth API | ✅ 已适配 |
| React Native | @react-native-ble-plx | ✅ 已适配 |
💡 为什么选择 taro-bluetooth-print?