ZaiZai 1 жил өмнө
parent
commit
15e7867d59

+ 1 - 1
package.json

@@ -18,7 +18,7 @@
         "dayjs": "^1.11.12",
         "echarts": "^5.5.1",
         "element-plus": "^2.8.0",
-        "hc-vue3-ui": "^4.1.6",
+        "hc-vue3-ui": "^4.2.0",
         "js-base64": "^3.7.7",
         "js-fast-way": "^0.5.6",
         "js-md5": "^0.8.3",

+ 45 - 0
src/api/modules/tentative/acquisition/humidity.js

@@ -0,0 +1,45 @@
+import { HcApi } from '../../../request/index'
+
+export default {
+    //获取token
+    async getToken(form) {
+        return HcApi({
+            url: '/yunApi/api/getToken',
+            method: 'get',
+            params: form,
+        }, false)
+    },
+    //查询实时数据
+    async getRealTimeData(token) {
+        return HcApi({
+            url: '/yunApi/api/data/getRealTimeData',
+            method: 'get',
+            params: { groupId: '' },
+            headers: { Authorization: token },
+        }, false)
+    },
+    //新增或修改
+    async submit(form) {
+        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 },
+        }, false)
+    },
+    //详情
+    async selectDataInfoById(id) {
+        return HcApi({
+            url: '/api/blade-business/entrustinfo/selectDataInfoById',
+            method: 'get',
+            params: { id },
+        })
+    },
+}

+ 65 - 26
src/views/tentative/acquisition/humidity.vue

@@ -12,14 +12,14 @@
             </div>
         </template>
         <div class="hc-tentative-acquisition-humidity-equipment">
-            <hc-card-item v-for="item in 2" :key="item" class="equipment-list">
+            <hc-card-item v-for="item in deviceDataList" :key="item.deviceAddr" class="equipment-list">
                 <template #header>
-                    <div class="status-dot" :class="item === 1 ? 'run' : ''" />
-                    <div class="name ml-10px">300900317</div>
+                    <div class="status-dot" :class="item.deviceStatus === 'normal' ? 'run' : ''" />
+                    <div class="name ml-10px">{{ item.deviceName }}</div>
                 </template>
                 <template #extra>
-                    <div class="icon-btn text-#2bb781">
-                        <el-tooltip content="重启">
+                    <div class="icon-btn text-#2bb781" @click="getDeviceList">
+                        <el-tooltip content="刷新">
                             <hc-icon name="restart" />
                         </el-tooltip>
                     </div>
@@ -30,27 +30,20 @@
                     </div>
                     <el-button size="small" class="ml-10px" @click="viewDetailsClick">查看详情</el-button>
                 </template>
-                <div class="equipment-list-data hc-flex">
-                    <div class="item temperature hc-flex">
-                        <div class="icon-box">
-                            <hc-icon name="temp-hot" />
+                <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">
+                        <div class="item hc-flex" :class="items.registerName === '温度' ? 'temperature' : 'humidity' ">
+                            <div class="icon-box">
+                                <hc-icon v-if="items.registerName === '温度'" name="temp-hot" />
+                                <hc-icon v-if="items.registerName === '湿度'" name="water-percent" />
+                            </div>
+                            <div class="content">
+                                <div class="name">{{ items.registerName }}</div>
+                                <div class="num">{{ items.data }}{{ items.unit }}</div>
+                                <div class="time">记录时间:{{ currentDateTime }}</div>
+                            </div>
                         </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>
-                    </div>
-                    <div class="item humidity hc-flex">
-                        <div class="icon-box">
-                            <hc-icon name="water-percent" />
-                        </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>
-                    </div>
+                    </template>
                 </div>
             </hc-card-item>
         </div>
@@ -60,8 +53,39 @@
 </template>
 
 <script setup>
-import { onMounted, 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'
+import mainApi from '~api/tentative/acquisition/humidity'
+
+//页面被激活
+onActivated(() => {
+    useDataApi()
+})
+
+//获取数据
+const useDataApi = async () => {
+    await useClick()
+    getToken().then()
+}
+
+//获取token
+const yunToken = ref('')
+const getToken = async () => {
+    const { code, msg, data } = await mainApi.getToken({
+        loginName: 'h240816wjbm',
+        password: 'h240816wjbm',
+    })
+    const { token } = getObjValue(data)
+    if (code === 1000 && !isNullES(token)) {
+        yunToken.value = token
+        await getDeviceList()
+    } else {
+        window.$message.error(msg ?? '获取数据失败,请联系管理员')
+    }
+}
 
 //搜索表单
 const searchForm = ref({ status: null, ip: null })
@@ -69,6 +93,21 @@ const searchClick = () => {
     window.$message.warning('暂不支持此操作')
 }
 
+//获取设备列表
+const deviceDataList = ref([])
+const currentDateTime = ref('')
+const getDeviceList = async () => {
+    await useClick()
+    if (isNullES(yunToken.value)) {
+        deviceDataList.value = []
+        return
+    }
+    const { data } = await mainApi.getRealTimeData(yunToken.value)
+    deviceDataList.value = getArrValue(data)
+    //获取当前时间
+    currentDateTime.value = new dayjs().format('YYYY年MM月DD日 HH:mm:ss')
+}
+
 //查看详情
 const isEquipmentDataShow = ref(false)
 const viewDetailsClick = () => {

+ 12 - 0
vite.config.js

@@ -60,6 +60,18 @@ export default defineConfig({
                 changeOrigin: true,
                 target: config.target,
                 rewrite: (path) => path.replace(new RegExp('^/api'), '/'),
+                // 排除特定文件名
+                bypass: (req) => {
+                    const excludedFiles = ['humidity.js']
+                    const requestFile = req.url.split('/').pop()
+                    return excludedFiles.includes(requestFile) ? req.url : null
+                },
+            },
+            '/yunApi': {
+                ws: true,
+                changeOrigin: true,
+                target: 'http://www.0531yun.com',
+                rewrite: (path) => path.replace(new RegExp('^/yunApi'), '/'),
             },
         },
     },

+ 4 - 4
yarn.lock

@@ -1982,10 +1982,10 @@ has-flag@^4.0.0:
   resolved "http://39.108.216.210:9000/has-flag/-/has-flag-4.0.0.tgz#944771fd9c81c81265c4d6941860da06bb59479b"
   integrity sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==
 
-hc-vue3-ui@^4.1.6:
-  version "4.1.6"
-  resolved "http://39.108.216.210:9000/hc-vue3-ui/-/hc-vue3-ui-4.1.6.tgz#8997a29c818a009e3436b8ed9cad269fe3776b6c"
-  integrity sha512-g3GTPNcoH9NblPCSqki1aKpHaW7CPqOwMGDBqgxhAtvZU0lD7xaV86zINyTeYiVNTszOow+1Jea2Hl25LTeUHQ==
+hc-vue3-ui@^4.2.0:
+  version "4.2.0"
+  resolved "http://39.108.216.210:9000/hc-vue3-ui/-/hc-vue3-ui-4.2.0.tgz#4935b2f60cd297cac39204f6f1c950c0465eff73"
+  integrity sha512-AnSA0Wmu+x502QaARBlFU0SleYJX9muVkBcu9DJolbb9hPbHT6Ious0foya07hR8BS3ySyWcjqv6YbV47N5Y0w==
   dependencies:
     axios "^1.7.4"
     dayjs "^1.11.12"