Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

权限模块添加角色树形菜单选中状态无法正确保存,代码role.vue中的generateArr方法有bug #3862

Open
xufeng888 opened this issue Nov 6, 2021 · 3 comments

Comments

@xufeng888
Copy link

Bug report(问题描述)

Steps to reproduce(问题复现步骤)

Screenshot or Gif(截图或动态图)

Link to minimal reproduction(最小可在线还原demo)

Other relevant information(格外信息)

  • Your OS:
  • Node.js version:
  • vue-element-admin version:
@jiefangen
Copy link

我也遇到了这个问题, 网上没找到解决方案, 尝试解决一下吧

@jiefangen
Copy link

问题已解决, 根本原因是使用path路径作为树形控件的唯一ID, 而vue系统的路由菜单结构是拼接而来的. 解决方案: 树形控件绑定key修改为: node-key="id"; generateRoutes方法增加唯一id: const data = {
id: route.id,
path: path.resolve(basePath, route.path),
title: route.meta && route.meta.title
}
调整检查节点方法
generateCheckedKeys(routes) {
let checkedKeys = []
routes.forEach(route => {
checkedKeys.push(route.id)
if (route.children) {
const temp = this.generateCheckedKeys(route.children)
if (temp.length > 0) {
checkedKeys = [...checkedKeys, ...temp]
}
}
})
return checkedKeys
},
handleEdit方法调整 const checkedKeys = this.generateCheckedKeys(routes)
this.$refs.tree.setCheckedKeys(checkedKeys)

最后generateTree方法
generateTree(routes, basePath = '/', checkedKeys) {
const res = []
for (const route of routes) {
// const routePath = path.resolve(basePath, route.path)
const routeId = route.id
// recursive child routes
if (route.children) {
route.children = this.generateTree(route.children, routeId, checkedKeys)
}
if (checkedKeys.includes(routeId) || (route.children && route.children.length >= 1)) {
res.push(route)
}
}
return res
},
如有不太清晰的点, 可直接看我的源文件:
https://github.com/jiefangen/frontend-vue/blob/main/bamboo-admin-v1/src/views/system/role/index.vue

@jiefangen
Copy link

image 补充一下修复后的截图证明, 之前是这种选中的情况下, 再次打开时·菜单 1-2-2·节点未渲染选中

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants