'admin-21.07.07:优化内嵌iframe、外链,解决tagsView刷新问题'

This commit is contained in:
lyt-Top 2021-07-07 20:16:31 +08:00
parent ae27489247
commit b3a6bb6a8e
5 changed files with 75 additions and 75 deletions

View File

@ -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`

View File

@ -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),
}; };
}, },

View File

@ -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),
}; };

View File

@ -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),
}; };
}, },
}); });

View File

@ -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',