diff --git a/src/api/device.ts b/src/api/device.ts index 8eecd47..69d250a 100644 --- a/src/api/device.ts +++ b/src/api/device.ts @@ -13,6 +13,10 @@ export interface DeviceRecord { longitude?: number; latitude?: number; icon?: string; + hardwareVersion?: string; + firmwareVersion?: string; + productName?: string; + id?: number; } export interface DeviceCreateRecord { @@ -108,10 +112,15 @@ export function triggerEvent(data: DeviceEventRecord) { // 下发命令 export function sendCommand(data: any) { + const { deviceId, qos, ...rest } = data; return axios({ url: `/api/rest/device/send`, method: 'post', - data, + params: { + deviceId, + qos, + }, + data: rest, }); } diff --git a/src/views/iot/device/components/device-detail.vue b/src/views/iot/device/components/device-detail.vue index 4583dcb..2d99c4b 100644 --- a/src/views/iot/device/components/device-detail.vue +++ b/src/views/iot/device/components/device-detail.vue @@ -78,7 +78,7 @@ status="success" @click="openServeForm(record)" > - 执行 + 执行 @@ -90,7 +90,7 @@ import dayjs from 'dayjs'; import { useRoute } from 'vue-router'; - import { onMounted, ref } from 'vue'; + import { onMounted, reactive, ref } from 'vue'; import { Message } from '@arco-design/web-vue'; import { queryDeviceDetail, queryDeviceRecord, sendCommand } from '@/api/device'; import { queryServeDetail, queryServeList } from '@/api/tsl'; @@ -174,6 +174,7 @@ ]; const activeKey = ref('1'); const renderData = ref({ + deviceId: 0, clientId: 1, productId: 1 }); @@ -200,6 +201,7 @@ activeKey.value = e; }; const dynamicFormData = ref(); + const formRef = ref(); // 关闭 const handleCancel = async () => { setVisible(false); @@ -211,21 +213,35 @@ fields.value = res.data.inputs; }; - const handleFormDataUpdate = (newFormData) => { + const handleFormDataUpdate = (newFormData: any) => { dynamicFormData.value = newFormData; // 更新 formData }; // 确定 const handleSubmit = async () => { - const res = await sendCommand(dynamicFormData.value); - if (res.status === 200) { - Message.success({ - content: '执行成功', - duration: 5 * 1000, - }); - setVisible(false); - } else { + try { + const { qos, ...rest } = dynamicFormData.value; + const params = { + deviceId: id, + qos, + paras: rest, + }; + console.log(params); + const res = await sendCommand(params); + if (res.status === 200) { + Message.success({ + content: '执行成功', + duration: 5 * 1000, + }); + setVisible(false); + } else { + Message.error({ + content: '执行失败', + duration: 5 * 1000, + }); + } + } catch (error) { Message.error({ - content: '执行失败', + content: '表单不能为空', duration: 5 * 1000, }); } diff --git a/src/views/iot/device/components/device-edit.vue b/src/views/iot/device/components/device-edit.vue index 97a3956..0524729 100644 --- a/src/views/iot/device/components/device-edit.vue +++ b/src/views/iot/device/components/device-edit.vue @@ -122,7 +122,7 @@ style="width: 140px" /> diff --git a/src/views/iot/device/components/dynamic-form.vue b/src/views/iot/device/components/dynamic-form.vue index fda01a6..166b288 100644 --- a/src/views/iot/device/components/dynamic-form.vue +++ b/src/views/iot/device/components/dynamic-form.vue @@ -1,10 +1,22 @@