Skip to content

重新打开已保存的画面 ​

设计人员保存的泵站画面可以交给两种用户。再次打开编辑器,可以移动设备和修改绑定;在值班页面打开预览,同一张图即可显示实时数据。两端读取同一份画面 JSON。

加载编辑器数据 ​

在宿主组件中接收 @on-save-click 的第一个参数,将它保存到业务系统。下例把从业务系统取回的画面作为 scene 属性传入;点击“重新载入”会以保存的版本替换当前设计。

vue
<script setup lang="ts">
import { ref } from 'vue';
import { MtEdit, type IExportJson } from 'maotu';
import 'maotu/dist/style.css';

const props = defineProps<{ scene: IExportJson }>();
const editor = ref<InstanceType<typeof MtEdit>>();
</script>

<template>
  <button @click="editor?.setImportJson(props.scene)">重新载入</button>
  <div style="height: 80vh"><MtEdit ref="editor" /></div>
</template>

首次进入即载入时,可在数据就绪且编辑器挂载后调用同一方法。

加载预览数据 ​

首次进入监控页面,传入 exportJson;在同一预览实例中切换画面,调用 setImportJson(nextScene)。预览会清理上一幅画面的内置数据源,再使用新配置。

vue
<script setup lang="ts">
import { MtPreview, type IExportJson } from 'maotu';
defineProps<{ scene: IExportJson }>();
</script>

<template>
  <div style="height: 80vh"><MtPreview :export-json="scene" fit="contain" /></div>
</template>

导出文件会带上已用的声明式 SVG 定义。若画面使用自己的 Vue 组件,请在运行它的应用里注册这些组件。旧画面在导入时按版本迁移。画面保存格式与迁移