fix: fix keepAlive not work
This commit is contained in:
parent
4cca007176
commit
b884654761
|
|
@ -45,7 +45,7 @@ export default defineComponent({
|
||||||
const renderComp = () => <Component key={route.fullPath} />;
|
const renderComp = () => <Component key={route.fullPath} />;
|
||||||
|
|
||||||
const PageContent = unref(openCache) ? (
|
const PageContent = unref(openCache) ? (
|
||||||
<KeepAlive>{renderComp()}</KeepAlive>
|
<KeepAlive include={cacheTabs}>{renderComp()}</KeepAlive>
|
||||||
) : (
|
) : (
|
||||||
renderComp()
|
renderComp()
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -35,17 +35,18 @@ export function useCache(isPage: boolean) {
|
||||||
// not parent layout
|
// not parent layout
|
||||||
return cached.get(PAGE_LAYOUT_KEY) || [];
|
return cached.get(PAGE_LAYOUT_KEY) || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
const cacheSet = new Set<string>();
|
const cacheSet = new Set<string>();
|
||||||
cacheSet.add(unref(name));
|
cacheSet.add(unref(name));
|
||||||
|
|
||||||
const list = cached.get(unref(name));
|
const list = cached.get(unref(name));
|
||||||
|
|
||||||
if (!list) {
|
if (!list) {
|
||||||
return Array.from(cacheSet);
|
return Array.from(cacheSet);
|
||||||
}
|
}
|
||||||
list.forEach((item) => {
|
list.forEach((item) => {
|
||||||
cacheSet.add(item);
|
cacheSet.add(item);
|
||||||
});
|
});
|
||||||
|
|
||||||
return Array.from(cacheSet);
|
return Array.from(cacheSet);
|
||||||
});
|
});
|
||||||
return { getCaches };
|
return { getCaches };
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
import { isNavigationFailure, RouteLocationNormalized, Router } from 'vue-router';
|
import { RouteLocationNormalized, Router } from 'vue-router';
|
||||||
|
|
||||||
import { Modal, notification } from 'ant-design-vue';
|
import { Modal, notification } from 'ant-design-vue';
|
||||||
|
|
||||||
|
|
@ -50,7 +50,7 @@ export function createGuard(router: Router) {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
router.afterEach((to, from, failure) => {
|
router.afterEach((to) => {
|
||||||
// scroll top
|
// scroll top
|
||||||
isHash((to as RouteLocationNormalized & { href: string })?.href) && body.scrollTo(0, 0);
|
isHash((to as RouteLocationNormalized & { href: string })?.href) && body.scrollTo(0, 0);
|
||||||
|
|
||||||
|
|
@ -60,10 +60,6 @@ export function createGuard(router: Router) {
|
||||||
|
|
||||||
// change html title
|
// change html title
|
||||||
to.name !== REDIRECT_NAME && setTitle(t(to.meta.title), globSetting.title);
|
to.name !== REDIRECT_NAME && setTitle(t(to.meta.title), globSetting.title);
|
||||||
|
|
||||||
if (isNavigationFailure(failure)) {
|
|
||||||
console.error('router navigation failed:', failure);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
createPageLoadingGuard(router);
|
createPageLoadingGuard(router);
|
||||||
createProgressGuard(router);
|
createProgressGuard(router);
|
||||||
|
|
|
||||||
|
|
@ -35,8 +35,8 @@ export function setupRouter(app: App<Element>) {
|
||||||
createGuard(router);
|
createGuard(router);
|
||||||
}
|
}
|
||||||
|
|
||||||
router.onError((error) => {
|
// router.onError((error) => {
|
||||||
console.error(error);
|
// console.error(error);
|
||||||
});
|
// });
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@ const permission: AppRouteModule = {
|
||||||
component: () => import('/@/views/demo/level/Menu2.vue'),
|
component: () => import('/@/views/demo/level/Menu2.vue'),
|
||||||
meta: {
|
meta: {
|
||||||
title: 'Menu2',
|
title: 'Menu2',
|
||||||
|
// ignoreKeepAlive: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|
|
||||||
|
|
@ -97,11 +97,13 @@ class Tab extends VuexModule {
|
||||||
const pageCacheSet = new Set<string>();
|
const pageCacheSet = new Set<string>();
|
||||||
this.tabsState.forEach((tab) => {
|
this.tabsState.forEach((tab) => {
|
||||||
const item = getRoute(tab);
|
const item = getRoute(tab);
|
||||||
const needAuth = !item.meta.ignoreAuth;
|
const needCache = !item.meta.ignoreKeepAlive;
|
||||||
|
if (!needCache) return;
|
||||||
|
|
||||||
if (item.meta.affix) {
|
if (item.meta.affix) {
|
||||||
const name = item.name as string;
|
const name = item.name as string;
|
||||||
pageCacheSet.add(name);
|
pageCacheSet.add(name);
|
||||||
} else if (item.matched && needAuth) {
|
} else if (item.matched && needCache) {
|
||||||
const matched = item.matched;
|
const matched = item.matched;
|
||||||
const len = matched.length;
|
const len = matched.length;
|
||||||
|
|
||||||
|
|
@ -115,7 +117,7 @@ class Tab extends VuexModule {
|
||||||
}
|
}
|
||||||
if (i < len - 1) {
|
if (i < len - 1) {
|
||||||
const { meta, name } = matched[i + 1];
|
const { meta, name } = matched[i + 1];
|
||||||
if (meta && (meta.affix || needAuth)) {
|
if (meta && (meta.affix || needCache)) {
|
||||||
const mapList = cacheMap.get(key) || [];
|
const mapList = cacheMap.get(key) || [];
|
||||||
if (!mapList.includes(name as string)) {
|
if (!mapList.includes(name as string)) {
|
||||||
mapList.push(name as string);
|
mapList.push(name as string);
|
||||||
|
|
@ -210,7 +212,6 @@ class Tab extends VuexModule {
|
||||||
@Mutation
|
@Mutation
|
||||||
commitRedoPage() {
|
commitRedoPage() {
|
||||||
const route = router.currentRoute.value;
|
const route = router.currentRoute.value;
|
||||||
|
|
||||||
for (const [key, value] of this.cachedMapState) {
|
for (const [key, value] of this.cachedMapState) {
|
||||||
const index = value.findIndex((item) => item === (route.name as string));
|
const index = value.findIndex((item) => item === (route.name as string));
|
||||||
if (index === -1) {
|
if (index === -1) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue