Commit 17c070d3ded8dfaba020f56df39005bedf2d03ea

Authored by ww
1 parent cd633e31

fix: replace model of matter tsl content editor to textarea

@@ -13,12 +13,6 @@ @@ -13,12 +13,6 @@
13 <Tabs.TabPane :key="FunctionType.SERVICE" tab="服务" /> 13 <Tabs.TabPane :key="FunctionType.SERVICE" tab="服务" />
14 <!-- <Tabs.TabPane :key="FunctionType.EVENTS" tab="事件" /> --> 14 <!-- <Tabs.TabPane :key="FunctionType.EVENTS" tab="事件" /> -->
15 <template #tabBarExtraContent> 15 <template #tabBarExtraContent>
16 - <Button @click="handlePremitter">  
17 - <template #icon>  
18 - <SortAscendingOutlined />  
19 - </template>  
20 - 格式化  
21 - </Button>  
22 <Button class="ml-2" @click="handleCopy"> 16 <Button class="ml-2" @click="handleCopy">
23 <template #icon> 17 <template #icon>
24 <CopyOutlined /> 18 <CopyOutlined />
@@ -30,24 +24,21 @@ @@ -30,24 +24,21 @@
30 </div> 24 </div>
31 <div class="relative"> 25 <div class="relative">
32 <Spin :spinning="loading"> 26 <Spin :spinning="loading">
33 - <div id="jsoneditor" ref="jsoneditorEl"></div>  
34 - <div class="absolute top-0 left-0 w-full h-full"></div> 27 + <Textarea :disabled="true" :auto-size="{ minRows: 20, maxRows: 20 }" :value="jsonValue" />
35 </Spin> 28 </Spin>
36 </div> 29 </div>
37 </div> 30 </div>
38 </template> 31 </template>
39 <script lang="ts" setup> 32 <script lang="ts" setup>
40 - import { ref, unref, onMounted, nextTick } from 'vue';  
41 - import { CopyOutlined, SortAscendingOutlined } from '@ant-design/icons-vue';  
42 - import { useCopyToClipboard } from '/@/hooks/web/useCopyToClipboard'; 33 + import { ref, unref, onMounted } from 'vue';
  34 + import { CopyOutlined } from '@ant-design/icons-vue';
43 import { useMessage } from '/@/hooks/web/useMessage'; 35 import { useMessage } from '/@/hooks/web/useMessage';
44 - import jsoneditor from 'jsoneditor';  
45 - import 'jsoneditor/dist/jsoneditor.min.css';  
46 - import { Button, Typography, TypographyParagraph, Tabs, Spin } from 'ant-design-vue'; 36 + import { Button, Typography, TypographyParagraph, Tabs, Spin, Textarea } from 'ant-design-vue';
47 import { FunctionType } from './config'; 37 import { FunctionType } from './config';
48 import useCommon from '../hook/useCommon'; 38 import useCommon from '../hook/useCommon';
49 import { DeviceRecord } from '/@/api/device/model/deviceModel'; 39 import { DeviceRecord } from '/@/api/device/model/deviceModel';
50 import { getModelTsl } from '/@/api/device/modelOfMatter'; 40 import { getModelTsl } from '/@/api/device/modelOfMatter';
  41 + import { useClipboard } from '@vueuse/core';
51 42
52 const props = defineProps<{ 43 const props = defineProps<{
53 record: DeviceRecord; 44 record: DeviceRecord;
@@ -61,40 +52,17 @@ @@ -61,40 +52,17 @@
61 52
62 const jsonValue = ref(); 53 const jsonValue = ref();
63 54
64 - const jsonInstance = ref<{  
65 - set: (value?: Recordable) => void;  
66 - get: () => Recordable;  
67 - }>();  
68 -  
69 - const jsoneditorEl = ref<HTMLDivElement>();  
70 -  
71 const activeKey = ref(FunctionType.PROPERTIES); 55 const activeKey = ref(FunctionType.PROPERTIES);
72 56
73 - onMounted(() => {  
74 - nextTick(() => {  
75 - let options = {  
76 - mode: 'code',  
77 - mainMenuBar: false,  
78 - statusBar: false,  
79 - };  
80 - let editor = new jsoneditor(jsoneditorEl.value, options);  
81 - editor.set(jsonValue.value);  
82 - jsonInstance.value = editor;  
83 - });  
84 - });  
85 -  
86 - const { clipboardRef, copiedRef } = useCopyToClipboard();  
87 - 57 + const { copy, isSupported } = useClipboard({ source: jsonValue });
88 const handleCopy = () => { 58 const handleCopy = () => {
89 try { 59 try {
90 - const valueRef = unref(jsonInstance)?.get();  
91 - const value = JSON.stringify(unref(valueRef));  
92 - if (!value) { 60 + if (!jsonValue.value) {
93 createMessage.warning('请输入要拷贝的内容!'); 61 createMessage.warning('请输入要拷贝的内容!');
94 return; 62 return;
95 } 63 }
96 - clipboardRef.value = value;  
97 - if (unref(copiedRef)) { 64 + if (unref(isSupported)) {
  65 + copy();
98 createMessage.success('复制成功!'); 66 createMessage.success('复制成功!');
99 } 67 }
100 } catch (e) { 68 } catch (e) {
@@ -103,25 +71,18 @@ @@ -103,25 +71,18 @@
103 }; 71 };
104 72
105 const getFormData = () => { 73 const getFormData = () => {
106 - const value = unref(jsonInstance)?.get();  
107 - if (!value) return;  
108 - return value; 74 + return JSON.parse(jsonValue.value);
109 }; 75 };
110 76
111 const resetFormData = () => { 77 const resetFormData = () => {
112 - unref(jsonInstance)?.set();  
113 - };  
114 -  
115 - const handlePremitter = () => {  
116 - const value = unref(jsonInstance)?.get();  
117 - return unref(jsonInstance)?.set(value); 78 + jsonValue.value = null;
118 }; 79 };
119 80
120 const handleSwitchTsl = async (functionType: FunctionType) => { 81 const handleSwitchTsl = async (functionType: FunctionType) => {
121 try { 82 try {
122 loading.value = true; 83 loading.value = true;
123 const record = await getModelTsl({ deviceProfileId: props.record.id, functionType }); 84 const record = await getModelTsl({ deviceProfileId: props.record.id, functionType });
124 - jsonInstance.value?.set(record); 85 + jsonValue.value = JSON.stringify(record, null, 2);
125 } catch (error) { 86 } catch (error) {
126 } finally { 87 } finally {
127 loading.value = false; 88 loading.value = false;
@@ -138,10 +99,3 @@ @@ -138,10 +99,3 @@
138 resetFormData, 99 resetFormData,
139 }); 100 });
140 </script> 101 </script>
141 -  
142 -<style lang="less" scope>  
143 - #jsoneditor {  
144 - width: 100%;  
145 - height: 450px;  
146 - }  
147 -</style>