21 lines
642 B
TypeScript
21 lines
642 B
TypeScript
import type { AppRouteRecord } from '@/types/router'
|
|
import { classifyMenuNode, getVisibleChildren } from '@/utils/router/leaf-group'
|
|
|
|
export function sumLeafBadgeCounts(
|
|
item: AppRouteRecord,
|
|
getCount: (menuCode: string) => number
|
|
): string {
|
|
let total = 0
|
|
const visit = (node: AppRouteRecord) => {
|
|
if (node.meta?.isHide) return
|
|
if (classifyMenuNode(node) === 'leaf') {
|
|
const code = String(node.meta?.menuCode || '').trim()
|
|
if (code) total += Number(getCount(code) || 0)
|
|
return
|
|
}
|
|
for (const child of getVisibleChildren(node)) visit(child)
|
|
}
|
|
visit(item)
|
|
return total > 0 ? String(total) : ''
|
|
}
|