| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- import {
- addDevice, addSubDevice, delDevice, delDeviceMul, delDeviceTag,
- getDeviceById, getDeviceCount, getDeviceList, getDeviceMsgList, addDeviceMsg, getDeviceTag,
- getSubDeviceList, updateDeviceLabel, addDeviceCmd, getDeviceCmdList, addDeviceTag, addDeviceGroup,
- listDeviceGroup, postGroupBindDevice, delGroupBindDevice, getDeviceByGroup
- } from '@/api/iot/device'
- import { DeviceMsgEnum } from '@/enum/common'
- import { message } from 'ant-design-vue'
- export class DeviceContriller {
- static deviceStatus = [
- { name: '初始化', key: 'INIT' },
- { name: '链接中', key: 'CONNECT' },
- { name: '断开链接', key: 'DISCONNECT' },
- { name: '禁止连接', key: 'DISABLED' }
- ]
- static transDeviceCountMap = new Map([
- ['TOTAL', { label: '总数', color: 'green' }],
- ['DISABLED', { label: '禁用数', color: 'grey' }],
- ['INIT', { label: '初始化状态数', color: 'orange' }],
- ['CONNECT', { label: '连接数', color: 'skyblue' }],
- ['DISCONNECT', { label: '断开连接数', color: 'red' }]
- ])
- static deviceStatusMap = new Map([
- ['INIT', { color: 'cyan', name: '初始化', key: 'INIT' }],
- ['CONNECT', { color: '#87d068', name: '链接中', key: 'CONNECT' }],
- ['DISCONNECT', { color: '#f50', name: '断开链接', key: 'DISCONNECT' }],
- ['DISABLED', { color: 'grey', name: '禁止连接', key: 'DISABLED' }]
- ])
- static deviceMag = new Map([
- [DeviceMsgEnum.QUEUED, { name: '队列中', key: DeviceMsgEnum.QUEUED }],
- [DeviceMsgEnum.SENT, { name: '已发送', key: DeviceMsgEnum.SENT }],
- [DeviceMsgEnum.DELIVERED, { name: '设备收到', key: DeviceMsgEnum.DELIVERED }],
- [DeviceMsgEnum.TIMEOUT, { name: '超时', key: DeviceMsgEnum.TIMEOUT }],
- [DeviceMsgEnum.FAILED, { name: '失败', key: DeviceMsgEnum.FAILED }]
- ])
- static searchKeyList = [
- { name: '设备ID', key: 'deviceId' },
- { name: '设备标识码', key: 'deviceCode' },
- { name: '设备名称', key: 'deviceLabel' }
- ]
- static async page (params: IOT.API.DEVICE.QueryPamars) {
- const { data: _data, sum } = await getDeviceList(params)
- const data = _data.map(item => {
- return {
- ...item,
- deviceStatus: DeviceContriller.deviceStatusMap.get(item.deviceStatus)
- }
- })
- return {
- data,
- sum
- }
- }
- static async post (data: IOT.API.DEVICE.BodyParams) {
- await addDevice(data)
- message.success('新增成功')
- }
- static async del (id: string | string[]) {
- if (typeof id === 'string') {
- await delDevice(id)
- } else {
- await delDeviceMul(id)
- }
- message.success('删除成功')
- }
- static async byId (id: string) {
- const { data } = await getDeviceById(id)
- return data
- }
- /** 分页获取子设备列表 */
- 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 ListTag (params: {deviceId: number | string}) {
- return await getDeviceTag(params)
- }
- static async delTag (id: string) {
- await delDeviceTag(id)
- message.success('删除标签成功')
- }
- static async postTag (data: IOT.API.DEVICE.DeviceTag[]) {
- await addDeviceTag(data)
- message.success('新增标签成功')
- }
- static async updateLabel (data: {id: string, deviceLabel: string}) {
- await updateDeviceLabel(data)
- message.success('修改设备名称成功')
- }
- /** 设备统计 */
- static async statistics (params: {modelId: string}) {
- const { data } = await getDeviceCount(params)
- return Object.keys(data).map((key) => {
- return {
- key: key,
- label: DeviceContriller.transDeviceCountMap.get(key)?.label,
- color: DeviceContriller.transDeviceCountMap.get(key)?.color,
- value: data[key as keyof typeof data]
- }
- })
- }
- /** 消息下发 获取列表 */
- static async listDeviceMsg (params: {deviceId: string}) {
- const { data } = await getDeviceMsgList(params)
- return data
- }
- /** 消息下发 下发消息 */
- static async addDeviceMsg (data: {deviceId: string, msgPayload: string, msgLabel: string, topic: string}) {
- await addDeviceMsg(data)
- message.success('新增下发消息成功')
- }
- /** 命令下发 获取列表 */
- static async listDeviceCmd (params: {deviceId: string}) {
- const { data } = await getDeviceCmdList(params)
- return data
- }
- /** 命令下发 新增命令 */
- static async addDeviceCmd (data: { deviceId: string, cmdLabel: string, cmdParameters: any}) {
- await addDeviceCmd(data)
- message.success('新增命令成功')
- }
- /** 设备分组 新增分组 */
- static async postDeviceGroup (data: { groupLabel: string, upperGroupId: string }) {
- await addDeviceGroup(data)
- message.success('新增分组成功')
- }
- /** 设备分组 查询分组 */
- static async listDeviceGroup (params: { upperGroupId: string }) {
- return await listDeviceGroup(params)
- }
- /** 设备分组 设备绑定分组 */
- static async postGroupBindDevice (data: { deviceGroupId: string, deviceId: string }[]) {
- await postGroupBindDevice(data)
- message.success('绑定成功')
- }
- /**
- * 此函数删除设备和设备组之间的绑定并显示成功消息。
- * @param data - 参数 `data` 是一个包含两个属性的对象:
- */
- static async delGroupBindDevice (data: { deviceGroupId: string, deviceId: string }[]) {
- await delGroupBindDevice(data)
- message.success('取消绑定成功')
- }
- /**
- * 此函数根据 TypeScript 中的组查询参数检索设备。
- * @param params -
- * 参数“params”的类型为“IOT.API.DEVICE.GroupQueryParams”,这可能是代码库中定义的接口或类型。它用作函数“getDeviceByGroup”的参数,该函数使用“await”关键字调用以生成函数
- * @returns 正在使用 params 参数调用 getDeviceByGroup 函数,并使用 return
- * 关键字返回该函数调用的结果。该函数被标记为“async”,因此它将返回一个解析为“getDeviceByGroup”函数调用结果的承诺。
- */
- static async getDeviceByGroup (params: IOT.API.DEVICE.GroupQueryParams) {
- return await getDeviceByGroup(params)
- }
- }
|