mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-24 18:40:22 +08:00
fix: fix iframe heigth error (#1012)
This commit is contained in:
parent
2fd0fd281e
commit
d76cfd7f80
@ -1,21 +1,25 @@
|
|||||||
<template>
|
<template>
|
||||||
<div :class="prefixCls" :style="getWrapStyle">
|
<div :class="prefixCls" :style="getWrapStyle">
|
||||||
<Spin :spinning="loading" size="large" :style="getWrapStyle">
|
<Spin :spinning="loading" size="large" :style="getWrapStyle">
|
||||||
<iframe :src="frameSrc" :class="`${prefixCls}__main`" ref="frameRef"></iframe>
|
<iframe
|
||||||
|
:src="frameSrc"
|
||||||
|
:class="`${prefixCls}__main`"
|
||||||
|
ref="frameRef"
|
||||||
|
@load="hideLoading"
|
||||||
|
></iframe>
|
||||||
</Spin>
|
</Spin>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import type { CSSProperties } from 'vue';
|
import type { CSSProperties } from 'vue';
|
||||||
import { defineComponent, ref, unref, onMounted, nextTick, computed } from 'vue';
|
import { defineComponent, ref, unref, computed } from 'vue';
|
||||||
import { Spin } from 'ant-design-vue';
|
import { Spin } from 'ant-design-vue';
|
||||||
|
|
||||||
import { getViewportOffset } from '/@/utils/domUtils';
|
|
||||||
|
|
||||||
import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn';
|
import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn';
|
||||||
|
|
||||||
import { propTypes } from '/@/utils/propTypes';
|
import { propTypes } from '/@/utils/propTypes';
|
||||||
import { useDesign } from '/@/hooks/web/useDesign';
|
import { useDesign } from '/@/hooks/web/useDesign';
|
||||||
|
import { useLayoutHeight } from '/@/layouts/default/content/useContentViewHeight';
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'IFrame',
|
name: 'IFrame',
|
||||||
@ -24,10 +28,11 @@
|
|||||||
frameSrc: propTypes.string.def(''),
|
frameSrc: propTypes.string.def(''),
|
||||||
},
|
},
|
||||||
setup() {
|
setup() {
|
||||||
const loading = ref(false);
|
const loading = ref(true);
|
||||||
const topRef = ref(50);
|
const topRef = ref(50);
|
||||||
const heightRef = ref(window.innerHeight);
|
const heightRef = ref(window.innerHeight);
|
||||||
const frameRef = ref<HTMLFrameElement | null>(null);
|
const frameRef = ref<HTMLFrameElement>();
|
||||||
|
const { headerHeightRef } = useLayoutHeight();
|
||||||
|
|
||||||
const { prefixCls } = useDesign('iframe-page');
|
const { prefixCls } = useDesign('iframe-page');
|
||||||
useWindowSizeFn(calcHeight, 150, { immediate: true });
|
useWindowSizeFn(calcHeight, 150, { immediate: true });
|
||||||
@ -43,8 +48,7 @@
|
|||||||
if (!iframe) {
|
if (!iframe) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let { top } = getViewportOffset(iframe);
|
const top = headerHeightRef.value;
|
||||||
top += 20;
|
|
||||||
topRef.value = top;
|
topRef.value = top;
|
||||||
heightRef.value = window.innerHeight - top;
|
heightRef.value = window.innerHeight - top;
|
||||||
const clientHeight = document.documentElement.clientHeight - top;
|
const clientHeight = document.documentElement.clientHeight - top;
|
||||||
@ -56,33 +60,13 @@
|
|||||||
calcHeight();
|
calcHeight();
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
|
||||||
nextTick(() => {
|
|
||||||
const iframe = unref(frameRef);
|
|
||||||
if (!iframe) return;
|
|
||||||
|
|
||||||
const _frame = iframe as any;
|
|
||||||
if (_frame.attachEvent) {
|
|
||||||
_frame.attachEvent('onload', () => {
|
|
||||||
hideLoading();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
iframe.onload = () => {
|
|
||||||
hideLoading();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
onMounted(() => {
|
|
||||||
loading.value = true;
|
|
||||||
init();
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getWrapStyle,
|
getWrapStyle,
|
||||||
loading,
|
loading,
|
||||||
frameRef,
|
frameRef,
|
||||||
prefixCls,
|
prefixCls,
|
||||||
|
|
||||||
|
hideLoading,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user