角色接口 接入

This commit is contained in:
mmc
2026-04-28 15:16:50 +08:00
parent 2a2d40d772
commit b540f842ab
4 changed files with 145 additions and 72 deletions

View File

@@ -26,3 +26,38 @@ export function setTokenAi(token) {
path: "/"
});
}
export const buildTreeFromFlat = (data) => {
const map = {};
const tree = [];
data.forEach(item => {
map[item.menuId] = { ...item, children: [] };
});
data.forEach(item => {
if (item.parentId === 0 || !item.parentId) {
tree.push(map[item.menuId]);
} else {
if (map[item.parentId]) {
map[item.parentId].children.push(map[item.menuId]);
}
}
});
return tree;
};
// 菜单数据转 Tree组件
export const buildPermTree = (treeData) => {
const loop = (list) => {
return list.map(item => {
const node = {
title: item.menuName,
key: item.menuId,
};
if (item.children && item.children.length) {
node.children = loop(item.children);
}
return node;
});
};
return loop(treeData);
};