chore: 内嵌iframe高度根据表单高度调整

This commit is contained in:
dap 2024-12-18 09:57:31 +08:00
parent 129059b7a5
commit ada0a7edf6
2 changed files with 23 additions and 3 deletions

View File

@ -93,6 +93,7 @@ const currentFlowInfo = ref<FlowInfoResponse>();
*/ */
const loading = ref(false); const loading = ref(false);
const iframeLoaded = ref(false); const iframeLoaded = ref(false);
const iframeHeight = ref(300);
useEventListener('message', (event) => { useEventListener('message', (event) => {
/** /**
* iframe通信 加载完毕后才显示表单 解决卡顿问题 * iframe通信 加载完毕后才显示表单 解决卡顿问题
@ -100,6 +101,13 @@ useEventListener('message', (event) => {
if (event.data === 'mounted') { if (event.data === 'mounted') {
iframeLoaded.value = true; iframeLoaded.value = true;
} }
/**
* 高度与表单高度保持一致
*/
if (event.data.includes('height')) {
const height = event.data.split('height:')[1];
iframeHeight.value = height;
}
}); });
async function handleLoadInfo(task: TaskInfo | undefined) { async function handleLoadInfo(task: TaskInfo | undefined) {
@ -348,7 +356,8 @@ function handleReductionSignature(userList: User[]) {
<iframe <iframe
v-show="iframeLoaded" v-show="iframeLoaded"
:src="`${task.formPath}/iframe?readonly=true&id=${task.businessId}`" :src="`${task.formPath}/iframe?readonly=true&id=${task.businessId}`"
class="h-[300px] w-full" :style="{ height: `${iframeHeight}px` }"
class="w-full"
></iframe> ></iframe>
<Skeleton v-show="!iframeLoaded" :paragraph="{ rows: 6 }" active /> <Skeleton v-show="!iframeLoaded" :paragraph="{ rows: 6 }" active />
<Divider /> <Divider />

View File

@ -1,7 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import type { StartWorkFlowReqData } from '#/api/workflow/task/model'; import type { StartWorkFlowReqData } from '#/api/workflow/task/model';
import { computed, onMounted } from 'vue'; import { computed, onMounted, useTemplateRef } from 'vue';
import { useRoute, useRouter } from 'vue-router'; import { useRoute, useRouter } from 'vue-router';
import { useVbenModal } from '@vben/common-ui'; import { useVbenModal } from '@vben/common-ui';
@ -45,6 +45,7 @@ const [BasicForm, formApi] = useVbenForm({
wrapperClass: 'grid-cols-2', wrapperClass: 'grid-cols-2',
}); });
const cardRef = useTemplateRef('cardRef');
onMounted(async () => { onMounted(async () => {
// //
if (id) { if (id) {
@ -58,7 +59,17 @@ onMounted(async () => {
* 主要解决内嵌iframe卡顿的问题 * 主要解决内嵌iframe卡顿的问题
*/ */
if (readonly) { if (readonly) {
//
window.parent.postMessage('mounted', '*'); window.parent.postMessage('mounted', '*');
//
setTimeout(() => {
const el = cardRef.value?.$el as HTMLDivElement;
//
const height = el?.offsetHeight ?? 0;
if (height) {
window.parent.postMessage(`height:${height}`, '*');
}
});
} }
} }
}); });
@ -140,7 +151,7 @@ function handleComplete() {
</script> </script>
<template> <template>
<Card> <Card ref="cardRef">
<div id="leave-form"> <div id="leave-form">
<BasicForm /> <BasicForm />
<div v-if="showActionBtn" class="flex justify-end gap-2"> <div v-if="showActionBtn" class="flex justify-end gap-2">