Răsfoiți Sursa

fix: 第三方设备

lvkun 2 ani în urmă
părinte
comite
23579b8899

+ 7 - 0
src/api/iot/thirdDevice.ts

@@ -38,3 +38,10 @@ export const getThirdDeviceByCode = (deviceCode: string) => {
     method: 'GET'
   })
 }
+
+export const getThirdDeviceDataByCode = (deviceCode: string) => {
+  return request<IOT.API.THIRDDEVICE.Detail>({
+    url: `/thirdDevice/data/${deviceCode}`,
+    method: 'GET'
+  })
+}

+ 6 - 1
src/controller/iot/thirdDevice.ts

@@ -1,4 +1,4 @@
-import { addThirdDevice, delThirdDevice, getThirdDeviceByCode, getThirdDevicePage, updateThirdDevice } from '@/api/iot/thirdDevice'
+import { addThirdDevice, delThirdDevice, getThirdDeviceByCode, getThirdDeviceDataByCode, getThirdDevicePage, updateThirdDevice } from '@/api/iot/thirdDevice'
 import { message } from 'ant-design-vue'
 
 export class ThirdDeviceController {
@@ -25,4 +25,9 @@ export class ThirdDeviceController {
     const { code: _code, msg } = await delThirdDevice(code)
     _code === 200 ? message.success('删除成功') : message.error(msg)
   }
+
+  static async dataByCode (code: string) {
+    const { data } = await getThirdDeviceDataByCode(code)
+    return data
+  }
 }

+ 87 - 8
src/pages/Iot/thirdDevice/index.vue

@@ -1,6 +1,5 @@
 <template>
 <a-card title="第三方平台" >
-
   <table-pro
     :service="ThirdDeviceController.page"
     :columns="columns"
@@ -9,8 +8,12 @@
     @add="openModal('add', {})"
   >
     <template #render="{column, record}" >
+      <template v-if="column.key === 'onLineState'">
+        {{record.onLineState == 0 ? '离线' : '在线'}}
+      </template>
       <template v-if="column.key === 'action'" >
         <a-space>
+          <a @click="openDataView(record)" >查看</a>
           <a @click="openModal('update', record)" >编辑</a>
           <a-popconfirm
             title="确定要删除这个设备吗?"
@@ -59,11 +62,30 @@
       </a-form-item>
     </a-form>
 </modal-pro>
+
+<RealView
+  title="设备数据详情"
+  :open="realViewVisible"
+  @cancel="realViewVisible = false"
+  @ok='realViewVisible = false'
+  footer
+>
+  <a-card style="height: 100%;" >
+    <a-table
+      :dataSource="deviceData"
+      :columns="dataColumns"
+      :pagination="false"
+      :scroll="{y: '100%'}"
+    >
+    </a-table>
+  </a-card>
+</RealView>
 </template>
 <script lang='ts' setup >
 import { ThirdDeviceController } from '@/controller'
 import { reactive, ref } from 'vue'
 import { Form, message } from 'ant-design-vue'
+import { RealView } from '@/components/RealView/index'
 
 const columns = [
   {
@@ -82,15 +104,25 @@ const columns = [
     key: 'deviceType'
   },
   {
-    title: '设备状态',
+    title: '设备事件状态',
     dataIndex: 'deviceStatus',
     key: 'deviceStatus'
   },
   {
-    title: '设备状态描述',
+    title: '设备事件状态描述',
     dataIndex: 'deviceStatusDesc',
     key: 'deviceStatusDesc'
   },
+  {
+    title: '设备在线状态',
+    dataIndex: 'onLineState',
+    key: 'onLineState'
+  },
+  {
+    title: '在线状态描述展示',
+    dataIndex: 'onLineStateDesc',
+    key: 'onLineStateDesc'
+  },
   {
     title: '设备描述',
     dataIndex: 'deviceDesc',
@@ -101,11 +133,6 @@ const columns = [
     dataIndex: 'deviceAddr',
     key: 'deviceAddr'
   },
-  {
-    title: '设备数据',
-    dataIndex: 'deviceData',
-    key: 'deviceData'
-  },
   {
     title: '操作',
     dataIndex: 'action',
@@ -113,6 +140,44 @@ const columns = [
   }
 ]
 
+const dataColumns = [
+  {
+    title: 'id',
+    dataIndex: 'id',
+    key: 'id'
+  },
+  {
+    title: '设备编码',
+    dataIndex: 'deviceCode',
+    key: 'deviceCode'
+  },
+  {
+    title: '设备数据key',
+    dataIndex: 'devicePropCode',
+    key: 'devicePropCode'
+  },
+  {
+    title: '设备数据值',
+    dataIndex: 'devicePropVal',
+    key: 'devicePropVal'
+  },
+  {
+    title: '设备数据单位',
+    dataIndex: 'devicePropUnit',
+    key: 'devicePropUnit'
+  },
+  {
+    title: '设备数据事件',
+    dataIndex: 'devicePropTime',
+    key: 'devicePropTime'
+  }
+]
+
+const onLineStateDescMap = new Map([
+  ['UN_ACTIVE', '223'],
+  ['UN_ACTIVE1', '']
+])
+
 const useForm = Form.useForm
 
 const queryParams = reactive({
@@ -161,6 +226,20 @@ const delDevice = async (deviceCode: string) => {
   tableProDom.value.reload()
 }
 
+const deviceData = ref()
+
+const realViewVisible = ref(false)
+
+const openDataView = (record) => {
+  realViewVisible.value = true
+  getDataByCode(record.deviceCode)
+}
+
+// 根据设备码获取设备数据详情
+const getDataByCode = async (code: string) => {
+  deviceData.value = await ThirdDeviceController.dataByCode(code)
+}
+
 </script>
 <style lang='less' scoped >
 </style>