@fmdevui/fm-dev
Version:
Page level components developed based on Element Plus.
140 lines (137 loc) • 5.09 kB
JavaScript
import { defineComponent, reactive, computed, onBeforeMount, nextTick, onMounted, onUnmounted, watch, resolveComponent, createElementBlock, openBlock, createVNode, withCtx, Transition, createBlock, KeepAlive, withDirectives, resolveDynamicComponent, vShow, unref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { storeToRefs } from 'pinia';
import '../../stores/index.mjs';
import '../../utils/index.mjs';
import emitter from '../../utils/emit/index.mjs';
import './iframes.vue.mjs';
import _sfc_main$1 from './iframes.vue2.mjs';
import { useKeepALiveNames } from '../../stores/keepAliveNames.mjs';
import { useThemeConfig } from '../../stores/themeConfig.mjs';
import { Session } from '../../utils/storage/index.mjs';
const _hoisted_1 = { class: "layout-parent" };
var _sfc_main = /* @__PURE__ */ defineComponent({
__name: "parent",
setup(__props) {
const Iframes = _sfc_main$1;
const route = useRoute();
const router = useRouter();
const storesKeepAliveNames = useKeepALiveNames();
const storesThemeConfig = useThemeConfig();
const { keepAliveNames, cachedViews } = storeToRefs(storesKeepAliveNames);
const { themeConfig } = storeToRefs(storesThemeConfig);
const state = reactive({
refreshRouterViewKey: "",
// 非 iframe tagsview 右键菜单刷新时
iframeRefreshKey: "",
// iframe tagsview 右键菜单刷新时
keepAliveNameList: [],
iframeList: []
});
const setTransitionName = computed(() => {
return themeConfig.value.animation;
});
const getKeepAliveNames = computed(() => {
return themeConfig.value.isTagsview ? cachedViews.value : state.keepAliveNameList;
});
const isIframePage = computed(() => {
return route.meta.isIframe;
});
const getIframeListRoutes = async () => {
router.getRoutes().forEach((v) => {
if (v.meta.isIframe) {
v.meta.isIframeOpen = false;
v.meta.loading = true;
state.iframeList.push({ ...v });
}
});
};
onBeforeMount(() => {
state.keepAliveNameList = keepAliveNames.value;
emitter.on("onTagsViewRefreshRouterView", (fullPath) => {
const cacheList = cachedViews.value;
if (route.meta.isKeepAlive) cachedViews.value = cachedViews.value?.filter((name) => route.name !== name);
state.keepAliveNameList = keepAliveNames.value.filter((name) => route.name !== name);
state.refreshRouterViewKey = "";
state.iframeRefreshKey = "";
nextTick(() => {
if (route.meta.isKeepAlive) cachedViews.value = cacheList;
state.keepAliveNameList = keepAliveNames.value;
state.refreshRouterViewKey = fullPath;
state.iframeRefreshKey = fullPath;
});
});
});
onMounted(() => {
getIframeListRoutes();
nextTick(() => {
setTimeout(() => {
if (themeConfig.value.isCacheTagsView) {
let tagsViewArr = Session.get("tagsViewList") || [];
cachedViews.value = tagsViewArr.filter((item) => item.meta?.isKeepAlive).map((item) => item.name);
}
}, 0);
});
});
onUnmounted(() => {
emitter.off("onTagsViewRefreshRouterView", () => {
});
});
watch(
() => route.fullPath,
() => {
state.refreshRouterViewKey = decodeURI(route.fullPath);
},
{
immediate: true
}
);
return (_ctx, _cache) => {
const _component_router_view = resolveComponent("router-view");
return openBlock(), createElementBlock("div", _hoisted_1, [
createVNode(_component_router_view, null, {
default: withCtx(({ Component }) => [
createVNode(Transition, {
name: setTransitionName.value,
mode: "out-in"
}, {
default: withCtx(() => [
(openBlock(), createBlock(KeepAlive, { include: getKeepAliveNames.value }, [
withDirectives((openBlock(), createBlock(resolveDynamicComponent(Component), {
key: state.refreshRouterViewKey,
class: "w100"
})), [
[vShow, !isIframePage.value]
])
], 1032, ["include"]))
]),
_: 2
/* DYNAMIC */
}, 1032, ["name"])
]),
_: 1
/* STABLE */
}),
createVNode(Transition, {
name: setTransitionName.value,
mode: "out-in",
persisted: ""
}, {
default: withCtx(() => [
withDirectives(createVNode(unref(Iframes), {
class: "w100",
refreshKey: state.iframeRefreshKey,
name: setTransitionName.value,
list: state.iframeList
}, null, 8, ["refreshKey", "name", "list"]), [
[vShow, isIframePage.value]
])
]),
_: 1
/* STABLE */
}, 8, ["name"])
]);
};
}
});
export { _sfc_main as default };