ZaiZai 1 ano atrás
pai
commit
4c2728366f

+ 12 - 18
src/api/modules/tentative/acquisition/humidity.js

@@ -18,28 +18,22 @@ export default {
             headers: { Authorization: token },
         }, false)
     },
-    //新增或修改
-    async submit(form) {
+    //根据设备地址查询实时数据
+    async getRealTimeDataByDeviceAddr(token, deviceAddr) {
         return HcApi({
-            url: '/api/blade-system/dict-biz/submit',
-            method: 'post',
-            data: form,
-        }, false)
-    },
-    //删除
-    async remove(ids) {
-        return HcApi({
-            url: '/api/blade-system/dict/remove',
-            method: 'post',
-            params: { ids },
+            url: '/yunApi/api/data/getRealTimeDataByDeviceAddr',
+            method: 'get',
+            params: { deviceAddrs: deviceAddr },
+            headers: { Authorization: token },
         }, false)
     },
-    //详情
-    async selectDataInfoById(id) {
+    //获取历史数据列表
+    async getHistoryList(token, form) {
         return HcApi({
-            url: '/api/blade-business/entrustinfo/selectDataInfoById',
+            url: '/yunApi/api/data/historyList',
             method: 'get',
-            params: { id },
-        })
+            params: form,
+            headers: { Authorization: token },
+        }, false)
     },
 }

+ 44 - 7
src/views/tentative/acquisition/humidity.vue

@@ -28,7 +28,7 @@
                             <hc-icon name="shut-down" />
                         </el-tooltip>
                     </div>
-                    <el-button size="small" class="ml-10px" @click="viewDetailsClick">查看详情</el-button>
+                    <el-button size="small" class="ml-10px" @click="viewDetailsClick(item.deviceAddr)">查看详情</el-button>
                 </template>
                 <div v-if="item.dataItem.length > 0" class="equipment-list-data hc-flex">
                     <template v-for="(items, indexs) in item.dataItem[0].registerItem" :key="indexs">
@@ -40,7 +40,7 @@
                             <div class="content">
                                 <div class="name">{{ items.registerName }}</div>
                                 <div class="num">{{ items.data }}{{ items.unit }}</div>
-                                <div class="time">记录时间:{{ currentDateTime }}</div>
+                                <div class="time">记录时间:{{ items.time }}</div>
                             </div>
                         </div>
                     </template>
@@ -48,13 +48,13 @@
             </hc-card-item>
         </div>
         <!-- 详情 -->
-        <HcEquipmentData v-model="isEquipmentDataShow" />
+        <HcEquipmentData v-model="isEquipmentDataShow" :data="equipmentData" />
     </hc-card>
 </template>
 
 <script setup>
+import { nextTick, onActivated, ref } from 'vue'
 import { getArrValue, getObjValue, isNullES } from 'js-fast-way'
-import { onActivated, onMounted, ref } from 'vue'
 import { useClick } from 'hc-vue3-ui'
 import dayjs from 'dayjs'
 import HcEquipmentData from './model/equipment-data.vue'
@@ -103,14 +103,51 @@ const getDeviceList = async () => {
         return
     }
     const { data } = await mainApi.getRealTimeData(yunToken.value)
-    deviceDataList.value = getArrValue(data)
     //获取当前时间
-    currentDateTime.value = new dayjs().format('YYYY年MM月DD日 HH:mm:ss')
+    const dateTime = new dayjs().format('YYYY年MM月DD日 HH:mm:ss')
+    //数据是否存在
+    const arr = getArrValue(data)
+    if (arr.length <= 0) {
+        deviceDataList.value = arr
+        return
+    }
+    //子级数据是否存在
+    const dataItem = getArrValue(arr[0].dataItem)
+    if (dataItem.length <= 0) {
+        arr[0].dataItem = [{
+            registerItem: [
+                { registerName: '温度', data: '0', unit: '℃', time: dateTime },
+                { registerName: '湿度', data: '0', unit: '%', time: dateTime },
+            ],
+        }]
+        deviceDataList.value = arr
+        return
+    }
+    //最子级数据判断
+    const registerItem = getArrValue(dataItem[0].registerItem)
+    if (registerItem.length <= 0) {
+        arr[0].dataItem[0].registerItem = [
+            { registerName: '温度', data: '0', unit: '℃', time: dateTime },
+            { registerName: '湿度', data: '0', unit: '%', time: dateTime },
+        ]
+        deviceDataList.value = arr
+        return
+    }
+    //最子级数据
+    for (let i = 0; i < registerItem.length; i++) {
+        arr[0].dataItem[0].registerItem[i].time = dateTime
+    }
 }
 
 //查看详情
 const isEquipmentDataShow = ref(false)
