Parcourir la source

feat: device controller

lvkun il y a 3 ans
Parent
commit
9616e4d24c

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

@@ -0,0 +1,93 @@
+import request from '@/service/request'
+
+/**
+ * 此函数根据给定的查询参数检索设备列表。
+ * @param params - “params”参数是一个“IOT.API.DEVICE.QueryPamars”类型的对象,其中包含 API 请求的查询参数。这些参数用于过滤和分页 API
+ * 返回的结果。
+ * @returns `getDevice` 函数返回一个解析为 `IOT.API.DEVICE.Device` 对象数组的 Promise。 Promise
+ * 由“request”函数返回,该函数使用指定的查询参数(“params”)向“/model/page”端点发出 GET 请求。
+ */
+export const getDeviceList = (params: IOT.API.DEVICE.QueryPamars) => {
+  return request<IOT.API.DEVICE.Device[]>({
+    url: '/device/page',
+    method: 'GET',
+    params
+  })
+}
+
+export const getDeviceById = (id: string) => {
+  return request<IOT.API.DEVICE.Device>({
+    url: `/device/${id}`,
+    method: 'GET'
+  })
+}
+
+export const addDevice = (data: IOT.API.DEVICE.BodyParams) => {
+  return request<string>({
+    url: '/device',
+    method: 'POST',
+    data
+  })
+}
+
+export const delDevice = (id: string) => {
+  return request<string>({
+    url: `/device/${id}`,
+    method: 'DELETE'
+  })
+}
+
+export const delDeviceMul = (data: string[]) => {
+  return request<string>({
+    url: '/device',
+    method: 'DELETE',
+    data
+  })
+}
+
+export const updateDeviceLabel = (data: {id: string, deviceLabel: string}) => {
+  return request<string>({
+    url: '/device/deviceLabel',
+    method: 'PUT',
+    data
+  })
+}
+
+export const getSubDeviceList = (id: string, params: IOT.API.DEVICE.QueryPamars) => {
+  return request<string>({
+    url: `/device/subDevice/${id}`,
+    method: 'GET',
+    params
+  })
+}
+
+export const addSubDevice = (data: IOT.API.DEVICE.SubBodyParams) => {
+  return request<string>({
+    url: '/device/subDevice',
+    method: 'POST',
+    data
+  })
+}
+
+export const addDeviceTag = (data: IOT.API.DEVICE.DeviceTag) => {
+  return request<string>({
+    url: '/deviceTage',
+    method: 'POST',
+    data
+  })
+}
+
+export const getDeviceTag = (params: {deviceId: number | string}) => {
+  return request<string>({
+    url: '/deviceTage',
+    method: 'GET',
+    params
+  })
+}
+
+export const delDeviceTag = (id: string) => {
+  return request<string>({
+    url: `/deviceTage/${id}`,
+    method: 'DELETE'
+  })
+}

+ 49 - 0
src/controller/iot/device.ts

@@ -0,0 +1,49 @@
+import { addDevice, addSubDevice, delDevice, delDeviceMul, delDeviceTag, getDeviceById, getDeviceList, getDeviceTag, getSubDeviceList, updateDeviceLabel } from '@/api/iot/device'
+import { message } from 'ant-design-vue'
+
+export class DeviceContriller {
+  static async page (params: IOT.API.DEVICE.QueryPamars) {
+    return await getDeviceList(params)
+  }
+
+  static async post (data: IOT.API.DEVICE.BodyParams) {
+    await addDevice(data)
+    message.success('新增成功')
+  }
+
+  static async del (id: string | string[]) {
+    // return await delDevice(id)
+    if (typeof id === 'string') {
+      await delDevice(id)
+    } else {
+      await delDeviceMul(id)
+    }
+    message.success('删除成功')
+  }
+
+  static async byId (id: string) {
+    return await getDeviceById(id)
+  }
+
+  static async pageSub (id: string, params: IOT.API.DEVICE.QueryPamars) {
+    return await getSubDeviceList(id, params)
+  }
+
+  static async postSub (data: IOT.API.DEVICE.SubBodyParams) {
+    await addSubDevice(data)
+    message.success('新增成功')
+  }
+
+  static async pageTag (params: {deviceId: number | string}) {
+    return await getDeviceTag(params)
+  }
+
+  static async delTag (id: string) {
+    await delDeviceTag(id)
+    message.success('删除标签成功')
+  }
+
+  static async updateLabel (data: {id: string, deviceLabel: string}) {
+    await updateDeviceLabel(data)
+  }
+}

