🔗
多平台适配
一套 API,微信/支付宝/百度/字节跳动小程序、H5 WebBluetooth、鸿蒙、React Native 全覆盖。零平台迁移成本。
pnpm add taro-bluetooth-printimport { BluetoothPrinter, DeviceManager } from 'taro-bluetooth-print';
async function main() {
// 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();
await printer.disconnect();
}| 驱动 | 协议 | 典型品牌 |
|---|---|---|
| EscPos | ESC/POS | 佳博、芯烨、商米、汉印 |
| TsplDriver | TSPL | TSC ME240、TA210、TTP-244 |
| ZplDriver | ZPL | Zebra ZD420、GT800、ZM400 |
| CpclDriver | CPCL | HP IR3222、霍尼韦尔移动机 |
| StarPrinter | STAR | STAR TSP100、TSP700、TSP800 |
| GPrinterDriver | 自定义 | 佳博 GP-5890X 系列 |
| XprinterDriver | ESC/POS | 芯烨 XP-58 系列 |
| SprtDriver | ESC/POS | 思普瑞特系列 |
为什么选择 taro-bluetooth-print?