This commit is contained in:
zlwu committed 2026-05-20 09:28:36 +08:00
1 parent e6072457fd
commit be4fab78e1
578 files changed
+174415 -214

No files matched your search

+72 -6
View File
@@ -23,12 +23,44 @@
*/
import { AppRouteRecord } from '@/types'
import { filterSidebarRoutes } from '@/utils/router/sidebar-menu-filter'
// 检查是否为 iframe 路由
export function isIframe(url: string): boolean {
return url.startsWith('/outside/iframe/')
}
const WORKBENCH_PATH_RE = /\/console$|\/dashboard\/console(\/|$)/
/** 是否为已废弃/不需展示标签的「工作台」路由 */
export function isWorkbenchRoute(path?: string): boolean {
if (!path?.trim()) {
return false
}
const normalized = path.replace(/\/+$/, '') || '/'
return WORKBENCH_PATH_RE.test(normalized) || normalized === '/console'
}
/** 菜单项是否为工作台(侧栏可保留,标签栏与默认落点需排除) */
export function isWorkbenchMenuItem(menuItem: AppRouteRecord): boolean {
if (isWorkbenchRoute(menuItem.path)) {
return true
}
const component = String(menuItem.component ?? '')
if (component.includes('/dashboard/console')) {
return true
}
if (menuItem.meta?.menuCode === 'dashboard:console') {
return true
}
const name = String(menuItem.name ?? '')
if (name === 'Console' || name === 'console') {
return true
}
const title = String(menuItem.meta?.title ?? '')
return title === '工作台' || title === 'menus.dashboard.console'
}
/**
* 判断菜单项是否可作为默认导航落点
* 隐藏的全屏页面虽然不展示在菜单中,但仍然可能是合法首页。
@@ -57,29 +89,63 @@ const normalizePath = (path: string): string => {
/**
* 递归获取菜单的第一个有效路径
* @param menuList 菜单列表
* @param parentPath 父级路径前缀(内部递归使用)
* @returns 第一个有效路径,如果没有找到则返回空字符串
*/
export const getFirstMenuPath = (menuList: AppRouteRecord[]): string => {
export const getFirstMenuPath = (menuList: AppRouteRecord[], parentPath = ''): string => {
if (!Array.isArray(menuList) || menuList.length === 0) {
return ''
}
for (const menuItem of menuList) {
if (!isNavigableMenuItem(menuItem)) {
if (!isNavigableMenuItem(menuItem) || isWorkbenchMenuItem(menuItem)) {
continue
}
// 如果有子菜单,优先查找子菜单
const currentFullPath = menuItem.path!.startsWith('/')
? menuItem.path!
: parentPath
? `${parentPath}/${menuItem.path!}`
: normalizePath(menuItem.path!)
if (menuItem.children?.length) {
const childPath = getFirstMenuPath(menuItem.children)
const childPath = getFirstMenuPath(menuItem.children, currentFullPath)
if (childPath) {
return childPath
}
}
// 返回当前菜单项的标准化路径
return normalizePath(menuItem.path!)
return currentFullPath.startsWith('/') ? currentFullPath : `/${currentFullPath}`
}
return ''
}
/**
* 获取侧栏第一个二级菜单对应的路由路径(与 SidebarSubmenu level=1 一致)
* 若不存在二级结构则回退到第一个可导航菜单路径
*/
export const getFirstSecondLevelMenuPath = (menuList: AppRouteRecord[]): string => {
const filtered = filterSidebarRoutes(menuList)
if (!filtered.length) {
return ''
}
for (const topItem of filtered) {
const children = topItem.children ? filterSidebarRoutes(topItem.children) : []
if (!children.length) {
continue
}
const topPath = topItem.path!.startsWith('/')
? topItem.path!
: normalizePath(topItem.path!)
const childPath = getFirstMenuPath(children, topPath)
if (childPath) {
return childPath
}
}
return getFirstMenuPath(filtered)
}
+4 -1
View File
@@ -23,7 +23,7 @@
*/
import { useWorktabStore } from '@/store/modules/worktab'
import { RouteLocationNormalized } from 'vue-router'
import { isIframe } from './route'
import { isIframe, isWorkbenchRoute } from './route'
import { useSettingStore } from '@/store/modules/setting'
import { IframeRouteManager } from '@/router/core'
import { useCommon } from '@/hooks/core/useCommon'
@@ -35,6 +35,9 @@ import { useCommon } from '@/hooks/core/useCommon'
export const setWorktab = (to: RouteLocationNormalized): void => {
const worktabStore = useWorktabStore()
const { meta, path, name, params, query } = to
if (isWorkbenchRoute(path)) {
return
}
if (!meta.isHideTab) {
// 如果是 iframe 页面,则特殊处理工作标签页
if (isIframe(path)) {