1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495 |
- <template>
- <div class="app-views">
- <router-view v-slot="{ Component }">
- <transition :name="app.info.router.transition || 'none'">
- <keep-alive :include="caches" :key="key">
- <component :is="Component" />
- </keep-alive>
- </transition>
- </router-view>
- </div>
- </template>
- <script lang="ts" name="app-views" setup>
- import { computed, onMounted, onUnmounted, ref } from "vue";
- import { useBase } from "/$/base";
- import { useCool } from "/@/cool";
- const { mitt } = useCool();
- const { process, app } = useBase();
- // 缓存数
- const key = ref(1);
- // 缓存列表
- const caches = computed(() => {
- return process.list
- .filter((e) => e.meta?.keepAlive)
- .map((e) => {
- return e.path.substring(1, e.path.length).replace(/\//g, "-");
- });
- });
- // 刷新页面
- function refresh() {
- key.value += 1;
- }
- onMounted(() => {
- mitt.on("view.refresh", refresh);
- });
- onUnmounted(() => {
- mitt.off("view.refresh");
- });
- </script>
- <style lang="scss" scoped>
- .app-views {
- flex: 1;
- overflow: hidden;
- margin: 0 10px 10px 10px;
- width: calc(100% - 20px);
- box-sizing: border-box;
- border-radius: 4px;
- position: relative;
- .none-enter-active {
- position: absolute;
- }
- .slide-enter-active {
- position: absolute;
- top: 0;
- width: 100%;
- transition: all 0.4s ease-in-out 0.2s;
- }
- .slide-leave-active {
- position: absolute;
- top: 0;
- width: 100%;
- transition: all 0.4s ease-in-out;
- }
- .slide-enter-to {
- transform: translate3d(0, 0, 0);
- opacity: 1;
- }
- .slide-enter-from {
- transform: translate3d(-5%, 0, 0);
- opacity: 0;
- }
- .slide-leave-to {
- transform: translate3d(5%, 0, 0);
- opacity: 0;
- }
- .slide-leave-from {
- transform: translate3d(0, 0, 0);
- opacity: 1;
- }
- }
- </style>
|