From 51f8d59bbd079e41f0bb1f8ef334c5eeed154a22 Mon Sep 17 00:00:00 2001 From: kyy <3283105747@qq.com> Date: 星期六, 16 八月 2025 17:29:14 +0800 Subject: [PATCH] 1、更新蓝牙 --- PadClient2/utils/printSupport.js | 218 +++++++++++++++++++++++++++++++++++++++--------------- 1 files changed, 157 insertions(+), 61 deletions(-) diff --git a/PadClient2/utils/printSupport.js b/PadClient2/utils/printSupport.js index 3d48062..e5b0309 100644 --- a/PadClient2/utils/printSupport.js +++ b/PadClient2/utils/printSupport.js @@ -24,70 +24,115 @@ */ // 鏍峰紡璋冩暣demo -// export const queue = async (arr, ip, port) => { -// let jsons = ``; - -// console.log(arr[0]); -// console.log(arr[1]); -// console.log(ip); -// console.log(port); -// const printArr = arr; -// console.log(printArr); - -// jsons = "! 0 200 200 200 1\r\n" + -// "PAGE - WIDTH 700 \r\n" + -// "GAP-SENSE \r\n" + -// // "BOX 0 0 700 180 0 \r\n" + -// "T 16 0 10 10 鐗╂枡缂栫爜锛�" + "\r\n" + -// "T 55 3 120 10 " + "{itemNo}" + "\r\n" + -// "T 16 0 300 10 " + "{itemName1111111111111111}" + "\r\n" + -// "T 55 2 10 42 鐗╂枡瑙勬牸锛�" + "\r\n" + -// "T 55 2 110 42 " + "{itemModel11111111111111111111111111111}" + "\r\n" + -// "T 16 0 10 78 鏁伴噺锛�" + "\r\n" + -// "T 0 5 90 78 " + "200.102000" + "\r\n" + -// "BARCODE 128 1 25 35 350 130 " + 'TM12131ASFASF123456' + "\r\n" + -// "T 0 1 350 130 " + "TM12131ASFASF123456" + "\r\n" + -// "T 55 0 10 125 鍒涘缓鏃堕棿锛�" + "\r\n" + -// "T 55 0 120 125 " + "{2025-05-07 15:55:59}" + "\r\n" + -// "T 55 0 10 150 鎵撳嵃鏃堕棿锛�" + "\r\n" + -// "T 55 0 120 150 " + "{2025-05-07 15:55:59}" + "\r\n" + -// //"B QR 500 10 M 1 U 9 \r\n" + -// //"MA," + '001' + "\r\n" + -// "B QR 580 12 M 2 U 4" + "\r\n" + -// "MA," + "TM12345620154" + "\r\n" + -// "ENDQR\r\n" + -// "FORM\r\n" + -// "PRINT\r\n"; -// await printHandle(jsons, ip, port); - -// }; - -//姝e紡浠g爜 export const queue = async (arr, ip, port) => { - try { - const printArr = arr; // 鎺ユ敹浼犲叆鐨勬墦鍗版寚浠ゆ暟缁� - console.log('褰撳墠鎵撳嵃鍙傛暟:', { - ip, - port - }); + let jsons = ``; - // 寰幆澶勭悊姣忎竴鏉℃墦鍗版寚浠� - for (const [index, jsons] of printArr.entries()) { - console.log(`姝e湪澶勭悊绗� ${index + 1} 鏉℃墦鍗版寚浠); - console.debug('鎵撳嵃鎸囦护鍐呭:', jsons); + console.log(arr[0]); + console.log(arr[1]); + console.log(ip); + console.log(port); + const printArr = arr; + console.log(printArr); - // 鎵ц寮傛鎵撳嵃鎿嶄綔 - await printHandle( - jsons, // 鍔ㄦ�佹浛鎹㈡枃鏈� - ip, - port - ); - } - } catch (error) { - console.error('鎵撳嵃闃熷垪鎵ц鍑洪敊:', error); - throw error; // 鍚戜笂鎶涘嚭閿欒渚涜皟鐢ㄦ柟澶勭悊 - } + +jsons = + "! 0 195 200 472 1\r\n" + // 鍩虹鍋忕Щ閲忓乏绉�5鍍忕礌 + "PAGE-WIDTH 545\r\n" + // 椤甸潰瀹藉害鍑忓皯5鍍忕礌 + "GAP-SENSE\r\n" + + + // 澶栨 - 鏁翠綋宸︾Щ5鍍忕礌 + "BOX -3 2 543 470 2\r\n" + + // ==================== 鐗╂枡鏉$爜锛堢涓�琛岋級==================== + "LINE -3 62 425 62 1\r\n" + + "T 55 0 8 27 鐗╂枡鏉$爜:\r\n" + + + + // ==================== 鐗╂枡缂栫爜锛堢浜岃锛�==================== + "LINE -3 124 543 124 1\r\n" + + "T 55 0 8 89 缂栫爜:\r\n" + + + + // ==================== 渚涘簲鍟嗭紙绗笁琛岋級==================== + "LINE -3 186 543 186 1\r\n" + // 绗�3鏉″垎闅旂嚎锛堥棿闅�62锛� + "T 55 0 8 151 渚涘簲鍟�:\r\n" + + + + // ==================== 鐗╂枡鍚嶇О锛堢鍥涜锛�==================== + "LINE -3 248 543 248 1\r\n" + // 绗�4鏉″垎闅旂嚎锛堥棿闅�62锛� + "T 55 0 8 213 鍚嶇О:\r\n" + + + + // ==================== 瑙勬牸鍨嬪彿锛堢浜旇锛�==================== + "LINE -3 310 543 310 1\r\n" + // 绗�5鏉″垎闅旂嚎锛堥棿闅�62锛� + "T 55 0 8 275 瑙勬牸:\r\n" + + + + // ==================== 浠撳簱锛堢鍏锛�==================== + "LINE -3 360 543 360 1\r\n" + // 绗�6鏉″垎闅旂嚎锛堢Щ鑷崇珫绾块《绔痀=360锛� + "T 55 0 8 335 浠撳簱:\r\n" + + + + // ==================== 鏁伴噺鍜屼粨绠″憳锛堢涓冭锛�==================== + "LINE -3 430 543 430 1\r\n" + // 搴曢儴妯嚎锛堜笌绔栫嚎搴曠瀵归綈锛� + "T 55 0 8 380 鏁伴噺:\r\n" + // 鏂囨湰浣嶇疆淇濇寔 + "T 55 0 275 380 浠撶鍛�:\r\n" + // 鏂囨湰浣嶇疆淇濇寔 + + + // 涓棿绔栫嚎鍒嗛殧锛堣寖鍥碮=360-430锛屼笌涓婁笅妯嚎琛旀帴锛� + "LINE 265 430 265 360 1\r\n" + // 绔栫嚎椤剁瀵归綈浠撳簱琛屽垎闅旂嚎 + + // ==================== 搴曢儴鏃堕棿淇℃伅 ==================== + "T 55 0 395 440 鎵撳嵃鏃堕棿\r\n" + // 浣嶇疆淇濇寔 + "T 55 0 8 440 " + new Date().toLocaleString('zh-CN', { // 鏃堕棿鏍煎紡鏀逛负骞存湀鏃ユ椂鍒嗙 + year: 'numeric', + month: '2-digit', + day: '2-digit', + hour: '2-digit', + minute: '2-digit', + second: '2-digit' + }) + "\r\n" + + + + // ==================== 浜岀淮鐮佸尯鍩燂紙宸︾Щ5鍍忕礌锛�==================== + "BOX 425 3 535 113 1\r\n" + // 浣嶇疆淇濇寔 + "B QR 430 8 M 2 U 5\r\n" + // 浣嶇疆淇濇寔 + "MA,{zb.鐗╂枡鏉$爜}\r\n" + + "ENDQR\r\n" + + + "FORM\r\n" + + "PRINT\r\n"; + +await printHandle(jsons, ip, port); + + }; + +// //姝e紡浠g爜 +// export const queue = async (arr, ip, port) => { +// try { +// const printArr = arr; // 鎺ユ敹浼犲叆鐨勬墦鍗版寚浠ゆ暟缁� +// console.log('褰撳墠鎵撳嵃鍙傛暟:', { +// ip, +// port +// }); + +// // 寰幆澶勭悊姣忎竴鏉℃墦鍗版寚浠� +// for (const [index, jsons] of printArr.entries()) { +// console.log(`姝e湪澶勭悊绗� ${index + 1} 鏉℃墦鍗版寚浠); +// console.debug('鎵撳嵃鎸囦护鍐呭:', jsons); + +// // 鎵ц寮傛鎵撳嵃鎿嶄綔 +// await printHandle( +// jsons, // 鍔ㄦ�佹浛鎹㈡枃鏈� +// ip, +// port +// ); +// } +// } catch (error) { +// console.error('鎵撳嵃闃熷垪鎵ц鍑洪敊:', error); +// throw error; // 鍚戜笂鎶涘嚭閿欒渚涜皟鐢ㄦ柟澶勭悊 +// } +// }; export const queue111 = async (arr, ip, port) => { let jsons = ``; @@ -260,7 +305,8 @@ * @param {string} ip ip鍦板潃 * @param {Number} port //绔彛鍙� */ -export const printHandle = async (jsons, ip, port) => { + +/* export const printHandle = async (jsons, ip, port) => { return new Promise((resolve, reject) => { try { var Socket = plus.android.importClass('java.net.Socket'); @@ -304,4 +350,54 @@ } } }); +}; */ + + +export const printHandle = async (jsons, ip, port) => { + + var mac_address = uni.getStorageSync('printMac'); + console.log('鎵撳嵃寮�濮�:'+mac_address) + var device = null, + BAdapter = null, + BluetoothAdapter = null, + uuid = null, + main = null, + bluetoothSocket = null; + if (!mac_address) { + this.$showMessage('璇烽�夋嫨钃濈墮鎵撳嵃鏈�'); + return false; + } + main = plus.android.runtimeMainActivity(); + BluetoothAdapter = plus.android.importClass("android.bluetooth.BluetoothAdapter"); + let UUID = plus.android.importClass("java.util.UUID"); + uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); + BAdapter = BluetoothAdapter.getDefaultAdapter(); + device = BAdapter.getRemoteDevice(mac_address); + plus.android.importClass(device); + bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); + plus.android.importClass(bluetoothSocket); + if (!bluetoothSocket.isConnected()) { + console.log('妫�娴嬪埌璁惧鏈繛鎺ワ紝灏濊瘯杩炴帴....'); + bluetoothSocket.connect(); + } + console.log('璁惧宸茶繛鎺�'); + if (bluetoothSocket.isConnected()) { + var outputStream = bluetoothSocket.getOutputStream(); + plus.android.importClass(outputStream); + let printStr =jsons; + var bytes = plus.android.invoke(printStr, 'getBytes', 'gbk'); + outputStream.write(bytes); + outputStream.flush(); + device = null //杩欓噷鍏抽敭 + bluetoothSocket.close(); //蹇呴』鍏抽棴钃濈墮杩炴帴鍚﹀垯鎰忓鏂紑鐨勮瘽鎵撳嵃閿欒 + //this.$showMessage('OK'); + console.log("鎵撳嵃鏈鸿繛鎺ョ姸鎬侊細111"); + return true; + } else { + //this.$showMessage('NG'); + console.log("鎵撳嵃鏈鸿繛鎺ョ姸鎬侊細222"); + return false; + } + + }; \ No newline at end of file -- Gitblit v1.9.3