Showing
1 changed file
with
40 additions
and
19 deletions
| @@ -3,7 +3,12 @@ | @@ -3,7 +3,12 @@ | ||
| 3 | <div class="mt-4"> | 3 | <div class="mt-4"> |
| 4 | <BasicForm @register="registerForm"> | 4 | <BasicForm @register="registerForm"> |
| 5 | <template #commandSlot> | 5 | <template #commandSlot> |
| 6 | - <JsonEditorVue class="editor" v-model="jsonData" @blur="jsonValidate" language="zh" /> | 6 | + <div class="flex"> |
| 7 | + <div ref="jsoneditorRef" style="height: 100%; width: 100%"></div> | ||
| 8 | + <Tooltip title='{"method":"setGpio","params":{"pin":7,"value":1}}' class="ml-2"> | ||
| 9 | + <QuestionCircleOutlined style="font-size: 1rem" /> | ||
| 10 | + </Tooltip> | ||
| 11 | + </div> | ||
| 7 | </template> | 12 | </template> |
| 8 | </BasicForm> | 13 | </BasicForm> |
| 9 | <div> | 14 | <div> |
| @@ -14,16 +19,19 @@ | @@ -14,16 +19,19 @@ | ||
| 14 | </div> | 19 | </div> |
| 15 | </template> | 20 | </template> |
| 16 | <script lang="ts"> | 21 | <script lang="ts"> |
| 17 | - import { defineComponent, ref } from 'vue'; | 22 | + import { defineComponent, ref, onMounted, unref, nextTick } from 'vue'; |
| 18 | import { BasicForm, useForm } from '/@/components/Form'; | 23 | import { BasicForm, useForm } from '/@/components/Form'; |
| 19 | import { CommandSchemas } from '../../config/data'; | 24 | import { CommandSchemas } from '../../config/data'; |
| 20 | import { commandIssuanceApi } from '/@/api/device/deviceManager'; | 25 | import { commandIssuanceApi } from '/@/api/device/deviceManager'; |
| 21 | import { useMessage } from '/@/hooks/web/useMessage'; | 26 | import { useMessage } from '/@/hooks/web/useMessage'; |
| 22 | import { Button } from '/@/components/Button'; | 27 | import { Button } from '/@/components/Button'; |
| 23 | - import JsonEditorVue from 'json-editor-vue3'; | 28 | + import jsoneditor from 'jsoneditor'; |
| 29 | + import 'jsoneditor/dist/jsoneditor.min.css'; | ||
| 30 | + import { QuestionCircleOutlined } from '@ant-design/icons-vue'; | ||
| 31 | + import { Tooltip } from 'ant-design-vue'; | ||
| 24 | 32 | ||
| 25 | export default defineComponent({ | 33 | export default defineComponent({ |
| 26 | - components: { BasicForm, Button, JsonEditorVue }, | 34 | + components: { BasicForm, Button, QuestionCircleOutlined, Tooltip }, |
| 27 | props: { | 35 | props: { |
| 28 | deviceDetail: { | 36 | deviceDetail: { |
| 29 | type: Object, | 37 | type: Object, |
| @@ -33,19 +41,7 @@ | @@ -33,19 +41,7 @@ | ||
| 33 | emits: ['register'], | 41 | emits: ['register'], |
| 34 | setup(props) { | 42 | setup(props) { |
| 35 | const { createMessage } = useMessage(); | 43 | const { createMessage } = useMessage(); |
| 36 | - const jsonData: any = ref({ | ||
| 37 | - method: 'setGpio', | ||
| 38 | - params: { | ||
| 39 | - pin: 7, | ||
| 40 | - value: 1, | ||
| 41 | - }, | ||
| 42 | - }); | ||
| 43 | - const jsonValidate = async (editor) => { | ||
| 44 | - const res = await editor.validate(); | ||
| 45 | - // res 是错误列表,如果是空数组,则表示检测没有错误 | ||
| 46 | - // console.log(res); | ||
| 47 | - if (res.length !== 0) createMessage.error('请填写正确的命令下发json数据格式'); | ||
| 48 | - }; | 44 | + const jsonData: any = ref({}); |
| 49 | const disable = ref(false); | 45 | const disable = ref(false); |
| 50 | const [registerForm, { getFieldsValue, validate, resetFields }] = useForm({ | 46 | const [registerForm, { getFieldsValue, validate, resetFields }] = useForm({ |
| 51 | labelWidth: 100, | 47 | labelWidth: 100, |
| @@ -57,6 +53,23 @@ | @@ -57,6 +53,23 @@ | ||
| 57 | span: 12, | 53 | span: 12, |
| 58 | }, | 54 | }, |
| 59 | }); | 55 | }); |
| 56 | + // json 以及初始化JSON | ||
| 57 | + const jsoneditorRef = ref(); | ||
| 58 | + const jsonValue = ref({}); | ||
| 59 | + const jsonInstance = ref(); | ||
| 60 | + onMounted(() => { | ||
| 61 | + nextTick(() => { | ||
| 62 | + let options = { | ||
| 63 | + mode: 'code', | ||
| 64 | + mainMenuBar: false, | ||
| 65 | + statusBar: false, | ||
| 66 | + }; | ||
| 67 | + let editor = new jsoneditor(jsoneditorRef.value, options); | ||
| 68 | + editor.set(jsonValue.value); | ||
| 69 | + jsonInstance.value = editor; | ||
| 70 | + }); | ||
| 71 | + }); | ||
| 72 | + | ||
| 60 | const handleCancel = () => { | 73 | const handleCancel = () => { |
| 61 | resetFields(); | 74 | resetFields(); |
| 62 | }; | 75 | }; |
| @@ -67,6 +80,7 @@ | @@ -67,6 +80,7 @@ | ||
| 67 | if (!valid) return; | 80 | if (!valid) return; |
| 68 | // 收集表单数据 | 81 | // 收集表单数据 |
| 69 | const field = getFieldsValue(); | 82 | const field = getFieldsValue(); |
| 83 | + jsonData.value = unref(jsonInstance).get(); | ||
| 70 | jsonData.value.persistent = true; | 84 | jsonData.value.persistent = true; |
| 71 | jsonData.value.additionalInfo = { | 85 | jsonData.value.additionalInfo = { |
| 72 | cmdType: 'API', | 86 | cmdType: 'API', |
| @@ -96,9 +110,16 @@ | @@ -96,9 +110,16 @@ | ||
| 96 | handleOk, | 110 | handleOk, |
| 97 | disable, | 111 | disable, |
| 98 | jsonData, | 112 | jsonData, |
| 99 | - jsonValidate, | 113 | + jsoneditorRef, |
| 114 | + jsonValue, | ||
| 115 | + jsonInstance, | ||
| 100 | }; | 116 | }; |
| 101 | }, | 117 | }, |
| 102 | }); | 118 | }); |
| 103 | </script> | 119 | </script> |
| 104 | -<style lang="less" scoped></style> | 120 | +<style scoped> |
| 121 | + .jsoneditor-transform { | ||
| 122 | + background-position: -144px -96px; | ||
| 123 | + display: none !important; | ||
| 124 | + } | ||
| 125 | +</style> |