Bläddra i källkod

feat: 设备解析弹窗

lvkun996 2 år sedan
förälder
incheckning
db7ed03243
4 ändrade filer med 99 tillägg och 18 borttagningar
  1. 18 0
      src/api/iot/device.ts
  2. 9 13
      src/controller/iot/device.ts
  3. 43 4
      src/pages/Iot/device/index.vue
  4. 29 1
      src/type/iot.d.ts

+ 18 - 0
src/api/iot/device.ts

@@ -259,3 +259,21 @@ export const getDeviceTopology = (modelId: string) => {
     method: 'GET'
   })
 }
+
+/** 设备上下线 */
+export const getDeviceSession = (params: {deviceId: string, start: number, end: number}) => {
+  return request<IOT.API.DEVICE.Session[]>({
+    url: '/deviceAnalysis/session',
+    method: 'GET',
+    params
+  })
+}
+
+/** 设备属性 */
+export const getDeviceAttributes = (params: {deviceId: string, start: number, end: number}) => {
+  return request<IOT.API.DEVICE.Attr>({
+    url: '/deviceAnalysis/attributes',
+    method: 'GET',
+    params
+  })
+}

+ 9 - 13
src/controller/iot/device.ts

@@ -2,7 +2,7 @@ import {
   addDevice, addSubDevice, delDevice, delDeviceMul, delDeviceTag,
   getDeviceById, getDeviceCount, getDeviceList, getDeviceMsgList, addDeviceMsg, getDeviceTag,
   getSubDeviceList, updateDeviceLabel, addDeviceCmd, getDeviceCmdList, addDeviceTag, addDeviceGroup,
-  listDeviceGroup, postGroupBindDevice, delGroupBindDevice, getDeviceByGroup, getDevicePage, delSubDevice, getDeviceAttribute, getDevicShadow, getDeviceTopology
+  listDeviceGroup, postGroupBindDevice, delGroupBindDevice, getDeviceByGroup, getDevicePage, delSubDevice, getDeviceAttribute, getDevicShadow, getDeviceTopology, getDeviceSession, getDeviceAttributes
 } from '@/api/iot/device'
 import { DeviceMsgEnum } from '@/enum/common'
 import { message } from 'ant-design-vue'
@@ -209,18 +209,14 @@ export class DeviceContriller {
   }
 
   static async getDeviceTopology (modelId: string) {
-    // const { data } = await getDeviceTopology(modelId)
-    // const { gatewayDevice, model, subDevice } = data
-
-    // return {
-    //   data: {
-    //     gatewayDevice: gatewayDevice.map(item => {
-    //       return {
-    //         name: item.
-    //       }
-    //     })
-    //   }
-    // }
     return await getDeviceTopology(modelId)
   }
+
+  static async getSession (params: {deviceId: string, start: number, end: number}) {
+    return await getDeviceSession(params)
+  }
+
+  static async getAttr (params: {deviceId: string, start: number, end: number}) {
+    return await getDeviceAttributes(params)
+  }
 }

+ 43 - 4
src/pages/Iot/device/index.vue

@@ -63,16 +63,30 @@
             <a-space>
               <a @click="goDetailPage(record.id)">查看</a>
               <a @click="goDebugPage(record.id)" >调试</a>
-                <a-popconfirm
+              <a-popconfirm
                   title="确实要删除吗?"
                   ok-text="确定"
                   cancel-text="取消"
                   @confirm="delDevice(record.id)"
                 >
                   <a href="#">删除</a>
-                </a-popconfirm>
+              </a-popconfirm>
+              <a-dropdown>
+                <a class="ant-dropdown-link" @click.prevent>分析 <DownOutlined /> </a>
+                <template #overlay>
+                  <a-menu>
+                    <a-menu-item
+                      v-for="item in analysisList"
+                      :key="item.key"
+                      @click="openAnalysisModal(item.key)"
+                    >
+                      <a href="javascript:;">{{item.label}}</a>
+                    </a-menu-item>
+                  </a-menu>
+                </template>
+              </a-dropdown>
             </a-space>
-          </template>
+        </template>
       </template>
     </a-table>
   </a-card>
@@ -115,11 +129,20 @@
       </a-form-item>
     </a-form>
   </a-modal>
+
+  <modal-pro
+    :label="analysisTitle"
+    :open="state.analysisVisible"
+    @cancel="state.analysisVisible = false"
+    @ok="state.analysisVisible = false"
+  >
+
+  </modal-pro>
 </template>
 
 <script lang="ts" setup >
 import { DeviceContriller, ModelController } from '@/controller/index'
-import { onMounted, reactive, ref, toRefs, nextTick } from 'vue'
+import { onMounted, reactive, ref, toRefs, nextTick, computed } from 'vue'
 import { Form, message } from 'ant-design-vue'
 import { DeviceAuthTypeEnum } from '@/enum/common'
 import { useRouter } from 'vue-router'
@@ -172,6 +195,13 @@ const searchList = [
   { name: '设备标识码', key: 'deviceCode' }
 ]
 
+const analysisList = [
+  { label: '上下线分析', key: 'session' },
+  { label: '属性分析', key: 'attr' }
+]
+
+const analysisTitle = computed(() => state.analysisType === 'session' ? '上下线分析' : '属性分析')
+
 const state = reactive<{
   modelId: string,
   deviceCount: any,
@@ -180,6 +210,8 @@ const state = reactive<{
   visible: boolean,
   opraState: 'add' | 'update',
   modelList: IOT.API.MODEL.ModelDot[]
+  analysisVisible: boolean
+  analysisType: 'session' | 'attr' | ''
 }>({
   modelId: '',
   deviceCount: [],
@@ -187,6 +219,8 @@ const state = reactive<{
   modelList: [],
   loading: false,
   visible: false,
+  analysisVisible: false,
+  analysisType: '',
   opraState: 'add'
 })
 
@@ -219,6 +253,11 @@ const { resetFields: resetFieldsDevice, validate: validateDevice, validateInfos:
   deviceCode: [{ required: true, message: '请填写设备码' }]
 }))
 
+const openAnalysisModal = (key: 'session' | 'attr') => {
+  state.analysisVisible = true
+  state.analysisType = key
+}
+
 const changePage = ({ current }) => {
   searchState.page = current
   getDevicePage()

+ 29 - 1
src/type/iot.d.ts

@@ -216,7 +216,35 @@ declare namespace IOT {
           'lastActivityTs': string,
           'gatewayId': string
         }[]
-    }
+      }
+
+      interface Session {
+        'id': string,
+        'createAt': 1683171293012,
+        'updateAt': string,
+        'deviceId': string,
+        'sessionType': 'CONNECT' | 'DISCONNECT',
+        'connectTime': string,
+        'activityTime': string
+      }
+
+      interface Attr {
+        hum?: {
+          'deviceId':string,
+          'ts': string,
+          'key': string,
+          'keyLabel': string,
+          'stringValue': any,
+          'doubleValue': any,
+          'longValue': number,
+          'booleanValue': null,
+          'jsonValue': null,
+          'dataUnit': string,
+          'scope': null,
+          'dataType': string
+        }[]
+        [key: string]: any
+      }
     }
 
     namespace EVENT {