From 84feb9f1e821acf382de93a57eb5264dfc89f630 Mon Sep 17 00:00:00 2001 From: liub Date: Thu, 19 Mar 2026 14:37:58 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.vue | 8 +- pages/6155/BJQ6155.vue | 2 +- pages/common/addBLE/LinkBle.vue | 31 +++- pages/common/addBLE/addEquip.vue | 240 +++++++++++++------------------ pages/common/index/index.vue | 4 +- utils/BleHelper.js | 24 ++-- utils/BleReceive.js | 3 +- 7 files changed, 150 insertions(+), 162 deletions(-) diff --git a/App.vue b/App.vue index f9538fe..9e90f0f 100644 --- a/App.vue +++ b/App.vue @@ -27,7 +27,7 @@ // uni.removeStorageSync(val); // } // }); - uni.clearStorageSync(); + // uni.clearStorageSync(); //以上代码仅在开发时使用,否则会出现不可预知的问题。 // #ifdef APP|APP-PLUS @@ -93,8 +93,10 @@ // #ifdef APP|APP-PLUS let ble = bleTool.getBleTool(); if (ble) { - console.log("断开所有蓝牙设备"); - ble.disconnectDevice(); + console.log("App隐藏了,断开所有蓝牙设备,停止搜索"); + ble.StopSearch().catch(ex=>{}); + ble.disconnectDevice().catch(ex=>{}); + } // #endif }, diff --git a/pages/6155/BJQ6155.vue b/pages/6155/BJQ6155.vue index 6c788e6..bb4b850 100644 --- a/pages/6155/BJQ6155.vue +++ b/pages/6155/BJQ6155.vue @@ -385,7 +385,7 @@ } let f = ble.data.LinkedList.find((v) => { if (v.macAddress == device.deviceMac) { - console.log("找到设备了", v); + // console.log("找到设备了", v); these.formData.deviceId = v.deviceId; return true; } diff --git a/pages/common/addBLE/LinkBle.vue b/pages/common/addBLE/LinkBle.vue index ca79c68..c882392 100644 --- a/pages/common/addBLE/LinkBle.vue +++ b/pages/common/addBLE/LinkBle.vue @@ -53,7 +53,9 @@ Statu: { bound: null, timeInteval: null, - isSearch: false + isSearch: false, + pageHide:false, + isBind:false }, device: { "deviceId": "", @@ -115,17 +117,32 @@ return ""; } }, - + onShow() { + this.Statu.pageHide=false; + }, + onHide() { + this.Statu.pageHide=true; + }, onUnload() { console.log("返回取消订阅"); clearInterval(inteval); ble.removeAllCallback(pagePath); + + if(!this.Statu.isBind && these.device.deviceId){ + ble.disconnectDevice(these.device.deviceId).catch(ex=>{ + console.error("无法断开蓝牙连接"); + }); + } }, + onLoad(option) { these = this; ble = bleTool.getBleTool(); ble.addStateBreakCallback(res => { + if(this.Statu.pageHide){ + return; + } these.device.linkStatu = false; hideLoading(these); uni.showToast({ @@ -135,6 +152,9 @@ },pagePath); ble.addStateRecoveryCallback(res => { + if(this.Statu.pageHide){ + return; + } if (these.device.deviceId) { showLoading(these, { text: '蓝牙已恢复正在连接设备' @@ -144,6 +164,9 @@ } },pagePath); ble.addDisposeCallback(res => { + if(this.Statu.pageHide){ + return; + } console.log("处理蓝牙断开连接"); these.device.linkStatu = false; if (these.device.deviceId == res.deviceId) { @@ -156,6 +179,9 @@ },pagePath); ble.addReceiveCallback((receive, f, path) => { + if(this.Statu.pageHide){ + return; + } console.log("收到设备消息,", receive); if (these.device.deviceId == receive.deviceId) { console.log("11111:", receive); @@ -372,6 +398,7 @@ clearTimeout(this.Statu.timeInteval); this.device.macAddress = null; this.Statu.timeInteval = null; + this.Statu.isBind=true; uni.$emit("refreshDeviceList"); setTimeout(() => { uni.switchTab({ diff --git a/pages/common/addBLE/addEquip.vue b/pages/common/addBLE/addEquip.vue index 5606d56..0ecfda4 100644 --- a/pages/common/addBLE/addEquip.vue +++ b/pages/common/addBLE/addEquip.vue @@ -23,6 +23,7 @@ 配对设备 + @@ -33,9 +34,7 @@ - - 信号:{{item.RSSI}}dBm - + @@ -134,6 +133,7 @@ data() { return { Status: { + navigateTO: false, isPageHidden: false, intval: null, time: null, @@ -164,12 +164,14 @@ }, search: '', //筛选 - PairEquip: [], //已配对设备 + PairEquip: [], //本次已配对设备 EquipMents: [], //搜索出来的设备 device: null, item: { deviceId: '' - } + }, + + } }, computed: { @@ -189,9 +191,20 @@ if (ble) { ble.StopSearch(); ble.removeAllCallback(pagePath); + if (!this.device && !this.Status.navigateTO) { + if (this.PairEquip && this.PairEquip.length && this.PairEquip.length > 0) { + console.error("页面卸载时,断开所有连接") + let f = this.PairEquip.forEach((v) => { + ble.disconnectDevice(v.deviceId).catch(ex => { + console.error("无法断开设备连接", ex); + }); + }); + } + } } }, onLoad(option) { + debugger; eventChannel = this.getOpenerEventChannel(); eventChannel.on('detailData', function(rec) { @@ -211,8 +224,8 @@ const systemInfo = uni.getSystemInfoSync(); - ble = bleTool.getBleTool(); // Ensure ble is initialized - + // Ensure ble is initialized + if (systemInfo.uniPlatform == 'web') { @@ -236,86 +249,19 @@ "name": "EF4651", "linkStatu": false, "isTarget": true - }, - { - "RSSI": -69, - "advertisData": "", - "advertisServiceUUIDs": [ - "0000FFE0-0000-1000-8000-00805F9B34FB" - ], - "deviceId": "4F0DAC91-4391-CB07-905E-72D7F03EFCD3", - "name": "4877-BF743D", - "linkStatu": false - }, - { - "RSSI": -55, - "advertisData": "", - "advertisServiceUUIDs": [ - "0000FFE0-0000-1000-8000-00805F9B34FB" - ], - "deviceId": "EBDA4E6F-3A28-FF65-A845-AE8CC7B78375", - "name": "HBY670-BF74EA", - "linkStatu": false - }, - { - "RSSI": -61, - "advertisData": "", - "advertisServiceUUIDs": [ - "0000FFE0-0000-1000-8000-00805F9B34FB" - ], - "deviceId": "469FB381-B47E-1E40-8073-EF50B5704AAB", - "name": "EF4651", - "linkStatu": false, - "isTarget": true - }, - { - "RSSI": -69, - "advertisData": "", - "advertisServiceUUIDs": [ - "0000FFE0-0000-1000-8000-00805F9B34FB" - ], - "deviceId": "4F0DAC91-4391-CB07-905E-72D7F03EFCD3", - "name": "4877-BF743D", - "linkStatu": false - }, { - "RSSI": -55, - "advertisData": "", - "advertisServiceUUIDs": [ - "0000FFE0-0000-1000-8000-00805F9B34FB" - ], - "deviceId": "EBDA4E6F-3A28-FF65-A845-AE8CC7B78375", - "name": "HBY670-BF74EA", - "linkStatu": false - }, - { - "RSSI": -61, - "advertisData": "", - "advertisServiceUUIDs": [ - "0000FFE0-0000-1000-8000-00805F9B34FB" - ], - "deviceId": "469FB381-B47E-1E40-8073-EF50B5704AAB", - "name": "EF4651", - "linkStatu": false, - "isTarget": true - }, - { - "RSSI": -69, - "advertisData": "", - "advertisServiceUUIDs": [ - "0000FFE0-0000-1000-8000-00805F9B34FB" - ], - "deviceId": "4F0DAC91-4391-CB07-905E-72D7F03EFCD3", - "name": "4877-BF743D", - "linkStatu": false } ]; - - these.PairEquip = [this.EquipMents[0]]; - this.$forceUpdate(); + console.error("1111111111") + this.PairEquip=[this.EquipMents[0]]; + return; } + ble = bleTool.getBleTool(); + this.refreshLinked(); + let StartSubsrib = () => { + these.EquipMents = []; if (!ble) { ble = bleTool.getBleTool(); @@ -327,6 +273,7 @@ } console.log("处理蓝牙不可用"); hideLoading(these); + console.error("1111111111") these.PairEquip = []; these.EquipMents = []; uni.showToast({ @@ -336,13 +283,14 @@ these.showOpenSetting(); }, pagePath); - + //蓝牙恢复可用的回调 - ble.addStateRecoveryCallback(res=>{ + ble.addStateRecoveryCallback(res => { if (these.Status.isPageHidden) { return; } these.Status.BottomMenu.show = false; + console.error("1111111111") these.PairEquip = []; these.EquipMents = []; uni.showToast({ @@ -350,7 +298,7 @@ title: '蓝牙恢复可用' }); these.refreshBleList(); - }),pagePath; + }), pagePath; //蓝牙断开连接的回调 ble.addDisposeCallback(res => { @@ -360,10 +308,7 @@ // console.log("处理蓝牙断开连接"); - these.PairEquip.find(function(v, ind) { - these.PairEquip.splice(ind, 1); - return v.deviceId == res.deviceId; - }); + these.refreshLinked(); setTimeout(() => { hideLoading(these); @@ -422,39 +367,37 @@ these.EquipMents.sort((a, b) => b.RSSI - a.RSSI); //信号好的排前面,一般信号好的是目标设备 } }, pagePath); + + //蓝牙连接已恢复的回调 + ble.addRecoveryCallback(res => { + if (these.Status.isPageHidden) { + return; + } + these.refreshLinked(); + + // hideLoading(these); + + if (these.device) { + clearInterval(this.Status.intval); + showLoading(these, { + text: '蓝牙连接已恢复,正在验证设备' + }); + + setTimeout(() => { + these.DeviceVerdict(res.deviceId); + }, 0); + } else { + hideLoading(these); + } + + + }, pagePath); } let startValidDevice = () => { if (these.device) { console.log("进入配对模式,启用连接恢复和验证逻辑。"); - //蓝牙连接已恢复的回调 - ble.addRecoveryCallback(res => { - if (these.Status.isPageHidden) { - return; - } - // hideLoading(these); - these.EquipMents.find(function(v, ind) { - if (v.deviceId == res.deviceId) { - these.PairEquip.push(v); - return true; - } - return false; - }); - if (these.device) { - clearInterval(this.Status.intval); - showLoading(these, { - text: '蓝牙连接已恢复,正在验证设备' - }); - - setTimeout(() => { - these.DeviceVerdict(res.deviceId); - }, 0); - } else { - hideLoading(these); - } - - - }, pagePath); + //收到设备的消息回调 ble.addReceiveCallback((receivData, f, path, arr) => { @@ -488,15 +431,33 @@ StartSubsrib(); + }, onShow: function() { + debugger; this.Status.isPageHidden = false; + this.Status.navigateTO = false; this.refreshBleList(); + this.refreshLinked(); }, methods: { + refreshLinked(){ + + + + if(ble){ + let arr=[]; + arr=ble.data.LinkedList.filter(v=>{ + return v.Linked; + }); + this.PairEquip=arr; + } + + + }, checkAndRequestLocationPermission() { return new Promise((resolve) => { @@ -515,16 +476,21 @@ resolve(true); } else { // console.warn('定位权限被拒绝'); - + MsgClear(these); - showPop({headerTxt:'权限提醒',message:'扫描蓝牙设备,需要您开启定位权限',buttonText:'去开启',okCallback:uni.openSetting},these,true); - + showPop({ + headerTxt: '权限提醒', + message: '扫描蓝牙设备,需要您开启定位权限', + buttonText: '去开启', + okCallback: uni.openSetting + }, these, true); + resolve(false); } }, (error) => { - - MsgError('请求定位权限失败:'+error.code,'确定',these); + + MsgError('请求定位权限失败:' + error.code, '确定', these); resolve(false); } ); @@ -565,19 +531,20 @@ time = setTimeout(() => { these.EquipMents = []; + console.error("1111111111") these.PairEquip = []; ble.StartSearch().then(result => { - console.log("开始搜索成功", result); + // console.log("开始搜索成功", result); }).catch(err => { console.error("开始搜索失败:", err); if (err.code === 10001) { these.showOpenSetting(); } else { - + MsgClear(these); - MsgError('出现错误:' + err.msg,'确定',these); + MsgError('出现错误:' + err.msg, '确定', these); } }).finally(() => { @@ -587,8 +554,8 @@ } - ble.StopSearch().catch(err=>{ - console.error("err=",err); + ble.StopSearch().catch(err => { + console.error("err=", err); }).finally(startSearch); @@ -741,10 +708,10 @@ return; } - updateLoading(these, { - text: "等待设备上报Mac地址," + these.Status.time + 's' - }); + hideLoading(these); + }, 1000); + return undefined; } } @@ -760,14 +727,7 @@ let index = 1; let total = 5; - let linkCallback = (res) => { - let c = these.PairEquip.find(function(v) { - return v.deviceId == item.deviceId; - }); - if (!c) { - - these.PairEquip.push(item); - } + let linkCallback = (res) => { console.log("连接成功", these.device); if (!these.device) { console.log("跳转到绑定") @@ -778,7 +738,7 @@ }, success(res) { - + these.Status.navigateTO = true; res.eventChannel.emit('LinkItem', item); } }); @@ -825,8 +785,8 @@ }).catch(ex => { console.error("ex=", ex) MsgClear(these); - - MsgError("连接失败:" + ex.msg,'确定',these); + + MsgError("连接失败:" + ex.msg, '确定', these); hideLoading(these); }); diff --git a/pages/common/index/index.vue b/pages/common/index/index.vue index d384bde..a734c0d 100644 --- a/pages/common/index/index.vue +++ b/pages/common/index/index.vue @@ -304,14 +304,14 @@ }, bleBreak(res) { - console.error("蓝牙断开连接", res); + // console.error("蓝牙断开连接", res); if (res.deviceId) { this.updateBleStatu(res.deviceId); } }, bleRecovery(res) { - console.log("蓝牙连接成功", res); + // console.log("蓝牙连接成功", res); if (res.deviceId) { this.updateBleStatu(res.deviceId); } diff --git a/utils/BleHelper.js b/utils/BleHelper.js index 3b9d05c..a9b894b 100644 --- a/utils/BleHelper.js +++ b/utils/BleHelper.js @@ -36,7 +36,7 @@ class BleHelper { linkedDevices = uni.getStorageSync(this.StorageKey); } if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) { - console.log("111111", linkedDevices); + // console.log("111111", linkedDevices); linkedDevices = linkedDevices.filter((v) => { if (v) { v.Linked = false; @@ -613,13 +613,13 @@ class BleHelper { if (this.data.isSubscribe) { //整个App生命周期,只订阅一次 return; } - console.error("开始订阅各类变化消息"); + // console.error("开始订阅各类变化消息"); this.data.isSubscribe = true; this.BleStateChange(); //蓝牙适配器变化 this.BleConnChange(); //蓝牙连接变化 this.BleDeviceFound(); //发现新设备 this.BleReceive(); //收到消息 - console.error("订阅各类变化消息完成"); + // console.error("订阅各类变化消息完成"); }, fail: (ex2) => { console.error("蓝牙模块启动失败", ex2); @@ -962,7 +962,7 @@ class BleHelper { } } else { - console.log("蓝牙连接已恢复", res); + // console.log("蓝牙连接已恢复", res); // 系统级连接恢复:更新 LinkedList 并通知业务层,避免 sendData 误判未连接而重复 createBLEConnection let f = this.data.LinkedList.find(v => v.deviceId == res.deviceId); if (f) { @@ -1098,7 +1098,7 @@ class BleHelper { services: [], allowDuplicatesKey: true, success: (res) => { - console.log('开始搜索蓝牙设备成功'); + // console.log('开始搜索蓝牙设备成功'); resolve(res); }, @@ -1237,11 +1237,11 @@ class BleHelper { characteristicId: characteristicId, state: state, success: (res) => { - if (state) { - console.log("订阅消息成功", res); - } else { - console.log("取消订阅成功", res); - } + // if (state) { + // console.log("订阅消息成功", res); + // } else { + // console.log("取消订阅成功", res); + // } this.data.LinkedList.find((v) => { if (v.deviceId == deviceId) { @@ -1311,13 +1311,13 @@ class BleHelper { results.forEach((result, index) => { if (result.status === "fulfilled") { - console.log(`订阅消息操作${index + 1}成功:`, result.value); + // console.log(`订阅消息操作${index + 1}成功:`, result.value); } else { console.error(`订阅消息操作${index + 1}失败:`, result .reason); } }); - console.log("订阅消息完成,deviceId:", deviceId); + // console.log("订阅消息完成,deviceId:", deviceId); resolve(); }).catch((ex) => { console.error("异常,ex=", ex); diff --git a/utils/BleReceive.js b/utils/BleReceive.js index aee9c28..4793bb0 100644 --- a/utils/BleReceive.js +++ b/utils/BleReceive.js @@ -14,8 +14,7 @@ class BleReceive { '/pages/100/HBY100': this.Receive_100.bind(this), '/pages/102/HBY102': this.Receive_102.bind(this), '/pages/6170/deviceControl/index':this.Receive_6170.bind(this), - '/pages/100J/HBY100-J': this.Receive_100J.bind(this), - '/pages/102/HBY102': this.Receive_102.bind(this) + '/pages/100J/HBY100-J': this.Receive_100J.bind(this) }; } -- 2.43.5 From 1fcaf8a9a4e772ef221d73065592f6c6442dc3b9 Mon Sep 17 00:00:00 2001 From: liub Date: Thu, 19 Mar 2026 17:25:41 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E4=BD=93=E9=AA=8C=E6=80=A7=E5=B0=8F?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.json | 2 +- pages/100/HBY100.vue | 22 +++++++++++++++------- pages/6155/BJQ6155.vue | 13 ++++++++----- pages/7305/BJQ7305.vue | 6 +++++- pages/common/addBLE/addEquip.vue | 27 ++++++++++++--------------- 5 files changed, 41 insertions(+), 29 deletions(-) diff --git a/manifest.json b/manifest.json index a4ca526..f4b7d3c 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "name" : "星汉物联", "appid" : "__UNI__A21EF43", "description" : "设备管控", - "versionName" : "1.0.22", + "versionName" : "1.0.24", "versionCode" : 101, "transformPx" : false, /* 5+App特有相关 */ diff --git a/pages/100/HBY100.vue b/pages/100/HBY100.vue index d1c6fd3..6b11d7e 100644 --- a/pages/100/HBY100.vue +++ b/pages/100/HBY100.vue @@ -194,7 +194,7 @@ + @change="onBrightnessChanged" @changing="onBrightnessChanging" class="custom-slider" /> @@ -206,7 +206,7 @@ + @change="onFreqChanged" @changing="onFreqChanging" class="custom-slider" /> @@ -218,7 +218,7 @@ + @change="onVolumeChanged" @changing="onVolumeChanging" class="custom-slider" /> @@ -850,9 +850,11 @@ }); }, - +onFreqChanging(e){ + this.formData.sta_LightFreq = e.detail.value; +}, //频率 - onFreqChanging(e) { + onFreqChanged(e) { let f = this.getDevice(); // #ifdef APP-PLUS if (!f) { @@ -897,8 +899,11 @@ }, 100); }, + onVolumeChanging(e){ + this.formData.sta_VoiceVolume = e.detail.value; + }, //音量 - onVolumeChanging(e) { + onVolumeChanged(e) { let f = this.getDevice(); // #ifdef APP-PLUS if (!f) { @@ -938,8 +943,11 @@ }, 100); }, + onBrightnessChanging(e){ + this.formData.sta_LightDimmer = e.detail.value; + }, // 亮度调节 - onBrightnessChanging(e) { + onBrightnessChanged(e) { let f = this.getDevice(); // #ifdef APP-PLUS if (!f) { diff --git a/pages/6155/BJQ6155.vue b/pages/6155/BJQ6155.vue index bb4b850..eb8d161 100644 --- a/pages/6155/BJQ6155.vue +++ b/pages/6155/BJQ6155.vue @@ -74,7 +74,7 @@ @@ -1784,6 +1784,9 @@ }); }, + sliderChanging(evt){ + this.formData.liangDu = evt.detail.value; + }, sliderChange: function(evt) { if (!this.permissions.includes('1') && this.Status.apiType !== 'listA') { @@ -1834,10 +1837,10 @@ dataView.setUint8(0, 0x55); // 帧头 dataView.setUint8(1, 0x07); // 帧类型:亮度调节 - dataView.setUint8(2, 0x01); // 包序号 - dataView.setUint8(3, 0x00); // 包序号 - dataView.setUint8(4, 0x01); // 数据长度 - dataView.setUint8(5, liangDu); // 数据长度 + dataView.setUint8(2, 0x01); + dataView.setUint8(3, 0x00); + dataView.setUint8(4, 0x01); // + dataView.setUint8(5, liangDu); // 数据 let f = this.getDevice(); if (f) { diff --git a/pages/7305/BJQ7305.vue b/pages/7305/BJQ7305.vue index 6c4481c..0fe2112 100644 --- a/pages/7305/BJQ7305.vue +++ b/pages/7305/BJQ7305.vue @@ -74,7 +74,7 @@ + @changing="sliderChanging" class="custom-slider" /> @@ -1394,6 +1394,10 @@ debugger; }); }, + sliderChanging(evt){ + this.formData.liangDu = evt.detail.value; + }, + sliderChange: function(evt) { this.formData.liangDu = evt.detail.value; clearTimeout(BrighInteval) diff --git a/pages/common/addBLE/addEquip.vue b/pages/common/addBLE/addEquip.vue index 37b2b8b..ac06bba 100644 --- a/pages/common/addBLE/addEquip.vue +++ b/pages/common/addBLE/addEquip.vue @@ -378,17 +378,11 @@ // hideLoading(these); - if (these.device) { - clearInterval(this.Status.intval); - showLoading(these, { - text: '蓝牙连接已恢复,正在验证设备' - }); - - setTimeout(() => { - these.DeviceVerdict(res.deviceId); - }, 0); - } else { + if (!these.device) { hideLoading(these); + }else{ + clearInterval(this.Status.intval); + these.DeviceVerdict(res.deviceId); } @@ -420,7 +414,7 @@ showLoading(these, { text: '正在验证设备' }); - + setTimeout(() => { these.DeviceVerdict(f.deviceId); }, 0); @@ -690,6 +684,7 @@ this.Status.intval = setInterval(() => { this.Status.time = this.Status.time - 1; if (this.Status.time < 0) { + hideLoading(these); console.log("停止倒计时", this.Status.time); clearInterval(this.Status.intval) this.Status.intval = null; @@ -708,7 +703,10 @@ return; } - hideLoading(these); + updateLoading(these, { + + text: "等待设备上报Mac地址," + these.Status.time + 's' + }); }, 1000); @@ -744,8 +742,7 @@ }); return; } - // console.log("验证设备") - these.DeviceVerdict(item.deviceId); + } let execLink = () => { return new Promise((resolve, reject) => { @@ -993,7 +990,7 @@ box-sizing: border-box; padding: 20rpx; border-radius: 8px; - background: #1a1a1a; + background: #1a1a1a9e; display: flex; flex-direction: row; flex-wrap: nowrap; -- 2.43.5 From c286660a10f3875ad88badad7107914b2ca0dcd3 Mon Sep 17 00:00:00 2001 From: liub Date: Tue, 24 Mar 2026 12:00:27 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E4=BF=AE=E5=A4=8D102=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=8A=A0=E5=87=8F=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- manifest.json | 3 +- pages/100J/HBY100-J.vue | 105 ++++++++++++++++++++++++++----- pages/102/HBY102.vue | 119 ++++++++++++++++++++++++++++++++--- pages/102/HBY102_History.vue | 39 +++++++----- pages/6155/BJQ6155.vue | 2 +- utils/BleHelper.js | 12 ++-- utils/Common.js | 2 +- 7 files changed, 234 insertions(+), 48 deletions(-) diff --git a/manifest.json b/manifest.json index f4b7d3c..7c5ff47 100644 --- a/manifest.json +++ b/manifest.json @@ -56,7 +56,8 @@ "", "", "", - "" + "", + "" ], "minSdkVersion" : 21, "abiFilters" : [ "armeabi-v7a", "arm64-v8a", "x86" ], diff --git a/pages/100J/HBY100-J.vue b/pages/100J/HBY100-J.vue index 518460e..c9b7e72 100644 --- a/pages/100J/HBY100-J.vue +++ b/pages/100J/HBY100-J.vue @@ -50,7 +50,8 @@ 蓝牙状态 - {{device.getbleStatu}} + {{getbleStatu}} 设备状态 @@ -469,6 +470,17 @@ onLoad: function() { const eventChannel = this.getOpenerEventChannel(); var these = this; + + this.$watch("deviceInfo.batteryPercentage", (newVal, oldVal) => { + if (newVal <= 20) { + uni.showToast({ + title: '设备电量低', + icon: 'none', + duration: 2000 + }); + } + + }); eventChannel.on('detailData', function(data) { var device = data.data; these.device = device; @@ -609,7 +621,9 @@ } // 尝试连接蓝牙:需先扫描获取 BLE deviceId,不能直接用 MAC;延迟 500ms 确保蓝牙适配器就绪 if (data.data.deviceMac) { - setTimeout(() => { these.tryConnect100JBle(data.data.deviceMac); }, 500); + setTimeout(() => { + these.tryConnect100JBle(data.data.deviceMac); + }, 500); } }); this.createThrottledFunctions(); @@ -641,10 +655,53 @@ this.Status.pageHide = false; }, computed: { - + getbleStatu() { + if (this.formData.bleStatu === true) { + return '已连接'; + } + if (this.formData.bleStatu === 'connecting') { + return '连接中'; + } + if (this.formData.bleStatu === 'dicconnect') { + return '正在断开'; + } + if (this.formData.bleStatu === 'err') { + return '连接异常'; + } + return '未连接'; + } }, methods: { + bleStatuToggle() { + let f = bleTool.data.LinkedList.find((v) => { + return v.macAddress == this.device.deviceMac; + }); + + if (!f) { + this.tryConnect100JBle(this.device.deviceMac); + return; + } + if (this.formData.bleStatu === true) { + this.formData.bleStatu = 'dicconnect'; + bleTool.disconnectDevice(f.deviceId).finally(r => { + this.formData.bleStatu = false; + }); + return; + } + + 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'; + }); + return; + } + + + }, createThrottledFunctions() { // 创建节流函数 this.throttledBrightnessChange = this.throttle(this.handleBrightnessChange, 500); @@ -1014,20 +1071,31 @@ const NOTIFY = '0000AE02-0000-1000-8000-00805F9B34FB'; if (cached && cached.deviceId) { console.log('[100J] 使用缓存设备连接', cached.deviceId); + that.formData.bleStatu = 'connecting'; bleTool.LinkBlue(cached.deviceId, SVC, WRITE, NOTIFY, 2).then(() => { console.log('100J 蓝牙连接成功(缓存)'); - that.bleStateRecovry({ deviceId: cached.deviceId }); + that.formData.bleStatu = true; + that.bleStateRecovry({ + deviceId: cached.deviceId + }); }).catch(err => { console.log('100J 蓝牙连接失败(缓存),尝试扫描', err); + that.formData.bleStatu = 'err'; that.connect100JByScan(deviceMac, last6); }); return; } // 2. 无缓存:先尝试直连。Android 上 deviceId 多为 MAC 反序(11:22:33:44:55:02->02:55:44:33:22:11) + that.formData.bleStatu = 'connecting'; const tryDirect = (id) => bleTool.LinkBlue(id, SVC, WRITE, NOTIFY, 2).then(() => { console.log('100J 蓝牙连接成功(直连)', id); - that.bleStateRecovry({ deviceId: id }); + that.formData.bleStatu = true; + that.bleStateRecovry({ + deviceId: id + }); + }).catch(ex => { + that.formData.bleStatu = 'err'; }); const deviceIdReversed = macToDeviceId(deviceMac); console.log('[100J] 尝试直连', deviceIdReversed, '(MAC反序)'); @@ -1070,11 +1138,16 @@ bleTool.StopSearch(); bleTool.removeDeviceFound('HBY100J_SCAN'); console.log('[100J] 扫描到目标设备', match.name, match.deviceId); + that.formData.bleStatu = 'connecting'; bleTool.LinkBlue(match.deviceId, SVC, WRITE, NOTIFY, 2).then(() => { console.log('100J 蓝牙连接成功(扫描)'); - that.bleStateRecovry({ deviceId: match.deviceId }); + that.formData.bleStatu = true; + that.bleStateRecovry({ + deviceId: match.deviceId + }); }).catch(err => { console.log('100J 蓝牙连接失败,将使用4G', err); + that.formData.bleStatu = 'err'; }); } }, 'HBY100J_SCAN'); @@ -1091,6 +1164,7 @@ }); }, bleStateBreak() { + this.formData.bleStatu = false; updateBleStatus(false, '', this.deviceInfo.deviceId); }, bleStateRecovry(res) { @@ -1115,7 +1189,8 @@ previewImg(img) {}, bleValueNotify: function(receive, device, path, recArr) { //订阅消息 // 仅处理当前设备的数据(device 为 LinkedList 中匹配 receive.deviceId 的项) - if (device && device.device && this.deviceInfo.deviceId && device.device.id != this.deviceInfo.deviceId) return; + if (device && device.device && this.deviceInfo.deviceId && device.device.id != this.deviceInfo + .deviceId) return; // 解析蓝牙上报数据 (协议: FC=MAC主动上报, FB=指令响应) if (!receive.bytes || receive.bytes.length < 3) return; const parsedData = parseBleData(receive.bytes); @@ -1144,9 +1219,7 @@ this.$set(this.deviceInfo, 'batteryRemainingTime', parsedData.batteryRemainingTime); } - if (this.deviceInfo.batteryPercentage <= 20) { - uni.showToast({ title: '设备电量低', icon: 'none', duration: 2000 }); - } + // 设备物理按键切换:蓝牙响应同步到 APP 页面(与 4G MQTT 逻辑一致) const fc = parsedData.funcCode; @@ -1191,13 +1264,17 @@ else if (this.formData.sta_VoiceType === '7') this.formData.sta_VoiceType = '-1'; } if (parsedData.volume !== undefined) this.formData.volume = parsedData.volume; - if (parsedData.strobeFrequency !== undefined) this.formData.strobeFrequency = parsedData.strobeFrequency; - if (parsedData.redBrightness !== undefined) this.formData.lightBrightness = parsedData.redBrightness; + if (parsedData.strobeFrequency !== undefined) this.formData.strobeFrequency = parsedData + .strobeFrequency; + if (parsedData.redBrightness !== undefined) this.formData.lightBrightness = parsedData + .redBrightness; } // 0x09 音量、0x0D 亮度:单独响应时同步 if (fc === 0x09 && parsedData.volume !== undefined) this.formData.volume = parsedData.volume; - if (fc === 0x0B && parsedData.strobeFrequency !== undefined) this.formData.strobeFrequency = parsedData.strobeFrequency; - if (fc === 0x0D && parsedData.redBrightness !== undefined) this.formData.lightBrightness = parsedData.redBrightness; + if (fc === 0x0B && parsedData.strobeFrequency !== undefined) this.formData.strobeFrequency = parsedData + .strobeFrequency; + if (fc === 0x0D && parsedData.redBrightness !== undefined) this.formData.lightBrightness = parsedData + .redBrightness; }, showBleUnConnect() {}, diff --git a/pages/102/HBY102.vue b/pages/102/HBY102.vue index 4f74e42..d7c368e 100644 --- a/pages/102/HBY102.vue +++ b/pages/102/HBY102.vue @@ -60,12 +60,12 @@ 蓝牙状态 - {{getbleStatu}} + {{getbleStatu}} + + + 信道:{{formData.sta_Channel}} + 修改 - @@ -177,7 +177,14 @@ :iconUrl="Status.Pop.iconUrl" :message="Status.Pop.message" :buttonText="Status.Pop.buttonText" @buttonClick="HidePop" :visiblePrompt="Status.Pop.visiblePrompt" :promptTitle="Status.Pop.promptTitle" v-model="Status.Pop.modelValue" @closePop="closePop" :buttonCancelText="Status.Pop.buttonCancelText" - :showCancel="Status.Pop.showCancel" @cancelPop="closePop" /> + :showCancel="Status.Pop.showCancel" @cancelPop="closePop" :showSlot="Status.Pop.showSlot"> + + 修改信道 + + + + @@ -221,6 +228,7 @@ curr: 0, total: 0, pageHide: false, + ShowEditChannel: false, Pop: { showPop: false, //是否显示弹窗 popType: 'custom', @@ -325,8 +333,8 @@ warnTime: '', sta_sosadd: "", sta_sosName: '', - sta_IntrusTime: '' - + sta_IntrusTime: '', + ins_Channel:23 }, dic: { sta_LightType: [ @@ -519,7 +527,7 @@ }); } - this.getLinkedCnt(); + // this.getLinkedCnt(); }, computed: { Distance: function() { @@ -561,6 +569,73 @@ } }, methods: { + onChannelChanging() { + + let f = this.getDevice(); + // #ifdef APP-PLUS + if (!f) { + this.showBleUnConnect(); + return; + } + // #endif + + let regex = /^([1-9]|[1-7][0-9]|80)$/; + if (!regex.test(this.formData.ins_Channel)) { + uni.showModal({ + title: '提示', + content: '只能输入1-80整数' + }); + return; + } + var buffer = { + ins_Channel: this.formData.ins_Channel + } + ble.sendString(f.deviceId, buffer); + }, + ShowChannelEdit() { + + if (!this.permissions.includes('55') && this.Status.apiType !== 'listA') { + + this.showPop({ + message: '无操作权限', + iconUrl: "/static/images/6155/DeviceDetail/uploadErr.png", + borderColor: "#e034344d", + buttonBgColor: "#E03434", + okCallback: null, + buttonText: "确定" + }) + return; + } + + this.Status.ShowEditChannel = true; + this.showPop({ + showPop: true, //是否显示弹窗 + popType: 'custom', + bgColor: '#383934bd', + borderColor: '#BBE600', + textColor: '#ffffffde', + buttonBgColor: '#BBE600', + buttonTextColor: '#232323DE', + iconUrl: '', + message: '', + buttonText: '确定', + clickEvt: '', + visiblePrompt: false, + promptTitle: '', + modelValue: '', + visibleClose: false, + okCallback: () => { + this.onChannelChanging(); + this.Status.ShowEditChannel = false; + }, + showSlot: true, + buttonCancelText: '取消', + showCancel: true, + cancelCallback: () => { + this.Status.ShowEditChannel = false; + } + }); + }, getLinkedCnt() { //获取在线设备的数量 let f = this.getDevice(); @@ -2266,4 +2341,30 @@ /deep/ .uni-navbar--fixed { top: 0px; } + + .popup-prompt-input { + + width: 100%; + height: 60rpx; + line-height: 60rpx; + color: rgba(255, 255, 255, 0.87); + box-sizing: border-box; + border-bottom: 2rpx solid rgba(255, 255, 255, 0.4); + font-size: 28rpx; + font-weight: 400; + letter-spacing: 0.14px; + } + + .popup-prompt-input-placeHolder { + color: rgba(255, 255, 255, 0.4); + + font-family: PingFang SC; + font-size: 28rpx; + font-weight: 400; + + letter-spacing: 0.14px; + text-align: center; + + } + \ No newline at end of file diff --git a/pages/102/HBY102_History.vue b/pages/102/HBY102_History.vue index fc8fd88..4f0fd24 100644 --- a/pages/102/HBY102_History.vue +++ b/pages/102/HBY102_History.vue @@ -10,8 +10,8 @@ - - 连接记录 + 报警记录 @@ -90,7 +90,7 @@ 近三个月 近一个月 + @click.stop="mothItemChange('monthOne')" >近一个月 自定义 @@ -204,7 +204,7 @@ filterMode: true, //是否筛选日期 filterDayMode: 'end', //当前筛选的是开始还是结束 filterDayType: 'customer', //当前筛选的日期是哪种类型 - tabType: 'link', + tabType: 'warn', datePickValue: [999, 999, 999] //日期选择控件绑定的值 @@ -251,10 +251,10 @@ let eventChannel = this.getOpenerEventChannel(); - eventChannel.on('detailData', function(data) { + eventChannel.on('detailData', (data)=> { var device = data.data; - these.device = device; - these.tabChange('link'); + this.device = device; + this.tabChange('warn'); }); @@ -304,7 +304,7 @@ let today = new Date(); let end = Common.DateFormat(today, 'yyyy-MM-dd'); - let start = Common.DateFormat(today.setMonth(diff), 'yyyy-MM-dd'); + let start = Common.DateFormat(today.setMonth(today.getMonth()+ diff), 'yyyy-MM-dd'); this.filter.start = start; this.filter.end = end; @@ -595,7 +595,9 @@ if (!these.Status.filterMode) { if (these.filter.MM) { start = new Date(these.filter.MM + '-01'); - end = start.setMonth(1); + end = new Date(these.filter.MM + '-01') + end.setMonth(end.getMonth()+1); + end.setDate(end.getDate()+1); data = data.filter(v => { let t = v.linkEqs[0].linkTime @@ -613,7 +615,7 @@ console.log("these.filter.end=",these.filter.end); start = new Date(these.filter.start); end = new Date(these.filter.end); - end.setMonth(1); + end.setDate(end.getDate()+1); console.log("start=",start); console.log("end=",end); if(start && end){ @@ -643,7 +645,8 @@ return t >= start; }); } else if (these.filter.end) { - end = new Date(these.filter.end).setMonth(1); + end = new Date(these.filter.end); + end.setDate(end.getDate()+1); data = data.filter(v => { @@ -680,7 +683,7 @@ if (systemInfo.uniPlatform == 'web') { for (let i = 0; i < 20; i++) { - const timestamp = 1710072900000 + (i * 3600000); // 每小时递增 + const timestamp = new Date().getTime() - (i * 3600000); // 每小时递增 const numItems = Math.floor(Math.random() * 5) + 1; // 1-5条 const item = { @@ -740,7 +743,8 @@ console.log("hese.filter.end=" + these.filter.end); let start = new Date(these.filter.start); let end = new Date(these.filter.end); - end.setMonth(1); + + end.setDate(end.getDate()+ 1); data = data.filter(v => { let t = v.warnTime @@ -748,7 +752,7 @@ t = new Date(v.warnTime); } - return t >= start && t <= end; + return t >= start && t < end; }); } else if (these.filter.start) { let start = new Date(these.filter.start); @@ -762,7 +766,8 @@ return t >= start; }); } else if (these.filter.end) { - let end = new Date(these.filter.end).setMonth(1); + let end = new Date(these.filter.end); + end.setDate(end.getDate()+ 1); data = data.filter(v => { let t = v.warnTime if (!(t instanceof Date)) { @@ -774,7 +779,9 @@ } else { if (these.filter.MM) { let start = new Date(these.filter.MM + '-01'); - let end = start.setMonth(1); + let end = new Date(these.filter.MM + '-01'); + end.setMonth(end.getMonth()+1); + end.setDate(end.getDate()+1); data = data.filter((v) => { let t = v.warnTime if (!(t instanceof Date)){ diff --git a/pages/6155/BJQ6155.vue b/pages/6155/BJQ6155.vue index eb8d161..c4f0b0f 100644 --- a/pages/6155/BJQ6155.vue +++ b/pages/6155/BJQ6155.vue @@ -824,7 +824,7 @@ let packetData = these.rgb565Data.slice(startIndex, endIndex); // 构建数据包 - let bufferSize = os == 'Android' ? 505 :133; // 5 + packetData.length * 2; // 头部5字节 + 数据部分 + let bufferSize = os ==packetSize.length*2+5; // 5 + packetData.length * 2; // 头部5字节 + 数据部分 let buffer = new ArrayBuffer(bufferSize); let dataView = new DataView(buffer); diff --git a/utils/BleHelper.js b/utils/BleHelper.js index fe08a96..f700c1c 100644 --- a/utils/BleHelper.js +++ b/utils/BleHelper.js @@ -995,15 +995,15 @@ class BleHelper { // console.log("发现新设备",item.name+" "+item.RSSI); // } - let f = serviceDic.find(v => { - return item.advertisServiceUUIDs - .includes(v.serviceId); - }); - if (f) { + let f = serviceDic.find(v => { + return item.advertisServiceUUIDs + .includes(v.serviceId); + }); + if (f) { // console.log("发现目标设备:", item); arr.push(item); - } + } } if (arr.length === 0) { diff --git a/utils/Common.js b/utils/Common.js index e4be06d..58f0695 100644 --- a/utils/Common.js +++ b/utils/Common.js @@ -340,7 +340,7 @@ export default { value: "55", label: "修改信道", checked: false, - type: ['4877'] + type: ['4877','102'] }, { value: "56", -- 2.43.5