mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-01-24 18:40:22 +08:00
fix(tabs): close tab without navigation
修复多标签在某些情况下关闭页签不会跳转路由的问题 fixed: #1131
This commit is contained in:
parent
cecdfbaf29
commit
e85649bde2
@ -7,6 +7,7 @@
|
|||||||
- 修复点击遮罩、按下`Esc`键都不能关闭`Modal`的问题
|
- 修复点击遮罩、按下`Esc`键都不能关闭`Modal`的问题
|
||||||
- 修复点击关闭按钮、最大化按钮旁边的空白区域也会导致`Modal`关闭的问题
|
- 修复点击关闭按钮、最大化按钮旁边的空白区域也会导致`Modal`关闭的问题
|
||||||
- **BasicTree** 修复节点插槽不起作用的问题
|
- **BasicTree** 修复节点插槽不起作用的问题
|
||||||
|
- **其它** 修复多标签在某些情况下关闭页签不会跳转路由的问题
|
||||||
|
|
||||||
## 2.7.2(2021-09-14)
|
## 2.7.2(2021-09-14)
|
||||||
|
|
||||||
|
@ -26,6 +26,15 @@ function handleGotoPage(router: Router) {
|
|||||||
go(unref(router.currentRoute).path, true);
|
go(unref(router.currentRoute).path, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getToTarget = (tabItem: RouteLocationNormalized) => {
|
||||||
|
const { params, path, query } = tabItem;
|
||||||
|
return {
|
||||||
|
params: params || {},
|
||||||
|
path,
|
||||||
|
query: query || {},
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
const cacheTab = projectSetting.multiTabsSetting.cache;
|
const cacheTab = projectSetting.multiTabsSetting.cache;
|
||||||
|
|
||||||
export const useMultipleTabStore = defineStore({
|
export const useMultipleTabStore = defineStore({
|
||||||
@ -147,15 +156,6 @@ export const useMultipleTabStore = defineStore({
|
|||||||
},
|
},
|
||||||
|
|
||||||
async closeTab(tab: RouteLocationNormalized, router: Router) {
|
async closeTab(tab: RouteLocationNormalized, router: Router) {
|
||||||
const getToTarget = (tabItem: RouteLocationNormalized) => {
|
|
||||||
const { params, path, query } = tabItem;
|
|
||||||
return {
|
|
||||||
params: params || {},
|
|
||||||
path,
|
|
||||||
query: query || {},
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
const close = (route: RouteLocationNormalized) => {
|
const close = (route: RouteLocationNormalized) => {
|
||||||
const { fullPath, meta: { affix } = {} } = route;
|
const { fullPath, meta: { affix } = {} } = route;
|
||||||
if (affix) {
|
if (affix) {
|
||||||
@ -196,13 +196,36 @@ export const useMultipleTabStore = defineStore({
|
|||||||
toTarget = getToTarget(page);
|
toTarget = getToTarget(page);
|
||||||
}
|
}
|
||||||
close(currentRoute.value);
|
close(currentRoute.value);
|
||||||
replace(toTarget);
|
await replace(toTarget);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Close according to key
|
// Close according to key
|
||||||
async closeTabByKey(key: string, router: Router) {
|
async closeTabByKey(key: string, router: Router) {
|
||||||
const index = this.tabList.findIndex((item) => (item.fullPath || item.path) === key);
|
const index = this.tabList.findIndex((item) => (item.fullPath || item.path) === key);
|
||||||
index !== -1 && this.closeTab(this.tabList[index], router);
|
if (index !== -1) {
|
||||||
|
await this.closeTab(this.tabList[index], router);
|
||||||
|
const { currentRoute, replace } = router;
|
||||||
|
// 检查当前路由是否存在于tabList中
|
||||||
|
const isActivated = this.tabList.findIndex((item) => {
|
||||||
|
return item.fullPath === currentRoute.value.fullPath;
|
||||||
|
});
|
||||||
|
// 如果当前路由不存在于TabList中,尝试切换到其它路由
|
||||||
|
if (isActivated === -1) {
|
||||||
|
let pageIndex;
|
||||||
|
if (index > 0) {
|
||||||
|
pageIndex = index - 1;
|
||||||
|
} else if (index < this.tabList.length - 1) {
|
||||||
|
pageIndex = index + 1;
|
||||||
|
} else {
|
||||||
|
pageIndex = -1;
|
||||||
|
}
|
||||||
|
if (pageIndex >= 0) {
|
||||||
|
const page = this.tabList[index - 1];
|
||||||
|
const toTarget = getToTarget(page);
|
||||||
|
await replace(toTarget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Sort the tabs
|
// Sort the tabs
|
||||||
|
Loading…
Reference in New Issue
Block a user