perf/route (#54)

* perf: router

* perf: route
This commit is contained in:
啝裳
2021-10-12 23:33:13 +08:00
committed by GitHub
parent 0408fa6f96
commit a31d154806
18 changed files with 257 additions and 38 deletions

View File

@@ -1,17 +1,10 @@
<script setup lang="ts">
import { ref, unref, computed, getCurrentInstance } from "vue";
import { useSettingStoreHook } from "/@/store/modules/settings";
import { ref, getCurrentInstance } from "vue";
import { usePermissionStoreHook } from "/@/store/modules/permission";
const keepAlive: Boolean = ref(
getCurrentInstance().appContext.config.globalProperties.$config?.KeepAlive
);
const getCachedPageList = computed((): string[] => {
if (!unref(keepAlive)) {
return [];
}
return useSettingStoreHook().cachedPageList;
});
</script>
<template>
@@ -19,7 +12,10 @@ const getCachedPageList = computed((): string[] => {
<router-view>
<template #default="{ Component, route }">
<transition appear name="fade-transform" mode="out-in">
<keep-alive v-if="keepAlive" :include="getCachedPageList">
<keep-alive
v-if="keepAlive"
:include="usePermissionStoreHook().cachePageList"
>
<component :is="Component" :key="route.fullPath" />
</keep-alive>
<component v-else :is="Component" :key="route.fullPath" />

View File

@@ -12,8 +12,10 @@ import {
import { RouteConfigs, relativeStorageType, tagsViewsType } from "../../types";
import { emitter } from "/@/utils/mitt";
import { templateRef } from "@vueuse/core";
import { handleAliveRoute } from "/@/router";
import { storageLocal } from "/@/utils/storage";
import { useRoute, useRouter } from "vue-router";
import { usePermissionStoreHook } from "/@/store/modules/permission";
import { toggleClass, removeClass, hasClass } from "/@/utils/operate";
import close from "/@/assets/svg/close.svg";
@@ -171,6 +173,8 @@ function deleteDynamicTag(obj: any, current: any, tag?: string) {
relativeStorage.routesInStorage = routerArrays;
}
router.push(obj.path);
// 删除缓存路由
handleAliveRoute(route.matched, "delete");
};
if (tag === "other") {
@@ -253,7 +257,9 @@ function onClickDrop(key, item, selectRoute?: RouteConfigs) {
// 关闭全部标签页
routerArrays.splice(1, routerArrays.length);
relativeStorage.routesInStorage = routerArrays;
usePermissionStoreHook().clearAllCachePage();
router.push("/welcome");
break;
}
setTimeout(() => {