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