2021-01-21 00:18:30 +08:00
|
|
|
<template>
|
2022-11-16 15:34:23 +08:00
|
|
|
<div class="layout-padding layout-padding-unset layout-iframe">
|
|
|
|
<div class="layout-padding-auto layout-padding-view">
|
|
|
|
<div class="w100" v-for="v in setIframeList" :key="v.path" v-loading="v.meta.loading" element-loading-background="white">
|
|
|
|
<transition-group :name="name" mode="out-in">
|
|
|
|
<iframe
|
|
|
|
:src="v.meta.isLink"
|
|
|
|
:key="v.path"
|
|
|
|
frameborder="0"
|
|
|
|
height="100%"
|
|
|
|
width="100%"
|
|
|
|
style="position: absolute"
|
|
|
|
:data-url="v.path"
|
|
|
|
v-show="getRoutePath === v.path"
|
|
|
|
ref="iframeRef"
|
|
|
|
/>
|
|
|
|
</transition-group>
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-03-15 12:44:58 +08:00
|
|
|
</div>
|
2021-01-21 00:18:30 +08:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-11-16 15:34:23 +08:00
|
|
|
import { defineComponent, computed, watch, ref, nextTick } from 'vue';
|
2021-03-15 12:44:58 +08:00
|
|
|
import { useRoute } from 'vue-router';
|
2022-04-18 19:14:38 +08:00
|
|
|
|
2021-01-25 15:39:59 +08:00
|
|
|
export default defineComponent({
|
2022-11-16 15:34:23 +08:00
|
|
|
name: 'layoutIframeView',
|
|
|
|
props: {
|
|
|
|
refreshKey: {
|
|
|
|
type: String,
|
|
|
|
default: () => '',
|
|
|
|
},
|
|
|
|
name: {
|
|
|
|
type: String,
|
|
|
|
default: () => 'slide-right',
|
|
|
|
},
|
|
|
|
list: {
|
|
|
|
type: Array,
|
|
|
|
default: () => [],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
setup(props) {
|
|
|
|
const iframeRef = ref();
|
2021-03-15 12:44:58 +08:00
|
|
|
const route = useRoute();
|
2022-11-16 15:34:23 +08:00
|
|
|
// 处理 list 列表,当打开时,才进行加载
|
|
|
|
const setIframeList = computed(() => {
|
|
|
|
return (<any>props.list).filter((v: any) => v.meta.isIframeOpen);
|
2021-07-14 21:02:28 +08:00
|
|
|
});
|
2022-11-16 15:34:23 +08:00
|
|
|
// 获取 iframe 当前路由 path
|
|
|
|
const getRoutePath = computed(() => {
|
|
|
|
return route.path;
|
2021-03-15 12:44:58 +08:00
|
|
|
});
|
2022-11-17 01:18:18 +08:00
|
|
|
// 关闭 iframe loading
|
|
|
|
const closeIframeLoading = (val: string, item: any) => {
|
|
|
|
nextTick(() => {
|
|
|
|
if (!iframeRef.value) return false;
|
|
|
|
iframeRef.value.forEach((v: any) => {
|
|
|
|
if (v.dataset.url === val) {
|
|
|
|
v.onload = () => {
|
2022-11-17 08:25:32 +08:00
|
|
|
if (item.meta.isIframeOpen && item.meta.loading) item.meta.loading = false;
|
2022-11-17 01:18:18 +08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
2022-11-16 15:34:23 +08:00
|
|
|
// 监听路由变化,初始化 iframe 数据,防止多个 iframe 时,切换不生效
|
|
|
|
watch(
|
|
|
|
() => route.fullPath,
|
|
|
|
(val) => {
|
|
|
|
const item: any = props.list.find((v: any) => v.path === val);
|
2022-11-17 08:25:32 +08:00
|
|
|
if (!item) return false;
|
|
|
|
if (!item.meta.isIframeOpen) item.meta.isIframeOpen = true;
|
2022-11-17 01:18:18 +08:00
|
|
|
closeIframeLoading(val, item);
|
2022-11-16 15:34:23 +08:00
|
|
|
},
|
|
|
|
{
|
|
|
|
immediate: true,
|
|
|
|
}
|
|
|
|
);
|
|
|
|
// 监听 iframe refreshKey 变化,用于 tagsview 右键菜单刷新
|
2021-07-07 20:16:31 +08:00
|
|
|
watch(
|
2022-11-16 15:34:23 +08:00
|
|
|
() => props.refreshKey,
|
2022-11-17 00:39:38 +08:00
|
|
|
() => {
|
2022-11-17 00:44:00 +08:00
|
|
|
const item: any = props.list.find((v: any) => v.path === route.path);
|
2022-11-17 08:25:32 +08:00
|
|
|
if (!item) return false;
|
|
|
|
if (item.meta.isIframeOpen) item.meta.isIframeOpen = false;
|
2022-11-17 01:18:18 +08:00
|
|
|
setTimeout(() => {
|
2022-11-17 00:39:38 +08:00
|
|
|
item.meta.isIframeOpen = true;
|
2022-11-17 01:18:18 +08:00
|
|
|
item.meta.loading = true;
|
|
|
|
closeIframeLoading(route.fullPath, item);
|
2022-11-17 00:39:38 +08:00
|
|
|
});
|
2022-11-17 00:44:00 +08:00
|
|
|
},
|
2022-11-16 15:34:23 +08:00
|
|
|
{
|
|
|
|
deep: true,
|
2021-07-07 20:16:31 +08:00
|
|
|
}
|
|
|
|
);
|
2021-03-15 12:44:58 +08:00
|
|
|
return {
|
2022-11-16 15:34:23 +08:00
|
|
|
iframeRef,
|
|
|
|
setIframeList,
|
|
|
|
getRoutePath,
|
2021-03-15 12:44:58 +08:00
|
|
|
};
|
|
|
|
},
|
2021-01-25 15:39:59 +08:00
|
|
|
});
|
2021-03-15 12:44:58 +08:00
|
|
|
</script>
|