Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Fedex
/
EcomWeb
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
zhanbo.xu
2025-04-07 17:31:58 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ffe06e8562f7a87846fd232227dd404efa141f3b
ffe06e85
1 parent
285ae2a8
feat: 新增功能
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
41 deletions
src/utils/menuTree.js
src/views/roleConfig/dialog.vue
src/utils/menuTree.js
0 → 100644
View file @
ffe06e8
export
function
buildMenuTree
(
menuList
)
{
// 创建一个映射,用于快速查找菜单项
const
menuMap
=
new
Map
();
const
tree
=
[];
// 首先将所有菜单项放入映射中
menuList
.
forEach
((
menu
)
=>
{
menuMap
.
set
(
menu
.
menuId
,
{
...
menu
,
children
:
[]
});
});
// 构建树形结构
menuList
.
forEach
((
menu
)
=>
{
const
menuItem
=
menuMap
.
get
(
menu
.
menuId
);
if
(
menu
.
parentMenuId
===
0
)
{
// 如果是顶级菜单,直接添加到树中
tree
.
push
(
menuItem
);
}
else
{
// 如果不是顶级菜单,找到其父菜单并添加到父菜单的children中
const
parent
=
menuMap
.
get
(
menu
.
parentMenuId
);
if
(
parent
)
{
parent
.
children
.
push
(
menuItem
);
}
}
});
return
tree
;
}
src/views/roleConfig/dialog.vue
View file @
ffe06e8
...
...
@@ -39,7 +39,7 @@
:data="treeData"
show-checkbox
default-expand-all
node-key="
i
d"
node-key="
menuI
d"
:default-expanded-keys="expandedKeys"
:default-checked-keys="checkedKeys"
:props="defaultProps"
...
...
@@ -125,7 +125,7 @@ export default {
},
defaultProps: {
children: "children",
label: "
label
",
label: "
menuName
",
},
searchForm: {},
loadings: {
...
...
@@ -137,51 +137,81 @@ export default {
};
},
methods: {
buildMenuTree(menuList) {
// 创建一个映射,用于快速查找菜单项
const menuMap = new Map();
const tree = [];
// 首先将所有菜单项放入映射中
menuList.forEach((menu) => {
menuMap.set(menu.menuId, { ...menu, children: [] });
});
// 构建树形结构
menuList.forEach((menu) => {
const menuItem = menuMap.get(menu.menuId);
if (menu.parentMenuId === 0) {
// 如果是顶级菜单,直接添加到树中
tree.push(menuItem);
} else {
// 如果不是顶级菜单,找到其父菜单并添加到父菜单的children中
const parent = menuMap.get(menu.parentMenuId);
if (parent) {
parent.children.push(menuItem);
}
}
});
return tree;
},
//查询菜单数据
searchTreeData() {
this.loadings.dialogLoading = true;
getRouters()
.then((res) => {
if (res.code === "200") {
let arr = [];
res.data.forEach((item) => {
let status = true;
if (item.parentMenuId == 0) {
let obj = {
id: item.menuId,
label: item.menuName,
children: [],
};
arr.forEach((menuItem) => {
if (menuItem.id == item.menuId) {
status = false;
menuItem.label = item.menuName;
}
});
if (status) {
arr.push(obj);
}
} else {
let obj = {
id: item.menuId,
label: item.menuName,
};
arr.forEach((menuItem) => {
if (menuItem.id == item.parentMenuId) {
status = false;
menuItem.children.push(obj);
}
});
if (status) {
arr.push({
id: item.parentMenuId,
label: "",
children: [obj],
});
}
}
});
this.treeData = arr;
console.log(this.buildMenuTree(res.data));
// console.log(res.data);
// let arr = [];
// res.data.forEach((item) => {
// let status = true;
// if (item.parentMenuId == 0) {
// let obj = {
// id: item.menuId,
// label: item.menuName,
// children: [],
// };
// arr.forEach((menuItem) => {
// if (menuItem.id == item.menuId) {
// status = false;
// menuItem.label = item.menuName;
// }
// });
// if (status) {
// arr.push(obj);
// }
// } else {
// let obj = {
// id: item.menuId,
// label: item.menuName,
// };
// arr.forEach((menuItem) => {
// if (menuItem.id == item.parentMenuId) {
// status = false;
// menuItem.children.push(obj);
// }
// });
// if (status) {
// arr.push({
// id: item.parentMenuId,
// label: "",
// children: [obj],
// });
// }
// }
// });
this.treeData = this.buildMenuTree(res.data);
} else {
this.alertWarningMsg(res.message);
}
...
...
Please
register
or
login
to post a comment