fix: 菜单分组渲染逻辑 — 相同group合并为一个分组标题
This commit is contained in:
@@ -91,23 +91,26 @@ const filteredMenus = computed(() => {
|
||||
// 按分组组织菜单
|
||||
const menuGroups = computed(() => {
|
||||
const groups: { label: string; items: typeof MENU_ITEMS }[] = []
|
||||
let currentLabel = ''
|
||||
let currentItems: typeof MENU_ITEMS = []
|
||||
const groupMap = new Map<string, typeof MENU_ITEMS>()
|
||||
|
||||
for (const item of filteredMenus.value) {
|
||||
if (item.group) {
|
||||
if (currentItems.length > 0) {
|
||||
groups.push({ label: currentLabel, items: currentItems })
|
||||
}
|
||||
currentLabel = item.group as string
|
||||
currentItems = [item]
|
||||
} else {
|
||||
currentItems.push(item)
|
||||
const label = item.group || ''
|
||||
if (!label) continue
|
||||
if (!groupMap.has(label)) {
|
||||
groupMap.set(label, [])
|
||||
}
|
||||
groupMap.get(label)!.push(item)
|
||||
}
|
||||
if (currentItems.length > 0) {
|
||||
groups.push({ label: currentLabel, items: currentItems })
|
||||
|
||||
// 按出现顺序输出
|
||||
const seen = new Set<string>()
|
||||
for (const item of filteredMenus.value) {
|
||||
const label = item.group || ''
|
||||
if (!label || seen.has(label)) continue
|
||||
seen.add(label)
|
||||
groups.push({ label, items: groupMap.get(label)! })
|
||||
}
|
||||
|
||||
return groups
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user