-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec22052
commit 7b59c00
Showing
13 changed files
with
250 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,61 @@ | ||
<script lang="ts" setup> | ||
import { inject } from 'vue' | ||
import { inject } from 'vue' | ||
import { useKeepAliveCacheStore } from '@/layout/HKeepAlive/useKeepAliveCacheStore' | ||
const { isRefreshPage } = inject(layoutProvide)! | ||
const { isRefreshPage, isHeaderHeight, isTagViewHeight, isContentPadding, isFooterHeight } = inject(layoutProvide)! | ||
const cacheStore = useKeepAliveCacheStore() | ||
const { exclude } = storeToRefs(cacheStore) | ||
const topAttribute = computed(()=>{ | ||
return `${isHeaderHeight.value + isTagViewHeight.value}px` | ||
}) | ||
const bottomAttribute = computed(()=>{ | ||
return `${isFooterHeight.value + isContentPadding.value}px` | ||
}) | ||
const paddingAttribute = computed(()=>{ | ||
return `${isContentPadding.value}px` | ||
}) | ||
</script> | ||
|
||
<template> | ||
<RouterView v-slot="{ Component, route }"> | ||
<RouterView | ||
v-slot="{ | ||
Component, route: { | ||
fullPath, | ||
name, | ||
meta: { | ||
isIframe, | ||
}, | ||
}, | ||
}" | ||
> | ||
<Transition | ||
appear | ||
enterActiveClass="animated-fade-in-left animated animated-duration-300 ease-in-out" | ||
leaveActiveClass="animated-fade-out-right animated animated-duration-300 ease-in-out" | ||
mode="out-in" | ||
enterActiveClass="animated-fade-in-left animated animated-duration-300 ease-in-out !absolute absolute_orientation_keepAlive" | ||
leaveActiveClass="animated-fade-out-right animated animated-duration-300 ease-in-out !absolute absolute_orientation_keepAlive" | ||
> | ||
<KeepAlive | ||
:exclude="exclude" | ||
:max="2" | ||
> | ||
<component | ||
<KeepAlive :exclude="exclude"> | ||
<Component | ||
:is="Component" | ||
v-if="isRefreshPage" | ||
:key="route.fullPath" | ||
v-show="isIframe !== true" | ||
:key="fullPath" | ||
class="flex-1 overflow-hidden" | ||
/> | ||
</KeepAlive> | ||
</Transition> | ||
<!-- eslint-disable-next-line vue/valid-v-for --> | ||
<IframKeep | ||
:isIframe="isIframe" | ||
:routeName="name" | ||
/> | ||
</RouterView> | ||
</template> | ||
|
||
<style scoped> | ||
.absolute_orientation_keepAlive{ | ||
top:v-bind(topAttribute); | ||
bottom:v-bind(bottomAttribute); | ||
left:v-bind(paddingAttribute); | ||
right:v-bind(paddingAttribute); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
<script setup lang="ts"> | ||
import { forEach, isFunction, isString, some } from 'lodash-es' | ||
import type { Component } from 'vue' | ||
import { inject } from 'vue' | ||
import type { RouteRecordName } from 'vue-router' | ||
import { useKeepAliveCacheStore } from '@/layout/HKeepAlive/useKeepAliveCacheStore' | ||
import { routerHelper } from '@/router/helps/allRouters' | ||
defineOptions({ | ||
inheritAttrs: false, | ||
}) | ||
const props = defineProps<{ | ||
routeName?: RouteRecordName | null | ||
isIframe?: boolean | ||
}>() | ||
const { isRefreshPage, isHeaderHeight, isTagViewHeight, isContentPadding, isFooterHeight } = inject(layoutProvide)! | ||
const { allIframeRouters } = routerHelper() | ||
const topAttribute = computed(()=>{ | ||
return `${isHeaderHeight.value + isTagViewHeight.value}px` | ||
}) | ||
const bottomAttribute = computed(()=>{ | ||
return `${isFooterHeight.value + isContentPadding.value}px` | ||
}) | ||
const paddingAttribute = computed(()=>{ | ||
return `${isContentPadding.value}px` | ||
}) | ||
async function getComponent(name?: string | RouteRecordName) { | ||
const { component } = allIframeRouters.value.find(item => item.name === name)! | ||
if (isFunction(component)) { | ||
const result = await (component as () => Promise<{ | ||
default: Component | ||
}>)() | ||
return result.default | ||
} | ||
} | ||
const demoCom = shallowRef<{ | ||
component: any | ||
name?: string | RouteRecordName | ||
}[]>([]) | ||
onMounted(()=>{ | ||
forEach(allIframeRouters.value, async (item) => { | ||
const { name } = item | ||
const component = await getComponent(name) | ||
demoCom.value.push({ | ||
component, | ||
name, | ||
}) | ||
triggerRef(demoCom) | ||
}) | ||
}) | ||
const cacheStore = useKeepAliveCacheStore() | ||
const { exclude } = storeToRefs(cacheStore) | ||
function isVif(name?: RouteRecordName | null) { | ||
return props.routeName === name ? | ||
!some(exclude.value, item => item.test(isString(name) ? name : '')) | ||
&& isRefreshPage.value : true | ||
} | ||
function isVshow(name?: RouteRecordName | null) { | ||
return props.routeName === name && props.isIframe | ||
} | ||
</script> | ||
|
||
<template> | ||
<!-- eslint-disable-next-line vue/valid-v-for --> | ||
<Transition | ||
v-for="{ name, component } in demoCom" | ||
appear | ||
enterActiveClass="animated-fade-in-left animated animated-duration-300 ease-in-out absolute absolute_orientation" | ||
leaveActiveClass="animated-fade-out-right animated animated-duration-300 ease-in-out absolute absolute_orientation" | ||
> | ||
<div | ||
v-if="isVif(name)" | ||
v-show="isVshow(name)" | ||
:key="name" | ||
class="flex flex-1 flex-col" | ||
> | ||
<Component | ||
:is="component" | ||
:key="name" | ||
class="flex-1 overflow-hidden" | ||
/> | ||
</div> | ||
</Transition> | ||
</template> | ||
|
||
<style scoped> | ||
.absolute_orientation{ | ||
top:v-bind(topAttribute); | ||
bottom:v-bind(bottomAttribute); | ||
left:v-bind(paddingAttribute); | ||
right:v-bind(paddingAttribute); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.