index.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import request from '@/config/axios'
  2. // IoT 设备 VO
  3. export interface DeviceVO {
  4. id: number // 设备 ID,主键,自增
  5. deviceKey: string // 设备唯一标识符
  6. deviceName: string // 设备名称
  7. productId: number // 产品编号
  8. productKey: string // 产品标识
  9. deviceType: number // 设备类型
  10. nickname: string // 设备备注名称
  11. gatewayId: number // 网关设备 ID
  12. status: number // 设备状态
  13. statusLastUpdateTime: Date // 设备状态最后更新时间
  14. lastOnlineTime: Date // 最后上线时间
  15. lastOfflineTime: Date // 最后离线时间
  16. activeTime: Date // 设备激活时间
  17. createTime: Date // 创建时间
  18. ip: string // 设备的 IP 地址
  19. firmwareVersion: string // 设备的固件版本
  20. deviceSecret: string // 设备密钥,用于设备认证,需安全存储
  21. mqttClientId: string // MQTT 客户端 ID
  22. mqttUsername: string // MQTT 用户名
  23. mqttPassword: string // MQTT 密码
  24. authType: string // 认证类型
  25. latitude: number // 设备位置的纬度
  26. longitude: number // 设备位置的经度
  27. areaId: number // 地区编码
  28. address: string // 设备详细地址
  29. serialNumber: string // 设备序列号
  30. groupIds?: number[] // 添加分组 ID
  31. }
  32. export interface DeviceUpdateStatusVO {
  33. id: number // 设备 ID,主键,自增
  34. status: number // 设备状态
  35. }
  36. // IoT 设备数据 VO
  37. export interface DeviceDataVO {
  38. deviceId: number // 设备编号
  39. thinkModelFunctionId: number // 物模型编号
  40. productKey: string // 产品标识
  41. deviceName: string // 设备名称
  42. identifier: string // 属性标识符
  43. name: string // 属性名称
  44. dataType: string // 数据类型
  45. updateTime: Date // 更新时间
  46. value: string // 最新值
  47. }
  48. // IoT 设备数据 VO
  49. export interface DeviceHistoryDataVO {
  50. time: number // 时间
  51. data: string // 数据
  52. }
  53. // IoT 设备状态枚举
  54. export enum DeviceStatusEnum {
  55. INACTIVE = 0, // 未激活
  56. ONLINE = 1, // 在线
  57. OFFLINE = 2, // 离线
  58. DISABLED = 3 // 已禁用
  59. }
  60. // IoT 模拟设备数据
  61. export interface SimulatorDataVO {
  62. productKey: string
  63. deviceKey: string
  64. type: string
  65. subType: string
  66. reportTime: string
  67. content: string // 存储 JSON 字符串
  68. }
  69. // 设备 API
  70. export const DeviceApi = {
  71. // 查询设备分页
  72. getDevicePage: async (params: any) => {
  73. return await request.get({ url: `/iot/device/page`, params })
  74. },
  75. // 查询设备详情
  76. getDevice: async (id: number) => {
  77. return await request.get({ url: `/iot/device/get?id=` + id })
  78. },
  79. // 新增设备
  80. createDevice: async (data: DeviceVO) => {
  81. return await request.post({ url: `/iot/device/create`, data })
  82. },
  83. // 修改设备
  84. updateDevice: async (data: DeviceVO) => {
  85. return await request.put({ url: `/iot/device/update`, data })
  86. },
  87. // 修改设备状态
  88. updateDeviceStatus: async (data: DeviceUpdateStatusVO) => {
  89. return await request.put({ url: `/iot/device/update-status`, data })
  90. },
  91. // 修改设备分组
  92. updateDeviceGroup: async (data: {
  93. ids: number[]
  94. groupIds: number[]
  95. }) => {
  96. return await request.put({ url: `/iot/device/update-group`, data })
  97. },
  98. // 删除单个设备
  99. deleteDevice: async (id: number) => {
  100. return await request.delete({ url: `/iot/device/delete?id=` + id })
  101. },
  102. // 删除多个设备
  103. deleteDeviceList: async (ids: number[]) => {
  104. return await request.delete({ url: `/iot/device/delete-list`, params: { ids: ids.join(',') } })
  105. },
  106. // 导出设备
  107. exportDeviceExcel: async (params: any) => {
  108. return await request.download({ url: `/iot/device/export-excel`, params })
  109. },
  110. // 获取设备数量
  111. getDeviceCount: async (productId: number) => {
  112. return await request.get({ url: `/iot/device/count?productId=` + productId })
  113. },
  114. // 获取设备的精简信息列表
  115. getSimpleDeviceList: async (deviceType?: number) => {
  116. return await request.get({ url: `/iot/device/simple-list?`, params: { deviceType } })
  117. },
  118. // 获取设备属性最���数据
  119. getDevicePropertiesLatestData: async (params: any) => {
  120. return await request.get({ url: `/iot/device/data/latest`, params })
  121. },
  122. // 获取设备属性历史数据
  123. getDevicePropertiesHistoryData: async (params: any) => {
  124. return await request.get({ url: `/iot/device/data/history`, params })
  125. },
  126. // 获取导入模板
  127. importDeviceTemplate: async () => {
  128. return await request.download({ url: `/iot/device/get-import-template` })
  129. },
  130. // 模拟设备
  131. simulatorDevice: async (data: SimulatorDataVO) => {
  132. return await request.post({ url: `/iot/device/data/simulator`, data })
  133. }
  134. }