ソースを参照

fix: 修复害虫分析图表显示和设备详情刷新功能

修复害虫分析图表数据展示问题,优化设备详情页的刷新功能
调整权限查询逻辑,简化嵌套循环
修复设备详情数据合并逻辑,确保正确显示
allen 2 日 前
コミット
e987113ffd

+ 10 - 2
pages/cb/equip-detail/equip-detail-new.vue

@@ -463,6 +463,7 @@ export default {
   },
   onLoad(option) {
     this.equipInfo = JSON.parse(option.info);
+    console.log(this.equipInfo,'equipInfo')
     this.getDeviceStatus();
     this.type =
       Number(this.equipInfo.type) ||
@@ -494,8 +495,15 @@ export default {
           size: 999,
         },
       });
-      let newRes = res.device[0];
-      this.equipInfo = { ...this.equipInfo, ...newRes };
+      let newRes = res.device;
+      newRes.forEach(item => {
+        const itemId = item.device_id || item.imei || item.id;
+        const current = this.equipInfo.device_id || this.equipInfo.imei || this.equipInfo.id;
+        if(itemId === current){
+          this.equipInfo = { ...this.equipInfo, ...item };
+        }
+      })
+      // this.equipInfo = { ...this.equipInfo, ...newRes };
       console.log('响应', this.equipInfo);
     },
     async getState() {

+ 21 - 15
pages/cbd/components/pestEchart.vue

@@ -140,15 +140,19 @@ export default {
   },
   methods: {
     async getPestNameDetail(name){
-      const res = await this.$myRequest({
-        url: '/api/pest_name_detail',
-        method: 'POST',
-        data: {
-          name
-        },
-      });
-      this.deviceInfo = res
-      this.$emit('getInfo',res)
+      try{
+        const res = await this.$myRequest({
+          url: '/api/pest_name_detail',
+          method: 'POST',
+          data: {
+            name
+          },
+        });
+        this.deviceInfo = res
+        this.$emit('getInfo',res)
+      }catch(err){
+        this.$emit('getInfo',{})
+      }
     },
     async setChartData(){
       if(!this.currentPest){
@@ -176,15 +180,14 @@ export default {
     initChart() {
       this.$nextTick(() => {
         setTimeout(() => {
-          this.drawChart();
+          this.drawChart(0);
         }, 100);
       });
     },
-    drawChart() {
+    drawChart(index) {
       const dayData = this.day || [];
       this.dayData = dayData;
-      const pestData = (this.pest || []).map(item => Number(item) || 0);
-
+      const pestData = this.pest[index];
       const ctx = uni.createCanvasContext('pestChart', this);
       chartInstance = new uCharts({
         context: ctx,
@@ -199,7 +202,7 @@ export default {
         dataLabel: false,
         categories: dayData,
         series: [{
-          name: '虫量',
+          name: '',
           data: pestData
         }],
         color: ['#0085FF'],
@@ -261,7 +264,7 @@ export default {
       this.getPestNameDetail(name);
       this.setChartData();
       this.$nextTick(() => {
-        this.drawChart();
+        this.drawChart(index);
       });
     }
   }
@@ -272,6 +275,9 @@ export default {
 .pest-echart {
   overflow: hidden;
   margin-top: 24rpx;
+  &__header{
+    margin-bottom: 24rpx;
+  }
 }
 
 .tab-list {

+ 17 - 8
pages/cbd/detail.vue

@@ -18,7 +18,7 @@
       />
       <view class="tabs">
         <view class="tab-container" v-if="isShowTab">
-          <view class="tab-item" :class="activeTab === 'pestAnalysis'?'active':''" @click="handleTabClick('pestAnalysis')">
+          <view class="tab-item" :class="activeTab === 'pestAnalysis'?'active':''" @click="handleTabClick('pestAnalysis')" v-if="disableShow">
             害虫分析
           </view>
           <view class="tab-item" :class="activeTab === 'viewImage'?'active':''" @click="handleTabClick('viewImage')">
@@ -115,6 +115,7 @@ export default {
     return {
       isShowTab:false,
       showPicker: false,
+      disableShow: false,
       totalPage:0,
       currentYear: new Date().getFullYear(),
       selectorRange: [],
@@ -168,7 +169,7 @@ export default {
         return false;
       }
       let showStatus = true;
-      if(this.deviceInfo.disable == 0 || this.deviceInfo.device_model == 15 || this.deviceInfo.device_model == 12){
+      if(this.deviceInfo.device_model == 15 || this.deviceInfo.device_model == 12){
         showStatus = false;
       }
       if(showStatus){
@@ -178,6 +179,14 @@ export default {
       }
       this.initAction();
       this.isShowTab = showStatus;
+      if(this.deviceInfo.disable == 0){
+        this.disableShow = false;
+        if(showStatus){
+          this.activeTab = 'viewImage';
+        }
+      }else{
+        this.disableShow = true;
+      }
     },
     prevPage(e){
       if(e == 1){
@@ -353,12 +362,12 @@ export default {
       this.pest_order = pest_order;
       this.day = res?.day || [];
       const pest = res?.pest || [];
-      this.pest = [];
-      pest.forEach(p =>{
-        for(let i = 0;i< p.length;i++){
-          this.pest.push(p[i]);
-        }
-      })
+      this.pest = pest;
+      // pest.forEach(p =>{
+      //   for(let i = 0;i< p.length;i++){
+      //     this.pest.push(p[i]);
+      //   }
+      // })
       this.total = total;
     }
   }

+ 26 - 10
pages/deviceDetails/weatherStation/index.vue

@@ -18,12 +18,12 @@
         ></image>
       </view>
       <view class="info-item">
-        <text class="info-label">设备位置</text>
-        <text class="info-value">{{ deviceInfo.address }}</text>
-      </view>
-      <view class="info-item">
         <text class="info-label">上报时间</text>
         <text class="info-value">{{ formatTimestamp(deviceInfo.uptime) }}</text>
+      </view> 
+      <view class="info-item">
+        <text class="info-label">设备位置</text>
+        <text class="info-value">{{ deviceInfo.address }}</text>
       </view>
       <view class="dev-status">{{
         deviceInfo.devStatus == '1' ? '在线' : '离线'
@@ -97,10 +97,11 @@
         <!-- 设备参数 -->
         <view class="device-params">
           <view class="device-control">
-            <!-- <view class="control-left">
-              <view>2025-12-28 08:00:00</view>
-              <u-icon name="reload" class="reload-img"></u-icon>
-            </view> -->
+            <view class="control-left">
+              <view>{{formatTimestamp(deviceInfo.uptime)}}</view>
+              <u-icon name="reload" color="#0BBC58" style="margin-left: 12rpx" @click="refreshData"></u-icon>
+            </view>
+          <!-- {{formatDate(deviceInfo.uptime)}} -->
             <view class="control-right">
               <image
                 class="control-img"
@@ -260,6 +261,22 @@ export default {
     },
   },
   methods: {
+    async refreshData(){
+      //api/api_gateway?method=qxz.device.control
+      await this.$myRequest({
+        url: '/api/api_gateway?method=qxz.device.control',
+        data: {
+          device_id: this.deviceInfo.devBid,
+          cmd: 'READ',
+        },
+      });
+      //弹框提示
+      uni.showToast({
+        title: '刷新成功',
+        icon: 'success',
+      });
+      this.getDeviceData();
+    },
     formatTimestamp(timestamp) {
       if (!timestamp) return '';
       const date = new Date(Number(timestamp) * 1000);
@@ -675,13 +692,12 @@ export default {
     border-radius: 16rpx;
     padding: 32rpx;
     margin-bottom: 24rpx;
-    height: 400rpx;
     .device-control {
       position: relative;
       z-index: 3;
       display: flex;
       align-items: center;
-      justify-content: flex-end;
+      justify-content: space-between;
       margin-bottom: 24rpx;
       .control-left {
         color: #999999;

+ 1 - 0
pages/warning/index.vue

@@ -236,6 +236,7 @@ export default {
       this.current = warning;
       const params = {
         record_ids: warning.id,
+        fk_type:this.tabs[this.activeTab].id,
       };
       this.readHandler(params)
       this.popupShow = true;

+ 3 - 8
util/QueryPermission.js

@@ -7,15 +7,10 @@ function QueryPermission(id) {
 		if (list[i].children) {
 			var data = list[i].children
 			for (var j = 0; j < data.length; j++) {
-				if (data[j].children) {
-					var item = data[j].children
-					for (var k = 0; k < item.length; k++) {
-						if (item[k].pur_id == id) {
-							return true
-						}
+					var item = data[j]
+					if (item.pur_id == id) {
+						return true
 					}
-				}
-
 			}
 		}
 	}