diff --git a/components/tpx-bluetooth-native/nativeBlueTooth.js b/components/tpx-bluetooth-native/nativeBlueTooth.js index f645b75..0855187 100644 --- a/components/tpx-bluetooth-native/nativeBlueTooth.js +++ b/components/tpx-bluetooth-native/nativeBlueTooth.js @@ -420,6 +420,9 @@ var blueToothTool = { } }, 40); }, + getBtOutStream(){ + return btOutStream + }, /** * 发送数据 * @param {String} dataStr diff --git a/components/tpx-bluetooth-native/tpx-bluetooth-native.vue b/components/tpx-bluetooth-native/tpx-bluetooth-native.vue index 4348810..2e544fd 100644 --- a/components/tpx-bluetooth-native/tpx-bluetooth-native.vue +++ b/components/tpx-bluetooth-native/tpx-bluetooth-native.vue @@ -214,10 +214,6 @@ export default { }, getConData() { return { deviceId: this.deviceId, } - }, - sendByteData(data) { - let bl = bluetoothTool.sendByteData(data) - return bl } } } diff --git a/components/tpx-bluetooth-print/print/encoding-indexes.js b/components/tpx-bluetooth-print/nativePrint/encoding-indexes.js similarity index 100% rename from components/tpx-bluetooth-print/print/encoding-indexes.js rename to components/tpx-bluetooth-print/nativePrint/encoding-indexes.js diff --git a/components/tpx-bluetooth-print/print/encoding.js b/components/tpx-bluetooth-print/nativePrint/encoding.js similarity index 100% rename from components/tpx-bluetooth-print/print/encoding.js rename to components/tpx-bluetooth-print/nativePrint/encoding.js diff --git a/components/tpx-bluetooth-print/nativePrint/print.js b/components/tpx-bluetooth-print/nativePrint/print.js new file mode 100644 index 0000000..0f2c1ae --- /dev/null +++ b/components/tpx-bluetooth-print/nativePrint/print.js @@ -0,0 +1,14 @@ +import nativeBlueTooth from "@/components/tpx-bluetooth-native/nativeBlueTooth" + +const module = { + print(data){ + let outputStream = nativeBlueTooth.getBtOutStream() + outputStream.write([0x1b, 0x40]) //打印复位 + outputStream.flush() + nativeBlueTooth.sendByteData(data) + }, + sendByteData: nativeBlueTooth.sendByteData, + sendData: nativeBlueTooth.sendData +} + +export default module diff --git a/components/tpx-bluetooth-print/print/print.js b/components/tpx-bluetooth-print/nativePrint/printTest.js similarity index 100% rename from components/tpx-bluetooth-print/print/print.js rename to components/tpx-bluetooth-print/nativePrint/printTest.js diff --git a/components/tpx-bluetooth-print/print/tanexPrinterUniSdk.js b/components/tpx-bluetooth-print/nativePrint/tanexPrinterUniSdk.js similarity index 100% rename from components/tpx-bluetooth-print/print/tanexPrinterUniSdk.js rename to components/tpx-bluetooth-print/nativePrint/tanexPrinterUniSdk.js diff --git a/components/tpx-bluetooth-print/print/printJob.js b/components/tpx-bluetooth-print/print/printJob.js index 09767d7..ce59407 100644 --- a/components/tpx-bluetooth-print/print/printJob.js +++ b/components/tpx-bluetooth-print/print/printJob.js @@ -6,64 +6,6 @@ //蓝牙打印机一次接收的二级制数据有限制,不同的系统不同的蓝牙设备限制可能不同,微信建议一次20个字节,需做递归分包发送 //发送完要打印的内容后,一定要发送一个打印的指令才能顺利打印 (有些指令就不需要) -export function senBlData(uint8Array) { - let that = this - var uint8Buf = Array.from(uint8Array); - - function split_array(datas, size) { - var result = {}; - var j = 0 - for (var i = 0; i < datas.length; i += size) { - result[j] = datas.slice(i, i + size) - j++ - } - return result - } - var sendloop = split_array(uint8Buf, 20); - - function realWriteData(sendloop, i) { - var data = sendloop[i] - if (typeof(data) == "undefined") { - - uni.showLoading({ - title: '数据发送完毕,准备打印', - icon: 'loading', - }) - setTimeout(function() { - uni.hideLoading() - }, 1000); - return - } - // console.log("第【" + i + "】次写数据"+data) - var buffer = new ArrayBuffer(data.length) - var dataView = new DataView(buffer) - for (var j = 0; j < data.length; j++) { - dataView.setUint8(j, data[j]); - } - uni.writeBLECharacteristicValue({ - deviceId: that.deviceId, - serviceId: that.writeServiceId, - characteristicId: that.writeCharaterId, - value: buffer, - success(res) { - realWriteData(sendloop, i + 1); - }, - fail() { - uni.showLoading({ - title: '发送数据失败', - icon: 'loading', - }) - setTimeout(function() { - uni.hideLoading() - }, 1000); - } - }) - } - var i = 0; - realWriteData(sendloop, i); -} - -// 发送数据(递归分包发送) /** * * diff --git a/components/tpx-bluetooth-print/render-template-native.vue b/components/tpx-bluetooth-print/render-template-native.vue index 574df42..45b7c41 100644 --- a/components/tpx-bluetooth-print/render-template-native.vue +++ b/components/tpx-bluetooth-print/render-template-native.vue @@ -25,8 +25,8 @@