Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix iframe heigth error #1012

Merged
merged 1 commit into from
Aug 1, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 14 additions & 30 deletions src/views/sys/iframe/index.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
<template>
<div :class="prefixCls" :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>
</div>
</template>
<script lang="ts">
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 { getViewportOffset } from '/@/utils/domUtils';

import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn';

import { propTypes } from '/@/utils/propTypes';
import { useDesign } from '/@/hooks/web/useDesign';
import { useLayoutHeight } from '/@/layouts/default/content/useContentViewHeight';

export default defineComponent({
name: 'IFrame',
Expand All @@ -24,10 +28,11 @@
frameSrc: propTypes.string.def(''),
},
setup() {
const loading = ref(false);
const loading = ref(true);
const topRef = ref(50);
const heightRef = ref(window.innerHeight);
const frameRef = ref<HTMLFrameElement | null>(null);
const frameRef = ref<HTMLFrameElement>();
const { headerHeightRef } = useLayoutHeight();

const { prefixCls } = useDesign('iframe-page');
useWindowSizeFn(calcHeight, 150, { immediate: true });
Expand All @@ -43,8 +48,7 @@
if (!iframe) {
return;
}
let { top } = getViewportOffset(iframe);
top += 20;
const top = headerHeightRef.value;
topRef.value = top;
heightRef.value = window.innerHeight - top;
const clientHeight = document.documentElement.clientHeight - top;
Expand All @@ -56,33 +60,13 @@
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 {
getWrapStyle,
loading,
frameRef,
prefixCls,

hideLoading,
};
},
});
Expand Down