Showing
1 changed file
with
40 additions
and
19 deletions
... | ... | @@ -3,7 +3,12 @@ |
3 | 3 | <div class="mt-4"> |
4 | 4 | <BasicForm @register="registerForm"> |
5 | 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 | 12 | </template> |
8 | 13 | </BasicForm> |
9 | 14 | <div> |
... | ... | @@ -14,16 +19,19 @@ |
14 | 19 | </div> |
15 | 20 | </template> |
16 | 21 | <script lang="ts"> |
17 | - import { defineComponent, ref } from 'vue'; | |
22 | + import { defineComponent, ref, onMounted, unref, nextTick } from 'vue'; | |
18 | 23 | import { BasicForm, useForm } from '/@/components/Form'; |
19 | 24 | import { CommandSchemas } from '../../config/data'; |
20 | 25 | import { commandIssuanceApi } from '/@/api/device/deviceManager'; |
21 | 26 | import { useMessage } from '/@/hooks/web/useMessage'; |
22 | 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 | 33 | export default defineComponent({ |
26 | - components: { BasicForm, Button, JsonEditorVue }, | |
34 | + components: { BasicForm, Button, QuestionCircleOutlined, Tooltip }, | |
27 | 35 | props: { |
28 | 36 | deviceDetail: { |
29 | 37 | type: Object, |
... | ... | @@ -33,19 +41,7 @@ |
33 | 41 | emits: ['register'], |
34 | 42 | setup(props) { |
35 | 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 | 45 | const disable = ref(false); |
50 | 46 | const [registerForm, { getFieldsValue, validate, resetFields }] = useForm({ |
51 | 47 | labelWidth: 100, |
... | ... | @@ -57,6 +53,23 @@ |
57 | 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 | 73 | const handleCancel = () => { |
61 | 74 | resetFields(); |
62 | 75 | }; |
... | ... | @@ -67,6 +80,7 @@ |
67 | 80 | if (!valid) return; |
68 | 81 | // 收集表单数据 |
69 | 82 | const field = getFieldsValue(); |
83 | + jsonData.value = unref(jsonInstance).get(); | |
70 | 84 | jsonData.value.persistent = true; |
71 | 85 | jsonData.value.additionalInfo = { |
72 | 86 | cmdType: 'API', |
... | ... | @@ -96,9 +110,16 @@ |
96 | 110 | handleOk, |
97 | 111 | disable, |
98 | 112 | jsonData, |
99 | - jsonValidate, | |
113 | + jsoneditorRef, | |
114 | + jsonValue, | |
115 | + jsonInstance, | |
100 | 116 | }; |
101 | 117 | }, |
102 | 118 | }); |
103 | 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> | ... | ... |