Przeglądaj źródła

feat: 完善设备控制功能并优化页面显示

fix(photoImage): 添加addtime参数到跳转链接
fix(forecastResult): 移除冗余的this引用并优化日期显示
feat(modification): 为设备名称修改添加经纬度参数
feat(index): 添加IMEI显示并调整样式
fix(cmb): 优化设备信息显示兼容性
fix(deviceData): 优化图表数据更新逻辑
fix(pestEchart): 优化图表配置和显示逻辑
feat(devicePhoto): 重构日期选择和害虫分类显示
feat(deviceControl): 添加设备控制功能和完善设置保存
allen 3 dni temu
rodzic
commit
47c0225975

+ 5 - 7
pages/cbd/components/deviceData.vue

@@ -324,11 +324,9 @@ export default {
   watch:{
     polylineList:{
       handler(newVal, oldVal){
-        if(newVal.length > 0){
-          this.xData = newVal.map(item => this.formatDate(new Date(item.addtime)));
-          this.yData = newVal.map(item => Number(item.new_tem) || 0);
-          this.initChart();
-        }
+        this.xData = newVal.map(item => this.formatDate(new Date(item.addtime)));
+        this.yData = newVal.map(item => Number(item.new_tem) || 0);
+        this.initChart();
       },
       deep:true,
       immediate:true,
@@ -449,7 +447,7 @@ export default {
     },
     openSettings(){
       uni.navigateTo({
-        url: '/pages/cbd/deviceControl?deviceId=' + this.deviceInfo.id,
+        url: '/pages/cbd/deviceControl?deviceId=' + this.deviceInfo.id + '&d_id=' + this.deviceInfo.d_id,
       });
     },
     initChart() {
@@ -962,7 +960,7 @@ export default {
 
     .chart-canvas-container {
       width: 100%;
-      height: 400px;
+      height: 400rpx;
 
       .chart-canvas {
         width: 100%;

+ 19 - 12
pages/cbd/components/pestEchart.vue

@@ -1,5 +1,5 @@
 <template>
-  <view class="pest-echart">
+  <view class="pest-echart" v-show="tabs.length">
     <view class="pest-echart__header">
       <view class="tab-list">
         <view
@@ -14,7 +14,7 @@
       </view>
     </view>
 
-    <view class="pest-echart__content" v-if="dayData.length">
+    <view class="pest-echart__content" v-show="dayData.length">
       <!-- 三个关键时期 -->
       <view class="period-section">
         <view class="period-item">
@@ -99,20 +99,27 @@ export default {
         type: 'line',
         xAxis: {
           disableGrid: true,
-          itemCount: 4,
+          itemCount: 3,
           scrollShow: true
         },
         yAxis: {
           disableGrid: true,
-          data: [
-            {
-              min: 0
-            }
-          ]
+          gridType: 'dash',
+          splitNumber: 5,
+          min: 0,
+          format: (val) => {
+            return Math.round(val)
+          }
         },
         extra: {
           line: {
             type: 'curve'
+          },
+          tooltip: {
+            format: {
+              name: '',
+              value: (val) => Math.round(val)
+            }
           }
         },
         legend: {
@@ -155,7 +162,8 @@ export default {
       handler(){
         this.initChart();
       },
-      deep: true
+      deep: true,
+      immediate: true
     },
   },
   mounted() {
@@ -204,9 +212,7 @@ export default {
     },
     initChart() {
       this.$nextTick(() => {
-        setTimeout(() => {
-          this.updateChartsData(0);
-        }, 100);
+        this.updateChartsData(0);
       });
     },
     drawChart(index) {
@@ -240,6 +246,7 @@ export default {
         },
         yAxis: {
           min: 0,
+          minInterval: 1,
           splitNumber: 4,
           axisLine: true,
           lineColor: '#CCCCCC',

+ 1 - 1
pages/cbd/components/photoImage.vue

@@ -85,7 +85,7 @@ export default {
     },
     handleClick(item) {
       uni.navigateTo({
-        url: '/pages/cbd/devicePhoto?device_id=' + item?.device_id + '&img_id=' + item?.ids + '&id=' + this.deviceInfo.id + '&currentYear=' + this.currentYear
+        url: '/pages/cbd/devicePhoto?device_id=' + item?.device_id + '&addtime=' + item?.addtime + '&img_id=' + item?.ids + '&id=' + this.deviceInfo.id + '&currentYear=' + this.currentYear
       })
     }
   },

+ 128 - 23
pages/cbd/deviceControl.vue

@@ -24,38 +24,38 @@
         <view class="device-detail-item">
           <text class="device-detail-label">联网模块</text>
           <view class="device-detail-btn-container">
-            <view class="device-detail-btn">升级</view>
-            <view class="device-detail-btn">重启</view>
-            <view class="device-detail-btn">MQTT配置</view>
+            <view class="device-detail-btn" @click="setDeviceContorl('dtu_update')">升级</view>
+            <view class="device-detail-btn" @click="setDeviceContorl('dtu_reboot')">重启</view>
+            <!-- <view class="device-detail-btn" @click="showMqttConfig">MQTT配置</view> -->
           </view>
         </view>
         <view class="device-detail-item">
           <text class="device-detail-label">板子设置</text>
           <view class="device-detail-btn-container">
-            <view class="device-detail-btn">查看原始IMEI</view>
-            <view class="device-detail-btn">更改IMEI</view>
+            <!-- <view class="device-detail-btn">查看原始IMEI</view> -->
+            <view class="device-detail-btn" @click="showMqttConfig('imei')">更改IMEI</view>
           </view>
         </view>
         <view class="device-detail-item">
           <text class="device-detail-label">强制操作</text>
           <view class="device-detail-btn-container">
-            <view class="device-detail-btn force-btn">拍照</view>
-            <view class="device-detail-btn force-btn">升级</view>
-            <view class="device-detail-btn force-btn">重启</view>
-            <view class="device-detail-btn force-btn">震动关闭</view>
-            <view class="device-detail-btn force-btn">震动开启</view>
+            <view class="device-detail-btn force-btn" @click="setDeviceContorl('takephoto')">拍照</view>
+            <view class="device-detail-btn force-btn" @click="setDeviceContorl('update')">升级</view>
+            <view class="device-detail-btn force-btn" @click="setDeviceContorl('reboot')">重启</view>
+            <view class="device-detail-btn force-btn" @click="setDeviceContorl('open_shake')">震动开启</view>
+            <view class="device-detail-btn force-btn" @click="setDeviceContorl('close_shake')">震动关闭</view>
           </view>
         </view>
       </view>
       <view class="device-detail-content" style="padding-bottom: 50rpx" v-if="activeTab === 'viewImage'">
         <view class="device-detail-viewImage">
-          <text class="device-detail-label">联网模块</text>
-          <u-switch v-model="checked" size="40" active-color="#0BBC58"></u-switch>
+          <text class="device-detail-label">设备开关:</text>
+          <u-switch v-model="equipContrlForm.ds" size="40" active-color="#0BBC58" active-value="1" inactive-value="0"></u-switch>
         </view>
         <view class="device-detail-viewImage">
           <text class="device-detail-label">定时模式</text>
         </view>
-        <u-radio-group v-model="value" @change="radioGroupChange" active-color="#0BBC58">
+        <u-radio-group v-model="equipContrlForm.ts" @change="radioGroupChange" active-color="#0BBC58">
           <u-radio 
             :name="0"
           >光控
@@ -68,32 +68,43 @@
         <view class="device-detail-viewImage">
           <text class="device-detail-label">落虫时间(min)</text>
         </view>
-        <u-slider v-model="value" style="width:100%" max="100" active-color="#0BBC58"></u-slider>
+        <u-slider v-model="equipContrlForm.collt" style="width:100%" max="20" active-color="#0BBC58"></u-slider>
         <view class="device-detail-viewImage">
           <text class="device-detail-label">加热时间(min)</text>
         </view>
-        <u-slider v-model="value" style="width:100%" max="100" active-color="#0BBC58"></u-slider>
+        <u-slider v-model="equipContrlForm.htim" style="width:100%" max="100" active-color="#0BBC58"></u-slider>
         <view class="device-detail-viewImage">
           <text class="device-detail-label">加热温度(℃)</text>
         </view>
-        <u-slider v-model="value" style="width:100%" max="100" active-color="#0BBC58"></u-slider>
+        <u-slider v-model="equipContrlForm.hst" style="width:100%" max="100" active-color="#0BBC58"></u-slider>
         <view class="device-detail-viewImage">
           <text class="device-detail-label">高温保护阀值(℃)</text>
         </view>
-        <u-slider v-model="value" style="width:100%" max="100" active-color="#0BBC58"></u-slider>
+        <u-slider v-model="equipContrlForm.tph" style="width:100%" max="100" active-color="#0BBC58"></u-slider>
         <view class="device-detail-viewImage">
           <text class="device-detail-label">低温保护阀值(℃)</text>
         </view>
-        <u-slider v-model="value" style="width:100%" max="100" active-color="#0BBC58"></u-slider>
+        <u-slider v-model="equipContrlForm.tpl" style="width:100%" max="100" active-color="#0BBC58"></u-slider>
         <view class="device-detail-viewImage">
           <text class="device-detail-label">数据上传间隔(min)</text>
         </view>
-        <u-slider v-model="value" style="width:100%;" max="100" active-color="#0BBC58"></u-slider>
+        <u-slider v-model="equipContrlForm.datt" style="width:100%;" max="100" active-color="#0BBC58"></u-slider>
       </view>
     </view>
-    <view class="device-detail-btn-footer">
-      <view class="device-detail-btn">保存</view>
+    <view class="device-detail-btn-footer" v-if="activeTab === 'viewImage'">
+      <view class="device-detail-btn" @click="saveSettings">保存</view>
     </view>
+    <u-popup v-model="show" mode="bottom">
+      <view class="device-detail-content" style="height: 50vh">
+        <view class="device-detail-item">
+          <text class="device-detail-label">请输入imei</text>
+          <u-input v-model="equipContrlForm.imei" placeholder="请输入imei"></u-input>
+        </view>
+      </view>
+      <view class="device-detail-btn-footer">
+        <view class="device-detail-btn" @click="setDeviceContorl('imei')">保存</view>
+      </view>
+		</u-popup>
   </view>
 </template>
 <script>
@@ -103,15 +114,21 @@ export default {
     return {
       value: 10,
       imageList: [],
-      deviceInfo: {},
+      equipContrlForm: {},
       time: '',
       activeTab: 'pestAnalysis',
       title: '设置控制',
       deviceType: '',
       location: '',
+      d_id: '',
+      show: false,
       checked: false
     }
   },
+  onLoad(options){
+    this.d_id = options.d_id
+    this.getControlDeviceConfigInfo()
+  },
   methods: {
     handleBack() {
       uni.navigateBack({
@@ -120,7 +137,95 @@ export default {
     },
     handleTabClick(tab) {
       this.activeTab = tab;
-    }
+    },
+    showMqttConfig(){
+      this.show = true;
+    },
+    closeMqttConfig(){
+      this.show = false;
+    },
+    async setDeviceContorl(type){
+      const data = {
+        device_type_id: 3,
+        d_id: this.d_id,
+        cmd: type,
+      }
+      if(type === 'imei'){
+        data.imei = this.equipContrlForm.imei
+      }else{
+        delete data.imei
+      }
+      this.$myRequest({
+        url: '/api/api_gateway?method=forecast.send_control.admin_device_control',
+        method: 'POST',
+        data
+      }).then(res => {
+        this.closeMqttConfig()
+        if (res) {
+          uni.showToast({
+            title: '设备控制修改成功!',
+            icon: 'success',
+          });
+        } else {
+          uni.showToast({
+            title: '设备控制修改失败',
+            icon: 'error',
+          });
+        }
+      });
+    },
+    saveSettings(){
+      let newForm = Object.assign({}, this.equipContrlForm) // 深拷贝
+      newForm.st = newForm.st + ''
+      newForm.et = newForm.et + ''
+      newForm.st && newForm.st.slice(0, 2).charAt(0) != '0'
+        ? newForm.st.slice(0, 2)
+        : newForm.st.slice(1, 2)
+      newForm.et =
+        newForm.et && newForm.et.slice(0, 2).charAt(0) != '0'
+          ? newForm.et.slice(0, 2)
+          : newForm.et.slice(1, 2)
+
+      for (let k in newForm) {
+        if (typeof newForm[k] === 'number') {
+          newForm[k] = newForm[k] + ''
+        }
+      }
+      newForm.st = newForm.st.replace(':00', '')
+      this.$myRequest({
+        url: '/api/api_gateway?method=forecast.send_control.device_control',
+        method: 'POST',
+        data: {
+          device_type_id: 3,
+          d_id: this.d_id,
+          config: JSON.stringify(newForm)
+        }
+      }).then(res => {
+        if (res) {
+          // 设备控制修改成功
+          uni.showToast({
+            title: '设备控制修改成功!',
+            icon: 'success',
+          });
+        } else {
+          uni.showToast({
+            title: '设备控制修改失败',
+            icon: 'error',
+          });
+        }
+      })
+    },
+    async getControlDeviceConfigInfo(){
+      const res = await this.$myRequest({
+        url: '/api/api_gateway?method=forecast.send_control.device_control_info',
+        method: 'POST',
+        data: {
+          d_id: this.d_id,
+          cmd:'paramconf'
+        },
+      });
+      this.equipContrlForm = res
+    },
   }
 }
 </script>

+ 32 - 19
pages/cbd/devicePhoto.vue

@@ -13,20 +13,20 @@
 
     <!-- 日期选择器 -->
      <view class="date-container">
-        <view class="select-year">
+        <!-- <view class="select-year">
           <view class="select-year-item" @click="showPicker = true">
             {{ currentYear }}
             <u-icon name="arrow-down" size="18" class="arrow-down"></u-icon>
           </view>
-        </view>
+        </view> -->
         <view class="date-picker" @click="show = true">
           <view class="date-input">
             <text class="date-label">{{ time_begin || '-' }}</text>
           </view>
-          <view class="date-separator">-</view>
+          <!-- <view class="date-separator">-</view>
           <view class="date-input">
             <text class="date-label">{{ time_end || '-' }}</text>
-          </view>
+          </view> -->
           <u-icon name="calendar" class="calendar"></u-icon>
         </view>
     </view>
@@ -110,10 +110,16 @@
       </view>
     </view>
     <u-empty v-else text="暂无数据"></u-empty>
-		<u-calendar v-model="show" :mode="mode" @change="handleChange" range-color="#999"
+		<u-calendar 
+      v-model="show"
+      :mode="mode"
+      @change="handleChange"
+      range-color="#999"
       btn-type="success"
       active-bg-color="#0BBC58"
-      range-bg-color="rgba(11,188,88,0.13)" :max-date="maxDate" :min-date="minDate" :defaultDate="defaultDate"></u-calendar>
+      range-bg-color="rgba(11,188,88,0.13)"
+      :defaultDate="defaultDate"
+    ></u-calendar>
 		<u-picker v-model="showPicker" mode="selector" :range="selectorRange" range-key="id" :default-selector="[0]" @confirm="confirmHandler"></u-picker>
   </view>
 </template>
@@ -123,7 +129,7 @@ export default {
   data() {
     return {
       show: false,
-      mode: 'range',
+      mode: 'date',
       maxDate: this.formatTime(new Date()),
       minDate: this.formatTime(new Date(new Date().getFullYear(), 0, 1)),
       defaultDate: this.formatTime(new Date(new Date().getFullYear(), 0, 1)),
@@ -153,6 +159,7 @@ export default {
       currentYear:'',
       pest_list_arr:[],
       thumbnails: [],
+      addtime:'',
       currentImg:{},
       bugMarkers: [],
       imageWidth: 0,
@@ -164,15 +171,14 @@ export default {
     };
   },
   async onLoad(options) {
-    const {id,img_id,currentYear} = options
-    console.log(options,'optionsoptions')
+    const {id,img_id,currentYear,addtime} = options
     this.device_id = id
     this.imgOld_id = img_id
     this.currentYear = currentYear
-    this.time_begin = this.currentYear + '-01-01'
-    this.time_end = this.currentYear + '-12-31'
-    this.maxDate = this.formatTime(this.time_end)
-    this.minDate = this.formatTime(this.time_begin)
+    this.addtime = this.formatTime(Number(addtime)*1000);
+    this.time_begin = this.addtime;
+    this.defaultDate = this.addtime;
+    this.time_end = this.addtime;
     this.selectorRange = [];
     const nowYear = new Date().getFullYear();
     for(let i = 0;i<50;i++){
@@ -213,8 +219,8 @@ export default {
     },
     async handleChange(e){
       console.log(e,'e')
-      this.time_begin = e.startDate;
-      this.time_begin = e.endDate;
+      this.time_begin = e.result;
+      this.time_end = e.result;
       this.pestList = [];
       await this.getPestList()
       this.currentImg = {};
@@ -335,18 +341,19 @@ export default {
           img_id: this.img_id,
         },
       });
-      console.log('获取图片详情成功:', res);
       this.currentImg = res;
       // 处理label参数生成bugMarkers
       this.processBugMarkers();
       const pest_list = res.pest_list
       const pestArr = new Map()
+      const pesAlltList = []
       for(let key in this.pestYype){
         for(let j in this.pestYype[key]){
           const pestName = this.pestYype[key][j]
+          pesAlltList.push(pestName)
           pest_list.forEach(item => {
             if(item.pest_name == pestName){
-              if(pestArr.has(item.level)){
+              if(pestArr.has(key)){
                 pestArr.get(key).push(item)
               }else{
                 pestArr.set(key, [item])
@@ -355,6 +362,11 @@ export default {
           })
         }
       }
+      pest_list.forEach(item => {
+        if(!pesAlltList.includes(item.pest_name)){
+          pestArr.get('其他害虫').push(item)
+        }
+      })
       const pestList = []
       for(let key of pestArr){
         pestList.push(key)
@@ -559,14 +571,15 @@ export default {
     padding: 20rpx 24rpx;
     background-color: #FFFFFF;
     margin-bottom: 24rpx;
-    width: 90%;
+    width: 100%;
     margin:20rpx auto;
     border-radius: 48rpx;
     position: relative;
     .date-input {
       display: flex;
       flex-direction: column;
-      width: 35%;
+      width: 100%;
+      text-align: center;
       .date-label {
         font-size: 24rpx;
         color: #999999;

+ 3 - 3
pages/disease/cmb.vue

@@ -9,16 +9,16 @@
 				<view class="info_item">
 					<image :src="$imageURL+'/bigdata_app/image/cb/onBg.png'" mode="" class="bgi"></image>
 					<p style="font-size: 32rpx" @click="copy(eqinfo.device_id)">
-						设备 ID:{{ eqinfo.device_id }}
+						设备 ID:{{ eqinfo.device_id || eqinfo.id || "无"}}
 						<image :src="$imageURL+'/bigdata_app/image/environment/fuzhi.png'" mode=""
 							class="tishi"></image>
 					</p>
-					<p>设备名称:{{ eqinfo.device_name || "无" }}</p>
+					<p>设备名称:{{ eqinfo.device_name || eqinfo.name || "无" }}</p>
 					<p>
 						最近上报时间:<span v-if="eqinfo.uptime">{{ eqinfo.uptime == 0 ? '无' : eqinfo.uptime | timeFormat()
             }}</span><span v-else>{{eqinfo.uptime == 0 ? '无' : eqinfo.uptime | timeFormat() }}</span>
 					</p>
-					<p>地址:{{ eqinfo.location || "暂无地址" }}</p>
+					<p>地址:{{ eqinfo.location || eqinfo.address || "暂无地址" }}</p>
 				</view>
 			</view>
 			<view class="control">

+ 3 - 4
pages/disease/forecastResult.vue

@@ -25,11 +25,11 @@
               class="tishi"
             ></image>
           </p>
-          <p>预测位置:{{ this.address || "无" }}</p>
+          <p>预测位置:{{ address || "无" }}</p>
           <p>
             最近预测时间:
-			<span v-if="this.latest_uptime">{{
-               formetDate(this.latest_uptime)
+			      <span v-if="latest_uptime">{{
+               formetDate(latest_uptime)
             }}</span>
             <span v-else>暂无数据</span>
           </p>
@@ -210,7 +210,6 @@ export default {
           end: this.end,
         },
       });
-      console.log(res);
       this.pagesum = Math.ceil(res.nums / 10) || 1;
       this.address = res.province + res.city + res.county;
       this.latest_uptime = res.latest_uptime;

+ 7 - 2
pages/equipList2/index.vue

@@ -77,6 +77,9 @@
 							</p>
 						</view>
 						<view class="list_item_text">
+							<p v-if="item.imei">
+                <span class="label">IMEI</span>{{ (item.dui || item.imei) }}
+              </p>
 							<p>
                 <span class="label">设备ID</span>{{ item.only_for_show || item.id || item.device_id }}
               </p>
@@ -202,7 +205,7 @@
 				this.loadingtf = true;
         let data = {
           device_type_id: this.type_id,
-          page: this.page,
+          page_num: this.page,
           page_size: this.size,
           pur_id: this.pur_id,
           device_status: this.device_status,
@@ -913,9 +916,11 @@
 				}
 				.label{
 					 color: #999999;
-					 text-align: right;
+					 text-align: left;
 					 margin-right: 32rpx;
 					 font-size: 24rpx;
+					 min-width: 90rpx;
+					 display: inline-block;
 				}
 				.nav-label{
 					//超出隐藏

+ 5 - 3
pages/equipList2/seabox/modification.vue

@@ -75,12 +75,14 @@
 					});
 				}
 			},
-			async eqlistname() { //修改设备名称
+			async eqlistname(lat, lng) { //修改设备名称
 				const res = await this.$myRequest({
 					url: '/api/api_gateway?method=forecast.worm_lamp.revise_device',
 					data: {
 						device_id: this.moddata.imei || this.moddata.device_id || this.moddata.id,
 						device_name: this.moddata.device_name,
+						lat: lat,
+						lng: lng,
 					}
 				})
 				console.log(res)
@@ -123,8 +125,8 @@
 				this.selectaddress(this.moddata.lng, this.moddata.lat)
 			},
 			btn() {
-				this.eqlistcity(this.moddata.lat, this.moddata.lng)
-				this.eqlistname()
+				// this.eqlistcity(this.moddata.lat, this.moddata.lng)
+				this.eqlistname(this.moddata.lat, this.moddata.lng)
 			},
 			clickLeft() {
 				uni.navigateBack({