提交
This commit is contained in:
1 parent
e1d6de45a3
commit
5ad07c8cac
616 files changed
+181132
-35125
No files matched your search
@@ -44,6 +44,7 @@ import { LocationQueryRaw, Router } from 'vue-router'
|
||||
import { WorkTab } from '@/types'
|
||||
import { useCommon } from '@/hooks/core/useCommon'
|
||||
import { useMenuStore } from '@/store/modules/menu'
|
||||
import { useSettingStore } from '@/store/modules/setting'
|
||||
import { getFirstSecondLevelMenuPath, isWorkbenchRoute } from '@/utils/navigation/route'
|
||||
|
||||
interface WorktabState {
|
||||
@@ -123,6 +124,54 @@ export const useWorktabStore = defineStore(
|
||||
return '/'
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据路径打开标签页(不依赖路由守卫 setWorktab,用于清空后同路径仍须保留一个标签的场景)
|
||||
*/
|
||||
const ensureTabForPath = (path: string): void => {
|
||||
if (!path || shouldIgnoreTab({ path })) {
|
||||
return
|
||||
}
|
||||
|
||||
let resolved
|
||||
try {
|
||||
resolved = router.resolve(path)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
if (resolved.matched.length === 0 || resolved.meta?.isHideTab) {
|
||||
return
|
||||
}
|
||||
|
||||
const { homePath } = useCommon()
|
||||
const { showWorkTab } = useSettingStore()
|
||||
if (!showWorkTab && resolved.path !== homePath.value) {
|
||||
return
|
||||
}
|
||||
|
||||
const { meta, name, params, query } = resolved
|
||||
openTab({
|
||||
title: meta.title as string,
|
||||
icon: meta.icon as string,
|
||||
path: resolved.path,
|
||||
name: name as string,
|
||||
keepAlive: meta.keepAlive as boolean,
|
||||
params,
|
||||
query: query as LocationQueryRaw,
|
||||
fixedTab: meta.fixedTab as boolean
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签全部关闭后,导航到默认页并确保至少保留一个标签
|
||||
*/
|
||||
const navigateToDefaultWithTab = (): void => {
|
||||
const fallbackPath = resolveEmptyTabsPath()
|
||||
current.value = {}
|
||||
safeRouterPush({ path: fallbackPath })
|
||||
ensureTabForPath(fallbackPath)
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全的路由跳转
|
||||
*/
|
||||
@@ -238,10 +287,9 @@ export const useWorktabStore = defineStore(
|
||||
addKeepAliveExclude(targetTab)
|
||||
}
|
||||
|
||||
// 如果关闭后无标签页,跳转侧栏第一个二级菜单
|
||||
// 如果关闭后无标签页,跳转默认页并保留一个标签
|
||||
if (!hasOpenedTabs.value) {
|
||||
current.value = {}
|
||||
safeRouterPush({ path: resolveEmptyTabsPath() })
|
||||
navigateToDefaultWithTab()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -367,11 +415,8 @@ export const useWorktabStore = defineStore(
|
||||
markTabsToRemove(closableTabs)
|
||||
opened.value = opened.value.filter((tab) => !isTabClosable(tab))
|
||||
|
||||
const fallbackPath = resolveEmptyTabsPath()
|
||||
|
||||
if (!hasOpenedTabs.value) {
|
||||
current.value = {}
|
||||
safeRouterPush({ path: fallbackPath })
|
||||
navigateToDefaultWithTab()
|
||||
return
|
||||
}
|
||||
|
||||
@@ -563,6 +608,8 @@ export const useWorktabStore = defineStore(
|
||||
currentTabIndex,
|
||||
|
||||
// 方法
|
||||
ensureTabForPath,
|
||||
navigateToDefaultWithTab,
|
||||
openTab,
|
||||
removeTab,
|
||||
removeLeft,
|
||||
|
||||
Reference in new issue
Block a user