Commit 17c070d3ded8dfaba020f56df39005bedf2d03ea

Authored by ww
1 parent cd633e31

fix: replace model of matter tsl content editor to textarea

... ... @@ -13,12 +13,6 @@
13 13 <Tabs.TabPane :key="FunctionType.SERVICE" tab="服务" />
14 14 <!-- <Tabs.TabPane :key="FunctionType.EVENTS" tab="事件" /> -->
15 15 <template #tabBarExtraContent>
16   - <Button @click="handlePremitter">
17   - <template #icon>
18   - <SortAscendingOutlined />
19   - </template>
20   - 格式化
21   - </Button>
22 16 <Button class="ml-2" @click="handleCopy">
23 17 <template #icon>
24 18 <CopyOutlined />
... ... @@ -30,24 +24,21 @@
30 24 </div>
31 25 <div class="relative">
32 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 28 </Spin>
36 29 </div>
37 30 </div>
38 31 </template>
39 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 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 37 import { FunctionType } from './config';
48 38 import useCommon from '../hook/useCommon';
49 39 import { DeviceRecord } from '/@/api/device/model/deviceModel';
50 40 import { getModelTsl } from '/@/api/device/modelOfMatter';
  41 + import { useClipboard } from '@vueuse/core';
51 42
52 43 const props = defineProps<{
53 44 record: DeviceRecord;
... ... @@ -61,40 +52,17 @@
61 52
62 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 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 58 const handleCopy = () => {
89 59 try {
90   - const valueRef = unref(jsonInstance)?.get();
91   - const value = JSON.stringify(unref(valueRef));
92   - if (!value) {
  60 + if (!jsonValue.value) {
93 61 createMessage.warning('请输入要拷贝的内容!');
94 62 return;
95 63 }
96   - clipboardRef.value = value;
97   - if (unref(copiedRef)) {
  64 + if (unref(isSupported)) {
  65 + copy();
98 66 createMessage.success('复制成功!');
99 67 }
100 68 } catch (e) {
... ... @@ -103,25 +71,18 @@
103 71 };
104 72
105 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 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 81 const handleSwitchTsl = async (functionType: FunctionType) => {
121 82 try {
122 83 loading.value = true;
123 84 const record = await getModelTsl({ deviceProfileId: props.record.id, functionType });
124   - jsonInstance.value?.set(record);
  85 + jsonValue.value = JSON.stringify(record, null, 2);
125 86 } catch (error) {
126 87 } finally {
127 88 loading.value = false;
... ... @@ -138,10 +99,3 @@
138 99 resetFormData,
139 100 });
140 101 </script>
141   -
142   -<style lang="less" scope>
143   - #jsoneditor {
144   - width: 100%;
145   - height: 450px;
146   - }
147   -</style>
... ...