Showing
4 changed files
with
154 additions
and
0 deletions
... | ... | @@ -21,6 +21,7 @@ enum DeviceManagerApi { |
21 | 21 | DEVICE_ALARM_URL = '/alarm', |
22 | 22 | |
23 | 23 | DEVICE_CREDENTIALS = '/device/credentials', |
24 | + COMMAND_ISSUANCE = '/rpc', | |
24 | 25 | } |
25 | 26 | |
26 | 27 | export const devicePage = (params: DeviceQueryParam) => { |
... | ... | @@ -207,3 +208,17 @@ export const generateSNCode = () => { |
207 | 208 | url: '/device/sn', |
208 | 209 | }); |
209 | 210 | }; |
211 | + | |
212 | +//命令下发 | |
213 | +export const commandIssuanceApi = (type, tbDeviceId, data) => { | |
214 | + const T = type === 'OneWay' ? 'oneway' : 'twoway'; | |
215 | + return defHttp.post( | |
216 | + { | |
217 | + url: DeviceManagerApi.COMMAND_ISSUANCE + '/' + T + '/' + tbDeviceId, | |
218 | + data, | |
219 | + }, | |
220 | + { | |
221 | + joinPrefix: false, | |
222 | + } | |
223 | + ); | |
224 | +}; | ... | ... |
... | ... | @@ -629,3 +629,45 @@ export const TokenSchemas: FormSchema[] = [ |
629 | 629 | }, |
630 | 630 | }, |
631 | 631 | ]; |
632 | + | |
633 | +export const CommandSchemas: FormSchema[] = [ | |
634 | + { | |
635 | + field: 'commandType', | |
636 | + component: 'RadioGroup', | |
637 | + label: '下发类型', | |
638 | + colProps: { | |
639 | + span: 8, | |
640 | + }, | |
641 | + defaultValue: 'OneWay', | |
642 | + componentProps: { | |
643 | + options: [ | |
644 | + { | |
645 | + label: 'OneWay', | |
646 | + value: 'OneWay', | |
647 | + }, | |
648 | + { | |
649 | + label: 'TwoWay', | |
650 | + value: 'TwoWay', | |
651 | + }, | |
652 | + ], | |
653 | + }, | |
654 | + }, | |
655 | + { | |
656 | + field: 'commandValue', | |
657 | + label: '请输入命令内容', | |
658 | + defaultValue: `{ | |
659 | + method: 'setGpio', | |
660 | + params: { | |
661 | + pin: 7, | |
662 | + value: 1 | |
663 | + } | |
664 | +}`, | |
665 | + component: 'InputTextArea', | |
666 | + componentProps: { | |
667 | + autoSize: { | |
668 | + maxRows: 10, | |
669 | + autoSize: true, | |
670 | + }, | |
671 | + }, | |
672 | + }, | |
673 | +]; | ... | ... |
... | ... | @@ -15,6 +15,9 @@ |
15 | 15 | <TabPane key="2" tab="实时数据" v-if="deviceDetail?.deviceType !== 'GATEWAY'"> |
16 | 16 | <RealTimeData :deviceDetail="deviceDetail" /> |
17 | 17 | </TabPane> |
18 | + <TabPane key="5" tab="命令下发" v-if="deviceDetail?.deviceType !== 'SENSOR'"> | |
19 | + <CommandIssuance :deviceDetail="deviceDetail" /> | |
20 | + </TabPane> | |
18 | 21 | <TabPane key="3" tab="告警"><Alarm :id="deviceDetail.id" /></TabPane> |
19 | 22 | <TabPane key="4" tab="子设备" v-if="deviceDetail?.deviceType === 'GATEWAY'"> |
20 | 23 | <ChildDevice :fromId="deviceDetail?.tbDeviceId" /> |
... | ... | @@ -31,6 +34,7 @@ |
31 | 34 | import RealTimeData from '../tabs/RealTimeData.vue'; |
32 | 35 | import Alarm from '../tabs/Alarm.vue'; |
33 | 36 | import ChildDevice from '../tabs/ChildDevice.vue'; |
37 | + import CommandIssuance from '../tabs/CommandIssuance.vue'; | |
34 | 38 | import { getDeviceDetail } from '/@/api/device/deviceManager'; |
35 | 39 | export default defineComponent({ |
36 | 40 | name: 'DeviceModal', |
... | ... | @@ -42,6 +46,7 @@ |
42 | 46 | RealTimeData, |
43 | 47 | Alarm, |
44 | 48 | ChildDevice, |
49 | + CommandIssuance, | |
45 | 50 | }, |
46 | 51 | emits: ['reload', 'register'], |
47 | 52 | setup() { | ... | ... |
1 | +<template> | |
2 | + <div class="tabs-detail"> | |
3 | + <div class="mt-4"> | |
4 | + <BasicForm @register="registerForm" /> | |
5 | + <div> | |
6 | + <Button :disabled="disable" type="primary" @click="handleOk" class="mr-2">确定</Button> | |
7 | + <Button type="default" @click="handleCancel" class="mr-2">重置</Button> | |
8 | + </div> | |
9 | + </div> | |
10 | + </div> | |
11 | +</template> | |
12 | +<script lang="ts"> | |
13 | + import { defineComponent, ref } from 'vue'; | |
14 | + import { BasicForm, useForm } from '/@/components/Form'; | |
15 | + import { CommandSchemas } from '../../config/data'; | |
16 | + import { commandIssuanceApi } from '/@/api/device/deviceManager'; | |
17 | + import { useMessage } from '/@/hooks/web/useMessage'; | |
18 | + import { Button } from '/@/components/Button'; | |
19 | + | |
20 | + export default defineComponent({ | |
21 | + components: { BasicForm, Button }, | |
22 | + props: { | |
23 | + deviceDetail: { | |
24 | + type: Object, | |
25 | + required: true, | |
26 | + }, | |
27 | + }, | |
28 | + emits: ['register'], | |
29 | + setup(props) { | |
30 | + const disable = ref(false); | |
31 | + const commandValueStr = JSON.stringify({ | |
32 | + method: 'setGpio', | |
33 | + params: { | |
34 | + pin: 7, | |
35 | + value: 1, | |
36 | + }, | |
37 | + }); | |
38 | + const [registerForm, { getFieldsValue, validate, resetFields }] = useForm({ | |
39 | + labelWidth: 100, | |
40 | + schemas: CommandSchemas, | |
41 | + labelAlign: 'right', | |
42 | + showSubmitButton: false, | |
43 | + showResetButton: false, | |
44 | + wrapperCol: { | |
45 | + span: 12, | |
46 | + }, | |
47 | + }); | |
48 | + const handleCancel = () => { | |
49 | + resetFields(); | |
50 | + }; | |
51 | + const handleOk = async () => { | |
52 | + disable.value = true; | |
53 | + const { createMessage } = useMessage(); | |
54 | + // 验证 | |
55 | + const valid = await validate(); | |
56 | + if (!valid) return; | |
57 | + // 收集表单数据 | |
58 | + const field = getFieldsValue(); | |
59 | + const commandValue = JSON.parse(commandValueStr); | |
60 | + commandValue.persistent = true; | |
61 | + commandValue.additionalInfo = { | |
62 | + cmdType: 'API', | |
63 | + }; | |
64 | + commandIssuanceApi(field.commandType, props.deviceDetail.tbDeviceId, commandValue) | |
65 | + .then((res) => { | |
66 | + if (!res) return; | |
67 | + createMessage.success('命令下发成功'); | |
68 | + disable.value = true; | |
69 | + // 请求 | |
70 | + handleCancel(); | |
71 | + }) | |
72 | + .catch((e) => { | |
73 | + if (e?.message) { | |
74 | + createMessage.error(e?.message); | |
75 | + } | |
76 | + }) | |
77 | + .finally(() => { | |
78 | + setTimeout(() => { | |
79 | + disable.value = false; | |
80 | + }, 300); | |
81 | + }); | |
82 | + }; | |
83 | + return { | |
84 | + registerForm, | |
85 | + handleCancel, | |
86 | + handleOk, | |
87 | + disable, | |
88 | + }; | |
89 | + }, | |
90 | + }); | |
91 | +</script> | |
92 | +<style lang="less" scoped></style> | ... | ... |