提交
This commit is contained in:
1 parent
e6072457fd
commit
be4fab78e1
578 files changed
+174415
-214
No files matched your search
@@ -31,7 +31,7 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
import { AppRouteRecord } from '@/types/router'
|
||||
import { getFirstMenuPath } from '@/utils'
|
||||
import { getFirstMenuPath, getFirstSecondLevelMenuPath } from '@/utils'
|
||||
import { HOME_PAGE_PATH } from '@/router'
|
||||
|
||||
/**
|
||||
@@ -54,7 +54,9 @@ export const useMenuStore = defineStore('menuStore', () => {
|
||||
*/
|
||||
const setMenuList = (list: AppRouteRecord[]) => {
|
||||
menuList.value = list
|
||||
setHomePath(HOME_PAGE_PATH || getFirstMenuPath(list))
|
||||
setHomePath(
|
||||
HOME_PAGE_PATH || getFirstSecondLevelMenuPath(list) || getFirstMenuPath(list)
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -43,6 +43,11 @@ import { router } from '@/router'
|
||||
import { LocationQueryRaw, Router } from 'vue-router'
|
||||
import { WorkTab } from '@/types'
|
||||
import { useCommon } from '@/hooks/core/useCommon'
|
||||
import { useMenuStore } from '@/store/modules/menu'
|
||||
import {
|
||||
getFirstSecondLevelMenuPath,
|
||||
isWorkbenchRoute
|
||||
} from '@/utils/navigation/route'
|
||||
|
||||
interface WorktabState {
|
||||
current: Partial<WorkTab>
|
||||
@@ -94,9 +99,33 @@ export const useWorktabStore = defineStore(
|
||||
* `/system` 仅用于承载与重定向,真实标签页为其子路由(如 `/system/tenant`)。
|
||||
*/
|
||||
const shouldIgnoreTab = (tab: Partial<WorkTab>): boolean => {
|
||||
return tab.path === '/system'
|
||||
if (tab.path === '/system') {
|
||||
return true
|
||||
}
|
||||
if (isWorkbenchRoute(tab.path)) {
|
||||
return true
|
||||
}
|
||||
const title = String(tab.title ?? tab.customTitle ?? '')
|
||||
return title === '工作台' || title === 'menus.dashboard.console'
|
||||
}
|
||||
|
||||
/**
|
||||
* 标签全部关闭后的默认落点:侧栏第一个二级菜单(无则回退首页路径)
|
||||
*/
|
||||
const resolveEmptyTabsPath = (): string => {
|
||||
const menuStore = useMenuStore()
|
||||
const { homePath } = useCommon()
|
||||
const fromMenu = getFirstSecondLevelMenuPath(menuStore.menuList)
|
||||
if (fromMenu) {
|
||||
return fromMenu
|
||||
}
|
||||
const home = homePath.value
|
||||
if (home && !isWorkbenchRoute(home)) {
|
||||
return home
|
||||
}
|
||||
return '/'
|
||||
}
|
||||
|
||||
/**
|
||||
* 安全的路由跳转
|
||||
*/
|
||||
@@ -212,14 +241,10 @@ export const useWorktabStore = defineStore(
|
||||
addKeepAliveExclude(targetTab)
|
||||
}
|
||||
|
||||
const { homePath } = useCommon()
|
||||
|
||||
// 如果关闭后无标签页,跳转首页
|
||||
// 如果关闭后无标签页,跳转侧栏第一个二级菜单
|
||||
if (!hasOpenedTabs.value) {
|
||||
if (path !== homePath.value) {
|
||||
current.value = {}
|
||||
safeRouterPush({ path: homePath.value })
|
||||
}
|
||||
current.value = {}
|
||||
safeRouterPush({ path: resolveEmptyTabsPath() })
|
||||
return
|
||||
}
|
||||
|
||||
@@ -335,40 +360,25 @@ export const useWorktabStore = defineStore(
|
||||
* 关闭所有可关闭的标签页
|
||||
*/
|
||||
const removeAll = (): void => {
|
||||
const { homePath } = useCommon()
|
||||
const hasFixedTabs = opened.value.some((tab) => tab.fixedTab)
|
||||
|
||||
// 获取可关闭的标签页
|
||||
const closableTabs = opened.value.filter((tab) => {
|
||||
if (!isTabClosable(tab)) return false
|
||||
// 如果有固定标签,则所有可关闭的都可以关闭;否则保留首页
|
||||
return hasFixedTabs || tab.path !== homePath.value
|
||||
})
|
||||
const closableTabs = opened.value.filter(isTabClosable)
|
||||
|
||||
if (closableTabs.length === 0) {
|
||||
console.warn('没有可关闭的标签页')
|
||||
return
|
||||
}
|
||||
|
||||
// 标记为缓存排除
|
||||
markTabsToRemove(closableTabs)
|
||||
opened.value = opened.value.filter((tab) => !isTabClosable(tab))
|
||||
|
||||
// 保留不可关闭的标签页和首页(当没有固定标签时)
|
||||
opened.value = opened.value.filter((tab) => {
|
||||
return !isTabClosable(tab) || (!hasFixedTabs && tab.path === homePath.value)
|
||||
})
|
||||
const fallbackPath = resolveEmptyTabsPath()
|
||||
|
||||
// 处理激活状态
|
||||
if (!hasOpenedTabs.value) {
|
||||
current.value = {}
|
||||
safeRouterPush({ path: homePath.value })
|
||||
safeRouterPush({ path: fallbackPath })
|
||||
return
|
||||
}
|
||||
|
||||
// 选择激活的标签页:优先首页,其次第一个可用标签
|
||||
const homeTab = opened.value.find((tab) => tab.path === homePath.value)
|
||||
const targetTab = homeTab || opened.value[0]
|
||||
|
||||
const targetTab = opened.value[0]
|
||||
current.value = targetTab
|
||||
safeRouterPush(targetTab)
|
||||
}
|
||||
@@ -481,6 +491,14 @@ export const useWorktabStore = defineStore(
|
||||
} else if (!isCurrentValid) {
|
||||
current.value = {}
|
||||
}
|
||||
|
||||
const activePath = routerInstance.currentRoute.value.path
|
||||
if (isWorkbenchRoute(activePath) || shouldIgnoreTab(current.value)) {
|
||||
const fallback = resolveEmptyTabsPath()
|
||||
if (fallback && fallback !== activePath) {
|
||||
safeRouterPush({ path: fallback })
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('验证工作台标签页失败:', error)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user