diff --git a/manifest.json b/manifest.json index b9a3e2f..262e3a2 100644 --- a/manifest.json +++ b/manifest.json @@ -86,7 +86,8 @@ "appkey_ios" : "065c43f02c7b627a74ad7dd23b16bb4f", "appkey_android" : "d7d852dbda2b95f6f796fb9a711a9fee" } - } + }, + "push" : {} }, "icons" : { "android" : { diff --git a/pages/650/HBY650.vue b/pages/650/HBY650.vue index 9d82461..a5aa98c 100644 --- a/pages/650/HBY650.vue +++ b/pages/650/HBY650.vue @@ -303,12 +303,12 @@ eventChannel.on('detailData', function(data) { - console.log("收到父页面的参数:" + JSON.stringify(data)); + // console.log("收到父页面的参数:" + JSON.stringify(data)); var device = data.data; these.device = device; 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; } @@ -591,7 +591,7 @@ buttonBgColor: "#E03434", buttonText: '去连接', okCallback: function() { - console.log("1111"); + uni.navigateTo({ url: "/pages/common/addBLE/addEquip", events: { @@ -1157,7 +1157,7 @@ if (this.Status.Pop.clickEvt == 'SendUsr') { } - console.log("1111"); + this.Status.Pop.showPop = false; if (this.Status.Pop.okCallback) { @@ -1246,14 +1246,14 @@ these.setBleFormData(); - // let json = { - // deviceId: these.device.id, - // name: these.formData.company, - // position: these.formData.name, - // unitName: these.formData.job, - // code: these.formData.id - // }; - // usrApi.sendUsr(json) + let json = { + deviceId: these.device.id, + name: these.formData.name, + position: these.formData.job, + unitName: these.formData.company, + code: these.formData.id + }; + usrApi.sendUsr(json) return; } diff --git a/pages/common/addBLE/LinkBle.vue b/pages/common/addBLE/LinkBle.vue index 0c1606e..81bbddc 100644 --- a/pages/common/addBLE/LinkBle.vue +++ b/pages/common/addBLE/LinkBle.vue @@ -157,7 +157,7 @@ } }) - let inteval = setInterval(this.initDevice, 5000); + let inteval = setInterval(this.initDevice, 10000); }, methods: { @@ -182,7 +182,7 @@ } }).then(res => { - // console.log("获取设备信息", res); + console.log("获取设备信息", res); if (res && res.code == 200) { let data = res.data; this.serverDevice=data; diff --git a/pages/common/addBLE/addEquip.vue b/pages/common/addBLE/addEquip.vue index 2ae01f3..52b9465 100644 --- a/pages/common/addBLE/addEquip.vue +++ b/pages/common/addBLE/addEquip.vue @@ -51,6 +51,7 @@ + @@ -60,14 +61,15 @@ {{item.name?item.name:'Unnamed'}} - + + 信号强度:{{110+item.RSSI>100?100:110+item.RSSI}}% - + @@ -162,122 +164,149 @@ ble.removeDeviceFound(pagePath); ble.removeReceiveCallback(pagePath); }, - onLoad() { + onLoad(option) { + let search = option.search; these = this; - ble = bleTool.getBleTool(); - //已连接过但删除了设备 - // let delArr = ble.data.deletedEqs.map(v => { - // return { - // "deviceId": v.deviceId, - // "name": v.name, - // "RSSI": -99, - // "localName": v.name, - // } - // }); - // //已连接过但没绑定过的设备 - // let noDev = ble.data.LinkedList.filter(v => { - // return !(v.device && v.device.id); - // }).map(v => { - // return { - // "deviceId": v.deviceId, - // "name": v.name, - // "RSSI": -99, - // "localName": v.name, - // } - // }); - // delArr = delArr.concat(noDev); - - // console.log("可能搜不到的设备=", delArr); - this.EquipMents = []; //delArr; - - - - ble.addDeviceFound((arr) => { - - arr = arr.devices; - for (var i = 0; i < arr.length; i++) { - - arr[i].linkStatu = false; - if (!arr[i].name) { - continue; - } - - let f = these.EquipMents.find((v, index) => { - if (v.deviceId == arr[i].deviceId) { - // v.RSSI=arr[i].RSSI;//同一设备上报更新信号强度 - these.$set(these.EquipMents[index], 'RSSI', arr[i].RSSI); - return true; - } - return false; - }); - - if (!f) { - console.log("发现新设备,", arr[i]); - arr[i].name=arr[i].name.replace('JQZM-',''); - these.EquipMents.push(arr[i]); - } else { - - } - } - // console.log("equip=", these.EquipMents) - }, pagePath); - // console.log("addEquip") - ble.addReceiveCallback((receivData, f, path, arr) => { - if (f.macAddress && these.device) { - clearInterval(this.Status.intval); - this.Status.intval = null; - this.Status.time = null; - - showLoading(these, { - text: '正在验证设备' - }); - - setTimeout(() => { - these.DeviceVerdict(f.deviceId); - }, 0); - } - - - }, pagePath); eventChannel = this.getOpenerEventChannel(); + // this.EquipMents = [{ + // "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 + // } + // ]; + + + let StartSubsrib = () => { + these.EquipMents=[]; + ble = bleTool.getBleTool(); + + + + + ble.addDeviceFound((arr) => { + + arr = arr.devices; + + for (var i = 0; i < arr.length; i++) { + + arr[i].linkStatu = false; + if (!arr[i].name) { + continue; + } + + let f = these.EquipMents.find((v, index) => { + if (v.deviceId == arr[i].deviceId) { + + these.$set(these.EquipMents[index], 'RSSI', arr[i].RSSI); + + return true; + } + return false; + }); + + if (!f) { + console.log("发现新设备,", arr[i]); + + if (these.device && these.device.bluetoothName) { + if (these.device.bluetoothName === arr[i].name || arr[i].name.indexOf(these + .device.bluetoothName) > -1 || these.device.bluetoothName.indexOf(arr[ + i].name) > -1) { + arr[i].isTarget = true; + } + } + arr[i].name = arr[i].name.replace('JQZM-', ''); + these.EquipMents.push(arr[i]); + } + } + console.log("EquipMents=", these.EquipMents) + }, pagePath); + + ble.addReceiveCallback((receivData, f, path, arr) => { + if (f.macAddress && these.device) { + clearInterval(this.Status.intval); + this.Status.intval = null; + this.Status.time = null; + + showLoading(these, { + text: '正在验证设备' + }); + + setTimeout(() => { + these.DeviceVerdict(f.deviceId); + }, 0); + } + + + }, pagePath); + + } + + if (search) { + StartSubsrib(); + } eventChannel.on('detailData', function(rec) { console.log("接收到父页面的参数:", rec); these.device = rec.data; + StartSubsrib(); + these.refreshBleList(); }); + }, onShow: function() { - - - // this.EquipMents = []; - - // this.PairEquip = []; - ble && ble.StartSearch().then(res => { - console.log("开始搜索成功", res); - }).catch((ex) => { - console.log("开始搜索出现异常", ex); - if (ex.code == 10001) { - these.showOpenSetting(); - } - }); + this.refreshBleList(); }, methods: { refreshBleList() { if (!ble) { return; } - console.log("111111"); + ble.StopSearch().then(res => { - console.log("停止搜索成功"); + // console.log("停止搜索成功"); this.EquipMents = []; ble.StartSearch().then(result => { - console.log("开始搜索成功"); + // console.log("开始搜索成功"); }).catch(err => { - console.log("err=", err); + console.error("开始搜索失败,err=", err); + if(err.code===10001){ + these.showOpenSetting(); + }else{ + uni.showModal({ + title:'提示', + content:'出现异常:'+err.msg + }); + } }); }).catch(ex => { - console.log("ex=", ex); + console.error("ex=", ex); }); }, isItemLink: function(item, index) { @@ -339,7 +368,6 @@ updateLoading(these, { text: "设备Mac地址错误,请重选设备连接" }); - setTimeout(() => { hideLoading(these); }, 1000) @@ -465,6 +493,7 @@ } execLink().then((res) => { + console.log("res=", res); linkCallback(res); }).catch(ex => { console.log("ex=", ex) @@ -565,7 +594,7 @@ .animate .titleIco { width: 36rpx; height: 36rpx; - + } .circle { @@ -575,7 +604,8 @@ animation: expand 4s infinite ease-out; display: inline-block; transform: translate(-50%, -50%); - border:1rpx solid #bbe6003d; + border: 1rpx solid #bbe6003d; + animation: expand 5s infinite ease-in-out; } .circle:nth-child(2) { @@ -587,21 +617,22 @@ } @keyframes expand { - 0% { - width: 0; - height: 0; - opacity: 0.8; - - } - - - - 100% { - width: 18.75rem; - height: 18.75rem; - opacity: 0.2; - - } + 0% { + width: 0; + height: 0; + opacity: 0.8; + } + 80% { + width: 18.75rem; + height: 18.75rem; + opacity: 0.2; + } + 100% { + + width: 0.5rem; + height: 0.5rem; + opacity: 0.5; + } } .mainContent { @@ -659,7 +690,9 @@ flex-wrap: nowrap; justify-content: flex-start; align-items: center; - margin-top: 10rpx; + margin-top: 20rpx; + position: relative; + overflow: hidden; } .list .item .leftImg { @@ -680,6 +713,33 @@ } + .list .item .before { + position: absolute; + bottom: 0px; + right: 0px; + content: ""; + width: 0; + height: 0; + border-right: 30rpx solid #bbe600d4; + border-top: 30rpx solid transparent; + animation-delay: 1s; + animation: fade 1.5s infinite ease-in-out; + } + + @keyframes fade { + 0% { + opacity: 0.3; + } + + 50% { + opacity: 1; + } + + 100% { + opacity: 0.3; + } + } + .list .item .rightIco { width: 40rpx; height: 100%; @@ -695,7 +755,7 @@ .list .item .leftImg .titleIco { width: 100%; height: 100%; - filter:invert(100%); + filter: invert(100%); } .list .item .name { diff --git a/pages/common/index/index.vue b/pages/common/index/index.vue index b65e4e4..50ba0fe 100644 --- a/pages/common/index/index.vue +++ b/pages/common/index/index.vue @@ -416,7 +416,7 @@ break; case 'bluetooth': uni.navigateTo({ - url: "/pages/common/addBLE/addEquip" + url: "/pages/common/addBLE/addEquip?search=all" }) break; } diff --git a/pages/common/qrcode/qrcode.vue b/pages/common/qrcode/qrcode.vue index d3137e3..c2fe001 100644 --- a/pages/common/qrcode/qrcode.vue +++ b/pages/common/qrcode/qrcode.vue @@ -65,7 +65,7 @@ deviceMac: '', communicationMode: '0', //0是4g,1是蓝牙 }) - console.log(this.deviceId, 'deerer ere'); + console.log(this.deviceId, res); if (res.code == 200) { this.isConnectNo = false diff --git a/utils/BleHelper.js b/utils/BleHelper.js index 8f89504..8272a94 100644 --- a/utils/BleHelper.js +++ b/utils/BleHelper.js @@ -31,7 +31,7 @@ class BleHelper { linkedDevices = uni.getStorageSync(key); } if (linkedDevices && linkedDevices.length && linkedDevices.length > 0) { - console.log("111111", linkedDevices); + // console.log("111111", linkedDevices); linkedDevices = linkedDevices.filter((v) => { v.Linked = false; v.notifyState = false; @@ -138,9 +138,9 @@ class BleHelper { for (var i = 0; i < this.data.LinkedList.length; i++) { let item = this.data.LinkedList[i]; - if (bleId) { + if (bleId && item.device) { if (item.device.id == bleId) { - console.log("找到要删除的设备", item); + // console.log("找到要删除的设备", item); this.data.LinkedList.splice(i, 1); this.disconnectDevice(item.deviceId); flag = true; @@ -152,7 +152,7 @@ class BleHelper { } else { if (deviceId && item.deviceId == deviceId) { - console.log("找到要删除的设备1,", item) + // console.log("找到要删除的设备1,", item) this.data.LinkedList.splice(i, 1); this.disconnectDevice(item.deviceId); flag = true; @@ -201,7 +201,7 @@ class BleHelper { this.updateCache(); } } else { - console.log("蓝牙未连接过任何设备"); + // console.log("蓝牙未连接过任何设备"); this.updateCache(); } } @@ -407,7 +407,7 @@ class BleHelper { return new Promise((resolve, reject) => { if (this.data.available) { - console.log("蓝牙模块是可用状态"); + // console.log("蓝牙模块是可用状态"); resolve({ available: this.data.available, discovering: this.data.discovering @@ -415,7 +415,7 @@ class BleHelper { return; } if (!this.data.isOpenBlue) { - console.log("蓝牙模块未打开"); + console.error("蓝牙模块未打开"); resolve({ available: false, discovering: false @@ -424,13 +424,13 @@ class BleHelper { } uni.getBluetoothAdapterState({ success: (info) => { - console.log("蓝牙状态获取成功,", info) + // console.log("蓝牙状态获取成功,", info) this.data.available = info.available; this.data.discovering = info.discovering; resolve(info); }, fail: (ex1) => { - console.log("蓝牙状态获取失败", ex1); + console.error("蓝牙状态获取失败", ex1); let res1 = { available: false, discovering: false @@ -446,14 +446,14 @@ class BleHelper { var init = () => { return new Promise((resolve, reject) => { if (this.data.isOpenBlue) { - console.log("蓝牙状态已可用,提前返回"); + // console.log("蓝牙状态已可用,提前返回"); resolve(false); return; } uni.openBluetoothAdapter({ success: (args) => { - console.log("蓝牙初始化成功:" + JSON.stringify(args)); + // console.log("蓝牙初始化成功:" + JSON.stringify(args)); this.data.isOpenBlue = true; this.data.available = true; resolve(true); @@ -471,7 +471,7 @@ class BleHelper { } uni.onBluetoothAdapterStateChange((state) => { - // console.log('蓝牙状态发生变化:' + JSON.stringify(state)); + console.log('蓝牙状态发生变化:' + JSON.stringify(state)); if (this.data.available !== state.available) { this.data.available = state.available; this.data.discovering = state.discovering; @@ -678,7 +678,7 @@ class BleHelper { }, fail: (ex2) => { - console.log("蓝牙模块启动失败", ex2); + console.error("蓝牙模块启动失败", ex2); reject(this.getError(ex2)); } }); @@ -692,7 +692,7 @@ class BleHelper { } this.CheckBlue().then((res) => { - console.log("res=", res) + // console.log("res=", res) return init(); }).then(resolve).catch((ex) => { console.error("异常:", ex); @@ -716,10 +716,11 @@ class BleHelper { uni.closeBluetoothAdapter({ success: () => { - console.log("蓝牙模块已关闭"); + // console.log("蓝牙模块已关闭"); this.data.isOpenBlue = false; }, fail: (ex) => { + console.error('无法关闭蓝牙模块:',ex); ex = this.getError(ex); ////console.log(msg); }, @@ -755,7 +756,7 @@ class BleHelper { }, fail: (err) => { - console.log(`搜索蓝牙设备失败:`, err); + console.error(`搜索蓝牙设备失败:`, err); reject(this.getError(err)); } @@ -797,11 +798,11 @@ class BleHelper { let p1= new Promise((resolve, reject) => { uni.stopBluetoothDevicesDiscovery({ success: (res) => { - console.log("停止搜索蓝牙设备成功"); + // console.log("停止搜索蓝牙设备成功"); resolve(); }, fail: (ex) => { - console.log("无法停止蓝牙搜索"); + console.error("无法停止蓝牙搜索"); reject(this.getError(ex)); } @@ -856,7 +857,7 @@ class BleHelper { //订阅消息 subScribe(deviceId, state) { - console.log("开始订阅消息", state); + // console.log("开始订阅消息", state); return new Promise((resolve, reject) => { setTimeout(() => { @@ -898,9 +899,9 @@ class BleHelper { state: state, success: (res) => { if (state) { - console.log("订阅消息成功", res); + // console.log("订阅消息成功", res); } else { - console.log("取消订阅成功", res); + // console.log("取消订阅成功", res); } this.data.LinkedList.find((v) => { @@ -960,8 +961,8 @@ class BleHelper { } } } else { - console.log("c=", c); - console.log("serv=", serv); + // console.log("c=", c); + // console.log("serv=", serv); reject({ code: 403, msg: "出现错误,找不到任何通知特征" @@ -991,7 +992,7 @@ class BleHelper { // console.log("finally") }); } else { - console.log("没有特征需要订阅"); + console.error("没有特征需要订阅"); resolve(); } @@ -1016,7 +1017,7 @@ class BleHelper { deviceId: id, success: (res) => { if (res.services && res.services.length > 0) { - console.log("获取到服务:" + JSON.stringify(res)); + // console.log("获取到服务:" + JSON.stringify(res)); this.data.LinkedList.find((v) => { if (v.deviceId == id) { @@ -1041,7 +1042,7 @@ class BleHelper { }); if (se) { - console.log("合作供应商的", s) + // console.log("合作供应商的", s) this.data.LinkedList.find((v) => { if (v.deviceId == id) { v.writeServiceId = s.serviceId; @@ -1060,7 +1061,7 @@ class BleHelper { } else { - console.log("预设的蓝牙服务和特征中找不到"); + console.error("预设的蓝牙服务和特征中找不到"); for (var i = 0; i < res.services.length; i++) { let service = res.services[i]; promises.push(this.getFeatrus(id, service.uuid, @@ -1070,7 +1071,7 @@ class BleHelper { if (promises.length == 0) { - console.log("未找到主服务"); + console.error("未找到主服务"); reject({ msg: "未找到主服务", code: -1 @@ -1089,8 +1090,8 @@ class BleHelper { }) .then((res) => { - console.log('设备连接成功,初始化完成', this.data - .LinkedList); + // console.log('设备连接成功,初始化完成', this.data + // .LinkedList); resolve(); }) @@ -1138,7 +1139,7 @@ class BleHelper { serviceId: serviceId, success: (res) => { - console.log("获取到特征:" + JSON.stringify(res)); + // console.log("获取到特征:" + JSON.stringify(res)); // res.characteristics.forEach((v) => { // v.serviceId = serviceId; // }); @@ -1277,12 +1278,12 @@ class BleHelper { return; } - console.log("正在连接" + deviceId); + // console.log("正在连接" + deviceId); uni.createBLEConnection({ deviceId: deviceId, timeout: 30000, success: (info) => { - console.log("新连接成功", this.data.LinkedList); + // console.log("新连接成功", this.data.LinkedList); this.getLinkBlue().then((arr) => { let cr = arr.devices.find(c => { if (c.deviceId == deviceId) { @@ -1299,8 +1300,8 @@ class BleHelper { } this.updateCache(); - console.log("LinkedList=", this.data - .LinkedList); + // console.log("LinkedList=", this.data + // .LinkedList); // 处理 MTU 设置 if (plus.os.name === 'Android') { @@ -1312,7 +1313,7 @@ class BleHelper { resolve(true); }, fail: () => { - console.log("mtu设置失败"); + console.error("mtu设置失败"); resolve( true ); // MTU设置失败不影响连接成功 @@ -1327,7 +1328,7 @@ class BleHelper { }, fail: (ex) => { ex = this.getError(ex); - console.log("蓝牙" + deviceId + "连接失败" + JSON.stringify(ex)); + console.error("蓝牙" + deviceId + "连接失败" + JSON.stringify(ex)); // 连接超时后自动重试 if (ex.code === 10012 && retryCount < maxRetries) { @@ -1517,7 +1518,7 @@ class BleHelper { }, fail: (ex) => { ex = this.getError(ex); - console.log("发送数据失败", ex); + console.error("发送数据失败", ex); err(ex); }