'admin-21.07.07:优化内嵌iframe、外链,解决tagsView刷新问题'
This commit is contained in:
parent
ae27489247
commit
b3a6bb6a8e
@ -2,6 +2,13 @@
|
|||||||
|
|
||||||
🎉🎉🔥 `vue-next-admin` 基于 vue3.x 、Typescript、vite、Element plus 等,适配手机、平板、pc 的后台开源免费模板库(vue2.x 请切换 vue-prev-admin 分支)
|
🎉🎉🔥 `vue-next-admin` 基于 vue3.x 、Typescript、vite、Element plus 等,适配手机、平板、pc 的后台开源免费模板库(vue2.x 请切换 vue-prev-admin 分支)
|
||||||
|
|
||||||
|
## 1.0.10
|
||||||
|
|
||||||
|
`2021.07.07`
|
||||||
|
|
||||||
|
- 🌟 更新 依赖更新最新版本(字体图标无问题)
|
||||||
|
- 🎯 优化 内嵌 iframe、外链,解决 tagsView 刷新问题
|
||||||
|
|
||||||
## 1.0.9
|
## 1.0.9
|
||||||
|
|
||||||
`2021.07.02`
|
`2021.07.02`
|
||||||
|
@ -3,68 +3,53 @@
|
|||||||
<el-scrollbar
|
<el-scrollbar
|
||||||
class="layout-scrollbar"
|
class="layout-scrollbar"
|
||||||
ref="layoutScrollbarRef"
|
ref="layoutScrollbarRef"
|
||||||
v-if="!currentRouteMeta.isLink && !currentRouteMeta.isIframe"
|
:style="{
|
||||||
:style="{ minHeight: `calc(100vh - ${headerHeight}` }"
|
minHeight: `calc(100vh - ${headerHeight}`,
|
||||||
|
padding: currentRouteMeta.isLink && currentRouteMeta.isIframe ? 0 : '',
|
||||||
|
transition: 'padding 0.3s ease-in-out',
|
||||||
|
}"
|
||||||
>
|
>
|
||||||
<LayoutParentView />
|
<LayoutParentView />
|
||||||
<Footer v-if="getThemeConfig.isFooter" />
|
<Footer v-if="getThemeConfig.isFooter" />
|
||||||
</el-scrollbar>
|
</el-scrollbar>
|
||||||
<Link :style="{ height: `calc(100vh - ${headerHeight}` }" :meta="currentRouteMeta" v-if="currentRouteMeta.isLink && !currentRouteMeta.isIframe" />
|
|
||||||
<Iframes
|
|
||||||
:style="{ height: `calc(100vh - ${headerHeight}` }"
|
|
||||||
:meta="currentRouteMeta"
|
|
||||||
v-if="currentRouteMeta.isLink && currentRouteMeta.isIframe && isShowLink"
|
|
||||||
@getCurrentRouteMeta="onGetCurrentRouteMeta"
|
|
||||||
/>
|
|
||||||
</el-main>
|
</el-main>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { computed, defineComponent, toRefs, reactive, getCurrentInstance, watch, onBeforeMount } from 'vue';
|
import { computed, defineComponent, toRefs, reactive, getCurrentInstance, watch, onBeforeMount } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
|
||||||
import { useStore } from '/@/store/index';
|
import { useStore } from '/@/store/index';
|
||||||
|
import { useRoute } from 'vue-router';
|
||||||
import LayoutParentView from '/@/layout/routerView/parent.vue';
|
import LayoutParentView from '/@/layout/routerView/parent.vue';
|
||||||
import Footer from '/@/layout/footer/index.vue';
|
import Footer from '/@/layout/footer/index.vue';
|
||||||
import Link from '/@/layout/routerView/link.vue';
|
|
||||||
import Iframes from '/@/layout/routerView/iframes.vue';
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'layoutMain',
|
name: 'layoutMain',
|
||||||
components: { LayoutParentView, Footer, Link, Iframes },
|
components: { LayoutParentView, Footer },
|
||||||
setup() {
|
setup() {
|
||||||
const { proxy } = getCurrentInstance() as any;
|
const { proxy } = getCurrentInstance() as any;
|
||||||
const store = useStore();
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const store = useStore();
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
headerHeight: '',
|
headerHeight: '',
|
||||||
currentRouteMeta: {},
|
currentRouteMeta: {},
|
||||||
isShowLink: false,
|
|
||||||
});
|
});
|
||||||
// 获取布局配置信息
|
// 获取布局配置信息
|
||||||
const getThemeConfig = computed(() => {
|
const getThemeConfig = computed(() => {
|
||||||
return store.state.themeConfig.themeConfig;
|
return store.state.themeConfig.themeConfig;
|
||||||
});
|
});
|
||||||
// 子组件触发更新
|
|
||||||
const onGetCurrentRouteMeta = () => {
|
|
||||||
initCurrentRouteMeta(route.meta);
|
|
||||||
};
|
|
||||||
// 初始化当前路由 meta 信息
|
|
||||||
const initCurrentRouteMeta = (meta: object) => {
|
|
||||||
state.isShowLink = false;
|
|
||||||
state.currentRouteMeta = meta;
|
|
||||||
setTimeout(() => {
|
|
||||||
state.isShowLink = true;
|
|
||||||
}, 100);
|
|
||||||
};
|
|
||||||
// 设置 main 的高度
|
// 设置 main 的高度
|
||||||
const initHeaderHeight = () => {
|
const initHeaderHeight = () => {
|
||||||
let { isTagsview } = store.state.themeConfig.themeConfig;
|
let { isTagsview } = store.state.themeConfig.themeConfig;
|
||||||
if (isTagsview) return (state.headerHeight = `84px`);
|
if (isTagsview) return (state.headerHeight = `84px`);
|
||||||
else return (state.headerHeight = `50px`);
|
else return (state.headerHeight = `50px`);
|
||||||
};
|
};
|
||||||
|
// 初始化获取当前路由 meta,用于设置 iframes padding
|
||||||
|
const initGetMeta = () => {
|
||||||
|
state.currentRouteMeta = route.meta;
|
||||||
|
};
|
||||||
// 页面加载前
|
// 页面加载前
|
||||||
onBeforeMount(() => {
|
onBeforeMount(() => {
|
||||||
initCurrentRouteMeta(route.meta);
|
|
||||||
initHeaderHeight();
|
initHeaderHeight();
|
||||||
|
initGetMeta();
|
||||||
});
|
});
|
||||||
// 监听 themeConfig 配置文件的变化,更新菜单 el-scrollbar 的高度
|
// 监听 themeConfig 配置文件的变化,更新菜单 el-scrollbar 的高度
|
||||||
watch(store.state.themeConfig.themeConfig, (val) => {
|
watch(store.state.themeConfig.themeConfig, (val) => {
|
||||||
@ -74,17 +59,15 @@ export default defineComponent({
|
|||||||
proxy.$refs.layoutScrollbarRef.update();
|
proxy.$refs.layoutScrollbarRef.update();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
// 监听路由的变化
|
// 监听路由变化
|
||||||
watch(
|
watch(
|
||||||
() => route.path,
|
() => route.path,
|
||||||
() => {
|
() => {
|
||||||
initCurrentRouteMeta(route.meta);
|
state.currentRouteMeta = route.meta;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return {
|
return {
|
||||||
getThemeConfig,
|
getThemeConfig,
|
||||||
initCurrentRouteMeta,
|
|
||||||
onGetCurrentRouteMeta,
|
|
||||||
...toRefs(state),
|
...toRefs(state),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
@ -1,31 +1,26 @@
|
|||||||
<template>
|
<template>
|
||||||
<div>
|
<div class="layout-view-bg-white flex" :style="{ height: `calc(100vh - ${iframeHeight}`, border: 'none' }" v-loading="iframeLoading">
|
||||||
<div class="layout-view-bg-white flex h100" v-loading="iframeLoading">
|
<iframe :src="iframeUrl" frameborder="0" height="100%" width="100%" id="iframe" v-show="!iframeLoading"></iframe>
|
||||||
<iframe :src="iframeUrl" frameborder="0" height="100%" width="100%" id="iframe" v-show="!iframeLoading"></iframe>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, reactive, toRefs, onMounted, onBeforeMount, onUnmounted, nextTick, getCurrentInstance } from 'vue';
|
import { defineComponent, reactive, toRefs, onMounted, nextTick, watch } from 'vue';
|
||||||
import { useRoute } from 'vue-router';
|
import { useRoute } from 'vue-router';
|
||||||
|
import { useStore } from '/@/store/index';
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'layoutIfameView',
|
name: 'layoutIfameView',
|
||||||
props: {
|
setup() {
|
||||||
meta: {
|
|
||||||
type: Object,
|
|
||||||
default: () => {},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
setup(props, { emit }) {
|
|
||||||
const { proxy } = getCurrentInstance() as any;
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
|
const store = useStore();
|
||||||
const state = reactive({
|
const state = reactive({
|
||||||
iframeLoading: true,
|
iframeLoading: true,
|
||||||
iframeUrl: '',
|
iframeUrl: '',
|
||||||
|
iframeHeight: '',
|
||||||
});
|
});
|
||||||
// 初始化页面加载 loading
|
// 初始化页面加载 loading
|
||||||
const initIframeLoad = () => {
|
const initIframeLoad = () => {
|
||||||
|
state.iframeUrl = route.meta.isLink;
|
||||||
nextTick(() => {
|
nextTick(() => {
|
||||||
state.iframeLoading = true;
|
state.iframeLoading = true;
|
||||||
const iframe = document.getElementById('iframe');
|
const iframe = document.getElementById('iframe');
|
||||||
@ -35,22 +30,24 @@ export default defineComponent({
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
// 页面加载前
|
// 设置 iframe 的高度
|
||||||
onBeforeMount(() => {
|
const initIframeHeight = () => {
|
||||||
state.iframeUrl = props.meta.isLink;
|
let { isTagsview } = store.state.themeConfig.themeConfig;
|
||||||
proxy.mittBus.on('onTagsViewRefreshRouterView', (path: string) => {
|
if (isTagsview) return (state.iframeHeight = `84px`);
|
||||||
if (route.path !== path) return false;
|
else return (state.iframeHeight = `20px`);
|
||||||
emit('getCurrentRouteMeta');
|
};
|
||||||
});
|
|
||||||
});
|
|
||||||
// 页面加载时
|
// 页面加载时
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
initIframeLoad();
|
initIframeLoad();
|
||||||
|
initIframeHeight();
|
||||||
});
|
});
|
||||||
// 页面卸载时
|
// 监听路由变化,多个 iframe 时使用
|
||||||
onUnmounted(() => {
|
watch(
|
||||||
proxy.mittBus.off('onTagsViewRefreshRouterView', () => {});
|
() => route.path,
|
||||||
});
|
() => {
|
||||||
|
initIframeLoad();
|
||||||
|
}
|
||||||
|
);
|
||||||
return {
|
return {
|
||||||
...toRefs(state),
|
...toRefs(state),
|
||||||
};
|
};
|
||||||
|
@ -1,28 +1,41 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="layout-scrollbar">
|
<div class="layout-view-bg-white flex layout-view-link" :style="{ height: `calc(100vh - ${linkHeight}` }">
|
||||||
<div class="layout-view-bg-white flex layout-view-link">
|
<a href="https://element-plus.gitee.io/#/zh-CN/component/installation" target="_blank" class="flex-margin"
|
||||||
<a :href="currentRouteMeta.isLink" target="_blank" class="flex-margin">{{ currentRouteMeta.title }}:{{ currentRouteMeta.isLink }}</a>
|
>{{ currentRouteMeta.title }}:{{ currentRouteMeta.isLink }}</a
|
||||||
</div>
|
>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, computed } from 'vue';
|
import { defineComponent, toRefs, reactive, onMounted } from 'vue';
|
||||||
|
import { useRoute } from 'vue-router';
|
||||||
|
import { useStore } from '/@/store/index';
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: 'layoutLinkView',
|
name: 'layoutLinkView',
|
||||||
props: {
|
setup() {
|
||||||
meta: {
|
const route = useRoute();
|
||||||
type: Object,
|
const store = useStore();
|
||||||
default: () => {},
|
const state = reactive({
|
||||||
},
|
currentRouteMeta: {},
|
||||||
},
|
linkHeight: '',
|
||||||
setup(props) {
|
});
|
||||||
// 获取父级菜单数据
|
// 初始化获取当前路由 meta
|
||||||
const currentRouteMeta = computed(() => {
|
const initGetMeta = () => {
|
||||||
return props.meta;
|
state.currentRouteMeta = route.meta;
|
||||||
|
};
|
||||||
|
// 设置 iframe 的高度
|
||||||
|
const initLinkHeight = () => {
|
||||||
|
let { isTagsview } = store.state.themeConfig.themeConfig;
|
||||||
|
if (isTagsview) return (state.linkHeight = `114px`);
|
||||||
|
else return (state.linkHeight = `50px`);
|
||||||
|
};
|
||||||
|
// 页面加载时
|
||||||
|
onMounted(() => {
|
||||||
|
initGetMeta();
|
||||||
|
initLinkHeight();
|
||||||
});
|
});
|
||||||
return {
|
return {
|
||||||
currentRouteMeta,
|
...toRefs(state),
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -850,7 +850,7 @@ export const dynamicRoutes: Array<RouteRecordRaw> = [
|
|||||||
{
|
{
|
||||||
path: '/link',
|
path: '/link',
|
||||||
name: 'layoutLinkView',
|
name: 'layoutLinkView',
|
||||||
component: () => import('/@/layout/routerView/parent.vue'),
|
component: () => import('/@/layout/routerView/link.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: 'message.router.layoutLinkView',
|
title: 'message.router.layoutLinkView',
|
||||||
isLink: 'https://element-plus.gitee.io/#/zh-CN/component/installation',
|
isLink: 'https://element-plus.gitee.io/#/zh-CN/component/installation',
|
||||||
@ -865,7 +865,7 @@ export const dynamicRoutes: Array<RouteRecordRaw> = [
|
|||||||
{
|
{
|
||||||
path: '/iframes',
|
path: '/iframes',
|
||||||
name: 'layoutIfameView',
|
name: 'layoutIfameView',
|
||||||
component: () => import('/@/layout/routerView/parent.vue'),
|
component: () => import('/@/layout/routerView/iframes.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: 'message.router.layoutIfameView',
|
title: 'message.router.layoutIfameView',
|
||||||
isLink: 'https://gitee.com/lyt-top/vue-next-admin',
|
isLink: 'https://gitee.com/lyt-top/vue-next-admin',
|
||||||
|
Loading…
Reference in New Issue
Block a user