diff --git a/components/print/bluetooth.js b/components/print/bluetooth.js index fc8c136..dc719f7 100644 --- a/components/print/bluetooth.js +++ b/components/print/bluetooth.js @@ -149,7 +149,6 @@ class Bluetooth { deviceId: deviceId, serviceId: uuid, success: res => { - console.log(res) for (let _obj of res.characteristics) { //获取notify if (_obj.properties.notify) { @@ -194,7 +193,7 @@ class Bluetooth { uni.closeBLEConnection({ deviceId, success(res) { - console.log(res) + } }) } diff --git a/components/print/index.js b/components/print/index.js index 8c09e1e..a3f3919 100644 --- a/components/print/index.js +++ b/components/print/index.js @@ -106,8 +106,6 @@ }, //写入控制命令 async writeBLECharacteristicValue(onDone) { - console.log('数据啊----------', data1) - let printerJobs = new PrinterJobs(); printerJobs.setAlign('ct').setSize(2, 2).setLineSpacing(60).print( @@ -251,24 +249,14 @@ const end = Math.min(currentIndex + maxChunk, totalLength); const chunkLength = end - currentIndex; - - // 创建一个全新的、长度精确的 ArrayBuffer const valueToSend = new ArrayBuffer(chunkLength); const dstView = new Uint8Array(valueToSend); - - // 将源数据拷贝到新的 ArrayBuffer 中 dstView.set(srcView.subarray(currentIndex, end)); - - console.log('发送分包:', currentIndex, '长度:', chunkLength); - - // 【核心修复】:直接调用 bluetooth 对象封装好的方法 - // 它内部会自动使用正确的 bluetooth.deviceId, bluetooth.serviceId, bluetooth.writeId bluetooth.writeBLECharacteristicValue(valueToSend).then(() => { currentIndex = end; - // 成功后,延迟再发下一个 setTimeout(sendNextChunk, delay); }).catch((err) => { - console.error('发送失败:', err); + isPrint = false; if (typeof onDone === 'function') onDone(err); });