【功能完善】IoT: ThingModelTSL

This commit is contained in:
puhui999 2025-03-28 14:03:43 +08:00
parent 314a1c2254
commit 73d83e8a88
2 changed files with 17 additions and 13 deletions

View File

@ -1,8 +1,18 @@
<template>
<Dialog v-model="dialogVisible" :title="dialogTitle">
<el-scrollbar height="600px">
<pre><code v-dompurify-html="highlightedCode()" class="hljs"></code></pre>
</el-scrollbar>
<div class="h-600px">
<JsonEditor
v-model="thingModelTSL"
:mode="viewMode === 'editor' ? 'code' : 'view'"
height="100%"
/>
</div>
<template #footer>
<el-radio-group v-model="viewMode" size="small">
<el-radio-button label="code">代码视图</el-radio-button>
<el-radio-button label="editor">编辑器视图</el-radio-button>
</el-radio-group>
</template>
</Dialog>
</template>
@ -19,6 +29,7 @@ defineOptions({ name: 'ThingModelTSL' })
const dialogVisible = ref(false) //
const dialogTitle = ref('物模型 TSL') //
const product = inject<Ref<ProductVO>>(IOT_PROVIDE_KEY.PRODUCT) //
const viewMode = ref('code') // code-editor-
/** 打开弹窗 */
const open = () => {
@ -27,17 +38,9 @@ const open = () => {
defineExpose({ open })
/** 获取 TSL */
const thingModelTSL = ref('')
const thingModelTSL = ref({})
const getTsl = async () => {
const res = await ThingModelApi.getThingModelTSLByProductId(product?.value?.id || 0)
thingModelTSL.value = JSON.stringify(res, null, 2)
}
/** 代码高亮 */
const highlightedCode = () => {
// TODO @puhui999 highlight json editor
const result = hljs.highlight('json', thingModelTSL.value, true)
return result.value || '&nbsp;'
thingModelTSL.value = await ThingModelApi.getThingModelTSLByProductId(product?.value?.id || 0)
}
/** 初始化 **/

View File

@ -108,6 +108,7 @@
import { ThingModelApi, ThingModelData } from '@/api/iot/thingmodel'
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
import ThingModelForm from './ThingModelForm.vue'
import ThingModelTSL from './ThingModelTSL.vue'
import { ProductVO } from '@/api/iot/product/product'
import { IOT_PROVIDE_KEY } from '@/views/iot/utils/constants'
import { getDataTypeOptionsLabel } from './config'