This commit is contained in:
zlwu committed 2026-08-01 17:29:37 +08:00
1 parent 06956b742b
commit e59b2aa6cb
104 files changed
+653227 -7621

No files matched your search

+102 -1
View File
@@ -1,6 +1,22 @@
import type { AppRouteRecord } from '@/types/router'
import { getFirstMenuPath, getFirstSecondLevelMenuPath, isIframe } from '@/utils/navigation/route'
import { filterSidebarRoutes } from '@/utils/router/sidebar-menu-filter'
import {
filterSidebarRoutes,
isSidebarNavigableRoute
} from '@/utils/router/sidebar-menu-filter'
/** 大面板一行:二级标题 + 三级可点链接 */
export interface PortalMegaPanelRow {
/** 二级菜单(仅展示标题,不可点) */
l2: AppRouteRecord
/** 三级链接(含虚拟三级) */
l3Links: AppRouteRecord[]
}
export interface PortalMegaPanelColumns {
left: PortalMegaPanelRow[]
right: PortalMegaPanelRow[]
}
/** 门户顶栏一级模块展示顺序(与路由注册顺序无关) */
export const PORTAL_TOP_MODULE_ORDER = [
@@ -179,3 +195,88 @@ export function getPortalDefaultPathForRoute(
return getFirstAccessiblePath(module)
}
/**
* 解析二级下的三级可点链接。
* 无子节点且二级自身可导航时,生成与二级同名的虚拟三级(路由继承二级)。
*/
export function resolveMegaPanelL3Links(l2: AppRouteRecord): AppRouteRecord[] {
const children = filterSidebarRoutes(l2.children || [])
if (!children.length) {
if (!isSidebarNavigableRoute(l2)) {
return []
}
return [
{
...l2,
children: undefined,
meta: {
...l2.meta,
title: l2.meta.title
}
}
]
}
const links: AppRouteRecord[] = []
for (const child of children) {
if (isSidebarNavigableRoute(child)) {
links.push(child)
continue
}
const grandChildren = filterSidebarRoutes(child.children || [])
for (const gc of grandChildren) {
if (isSidebarNavigableRoute(gc)) {
links.push(gc)
}
}
}
return links
}
/** 将一级模块下的二三级整理为大面板左右两栏行数据 */
export function buildMegaPanelColumns(
l1Module: AppRouteRecord | undefined
): PortalMegaPanelColumns {
if (!l1Module) {
return { left: [], right: [] }
}
const l2List = filterSidebarRoutes(l1Module.children || [])
const rows: PortalMegaPanelRow[] = []
for (const l2 of l2List) {
const l3Links = resolveMegaPanelL3Links(l2)
if (!l3Links.length) {
continue
}
rows.push({ l2, l3Links })
}
if (!rows.length) {
return { left: [], right: [] }
}
// 仅 1 个二级:单列展示,避免右侧空白
if (rows.length === 1) {
return { left: rows, right: [] }
}
// 左右均分;超出建议可见行数时由面板整体纵向滚动
// 例:4 → 2+2;7 → 4+3;10 → 5+5;12 → 6+6(不再 5+7)
const leftCount = Math.ceil(rows.length / 2)
return {
left: rows.slice(0, leftCount),
right: rows.slice(leftCount)
}
}
/** 判断三级链接是否为当前路由 */
export function isMegaPanelLinkActive(item: AppRouteRecord, routePath: string): boolean {
const activePath = String(routePath)
const itemPath = String(item.meta?.activePath || item.path || '')
if (!itemPath) {
return false
}
return activePath === itemPath || activePath.startsWith(`${itemPath}/`)
}