Page({ data: { id:'', typeList: [ { label: '全部传感器', value: '0' }, { label: '温度', value: '1' }, { label: '湿度', value: '2' }, { label: '噪声', value: '3' }, { label: '光照', value: '4' }, { label: '速度', value: '5' }, { label: '位移', value: '6' }, ], index: 0, requestList:[], list:[], deviceList:[], num1:0, num2:0, num3:0, num4:0, num5:0, num6:0, }, onChange(e) { const index = e.detail.value const value = this.data.typeList[index].value this.setData({ index }) if(value === '0'){ this.setData({ deviceList:this.data.list }) } if(value === '1'){ this.setData({ deviceList:this.data.list.filter(e=>e.type==1) }) } if(value === '2'){ this.setData({ deviceList:this.data.list.filter(e=>e.type==2) }) } if(value === '3'){ this.setData({ deviceList:this.data.list.filter(e=>e.type==3) }) } if(value === '4'){ this.setData({ deviceList:this.data.list.filter(e=>e.type==4) }) } if(value === '5'){ this.setData({ deviceList:this.data.list.filter(e=>e.type==5) }) } if(value === '6'){ this.setData({ deviceList:this.data.list.filter(e=>e.type==6) }) } }, onShow() { const tabBar = this.getTabBar?.() if (tabBar) { tabBar.setData({ nowPage:getCurrentPages().at(-1)?.route }) } const params = wx.getStorageSync('energyInfo') this.setData({ id: params.id }) wx.request({ url: 'http://119.45.202.115:9005/miniProgramApi/monitor/realtimeData/'+params.id, method: 'get', header: { 'content-type': 'application/json' }, success:(res)=> { let list = [] res.data.data.forEach(e=>{ if(e.iotEnvironmentData?.tempreture>0){ list.push({ name:e.monitor.monitorName, type:1, value:e.iotEnvironmentData.tempreture }) } if(e.iotEnvironmentData?.humidity>0){ list.push({ name:e.monitor.monitorName, type:2, value:e.iotEnvironmentData.humidity }) } if(e.iotEnvironmentData?.noise>0){ list.push({ name:e.monitor.monitorName, type:3, value:e.iotEnvironmentData.noise }) } if(e.iotEnvironmentData?.illuminance>0){ list.push({ name:e.monitor.monitorName, type:4, value:e.iotEnvironmentData.illuminance }) } if(e.vibrationData?.temperature>0){ list.push({ name:e.monitor.monitorName, type:1, value:e.vibrationData.temperature }) } if(e.vibrationData?.speed>0){ list.push({ name:e.monitor.monitorName, type:5, value:e.vibrationData.speed }) } if(e.vibrationData?.displacement>0){ list.push({ name:e.monitor.monitorName, type:6, value:e.vibrationData.displacement }) } }) this.setData({ requestList:res.data.data, list:list, deviceList:list, num1:list.filter(e=>e.type===1).length || 0, num2:list.filter(e=>e.type===2).length || 0, num3:list.filter(e=>e.type===3).length || 0, num4:list.filter(e=>e.type===4).length || 0, num5:list.filter(e=>e.type===5).length || 0, num6:list.filter(e=>e.type===6).length || 0, }) }, fail(err) { console.error(err) } }) }, })