From 7158293d8dbfa226c401dba29ee756a9320504cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=BE=AE=E4=B8=80=E7=AC=91?= <709648985@qq.com> Date: Tue, 24 Mar 2026 15:30:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D100J=E4=BD=8E=E7=94=B5?= =?UTF-8?q?=E9=87=8F=E6=8F=90=E7=A4=BA=E5=8F=AF=E8=83=BD=E9=87=8D=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/100J/HBY100-J.vue | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/pages/100J/HBY100-J.vue b/pages/100J/HBY100-J.vue index c9b7e72..2de22b4 100644 --- a/pages/100J/HBY100-J.vue +++ b/pages/100J/HBY100-J.vue @@ -466,7 +466,6 @@ deviceInfo: {}, } }, - onUnload() {}, onLoad: function() { const eventChannel = this.getOpenerEventChannel(); var these = this; @@ -488,12 +487,12 @@ these.Status.apiType = data.apiType; these.Status.isRightIconVisible = these.Status.apiType === 'listA'; - this.mqttClient = new MqttClient(); + these.mqttClient = new MqttClient(); - this.mqttClient.connect(() => { + these.mqttClient.connect(() => { // 订阅来自设备的状态更新 const statusTopic = `status/894078/HBY100/${data.data.deviceImei}`; - this.mqttClient.subscribe(statusTopic, (payload) => { + these.mqttClient.subscribe(statusTopic, (payload) => { try { // 解析MQTT返回的payload const payloadObj = typeof payload === 'string' ? JSON.parse( @@ -615,8 +614,8 @@ if (these.Status.apiType === 'listA') { these.fetchDeviceDetail(data.data.id) } else { - this.activePermissions = data.data.permission ? data.data.permission.split(',') : []; - console.log(this.activePermissions, 'this.activePermissions'); + these.activePermissions = data.data.permission ? data.data.permission.split(',') : []; + console.log(these.activePermissions, 'activePermissions'); these.fetchDeviceDetail(data.data.deviceId) } // 尝试连接蓝牙:需先扫描获取 BLE deviceId,不能直接用 MAC;延迟 500ms 确保蓝牙适配器就绪 From a7e1809fc8c86a33870ef0de663a65ca29203715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=AE=E5=BE=AE=E4=B8=80=E7=AC=91?= <709648985@qq.com> Date: Tue, 24 Mar 2026 15:47:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?100J=E5=8A=A0=E5=9B=BA=E8=93=9D=E7=89=99?= =?UTF-8?q?=E7=9B=B8=E5=85=B3=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pages/100J/HBY100-J.vue | 68 +++++++++++++++++++++++++++++++++-------- 1 file changed, 56 insertions(+), 12 deletions(-) diff --git a/pages/100J/HBY100-J.vue b/pages/100J/HBY100-J.vue index 2de22b4..69be8db 100644 --- a/pages/100J/HBY100-J.vue +++ b/pages/100J/HBY100-J.vue @@ -48,7 +48,7 @@ 蓝牙名称 {{device.bluetoothName}} - + 蓝牙状态 {{getbleStatu}} @@ -251,7 +251,6 @@ } from '@/api/100J/HBY100-J.js' import BleHelper from '@/utils/BleHelper.js'; var bleTool = BleHelper.getBleTool(); - var these = null; import Common from '@/utils/Common.js' const pagePath = "/pages/100/HBY100"; export default { @@ -627,12 +626,12 @@ }); this.createThrottledFunctions(); - // 注册蓝牙相关事件 + // 注册蓝牙相关事件(必须 bind(this),否则 BleHelper 直接调用回调时 this 丢失,蓝牙状态不更新) bleTool.addReceiveCallback(this.bleValueNotify.bind(this), "HBY100J"); - bleTool.addDisposeCallback(this.bleStateBreak, "HBY100J"); - bleTool.addRecoveryCallback(this.bleStateRecovry, "HBY100J"); - bleTool.addStateBreakCallback(this.bleStateBreak, "HBY100J"); - bleTool.addStateRecoveryCallback(this.bleStateRecovry, "HBY100J"); + bleTool.addDisposeCallback(this.bleStateBreak.bind(this), "HBY100J"); + bleTool.addRecoveryCallback(this.bleStateRecovry.bind(this), "HBY100J"); + bleTool.addStateBreakCallback(this.bleStateBreak.bind(this), "HBY100J"); + bleTool.addStateRecoveryCallback(this.bleStateRecovry.bind(this), "HBY100J"); @@ -652,6 +651,8 @@ }, onShow() { this.Status.pageHide = false; + // 从系统蓝牙开关/后台返回时,与 BleHelper.LinkedList 对齐,避免「蓝牙状态空白/不刷新」 + this.$nextTick(() => this.sync100JBleUiFromHelper()); }, computed: { getbleStatu() { @@ -672,6 +673,32 @@ }, methods: { + /** 与 BleHelper 实际连接状态对齐(系统关蓝牙再开、从后台回前台等) */ + sync100JBleUiFromHelper() { + const mac = (this.device && this.device.deviceMac) || (this.deviceInfo && this.deviceInfo.deviceMac); + if (!mac || !this.deviceInfo.deviceId) return; + const macNorm = (m) => (m || '').replace(/:/g, '').toUpperCase(); + const targetMacNorm = macNorm(mac); + const last6 = targetMacNorm.slice(-6); + const item = bleTool.data.LinkedList.find((v) => { + const m = macNorm(v.macAddress || ''); + return m === targetMacNorm || (m.length >= 6 && m.slice(-6) === last6); + }); + if (!bleTool.data.available) { + this.formData.bleStatu = false; + updateBleStatus(false, '', this.deviceInfo.deviceId); + return; + } + if (item && item.Linked) { + this.formData.bleStatu = true; + updateBleStatus(true, item.deviceId, this.deviceInfo.deviceId); + return; + } + if (this.formData.bleStatu === true || this.formData.bleStatu === 'connecting') { + this.formData.bleStatu = false; + updateBleStatus(false, '', this.deviceInfo.deviceId); + } + }, bleStatuToggle() { let f = bleTool.data.LinkedList.find((v) => { return v.macAddress == this.device.deviceMac; @@ -691,10 +718,11 @@ if (this.formData.bleStatu === false || this.formData.bleStatu === 'err') { this.formData.bleStatu = 'connecting'; - bleTool.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(res => { - these.formData.bleStatu = true; - }).catch(ex => { - these.formData.bleStatu = 'err'; + bleTool.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId).then(() => { + this.formData.bleStatu = true; + this.bleStateRecovry({ deviceId: f.deviceId }); + }).catch(() => { + this.formData.bleStatu = 'err'; }); return; } @@ -1162,7 +1190,22 @@ } }); }, - bleStateBreak() { + _match100JBleItemByRes(res) { + if (!res || !res.deviceId) return true; + const mac = (this.device && this.device.deviceMac) || (this.deviceInfo && this.deviceInfo.deviceMac); + if (!mac) return true; + const macNorm = (m) => (m || '').replace(/:/g, '').toUpperCase(); + const target = macNorm(mac); + const last6 = target.slice(-6); + const item = bleTool.data.LinkedList.find((v) => { + const m = macNorm(v.macAddress || ''); + return v.deviceId === res.deviceId && (m === target || (m.length >= 6 && m.slice(-6) === last6)); + }); + return !!item; + }, + bleStateBreak(res) { + // 仅处理本页 100J 的断开,避免其它型号设备断连误改本页状态 + if (res && res.deviceId && !this._match100JBleItemByRes(res)) return; this.formData.bleStatu = false; updateBleStatus(false, '', this.deviceInfo.deviceId); }, @@ -1176,6 +1219,7 @@ } return; } + if (!this._match100JBleItemByRes(res)) return; let bleDeviceId = res.deviceId; updateBleStatus(true, bleDeviceId, this.deviceInfo.deviceId); // 蓝牙连接成功后主动拉取电源状态、定位(优先蓝牙,设备也会每1分钟主动上报)