-const viewDetailsClick = () => {
+const equipmentData = ref({})
+const viewDetailsClick = async (deviceAddr) => {
+    equipmentData.value = {
+        deviceAddr,
+        token: yunToken.value,
+    }
+    await nextTick()
     isEquipmentDataShow.value = true
 }
 </script>

+ 61 - 6
src/views/tentative/acquisition/model/equipment-data.vue

@@ -9,8 +9,8 @@
                         </div>
                         <div class="content">
                             <div class="name">温度</div>
-                            <div class="num">24.1℃</div>
-                            <div class="time">记录时间:2024年8月19日 13:55:24</div>
+                            <div class="num">{{ deviceDataInfo.temperature }}</div>
+                            <div class="time">记录时间:{{ deviceDataInfo.time }}</div>
                         </div>
                     </div>
                     <div class="equipment-list-data-item humidity hc-flex">
@@ -19,8 +19,8 @@
                         </div>
                         <div class="content">
                             <div class="name">湿度</div>
-                            <div class="num">24.1%</div>
-                            <div class="time">记录时间:2024年8月19日 13:55:24</div>
+                            <div class="num">{{ deviceDataInfo.humidity }}</div>
+                            <div class="time">记录时间:{{ deviceDataInfo.time }}</div>
                         </div>
                     </div>
                     <div class="equipment-list-data-echart">
@@ -58,7 +58,10 @@
 
 <script setup>
 import { ref, watch } from 'vue'
-import { getObjValue } from 'js-fast-way'
+import { getArrValue, getObjValue, isNullES } from 'js-fast-way'
+import { useClick } from 'hc-vue3-ui'
+import dayjs from 'dayjs'
+import mainApi from '~api/tentative/acquisition/humidity'
 
 const props = defineProps({
     data: {
@@ -84,10 +87,62 @@ watch(isShow, (val) => {
 })
 
 //获取数据详情
-const getInfoData = () => {
+const getInfoData = async () => {
+    await getDeviceList()
     setChartsData()
 }
 
+//获取设备列表
+const deviceDataInfo = ref({})
+const getDeviceList = async () => {
+    const { token, deviceAddr } = getObjValue(dataInfo.value)
+    if (isNullES(token) || isNullES(deviceAddr)) {
+        deviceDataInfo.value = {}
+        return
+    }
+    let temperature = '0℃', humidity = '0%'
+    const { data } = await mainApi.getRealTimeDataByDeviceAddr(token, deviceAddr)
+    //数据是否存在
+    const arr = getArrValue(data)
+    if (arr.length <= 0) {
+        setDeviceData({ temperature, humidity })
+        return
+    }
+    //子级数据是否存在
+    const dataItem = getArrValue(arr[0].dataItem)
+    if (dataItem.length <= 0) {
+        setDeviceData({ temperature, humidity })
+        return
+    }
+    //最子级数据判断
+    const registerItem = getArrValue(dataItem[0].registerItem)
+    if (registerItem.length <= 0) {
+        setDeviceData({ temperature, humidity })
+        return
+    }
+    //最子级数据
+    for (let i = 0; i < registerItem.length; i++) {
+        if (registerItem[i].registerName === '温度') {
+            temperature = registerItem[i].data + registerItem[i].unit
+        }
+        if (registerItem[i].registerName === '湿度') {
+            humidity = registerItem[i].data + registerItem[i].unit
+        }
+    }
+    //设置数据
+    setDeviceData({ temperature, humidity })
+}
+
+//设置空数据
+const setDeviceData = ({ temperature, humidity }) => {
+    const currentDateTime = new dayjs().format('YYYY年MM月DD日 HH:mm:ss')
+    deviceDataInfo.value = {
+        temperature: temperature,
+        humidity: humidity,
+        time: currentDateTime,
+    }
+}
+
 //搜索表单
 const searchForm = ref({ nodeId: -1, startTime: '', endTime: '', deviceAddr: null, current: 1, size: 20, total: 0 })
 const searchClick = () => {