|
@@ -0,0 +1,124 @@
|
|
|
+<script setup lang="ts">
|
|
|
+import { computed, onMounted, onUnmounted, ref, useTemplateRef, watch } from 'vue';
|
|
|
+import qs from 'qs';
|
|
|
+
|
|
|
+import { useViewVisible } from '@/hooks/view-visible';
|
|
|
+
|
|
|
+import { getVisual2DMsgType, visual2DEditorPageUrl, Visual2DMsgType } from '.';
|
|
|
+
|
|
|
+import type { AllDevicesList, GroupModuleInfo, IframeMsg } from '@/types';
|
|
|
+
|
|
|
+interface Props {
|
|
|
+ info: GroupModuleInfo;
|
|
|
+ deviceList?: AllDevicesList[];
|
|
|
+}
|
|
|
+
|
|
|
+const props = defineProps<Props>();
|
|
|
+
|
|
|
+const { visible, showView, hideView } = useViewVisible();
|
|
|
+const iframeRef = useTemplateRef('editorIframe');
|
|
|
+const isIframeLoaded = ref(false);
|
|
|
+
|
|
|
+const iframeUrl = computed(() => {
|
|
|
+ const { leId, moduleType } = props.info;
|
|
|
+
|
|
|
+ return `${visual2DEditorPageUrl}?${qs.stringify({
|
|
|
+ id: leId,
|
|
|
+ moduleType,
|
|
|
+ })}`;
|
|
|
+});
|
|
|
+
|
|
|
+onMounted(() => {
|
|
|
+ window.addEventListener('message', handleIframeMsg);
|
|
|
+});
|
|
|
+
|
|
|
+onUnmounted(() => {
|
|
|
+ window.removeEventListener('message', handleIframeMsg);
|
|
|
+});
|
|
|
+
|
|
|
+watch(visible, () => {
|
|
|
+ if (visible.value && isIframeLoaded.value) {
|
|
|
+ // 刷新画布
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
+const handleIframeMsg = (e: MessageEvent<IframeMsg>) => {
|
|
|
+ const { msgType } = e.data;
|
|
|
+
|
|
|
+ if (msgType === getVisual2DMsgType(Visual2DMsgType.EditLoaded)) {
|
|
|
+ isIframeLoaded.value = true;
|
|
|
+ sendDeviceData();
|
|
|
+ } else if (msgType === getVisual2DMsgType(Visual2DMsgType.CloseEditor)) {
|
|
|
+ hideView();
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const sendDeviceData = () => {
|
|
|
+ if (props.deviceList) {
|
|
|
+ const msg: IframeMsg = {
|
|
|
+ msgType: getVisual2DMsgType(Visual2DMsgType.SendDeviceData),
|
|
|
+ ...JSON.parse(JSON.stringify(props.deviceList)),
|
|
|
+ };
|
|
|
+
|
|
|
+ iframeRef.value?.contentWindow?.postMessage(msg, '*');
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+defineExpose({
|
|
|
+ showView,
|
|
|
+ hideView,
|
|
|
+});
|
|
|
+</script>
|
|
|
+
|
|
|
+<template>
|
|
|
+ <AModal
|
|
|
+ v-model:open="visible"
|
|
|
+ wrap-class-name="visual-2d-editor-modal"
|
|
|
+ width="100%"
|
|
|
+ centered
|
|
|
+ :closable="false"
|
|
|
+ :mask-closable="false"
|
|
|
+ :footer="null"
|
|
|
+ >
|
|
|
+ <iframe ref="editorIframe" :src="iframeUrl"></iframe>
|
|
|
+ <ASpin v-if="!isIframeLoaded" class="center-loading visual-2d-editor-loading" :spinning="true" />
|
|
|
+ </AModal>
|
|
|
+</template>
|
|
|
+
|
|
|
+<style lang="scss">
|
|
|
+.visual-2d-editor-modal {
|
|
|
+ padding: 32px;
|
|
|
+
|
|
|
+ .ant-modal {
|
|
|
+ max-width: 1700px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .ant-modal,
|
|
|
+ .ant-modal > div,
|
|
|
+ .ant-modal-content {
|
|
|
+ height: 812px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .ant-modal-content {
|
|
|
+ padding: 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ .ant-modal-body,
|
|
|
+ iframe {
|
|
|
+ width: 100%;
|
|
|
+ height: 100%;
|
|
|
+ }
|
|
|
+
|
|
|
+ iframe {
|
|
|
+ overflow: hidden;
|
|
|
+ background: transparent;
|
|
|
+ border: none;
|
|
|
+ border-radius: 8px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .visual-2d-editor-loading {
|
|
|
+ background-color: #fff;
|
|
|
+ border-radius: 8px;
|
|
|
+ }
|
|
|
+}
|
|
|
+</style>
|