mirror of
https://github.com/jeecgboot/JeecgBoot.git
synced 2026-01-02 19:15:26 +08:00
前端和后端源码,合并到一个git仓库中,方便用户下载,避免前后端不匹配的问题
This commit is contained in:
25
jeecgboot-vue3/src/layouts/iframe/index.vue
Normal file
25
jeecgboot-vue3/src/layouts/iframe/index.vue
Normal file
@ -0,0 +1,25 @@
|
||||
<template>
|
||||
<div v-if="showFrame">
|
||||
<template v-for="frame in getFramePages" :key="frame.path">
|
||||
<FramePage v-if="frame.meta.frameSrc && hasRenderFrame(frame.name)" v-show="showIframe(frame)" :frameSrc="frame.meta.frameSrc" />
|
||||
</template>
|
||||
</div>
|
||||
</template>
|
||||
<script lang="ts">
|
||||
import { defineComponent, unref, computed } from 'vue';
|
||||
import FramePage from '/@/views/sys/iframe/index.vue';
|
||||
|
||||
import { useFrameKeepAlive } from './useFrameKeepAlive';
|
||||
|
||||
export default defineComponent({
|
||||
name: 'FrameLayout',
|
||||
components: { FramePage },
|
||||
setup() {
|
||||
const { getFramePages, hasRenderFrame, showIframe } = useFrameKeepAlive();
|
||||
|
||||
const showFrame = computed(() => unref(getFramePages).length > 0);
|
||||
|
||||
return { getFramePages, hasRenderFrame, showIframe, showFrame };
|
||||
},
|
||||
});
|
||||
</script>
|
||||
59
jeecgboot-vue3/src/layouts/iframe/useFrameKeepAlive.ts
Normal file
59
jeecgboot-vue3/src/layouts/iframe/useFrameKeepAlive.ts
Normal file
@ -0,0 +1,59 @@
|
||||
import type { AppRouteRecordRaw } from '/@/router/types';
|
||||
|
||||
import { computed, toRaw, unref } from 'vue';
|
||||
|
||||
import { useMultipleTabStore } from '/@/store/modules/multipleTab';
|
||||
|
||||
import { uniqBy } from 'lodash-es';
|
||||
|
||||
import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';
|
||||
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
export function useFrameKeepAlive() {
|
||||
const router = useRouter();
|
||||
const { currentRoute } = router;
|
||||
const { getShowMultipleTab } = useMultipleTabSetting();
|
||||
const tabStore = useMultipleTabStore();
|
||||
const getFramePages = computed(() => {
|
||||
const ret = getAllFramePages(toRaw(router.getRoutes()) as unknown as AppRouteRecordRaw[]) || [];
|
||||
return ret;
|
||||
});
|
||||
|
||||
const getOpenTabList = computed((): string[] => {
|
||||
return tabStore.getTabList.reduce((prev: string[], next) => {
|
||||
if (next.meta && Reflect.has(next.meta, 'frameSrc')) {
|
||||
prev.push(next.name as string);
|
||||
}
|
||||
return prev;
|
||||
}, []);
|
||||
});
|
||||
|
||||
function getAllFramePages(routes: AppRouteRecordRaw[]): AppRouteRecordRaw[] {
|
||||
let res: AppRouteRecordRaw[] = [];
|
||||
for (const route of routes) {
|
||||
const { meta: { frameSrc } = {}, children } = route;
|
||||
if (frameSrc) {
|
||||
res.push(route);
|
||||
}
|
||||
if (children && children.length) {
|
||||
res.push(...getAllFramePages(children));
|
||||
}
|
||||
}
|
||||
res = uniqBy(res, 'name');
|
||||
return res;
|
||||
}
|
||||
|
||||
function showIframe(item: AppRouteRecordRaw) {
|
||||
return item.name === unref(currentRoute).name;
|
||||
}
|
||||
|
||||
function hasRenderFrame(name: string) {
|
||||
if (!unref(getShowMultipleTab)) {
|
||||
return router.currentRoute.value.name === name;
|
||||
}
|
||||
return unref(getOpenTabList).includes(name);
|
||||
}
|
||||
|
||||
return { hasRenderFrame, getFramePages, showIframe, getAllFramePages };
|
||||
}
|
||||
Reference in New Issue
Block a user