chore: 更改postMessage参数

This commit is contained in:
dap 2024-12-18 10:08:02 +08:00
parent ada0a7edf6
commit f56ba6ba33
2 changed files with 8 additions and 5 deletions

View File

@ -23,6 +23,7 @@ import {
TabPane,
Tabs,
} from 'ant-design-vue';
import { isObject } from 'lodash-es';
import {
cancelProcessApply,
@ -95,17 +96,19 @@ const loading = ref(false);
const iframeLoaded = ref(false);
const iframeHeight = ref(300);
useEventListener('message', (event) => {
const data = event.data as { [key: string]: any; type: string };
if (!isObject(data)) return;
/**
* iframe通信 加载完毕后才显示表单 解决卡顿问题
*/
if (event.data === 'mounted') {
if (data.type === 'mounted') {
iframeLoaded.value = true;
}
/**
* 高度与表单高度保持一致
*/
if (event.data.includes('height')) {
const height = event.data.split('height:')[1];
if (data.type === 'height') {
const height = data.height;
iframeHeight.value = height;
}
});

View File

@ -60,14 +60,14 @@ onMounted(async () => {
*/
if (readonly) {
//
window.parent.postMessage('mounted', '*');
window.parent.postMessage({ type: 'mounted' }, '*');
//
setTimeout(() => {
const el = cardRef.value?.$el as HTMLDivElement;
//
const height = el?.offsetHeight ?? 0;
if (height) {
window.parent.postMessage(`height:${height}`, '*');
window.parent.postMessage({ type: 'height', height }, '*');
}
});
}