feat: add demo for modify menu badge data

This commit is contained in:
Netfan
2024-12-16 12:44:07 +08:00
parent f6faeb034e
commit 0f756503ff
5 changed files with 135 additions and 2 deletions

View File

@@ -41,6 +41,25 @@ interface AccessState {
*/
export const useAccessStore = defineStore('core-access', {
actions: {
getMenuByPath(path: string) {
function findMenu(
menus: MenuRecordRaw[],
path: string,
): MenuRecordRaw | undefined {
for (const menu of menus) {
if (menu.path === path) {
return menu;
}
if (menu.children) {
const matched = findMenu(menu.children, path);
if (matched) {
return matched;
}
}
}
}
return findMenu(this.accessMenus, path);
},
setAccessCodes(codes: string[]) {
this.accessCodes = codes;
},