Commit d76cfd7f809ba48880c950a64cb43a5c9c44176c
Committed by
GitHub
1 parent
2fd0fd28
fix: fix iframe heigth error (#1012)
Showing
1 changed file
with
14 additions
and
30 deletions
src/views/sys/iframe/index.vue
1 | <template> | 1 | <template> |
2 | <div :class="prefixCls" :style="getWrapStyle"> | 2 | <div :class="prefixCls" :style="getWrapStyle"> |
3 | <Spin :spinning="loading" size="large" :style="getWrapStyle"> | 3 | <Spin :spinning="loading" size="large" :style="getWrapStyle"> |
4 | - <iframe :src="frameSrc" :class="`${prefixCls}__main`" ref="frameRef"></iframe> | 4 | + <iframe |
5 | + :src="frameSrc" | ||
6 | + :class="`${prefixCls}__main`" | ||
7 | + ref="frameRef" | ||
8 | + @load="hideLoading" | ||
9 | + ></iframe> | ||
5 | </Spin> | 10 | </Spin> |
6 | </div> | 11 | </div> |
7 | </template> | 12 | </template> |
8 | <script lang="ts"> | 13 | <script lang="ts"> |
9 | import type { CSSProperties } from 'vue'; | 14 | import type { CSSProperties } from 'vue'; |
10 | - import { defineComponent, ref, unref, onMounted, nextTick, computed } from 'vue'; | 15 | + import { defineComponent, ref, unref, computed } from 'vue'; |
11 | import { Spin } from 'ant-design-vue'; | 16 | import { Spin } from 'ant-design-vue'; |
12 | 17 | ||
13 | - import { getViewportOffset } from '/@/utils/domUtils'; | ||
14 | - | ||
15 | import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn'; | 18 | import { useWindowSizeFn } from '/@/hooks/event/useWindowSizeFn'; |
16 | 19 | ||
17 | import { propTypes } from '/@/utils/propTypes'; | 20 | import { propTypes } from '/@/utils/propTypes'; |
18 | import { useDesign } from '/@/hooks/web/useDesign'; | 21 | import { useDesign } from '/@/hooks/web/useDesign'; |
22 | + import { useLayoutHeight } from '/@/layouts/default/content/useContentViewHeight'; | ||
19 | 23 | ||
20 | export default defineComponent({ | 24 | export default defineComponent({ |
21 | name: 'IFrame', | 25 | name: 'IFrame', |
@@ -24,10 +28,11 @@ | @@ -24,10 +28,11 @@ | ||
24 | frameSrc: propTypes.string.def(''), | 28 | frameSrc: propTypes.string.def(''), |
25 | }, | 29 | }, |
26 | setup() { | 30 | setup() { |
27 | - const loading = ref(false); | 31 | + const loading = ref(true); |
28 | const topRef = ref(50); | 32 | const topRef = ref(50); |
29 | const heightRef = ref(window.innerHeight); | 33 | const heightRef = ref(window.innerHeight); |
30 | - const frameRef = ref<HTMLFrameElement | null>(null); | 34 | + const frameRef = ref<HTMLFrameElement>(); |
35 | + const { headerHeightRef } = useLayoutHeight(); | ||
31 | 36 | ||
32 | const { prefixCls } = useDesign('iframe-page'); | 37 | const { prefixCls } = useDesign('iframe-page'); |
33 | useWindowSizeFn(calcHeight, 150, { immediate: true }); | 38 | useWindowSizeFn(calcHeight, 150, { immediate: true }); |
@@ -43,8 +48,7 @@ | @@ -43,8 +48,7 @@ | ||
43 | if (!iframe) { | 48 | if (!iframe) { |
44 | return; | 49 | return; |
45 | } | 50 | } |
46 | - let { top } = getViewportOffset(iframe); | ||
47 | - top += 20; | 51 | + const top = headerHeightRef.value; |
48 | topRef.value = top; | 52 | topRef.value = top; |
49 | heightRef.value = window.innerHeight - top; | 53 | heightRef.value = window.innerHeight - top; |
50 | const clientHeight = document.documentElement.clientHeight - top; | 54 | const clientHeight = document.documentElement.clientHeight - top; |
@@ -56,33 +60,13 @@ | @@ -56,33 +60,13 @@ | ||
56 | calcHeight(); | 60 | calcHeight(); |
57 | } | 61 | } |
58 | 62 | ||
59 | - function init() { | ||
60 | - nextTick(() => { | ||
61 | - const iframe = unref(frameRef); | ||
62 | - if (!iframe) return; | ||
63 | - | ||
64 | - const _frame = iframe as any; | ||
65 | - if (_frame.attachEvent) { | ||
66 | - _frame.attachEvent('onload', () => { | ||
67 | - hideLoading(); | ||
68 | - }); | ||
69 | - } else { | ||
70 | - iframe.onload = () => { | ||
71 | - hideLoading(); | ||
72 | - }; | ||
73 | - } | ||
74 | - }); | ||
75 | - } | ||
76 | - onMounted(() => { | ||
77 | - loading.value = true; | ||
78 | - init(); | ||
79 | - }); | ||
80 | - | ||
81 | return { | 63 | return { |
82 | getWrapStyle, | 64 | getWrapStyle, |
83 | loading, | 65 | loading, |
84 | frameRef, | 66 | frameRef, |
85 | prefixCls, | 67 | prefixCls, |
68 | + | ||
69 | + hideLoading, | ||
86 | }; | 70 | }; |
87 | }, | 71 | }, |
88 | }); | 72 | }); |