Merge pull request #272 from linjiangl/main
chore(projects): When tab is switched, keep the page without refreshing
This commit is contained in:
commit
1e6d52357e
@ -11,6 +11,7 @@ const management: AuthRoute.Route = {
|
|||||||
title: '权限管理',
|
title: '权限管理',
|
||||||
i18nTitle: 'routes.management.auth',
|
i18nTitle: 'routes.management.auth',
|
||||||
requiresAuth: true,
|
requiresAuth: true,
|
||||||
|
keepAlive: true,
|
||||||
icon: 'ic:baseline-security'
|
icon: 'ic:baseline-security'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -22,6 +23,7 @@ const management: AuthRoute.Route = {
|
|||||||
title: '角色管理',
|
title: '角色管理',
|
||||||
i18nTitle: 'routes.management.role',
|
i18nTitle: 'routes.management.role',
|
||||||
requiresAuth: true,
|
requiresAuth: true,
|
||||||
|
keepAlive: true,
|
||||||
icon: 'carbon:user-role'
|
icon: 'carbon:user-role'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -33,6 +35,7 @@ const management: AuthRoute.Route = {
|
|||||||
title: '用户管理',
|
title: '用户管理',
|
||||||
i18nTitle: 'routes.management.user',
|
i18nTitle: 'routes.management.user',
|
||||||
requiresAuth: true,
|
requiresAuth: true,
|
||||||
|
keepAlive: true,
|
||||||
icon: 'ic:round-manage-accounts'
|
icon: 'ic:round-manage-accounts'
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -44,6 +47,7 @@ const management: AuthRoute.Route = {
|
|||||||
title: '路由管理',
|
title: '路由管理',
|
||||||
i18nTitle: 'routes.management.route',
|
i18nTitle: 'routes.management.route',
|
||||||
requiresAuth: true,
|
requiresAuth: true,
|
||||||
|
keepAlive: true,
|
||||||
icon: 'material-symbols:route'
|
icon: 'material-symbols:route'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
|
import { nextTick } from 'vue';
|
||||||
import type { RouteLocationNormalizedLoaded, Router } from 'vue-router';
|
import type { RouteLocationNormalizedLoaded, Router } from 'vue-router';
|
||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
|
import { useRouteStore, useAppStore } from '@/store';
|
||||||
import { useRouterPush } from '@/composables';
|
import { useRouterPush } from '@/composables';
|
||||||
import { localStg } from '@/utils';
|
import { localStg } from '@/utils';
|
||||||
import { useThemeStore } from '../theme';
|
import { useThemeStore } from '../theme';
|
||||||
@ -121,6 +123,21 @@ export const useTabStore = defineStore('tab-store', {
|
|||||||
async removeTab(fullPath: string) {
|
async removeTab(fullPath: string) {
|
||||||
const { routerPush } = useRouterPush(false);
|
const { routerPush } = useRouterPush(false);
|
||||||
|
|
||||||
|
// 清除keepAlive缓存
|
||||||
|
const closeTabIndex = this.tabs.findIndex(tab => tab.fullPath === fullPath);
|
||||||
|
if (closeTabIndex !== -1) {
|
||||||
|
const appStore = useAppStore();
|
||||||
|
const routeStore = useRouteStore();
|
||||||
|
const closeTabName = this.tabs[closeTabIndex].name as AuthRoute.AllRouteKey;
|
||||||
|
|
||||||
|
routeStore.removeCacheRoute(closeTabName);
|
||||||
|
appStore.reloadPage();
|
||||||
|
|
||||||
|
nextTick(() => {
|
||||||
|
routeStore.addCacheRoute(closeTabName);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const isActive = this.activeTab === fullPath;
|
const isActive = this.activeTab === fullPath;
|
||||||
const updateTabs = this.tabs.filter(tab => tab.fullPath !== fullPath);
|
const updateTabs = this.tabs.filter(tab => tab.fullPath !== fullPath);
|
||||||
if (!isActive) {
|
if (!isActive) {
|
||||||
|
Loading…
Reference in New Issue
Block a user