diff --git a/page_Beehive/Beehive_detail.vue b/page_Beehive/Beehive_detail.vue index da17673..d6b4ac0 100644 --- a/page_Beehive/Beehive_detail.vue +++ b/page_Beehive/Beehive_detail.vue @@ -16,20 +16,23 @@ {{obj.apiaryName == undefined ? '--' : obj.apiaryName}}-{{obj.name == undefined ? '--' : obj.name}} - + 同步设置 - + - + - + - - + + @@ -137,15 +140,15 @@ {{obj.surplusPowerPoint == undefined ? '--' : obj.surplusPowerPoint}}% - - - - - {{this.point == undefined ? '--' : this.point}}% + {{point == undefined ? '--' : point}}% @@ -243,7 +246,7 @@ src="https://api.ccttiot.com/smartmeter/img/static/uhsU6Y1K35jxA4aRauzy" mode=""> - 当前 {{obj.ioCountDay == undefined ? '--' : obj.ioCountDay}}只 + 当前 {{obj.ioCountDay == undefined ? '--' : obj.ioCountDay}}只 当前 {{ver_data.out_day == undefined ? '--' : ver_data.out_day}}只 @@ -275,7 +278,8 @@ 当前 {{obj.volume / 1000 == 0 ? obj.volume : (obj.volume / 1000).toFixed(1)}}khz - 当前 {{(ver_data.MIC !== undefined && !isNaN(ver_data.MIC) && ver_data.MIC / 1000 === 0) ? ver_data.MIC : ((ver_data.MIC !== undefined && !isNaN(ver_data.MIC)) ? (ver_data.MIC / 1000).toFixed(1) : '--')}}khz + 当前 + {{(ver_data.MIC !== undefined && !isNaN(ver_data.MIC) && ver_data.MIC / 1000 === 0) ? ver_data.MIC : ((ver_data.MIC !== undefined && !isNaN(ver_data.MIC)) ? (ver_data.MIC / 1000).toFixed(1) : '--')}}khz @@ -332,7 +336,8 @@ - 蜂场位置:{{obj.apiaryCounty == undefined ? '--' : obj.apiaryCounty}} + 蜂场位置:{{obj.apiaryCounty == undefined ? '--' : obj.apiaryCounty}} {{daytime}}更新 @@ -346,7 +351,7 @@ {{item.textDay}} - + {{item.windDirDay}} @@ -448,16 +453,16 @@ eyht: false, beep: false, timer: null, - mac:'', - devicesList:[], - ver_data:{}, - zcljflag:false, - ljcgflag:false, - wljflag:false, - tbszflag:false, - shezhiobj:{}, - scdeviceflag:true, - point:'' + mac: '', + devicesList: [], + ver_data: {}, + zcljflag: false, + ljcgflag: false, + wljflag: false, + tbszflag: false, + shezhiobj: {}, + scdeviceflag: true, + point: '' } }, onLoad(option) { @@ -517,28 +522,48 @@ }) }, // 连接蓝牙成功 点击同步设置 - btntbsz(){ - // xBlufi.notifySendCustomData({ - //       customData: "" - // }) + btntbsz() { + console.log("11bat_stop" + this.shezhiobj.minPower + '@' + "temp_start" + this.shezhiobj.minHeat + '@' + "temp_stop" + this.shezhiobj.maxHeat + '@' + "fan_start" + this.shezhiobj.maxFan + '@' + "fan_stop" + this.shezhiobj.minFan + '@' + "co2_start" + this.shezhiobj.maxCo2 + '@' + "co2_stop" + this.shezhiobj.minCo2 + '@'); + if(this.ljcgflag == true){ + xBlufi.notifySendCustomData({ + customData: "11bat_stop" + this.shezhiobj.minPower + '@' + "temp_start" + this.shezhiobj.minHeat + '@' + "temp_stop" + this.shezhiobj.maxHeat + '@' + "fan_start" + this.shezhiobj.maxFan + '@' + "fan_stop" + this.shezhiobj.minFan + '@' + "co2_start" + this.shezhiobj.maxCo2 + '@' + "co2_stop" + this.shezhiobj.minCo2 + '@' + }) + uni.showToast({ + title: '同步成功', + icon: 'success', + duration: 2000 + }) + }else{ + let that = this + uni.showModal({ + title: "提示", + content: '设备暂未连接,是否连接?', + success: function(res) { + if (res.confirm) { + that.Binddevice() + } + } + }) + } + }, // 根据蜂箱id获取设备信息 getobj() { this.$u.get(`/app/beehive/${this.beehiveId}`).then(res => { if (res.code == 200) { - if(res.data.onlineStatus == 0){ //判断蜂箱离线时 - this.mac = res.data.mac - this.Binddevice() //执行连接蓝牙方法 - this.getinfo() //获取设置数值 - }else{ + if (res.data.onlineStatus == 0) { //判断蜂箱离线时 + this.mac = res.data.mac + this.Binddevice() //执行连接蓝牙方法 + this.getinfo() //获取设置数值 + } else { // 每次进入执行定时器 this.startTimer() } this.obj = res.data - if(res.data.lat == null || res.data.lng == null){ + if (res.data.lat == null || res.data.lng == null) { this.latitude = 27.100845 this.longitude = 120.25469 - }else{ + } else { this.latitude = res.data.lat this.longitude = res.data.lng } @@ -578,22 +603,22 @@ height: 33, iconPath: 'https://api.ccttiot.com/smartmeter/img/static/ukbyhyrDcp3VzgyeJo2G', }) - + this.gettq() - } else if(res.code == 401){ + } else if (res.code == 401) { uni.showModal({ title: '温馨提示', content: '您还未登录,是否先去登录', - showCancel: true , + showCancel: true, success: function(res) { - if (res.confirm) { - uni.reLaunch({ - url:'/pages/login/login' - }) - } - } + if (res.confirm) { + uni.reLaunch({ + url: '/pages/login/login' + }) + } + } }) - }else{ + } else { uni.showToast({ title: res.msg, icon: 'none', @@ -602,7 +627,7 @@ } }) }, - + // 蓝牙连接 Binddevice() { this.zcljflag = true @@ -635,40 +660,40 @@ } else { let uniqueDevicesList = Array.from(new Set(this.devicesList)) this.devicesList = uniqueDevicesList - console.log(this.devicesList,'列表'); + console.log(this.devicesList, '列表'); // 初始化一个标志变量,用于跟踪是否有匹配 let isMatched = false // 遍历设备列表 this.devicesList.forEach(device => { - // 从设备名称中提取MAC地址(假设MAC地址是设备名称的最后12个字符) - let macFromName = device.name.substring(device.name.length - 12) - console.log(macFromName,this.mac) - // 检查MAC地址是否匹配 - if (macFromName == this.mac) { - this.createBLEConnection(device) - console.log('对比正确') - isMatched = true // 设置标志为true,表示有匹配 - } else { - console.log('对比错误') - } + // 从设备名称中提取MAC地址(假设MAC地址是设备名称的最后12个字符) + let macFromName = device.name.substring(device.name.length - 12) + console.log(macFromName, this.mac) + // 检查MAC地址是否匹配 + if (macFromName == this.mac) { + this.createBLEConnection(device) + console.log('对比正确') + isMatched = true // 设置标志为true,表示有匹配 + } else { + console.log('对比错误') + } }) // 循环结束后检查是否有匹配 if (!isMatched) { - this.zcljflag = false - this.wljflag = true - this.ljcgflag = false + this.zcljflag = false + this.wljflag = true + this.ljcgflag = false let that = this uni.showModal({ title: '温馨提示', content: '暂未发现蜂箱设备,是否重新搜索连接', - showCancel: true , + showCancel: true, success: function(res) { - if (res.confirm) { - that.Binddevice() - } - } + if (res.confirm) { + that.Binddevice() + } + } }) - }else{ + } else { this.zcljflag = false this.wljflag = false this.ljcgflag = true @@ -708,11 +733,11 @@ break case xBlufi.XBLUFI_TYPE.TYPE_CONNECTED: console.log("连接回调:" + JSON.stringify(options)) - uni.showToast({ - title: '连接成功', - icon: 'success', - duration:2000 - }) + uni.showToast({ + title: '连接成功', + icon: 'success', + duration: 2000 + }) this.zcljflag = false this.wljflag = false this.ljcgflag = true @@ -737,27 +762,28 @@ let obj = {}; // 遍历键值对数组,并将它们添加到对象中 pairs.forEach(pair => { - let [key, value] = pair.split(':'); - obj[key] = !isNaN(value) ? parseFloat(value) : value; + let [key, value] = pair.split(':'); + obj[key] = !isNaN(value) ? parseFloat(value) : value; }) this.ver_data = obj - if(this.ver_data.bat != '' || this.ver_data.bat != undefined){ //判断是否接受到设备数据 - this.point = (1 - (this.obj.modelMaxV - this.ver_data.bat) / (this.obj.modelMaxV -this.obj.modelMinV)) * 100 - if(this.scdeviceflag == true){ //判断是否已经上传过 - let data = { - beehiveId:this.beehiveId, - sys:this.ver_data - } - this.$u.put(`app/beehive/btUpload`,data).then(res => { - if(res.code == 200){ + if (this.ver_data.bat != '' || this.ver_data.bat != undefined) { //判断是否接受到设备数据 + let dian = (1 - (this.obj.modelMaxV - this.ver_data.bat) / (this.obj.modelMaxV - this.obj.modelMinV)) * 100 + this.point = dian.toFixed(1) + if (this.scdeviceflag == true) { //判断是否已经上传过 + let data = { + beehiveId: this.beehiveId, + sys: this.ver_data + } + this.$u.put(`app/beehive/btUpload`, data).then(res => { + if (res.code == 200) { this.scdeviceflag = false //一次性只上传一次 - }else{ + } else { this.scdeviceflag = false //一次性只上传一次 } }) } } - console.log('收取到的蓝牙数据',this.ver_data,options.data) + console.log('收取到的蓝牙数据', this.ver_data, options.data) break case xBlufi.XBLUFI_TYPE.TYPE_INIT_ESP32_RESULT: if (options.result) { @@ -785,16 +811,22 @@ break case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED: { console.log('蓝牙异常断开', options.result) + if(options.result == false){ + this.zcljflag = false + this.wljflag = false + this.ljcgflag = false + this.tbszflag = false + } } break; } }, - - - + + + // 跳转天气 - btntqxq(){ - + btntqxq() { + }, // 每30秒上报数据 startTimer() { @@ -803,35 +835,35 @@ } this.timer = setInterval(() => { // 这里写你的定时任务 - this.$u.put(`/app/beehive/iot/${this.beehiveId}/upload`).then(res => { - if (res.code == 200) { - setTimeout(() => { - this.$refs.canvas1.init(this.initChart) - this.$refs.canvas2.init(this.initChart2) - this.$refs.canvas3.init(this.initChart3) - this.$refs.canvas4.init(this.initChart4) - this.$refs.canvas5.init(this.initChart5) - this.$refs.canvas6.init(this.initChart6) - this.$refs.canvas7.init(this.initChart7) - }, 1000) - this.getobj() - let now = new Date(); - let previousDay = new Date(now) - this.yeartime.year = now.getFullYear() - this.yeartime.month = String(previousDay.getMonth() + 1).padStart(2, '0') - this.yeartime.day = String(now.getDate()).padStart(2, '0') - previousDay.setDate(now.getDate() - 7) - this.yeartimes.year = previousDay.getFullYear() - this.yeartimes.month = String(previousDay.getMonth() + 1).padStart(2, '0') - this.yeartimes.day = String(previousDay.getDate()).padStart(2, '0') - this.getchartData1() - this.getchartData2() - this.getchartData3() - this.getchartData4() - this.getchartData5() - this.getchartData6() - } - }) + this.$u.put(`/app/beehive/iot/${this.beehiveId}/upload`).then(res => { + if (res.code == 200) { + setTimeout(() => { + this.$refs.canvas1.init(this.initChart) + this.$refs.canvas2.init(this.initChart2) + this.$refs.canvas3.init(this.initChart3) + this.$refs.canvas4.init(this.initChart4) + this.$refs.canvas5.init(this.initChart5) + this.$refs.canvas6.init(this.initChart6) + this.$refs.canvas7.init(this.initChart7) + }, 1000) + this.getobj() + let now = new Date(); + let previousDay = new Date(now) + this.yeartime.year = now.getFullYear() + this.yeartime.month = String(previousDay.getMonth() + 1).padStart(2, '0') + this.yeartime.day = String(now.getDate()).padStart(2, '0') + previousDay.setDate(now.getDate() - 7) + this.yeartimes.year = previousDay.getFullYear() + this.yeartimes.month = String(previousDay.getMonth() + 1).padStart(2, '0') + this.yeartimes.day = String(previousDay.getDate()).padStart(2, '0') + this.getchartData1() + this.getchartData2() + this.getchartData3() + this.getchartData4() + this.getchartData5() + this.getchartData6() + } + }) }, 30000); // 30秒 }, clearTimer() { @@ -852,26 +884,28 @@ // 点击跳转到操作详情 btnvideo() { const user = uni.getStorageSync('user') - if(this.obj.userId == user.userId){ - if(this.obj.apiaryId == '' || this.obj.apiaryId == null){ + if (this.obj.userId == user.userId) { + if (this.obj.apiaryId == '' || this.obj.apiaryId == null) { let that = this uni.showModal({ title: "提示", content: '请将该设备绑定蜂场在进行此操作', success: function(res) { if (res.confirm) { - uni.navigateTo({ - url:'/page_Beehive/add_Beehive?tit=' + '修改蜂箱' + '&beehiveId=' + that.beehiveId - }) + uni.navigateTo({ + url: '/page_Beehive/add_Beehive?tit=' + '修改蜂箱' + + '&beehiveId=' + that.beehiveId + }) } } }) - }else{ - uni.navigateTo({ - url: '/page_Beehive/Beehive_log?apiaryId=' + this.obj.apiaryId + ' &name=' + this.obj.apiaryName - }) + } else { + uni.navigateTo({ + url: '/page_Beehive/Beehive_log?apiaryId=' + this.obj.apiaryId + ' &name=' + this.obj + .apiaryName + }) } - }else{ + } else { uni.showToast({ title: '您没有权限操作', icon: 'none', @@ -890,11 +924,11 @@ // 点击跳转预警 btnyj() { const user = uni.getStorageSync('user') - if(this.obj.userId == user.userId){ + if (this.obj.userId == user.userId) { uni.navigateTo({ url: '/page_Beehive/Beehive_woring?apiaryId=' + this.beehiveId + '&tit=' + '蜂箱预警记录' }) - }else{ + } else { uni.showToast({ title: '您没有权限操作', icon: 'none', @@ -905,12 +939,12 @@ // 点击编辑 btnedit() { const user = uni.getStorageSync('user') - if(this.obj.userId == user.userId){ + if (this.obj.userId == user.userId) { this.menuflag = false uni.navigateTo({ url: '/page_Beehive/add_Beehive?tit=' + '修改蜂箱' + '&beehiveId=' + this.beehiveId - }) - }else{ + }) + } else { uni.showToast({ title: '您没有权限操作', icon: 'none', @@ -992,21 +1026,34 @@ } }) }, - // 点击进行蜂箱操作 + // 点击进行蜂箱操作 btndow(num) { const user = uni.getStorageSync('user') - if(this.obj.userId == user.userId){ + if (this.obj.userId == user.userId) { if (num == 1) { - if(this.obj.onlineStatus == 0){ - xBlufi.notifySendCustomData({ -       customData: "11clear_weight@" -  }) - uni.showToast({ - title: '去皮成功', - icon: 'success', - duration: 2000 - }) - }else{ + if (this.obj.onlineStatus == 0) { + if(this.ljcgflag == true){ + xBlufi.notifySendCustomData({ + customData: "11clear_weight@" + }) + uni.showToast({ + title: '去皮成功', + icon: 'success', + duration: 2000 + }) + }else{ + let that = this + uni.showModal({ + title: "提示", + content: '设备暂未连接,是否连接?', + success: function(res) { + if (res.confirm) { + that.Binddevice() + } + } + }) + } + } else { this.$u.put(`farm/beehive/iot/${this.beehiveId}/clearWeight`).then(res => { if (res.code == 200) { uni.showToast({ @@ -1024,16 +1071,29 @@ }) } } else if (num == 2) { - if(this.obj.onlineStatus == 0){ - xBlufi.notifySendCustomData({ -       customData: "11beep11@" + 10 -  }) - uni.showToast({ - title: '响铃成功', - icon: 'success', - duration: 2000 - }) - }else{ + if (this.obj.onlineStatus == 0) { + if(this.ljcgflag == true){ + xBlufi.notifySendCustomData({ + customData: "11beep11@" + 10 + }) + uni.showToast({ + title: '响铃成功', + icon: 'success', + duration: 2000 + }) + }else{ + let that = this + uni.showModal({ + title: "提示", + content: '设备暂未连接,是否连接?', + success: function(res) { + if (res.confirm) { + that.Binddevice() + } + } + }) + } + } else { this.$u.put(`farm/beehive/iot/${this.beehiveId}/buzzer`).then(res => { if (res.code == 200) { uni.showToast({ @@ -1052,17 +1112,30 @@ } } else if (num == 3) { if (this.fskx == '关') { - if(this.obj.onlineStatus == 0){ - xBlufi.notifySendCustomData({ -     customData: '11fan100@' - }) - this.fskx = '开' - uni.showToast({ - title: '风扇开启成功', - icon: 'success', - duration: 2000 - }) - }else{ + if (this.obj.onlineStatus == 0) { + if(this.ljcgflag == true){ + xBlufi.notifySendCustomData({ + customData: '11fan100@' + }) + this.fskx = '开' + uni.showToast({ + title: '风扇开启成功', + icon: 'success', + duration: 2000 + }) + }else{ + let that = this + uni.showModal({ + title: "提示", + content: '设备暂未连接,是否连接?', + success: function(res) { + if (res.confirm) { + that.Binddevice() + } + } + }) + } + } else { this.$u.put(`farm/beehive/iot/${this.beehiveId}/fan?open=true`).then(res => { if (res.code == 200) { if (this.fskx == '关') { @@ -1085,17 +1158,30 @@ }) } } else { - if(this.obj.onlineStatus == 0){ - xBlufi.notifySendCustomData({ -     customData: "11fan0@" - }) - this.fskx = '关' - uni.showToast({ - title: '风扇关闭成功', - icon: 'success', - duration: 2000 - }) - }else{ + if (this.obj.onlineStatus == 0) { + if(this.ljcgflag == true){ + xBlufi.notifySendCustomData({ + customData: "11fan0@" + }) + this.fskx = '关' + uni.showToast({ + title: '风扇关闭成功', + icon: 'success', + duration: 2000 + }) + }else{ + let that = this + uni.showModal({ + title: "提示", + content: '设备暂未连接,是否连接?', + success: function(res) { + if (res.confirm) { + that.Binddevice() + } + } + }) + } + } else { this.$u.put(`farm/beehive/iot/${this.beehiveId}/fan?open=false`).then(res => { if (res.code == 200) { if (this.fskx == '关') { @@ -1120,17 +1206,30 @@ } } else if (num == 4) { if (this.jrkg == '关') { - if(this.obj.onlineStatus == 0){ - xBlufi.notifySendCustomData({ -     customData: "11hot100@" - }) - this.jrkg = '开' - uni.showToast({ - title: '加热开启成功', - icon: 'success', - duration: 2000 - }) - }else{ + if (this.obj.onlineStatus == 0) { + if(this.ljcgflag == true){ + xBlufi.notifySendCustomData({ + customData: "11hot100@" + }) + this.jrkg = '开' + uni.showToast({ + title: '加热开启成功', + icon: 'success', + duration: 2000 + }) + }else{ + let that = this + uni.showModal({ + title: "提示", + content: '设备暂未连接,是否连接?', + success: function(res) { + if (res.confirm) { + that.Binddevice() + } + } + }) + } + } else { this.$u.put(`farm/beehive/iot/${this.beehiveId}/heat?open=true`).then(res => { if (res.code == 200) { if (this.jrkg == '关') { @@ -1153,17 +1252,30 @@ }) } } else { - if(this.obj.onlineStatus == 0){ - xBlufi.notifySendCustomData({ -     customData: "11hot0@" - }) - this.jrkg = '关' - uni.showToast({ - title: '加热关闭成功', - icon: 'success', - duration: 2000 - }) - }else{ + if (this.obj.onlineStatus == 0) { + if(this.ljcgflag == true){ + xBlufi.notifySendCustomData({ + customData: "11hot0@" + }) + this.jrkg = '关' + uni.showToast({ + title: '加热关闭成功', + icon: 'success', + duration: 2000 + }) + }else{ + let that = this + uni.showModal({ + title: "提示", + content: '设备暂未连接,是否连接?', + success: function(res) { + if (res.confirm) { + that.Binddevice() + } + } + }) + } + } else { this.$u.put(`farm/beehive/iot/${this.beehiveId}/heat?open=false`).then(res => { if (res.code == 200) { if (this.jrkg == '关') { @@ -1187,7 +1299,7 @@ } } } - }else{ + } else { uni.showToast({ title: '您没有权限操作', icon: 'none', @@ -2000,9 +2112,10 @@