2025-10-10 20:26:17 +08:00
|
|
|
|
<script setup lang="ts">
|
2025-10-13 10:17:19 +08:00
|
|
|
|
import type { Ref } from 'vue';
|
|
|
|
|
|
|
2025-10-13 10:41:08 +08:00
|
|
|
|
import type { IotProductApi } from '#/api/iot/product/product';
|
2025-10-13 10:17:19 +08:00
|
|
|
|
|
|
|
|
|
|
import { inject, onMounted, ref } from 'vue';
|
|
|
|
|
|
|
2025-10-13 10:41:08 +08:00
|
|
|
|
import { Modal, Radio } from 'ant-design-vue';
|
2025-10-10 20:26:17 +08:00
|
|
|
|
import hljs from 'highlight.js'; // 导入代码高亮文件
|
|
|
|
|
|
import json from 'highlight.js/lib/languages/json';
|
|
|
|
|
|
|
2025-10-13 10:17:19 +08:00
|
|
|
|
import { getThingModelListByProductId } from '#/api/iot/thingmodel';
|
2025-10-10 20:26:17 +08:00
|
|
|
|
import { IOT_PROVIDE_KEY } from '#/views/iot/utils/constants';
|
|
|
|
|
|
|
|
|
|
|
|
import 'highlight.js/styles/github.css'; // 导入代码高亮样式
|
|
|
|
|
|
|
|
|
|
|
|
defineOptions({ name: 'ThingModelTSL' });
|
|
|
|
|
|
|
|
|
|
|
|
const dialogVisible = ref(false); // 弹窗的是否展示
|
|
|
|
|
|
const dialogTitle = ref('物模型 TSL'); // 弹窗的标题
|
2025-10-13 10:41:08 +08:00
|
|
|
|
const product = inject<Ref<IotProductApi.Product>>(IOT_PROVIDE_KEY.PRODUCT); // 注入产品信息
|
2025-10-10 20:26:17 +08:00
|
|
|
|
const viewMode = ref('code'); // 查看模式:code-代码视图,editor-编辑器视图
|
|
|
|
|
|
|
|
|
|
|
|
/** 打开弹窗 */
|
2025-10-13 10:17:19 +08:00
|
|
|
|
function open() {
|
2025-10-10 20:26:17 +08:00
|
|
|
|
dialogVisible.value = true;
|
2025-10-13 10:17:19 +08:00
|
|
|
|
}
|
2025-10-10 20:26:17 +08:00
|
|
|
|
defineExpose({ open });
|
|
|
|
|
|
|
|
|
|
|
|
/** 获取 TSL */
|
|
|
|
|
|
const thingModelTSL = ref({});
|
2025-10-13 10:17:19 +08:00
|
|
|
|
async function getTsl() {
|
|
|
|
|
|
thingModelTSL.value = await getThingModelListByProductId(
|
2025-10-10 20:26:17 +08:00
|
|
|
|
product?.value?.id || 0,
|
|
|
|
|
|
);
|
2025-10-13 10:17:19 +08:00
|
|
|
|
}
|
2025-10-10 20:26:17 +08:00
|
|
|
|
|
|
|
|
|
|
/** 初始化 */
|
|
|
|
|
|
onMounted(async () => {
|
|
|
|
|
|
// 注册代码高亮的各种语言
|
|
|
|
|
|
hljs.registerLanguage('json', json);
|
|
|
|
|
|
await getTsl();
|
|
|
|
|
|
});
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
2025-10-07 19:58:59 +08:00
|
|
|
|
<template>
|
2025-10-13 10:41:08 +08:00
|
|
|
|
<Modal v-model="dialogVisible" :title="dialogTitle">
|
2025-10-07 19:58:59 +08:00
|
|
|
|
<JsonEditor
|
|
|
|
|
|
v-model="thingModelTSL"
|
|
|
|
|
|
:mode="viewMode === 'editor' ? 'code' : 'view'"
|
|
|
|
|
|
height="600px"
|
|
|
|
|
|
/>
|
|
|
|
|
|
<template #footer>
|
2025-10-13 10:41:08 +08:00
|
|
|
|
<Radio.Group v-model="viewMode" size="small">
|
|
|
|
|
|
<Radio.Button label="code">代码视图</Radio.Button>
|
|
|
|
|
|
<Radio.Button label="editor">编辑器视图</Radio.Button>
|
|
|
|
|
|
</Radio.Group>
|
2025-10-07 19:58:59 +08:00
|
|
|
|
</template>
|
2025-10-13 10:41:08 +08:00
|
|
|
|
</Modal>
|
2025-10-07 19:58:59 +08:00
|
|
|
|
</template>
|