角色接口 接入
This commit is contained in:
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user