+ 11 - 0
src/enum/common.ts

@@ -1,6 +1,17 @@
 
+/* 此代码定义了一个名为“TransportEnum”的枚举并将其导出以供其他模块使用。枚举有三个成员:`MQTT`、`HTTP` 和
+`COAP`,每个成员都有一个与其名称相同的字符串值。此枚举可用于表示系统中的设备可使用的不同传输协议。 */
 export enum TransportEnum {
   'MQTT' = 'MQTT',
   'HTTP' = 'HTTP',
   'COAP' = 'COAP'
 }
+
+/* 此代码定义了一个名为“DeviceTypeEnum”的枚举并将其导出以用于其他模块。该枚举有四个成员:“INIT”、“CONNECT”、“DISCONNECT”和“DISABLED”。
+每个成员都分配有一个与其名称相同的字符串值。此枚举可用于表示设备在系统中可以采取的不同状态或操作。 */
+export enum DeviceTypeEnum {
+  'INIT' = 'INIT',
+  'CONNECT' = 'CONNECT',
+  'DISCONNECT' = 'DISCONNECT',
+  'DISABLED' = 'DISABLED',
+}

+ 18 - 0
src/pages/Iot/model/components/onlineTest.vue

@@ -0,0 +1,18 @@
+<template>
+  <a-row>
+    <a-col>
+      online
+    </a-col>
+  </a-row>
+</template>
+
+<script lang="ts" setup >
+const columns = [
+  {
+
+  }
+]
+</script>
+
+<style>
+</style>

+ 9 - 2
src/pages/Iot/model/detail.vue

@@ -20,9 +20,10 @@
   </a-card>
 
   <a-card style="margin-top: 20px;" >
-    <a-tabs v-model:activeKey="state.activeKey">
+    <a-tabs v-model:activeKey="state.activeKey" @change="changeTabs">
       <a-tab-pane  :key="item.key" :tab="item.label" v-for="item in tabsdata">
-        <ModelDefine />
+        <ModelDefine v-if="state.activeKey === 0"/>
+        <OnlineTest v-else-if="state.activeKey === 2" />
       </a-tab-pane>
     </a-tabs>
   </a-card>
@@ -33,6 +34,7 @@ import { ModelController } from '@/controller'
 import { onMounted, reactive, ref } from 'vue'
 import { useRoute } from 'vue-router'
 import ModelDefine from './components/modelDefine.vue'
+import OnlineTest from './components/onlineTest.vue'
 
 const queryParams = useRoute().query as {id: string}
 
@@ -63,6 +65,11 @@ const tabsdata = [
   }
 ]
 
+const changeTabs = (record: number) => {
+  console.log(record)
+  state.activeKey = record
+}
+
 const getModelById = async (id: string) => {
   state.model = await ModelController.detail(id)
 }

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

@@ -1,4 +1,3 @@
-// import { TransportEnum } from '@/enum/common'
 
 declare namespace IOT {
 
@@ -65,5 +64,50 @@ declare namespace IOT {
         'modelId': string
       }
     }
+
+    namespace DEVICE {
+      type QueryPamars = {
+        page: string
+        pageSize: string
+        deviceStatus: DeviceTypeEnum
+        modelId?: string
+        searchKey?: string
+        searchValue: string
+      }
+
+      type BodyParams = {
+        modelId: string
+        deviceCode: string
+        deviceLabel: string
+        deviceAuthType: string
+        deviceSecret: string
+        confirmSecret: string
+      }
+
+      type SubBodyParams = {
+        gatewayId: string,
+        modelId: string
+        deviceCode: string
+        deviceLabel: string
+      }
+      interface Device {
+        id: string
+        deviceLabel: string
+        deviceCode: string
+        deviceDescription: string
+        modelId: string
+        modelLabel: string
+        deviceStatus: string
+        deviceNodeType: string
+        lastConnectTs: string
+        lastActivityTs: string
+      }
+
+      interface DeviceTag {
+        deviceId: string,
+        tagLabel: string
+        tagValue: string
+      }
+    }
   }
 }