diff --git a/pages/650/HBY650.vue b/pages/650/HBY650.vue index b45ba8c..f79f23a 100644 --- a/pages/650/HBY650.vue +++ b/pages/650/HBY650.vue @@ -286,55 +286,37 @@ ble = BleTool.getBleTool(); let eventChannel = this.getOpenerEventChannel(); - //eventChannel.on('receivdata', function(data) { - - let data = { - data: { - deviceMac: '35:06:00:EF:46:51', - bluetoothName: 'JQZM-EF4651', - deviceName: 'JQZM-EF4651', - devicePic: '', - id: '35:06:00:EF:46:51' - } - }; - console.log("收到父页面的参数:" + JSON.stringify(data)); - var device = data.data; - these.device.deviceId = device.deviceMac; - these.formData.name = device.bluetoothName ? device.bluetoothName : device.deviceName; - these.formData.img = device.devicePic; - these.formData.id = device.id; - //}); - ble.addReceiveCallback(these.bleValueNotify); + eventChannel.on('detailData', function(data) { - let startLink=()=>{ - ble.addDeviceFound((res) => { - console.log("发现新设备,",res); - let f = res.devices.find((v) => { - return v.name == device.deviceName; - }); - if (f) { - console.log("找到了目标设备,正在连接:"+f.deviceId) - these.device.deviceId = f.deviceId; - these.formData.id = f.deviceId; - ble.LinkBlue(f.deviceId); - } - }); - - ble.StartSearch(); - } - if(ble.data.LinkedList && ble.data.LinkedList.length>0){ - let f=ble.data.LinkedList.find((v)=>{ - return v.name==device.deviceName; - }); - if(!f){ - startLink(); - }else{ - these.device.deviceId = f.deviceId; - these.formData.id = f.deviceId; - } - }else{ - startLink(); - } + console.log("收到父页面的参数:" + JSON.stringify(data)); + var device = data.data; + + let f = ble.data.LinkedList.find((v) => { + if (v.macAddress == device.deviceMac) { + console.log("找到设备了"); + these.device.deviceId = v.deviceId; + return true; + } + return false; + }); + if (!f) { + uni.showModal({ + title: '提示', + content: "当前手机未连接过此设备,请删除后重新使用蓝牙添加" + }) + return; + } + + these.formData.name = device.bluetoothName ? device.bluetoothName : device.deviceName; + these.formData.img = device.devicePic; + these.formData.id = device.id; + if (f) { + + ble.LinkBlue(f.deviceId, f.writeServiceId, f.wirteCharactId, f.notifyCharactId); + + + } + }); }, onHide: function() {