Commit 3288bccc81b0f23f479d0b8930758d3da479534f
1 parent
00f647d4
feat:pc端 设备新增命令下发和引入json-editor-vue3
Showing
3 changed files
with
23 additions
and
22 deletions
| @@ -48,6 +48,7 @@ | @@ -48,6 +48,7 @@ | ||
| 48 | "echarts": "^5.1.2", | 48 | "echarts": "^5.1.2", |
| 49 | "hls.js": "^1.0.10", | 49 | "hls.js": "^1.0.10", |
| 50 | "intro.js": "^4.1.0", | 50 | "intro.js": "^4.1.0", |
| 51 | + "json-editor-vue3": "^1.0.6", | ||
| 51 | "jsoneditor": "^9.7.2", | 52 | "jsoneditor": "^9.7.2", |
| 52 | "jwt-decode": "^3.1.2", | 53 | "jwt-decode": "^3.1.2", |
| 53 | "lodash-es": "^4.17.21", | 54 | "lodash-es": "^4.17.21", |
| @@ -655,19 +655,7 @@ export const CommandSchemas: FormSchema[] = [ | @@ -655,19 +655,7 @@ export const CommandSchemas: FormSchema[] = [ | ||
| 655 | { | 655 | { |
| 656 | field: 'commandValue', | 656 | field: 'commandValue', |
| 657 | label: '请输入命令内容', | 657 | label: '请输入命令内容', |
| 658 | - defaultValue: `{ | ||
| 659 | - method: 'setGpio', | ||
| 660 | - params: { | ||
| 661 | - pin: 7, | ||
| 662 | - value: 1 | ||
| 663 | - } | ||
| 664 | -}`, | 658 | + slot: 'commandSlot', |
| 665 | component: 'InputTextArea', | 659 | component: 'InputTextArea', |
| 666 | - componentProps: { | ||
| 667 | - autoSize: { | ||
| 668 | - maxRows: 10, | ||
| 669 | - autoSize: true, | ||
| 670 | - }, | ||
| 671 | - }, | ||
| 672 | }, | 660 | }, |
| 673 | ]; | 661 | ]; |
| 1 | <template> | 1 | <template> |
| 2 | <div class="tabs-detail"> | 2 | <div class="tabs-detail"> |
| 3 | <div class="mt-4"> | 3 | <div class="mt-4"> |
| 4 | - <BasicForm @register="registerForm" /> | 4 | + <BasicForm @register="registerForm"> |
| 5 | + <template #commandSlot> | ||
| 6 | + <JsonEditorVue class="editor" v-model="jsonData" @blur="jsonValidate" /> | ||
| 7 | + </template> | ||
| 8 | + </BasicForm> | ||
| 5 | <div> | 9 | <div> |
| 6 | <Button :disabled="disable" type="primary" @click="handleOk" class="mr-2">确定</Button> | 10 | <Button :disabled="disable" type="primary" @click="handleOk" class="mr-2">确定</Button> |
| 7 | <Button type="default" @click="handleCancel" class="mr-2">重置</Button> | 11 | <Button type="default" @click="handleCancel" class="mr-2">重置</Button> |
| @@ -16,9 +20,10 @@ | @@ -16,9 +20,10 @@ | ||
| 16 | import { commandIssuanceApi } from '/@/api/device/deviceManager'; | 20 | import { commandIssuanceApi } from '/@/api/device/deviceManager'; |
| 17 | import { useMessage } from '/@/hooks/web/useMessage'; | 21 | import { useMessage } from '/@/hooks/web/useMessage'; |
| 18 | import { Button } from '/@/components/Button'; | 22 | import { Button } from '/@/components/Button'; |
| 23 | + import JsonEditorVue from 'json-editor-vue3'; | ||
| 19 | 24 | ||
| 20 | export default defineComponent({ | 25 | export default defineComponent({ |
| 21 | - components: { BasicForm, Button }, | 26 | + components: { BasicForm, Button, JsonEditorVue }, |
| 22 | props: { | 27 | props: { |
| 23 | deviceDetail: { | 28 | deviceDetail: { |
| 24 | type: Object, | 29 | type: Object, |
| @@ -27,14 +32,21 @@ | @@ -27,14 +32,21 @@ | ||
| 27 | }, | 32 | }, |
| 28 | emits: ['register'], | 33 | emits: ['register'], |
| 29 | setup(props) { | 34 | setup(props) { |
| 30 | - const disable = ref(false); | ||
| 31 | - const commandValueStr = JSON.stringify({ | 35 | + const { createMessage } = useMessage(); |
| 36 | + const jsonData: any = ref({ | ||
| 32 | method: 'setGpio', | 37 | method: 'setGpio', |
| 33 | params: { | 38 | params: { |
| 34 | pin: 7, | 39 | pin: 7, |
| 35 | value: 1, | 40 | value: 1, |
| 36 | }, | 41 | }, |
| 37 | }); | 42 | }); |
| 43 | + const jsonValidate = async (editor) => { | ||
| 44 | + const res = await editor.validate(); | ||
| 45 | + // res 是错误列表,如果是空数组,则表示检测没有错误 | ||
| 46 | + console.log(res); | ||
| 47 | + if (res.length !== 0) return createMessage.error('请填写正确的命令下发json数据格式'); | ||
| 48 | + }; | ||
| 49 | + const disable = ref(false); | ||
| 38 | const [registerForm, { getFieldsValue, validate, resetFields }] = useForm({ | 50 | const [registerForm, { getFieldsValue, validate, resetFields }] = useForm({ |
| 39 | labelWidth: 100, | 51 | labelWidth: 100, |
| 40 | schemas: CommandSchemas, | 52 | schemas: CommandSchemas, |
| @@ -50,18 +62,16 @@ | @@ -50,18 +62,16 @@ | ||
| 50 | }; | 62 | }; |
| 51 | const handleOk = async () => { | 63 | const handleOk = async () => { |
| 52 | disable.value = true; | 64 | disable.value = true; |
| 53 | - const { createMessage } = useMessage(); | ||
| 54 | // 验证 | 65 | // 验证 |
| 55 | const valid = await validate(); | 66 | const valid = await validate(); |
| 56 | if (!valid) return; | 67 | if (!valid) return; |
| 57 | // 收集表单数据 | 68 | // 收集表单数据 |
| 58 | const field = getFieldsValue(); | 69 | const field = getFieldsValue(); |
| 59 | - const commandValue = JSON.parse(commandValueStr); | ||
| 60 | - commandValue.persistent = true; | ||
| 61 | - commandValue.additionalInfo = { | 70 | + jsonData.value.persistent = true; |
| 71 | + jsonData.value.additionalInfo = { | ||
| 62 | cmdType: 'API', | 72 | cmdType: 'API', |
| 63 | }; | 73 | }; |
| 64 | - commandIssuanceApi(field.commandType, props.deviceDetail.tbDeviceId, commandValue) | 74 | + commandIssuanceApi(field.commandType, props.deviceDetail.tbDeviceId, jsonData.value) |
| 65 | .then((res) => { | 75 | .then((res) => { |
| 66 | if (!res) return; | 76 | if (!res) return; |
| 67 | createMessage.success('命令下发成功'); | 77 | createMessage.success('命令下发成功'); |
| @@ -85,6 +95,8 @@ | @@ -85,6 +95,8 @@ | ||
| 85 | handleCancel, | 95 | handleCancel, |
| 86 | handleOk, | 96 | handleOk, |
| 87 | disable, | 97 | disable, |
| 98 | + jsonData, | ||
| 99 | + jsonValidate, | ||
| 88 | }; | 100 | }; |
| 89 | }, | 101 | }, |
| 90 | }); | 102 | }); |