From 5079b0796a76b1421df220927df3c7bb2f6de8bb Mon Sep 17 00:00:00 2001 From: weipengfei <2187978347@qq.com> Date: Thu, 27 Jun 2024 18:38:44 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../searchDevices.js | 24 ++++++++++----- pages/index/index.vue | 6 ++-- unpackage/dist/dev/app-plus/app-service.js | 29 ++++++++++++------- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js b/js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js index 180eacc..240c84b 100644 --- a/js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js +++ b/js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js @@ -8,6 +8,8 @@ var device = null, UUID = null, bluetoothSocket = null, num = 0; +var isShow = false; + // 开始gps定位 function getLocationManager(callback) { plus.android.requestPermissions( @@ -289,14 +291,22 @@ function print(mac_address, data, callback) { bluetoothSocket.close(); //必须关闭蓝牙连接否则意外断开的话打印错误 callback(); }, 500) - } else uni.showModal({ - content: '连接打印机失败,是否重试', - success: (res) => { - if (res.confirm) { - print(mac_address, data, callback) + } else { + if(isShow) return; + isShow = true; + uni.showModal({ + content: '连接打印机失败,是否重试', + success: (res) => { + if (res.confirm) { + print(mac_address, data, callback) + } + isShow = false + }, + fail:()=> { + isShow = false } - } - }) + }) + } } // 关闭操作 diff --git a/pages/index/index.vue b/pages/index/index.vue index c606719..77c46f2 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -12,8 +12,8 @@ const vw = ref(null); // web-view // const src = ref("https://erp-cashier.lihaink.cn/#/login"); - // const src = ref("http://192.168.1.55:5181/#/"); - const src = ref("http://cashier-multi-store.lihaink.cn/#/"); + const src = ref("http://192.168.1.55:5181/#/"); + // const src = ref("http://cashier-multi-store.lihaink.cn/#/"); onLoad(() => { @@ -125,6 +125,7 @@ } console.log('连接成功',e); uni.setStorageSync('deviceId', e.address); + vw.value.evalJS(`receiveData('${JSON.stringify(obj)}')`); }) } @@ -139,5 +140,4 @@ \ No newline at end of file diff --git a/unpackage/dist/dev/app-plus/app-service.js b/unpackage/dist/dev/app-plus/app-service.js index 58d6328..ae47153 100644 --- a/unpackage/dist/dev/app-plus/app-service.js +++ b/unpackage/dist/dev/app-plus/app-service.js @@ -53,6 +53,7 @@ if (uni.restoreGlobal) { const onReady = /* @__PURE__ */ createHook(ON_READY); var BleDevice; var device = null, BAdapter = null, BluetoothAdapter = null, uuid = null, UUID = null, bluetoothSocket = null; + var isShow = false; function getLocationManager(callback) { plus.android.requestPermissions( ["android.permission.ACCESS_FINE_LOCATION"], @@ -102,7 +103,7 @@ if (uni.restoreGlobal) { main.startActivity(intent); } else { startBluetoothDiscovery(callback); - formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:66", "定位已开启"); + formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:68", "定位已开启"); } } }); @@ -119,12 +120,12 @@ if (uni.restoreGlobal) { callback(); }, fail: function(e2) { - formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:88", "失败2"); + formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:90", "失败2"); } }); }, fail: function(e) { - formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:92", "open failed: " + JSON.stringify(e)); + formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:94", "open failed: " + JSON.stringify(e)); } }); } @@ -142,7 +143,7 @@ if (uni.restoreGlobal) { }); return; } - formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:113", "开始搜索设备"); + formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:115", "开始搜索设备"); var filter = new IntentFilter(); var bdevice = new BluetoothDevice(); var on = null; @@ -166,7 +167,7 @@ if (uni.restoreGlobal) { BleDevice = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE); const name = BleDevice.getName(); const n_address = BleDevice.getAddress(); - formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:138", "====<<<", name, n_address); + formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:140", "====<<<", name, n_address); if (BleDevice.getBondState() === bdevice.BOND_NONE && name == "T58") { if (address === BleDevice.getAddress()) { if (BleDevice.createBond()) { @@ -232,10 +233,10 @@ if (uni.restoreGlobal) { } setTimeout(() => { if (bluetoothSocket.isConnected()) { - formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:220", "已连接=====", mac_address); + formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:222", "已连接=====", mac_address); callback(true); } else { - formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:224", "未连接", mac_address); + formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:226", "未连接", mac_address); callback(false); } bluetoothSocket.close(); @@ -259,7 +260,7 @@ if (uni.restoreGlobal) { plus.android.importClass(device); bluetoothSocket = device.createInsecureRfcommSocketToServiceRecord(uuid); plus.android.importClass(bluetoothSocket); - formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:253", "蓝牙", bluetoothSocket.isConnected()); + formatAppLog("log", "at js_sdk/wangqingzhou311-android-blueTooth/searchDevices.js:255", "蓝牙", bluetoothSocket.isConnected()); if (!bluetoothSocket.isConnected()) { uni.showToast({ title: "正在打印小票, 请耐心等待", @@ -281,15 +282,23 @@ if (uni.restoreGlobal) { bluetoothSocket.close(); callback(); }, 500); - } else + } else { + if (isShow) + return; + isShow = true; uni.showModal({ content: "连接打印机失败,是否重试", success: (res) => { if (res.confirm) { print(mac_address, data, callback); } + isShow = false; + }, + fail: () => { + isShow = false; } }); + } } const _export_sfc = (sfc, props) => { const target = sfc.__vccOpts || sfc; @@ -302,7 +311,7 @@ if (uni.restoreGlobal) { __name: "index", setup(__props) { const vw = vue.ref(null); - const src = vue.ref("http://cashier-multi-store.lihaink.cn/#/"); + const src = vue.ref("http://192.168.1.55:5181/#/"); onLoad(() => { plus.navigator.setFullscreen(true); getLocationManager(() => {