diff --git a/src/api/demo/device.ts b/src/api/demo/device.ts new file mode 100644 index 0000000..8941fa4 --- /dev/null +++ b/src/api/demo/device.ts @@ -0,0 +1,11 @@ +import { defHttp } from '@/utils/http/axios'; +enum Api { + GetDataList = '/api/Manage/GetDataList', +} + +export function GetDataList(params) { + return defHttp.get({ + url: Api.GetDataList, + params + }); +} \ No newline at end of file diff --git a/src/utils/debugging/events.ts b/src/utils/debugging/events.ts index 696285d..d1ff28f 100644 --- a/src/utils/debugging/events.ts +++ b/src/utils/debugging/events.ts @@ -1,5 +1,15 @@ import { clientReizePublish, clientReizeSubscribe } from '@/utils/mqtt'; +export const return_home_status = { + canceled: '取消或终止', + failed: '失败', + in_progress: '执行中', + ok: '执行成功', + paused: '暂停', + rejected: '拒绝', + sent: '已下发', + timeout: '超时', +}; export const eventsTopic = (data) => { // 发送消息 clientReizePublish('thing/product/8UUXN5400A079H/events', data); diff --git a/src/utils/debugging/remote.ts b/src/utils/debugging/remote.ts index 6a27985..2340c06 100644 --- a/src/utils/debugging/remote.ts +++ b/src/utils/debugging/remote.ts @@ -29,3 +29,12 @@ export const services_replyTopic = () => { // 订阅消息 clientSubscribe('thing/product/8UUXN5400A079H/services_reply'); }; +// 无人机 +export const servicesUAVTopic = (data) => { + // 发送消息 + clientPublish('thing/product/1581F8HGX254V00A0BUY/services', data); +}; +export const services_replyUAVTopic = () => { + // 订阅消息 + clientSubscribe('thing/product/1581F8HGX254V00A0BUY/services_reply'); +}; diff --git a/src/utils/mqtt.ts b/src/utils/mqtt.ts index 5b704a7..324899a 100644 --- a/src/utils/mqtt.ts +++ b/src/utils/mqtt.ts @@ -13,7 +13,7 @@ const connection = { connectTimeout: 30 * 1000, // ms reconnectPeriod: 4000, // ms // clientId: 'mqttx_' + Math.random().toString(16).substring(2, 8), - clientId: 'mqtt_client_1581F8HGX254V00A0BUY', + clientId: `mqtt_${Math.random().toString(16).slice(2)}`, // auth username: 'sdhc', password: '', @@ -43,11 +43,23 @@ const handleOnReConnect = () => { } }; // 创建连接函数 -const createConnection = () => { +const createConnection = (callback?) => { try { const { protocol, host, port, endpoint, ...options } = connection; const connectUrl = `${protocol}://${host}:${port}${endpoint}`; client = mqtt.connect(connectUrl, options); + client.on('connect', () => { + console.log('✅ 已连接'); + if(callback){ + callback() + } + }); + client.on('close', () => { + console.log('❌ 连接已关闭'); + }); + client.on('error', (err) => { + console.error('❌ 出错了:', err); + }); if (client.on) { } } catch (error) { @@ -95,6 +107,14 @@ const clientPublish = (topic: string, querys: any) => { } }); }; +// 获取连接状态 +const getConnectStatus = () => { + console.log('client',client) + if (!client.connected) { + return false + } + return true +} // on 事件 // connect 连接 // reconnect 重新连接 @@ -162,4 +182,5 @@ export { getReizeClient, clientReizeSubscribe, clientReizePublish, + getConnectStatus, }; diff --git a/src/utils/uuid.ts b/src/utils/uuid.ts index 934b9f0..39eeaf5 100644 --- a/src/utils/uuid.ts +++ b/src/utils/uuid.ts @@ -40,3 +40,32 @@ export function buildShortUUID(prefix = ''): string { unique++; return prefix + '_' + random + unique + String(time); } +export function uuid(len, radix) { + const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split(''); + let uuid = [], + i; + radix = radix || chars.length; + + if (len) { + // Compact form + for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)]; + } else { + // rfc4122, version 4 form + let r; + + // rfc4122 requires these characters + uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'; + uuid[14] = '4'; + + // Fill in random data. At i==19 set the high bits of clock sequence as + // per rfc4122, sec. 4.1.5 + for (i = 0; i < 36; i++) { + if (!uuid[i]) { + r = 0 | (Math.random() * 16); + uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r]; + } + } + } + + return uuid.join(''); +} diff --git a/src/views/demo/workmanagement/device/Airport/index.vue b/src/views/demo/workmanagement/device/Airport/index.vue index defc52f..8d07b91 100644 --- a/src/views/demo/workmanagement/device/Airport/index.vue +++ b/src/views/demo/workmanagement/device/Airport/index.vue @@ -1,16 +1,29 @@