zhouwx
2024-12-04 80c8993820fc3f958397bebe9dbd72be6a449c55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<template>
    <div class="layout-view-bg-white flex mt1" :style="{ height: `calc(100vh - ${setIframeHeight}`, border: 'none' }" v-loading="iframeLoading">
        <iframe :src="iframeUrl" frameborder="0" height="100%" width="100%" ref="iframeDom" v-show="!iframeLoading"></iframe>
    </div>
</template>
 
<script lang="ts">
import { defineComponent, reactive, toRefs, onMounted, nextTick, watch, computed } from 'vue';
import { storeToRefs } from 'pinia';
import { useRoute } from 'vue-router';
import { useThemeConfig } from '/@/stores/themeConfig';
import { useTagsViewRoutes } from '/@/stores/tagsViewRoutes';
 
export default defineComponent({
    name: 'layoutIfameView',
    setup() {
        const storesThemeConfig = useThemeConfig();
        const storesTagsViewRoutes = useTagsViewRoutes();
        const { themeConfig } = storeToRefs(storesThemeConfig);
        const { isTagsViewCurrenFull } = storeToRefs(storesTagsViewRoutes);
        const route = useRoute();
        const state = reactive({
            iframeDom: null as HTMLIFrameElement | null,
            iframeLoading: true,
            iframeUrl: '',
        });
        // 初始化页面加载 loading
        const initIframeLoad = () => {
            state.iframeUrl = <any>route.meta.isLink;
            nextTick(() => {
                state.iframeLoading = true;
                const iframe = state.iframeDom;
                if (!iframe) return false;
                iframe.onload = () => {
                    state.iframeLoading = false;
                };
            });
        };
        // 设置 iframe 的高度
        const setIframeHeight = computed(() => {
            let { isTagsview } = themeConfig.value;
            if (isTagsViewCurrenFull.value) {
                return `1px`;
            } else {
                if (isTagsview) return `86px`;
                else return `51px`;
            }
        });
        // 页面加载时
        onMounted(() => {
            initIframeLoad();
        });
        // 监听路由变化,多个 iframe 时使用
        watch(
            () => route.path,
            () => {
                initIframeLoad();
            }
        );
        return {
            setIframeHeight,
            ...toRefs(state),
        };
    },
});
</script>