fix
This commit is contained in:
parent
1eff524d55
commit
e135e6b6e3
|
@ -124,6 +124,7 @@ export default {
|
||||||
const data = {
|
const data = {
|
||||||
path: path.resolve(basePath, route.path),
|
path: path.resolve(basePath, route.path),
|
||||||
title: route.meta && route.meta.title
|
title: route.meta && route.meta.title
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// recursive child routes
|
// recursive child routes
|
||||||
|
@ -149,6 +150,7 @@ export default {
|
||||||
},
|
},
|
||||||
handleAddRole() {
|
handleAddRole() {
|
||||||
this.role = Object.assign({}, defaultRole)
|
this.role = Object.assign({}, defaultRole)
|
||||||
|
this.$refs.tree.setCheckedNodes([])
|
||||||
this.dialogType = 'new'
|
this.dialogType = 'new'
|
||||||
this.dialogVisible = true
|
this.dialogVisible = true
|
||||||
},
|
},
|
||||||
|
@ -180,17 +182,34 @@ export default {
|
||||||
})
|
})
|
||||||
.catch(err => { console.error(err) })
|
.catch(err => { console.error(err) })
|
||||||
},
|
},
|
||||||
|
generateTree(routes, basePath = '/', checkedKeys) {
|
||||||
|
const res = []
|
||||||
|
|
||||||
|
for (const route of routes) {
|
||||||
|
const routePath = path.resolve(basePath, route.path)
|
||||||
|
|
||||||
|
// recursive child routes
|
||||||
|
if (route.children) {
|
||||||
|
route.children = this.generateTree(route.children, routePath, checkedKeys)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkedKeys.includes(routePath) || (route.children && route.children.length >= 1)) {
|
||||||
|
res.push(route)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
},
|
||||||
async confirmRole() {
|
async confirmRole() {
|
||||||
const isEdit = this.dialogType === 'edit'
|
const isEdit = this.dialogType === 'edit'
|
||||||
|
|
||||||
// TODO:refactor
|
const checkedKeys = this.$refs.tree.getCheckedKeys()
|
||||||
// this.role.routes = this.$refs.tree.getCheckedNodes()
|
this.role.routes = this.generateTree(deepClone(this.serviceRoutes), '/', checkedKeys)
|
||||||
|
|
||||||
if (isEdit) {
|
if (isEdit) {
|
||||||
await updateRole(this.role.key, this.role)
|
await updateRole(this.role.key, this.role)
|
||||||
for (let index = 0; index < this.rolesList.length; index++) {
|
for (let index = 0; index < this.rolesList.length; index++) {
|
||||||
if (this.rolesList[index].key === this.role.key) {
|
if (this.rolesList[index].key === this.role.key) {
|
||||||
this.rolesList.splice(index, 1, this.role)
|
this.rolesList.splice(index, 1, Object.assign({}, this.role))
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -199,7 +218,7 @@ export default {
|
||||||
this.rolesList.push(this.role)
|
this.rolesList.push(this.role)
|
||||||
}
|
}
|
||||||
|
|
||||||
const { description, key, name, routes } = this.role
|
const { description, key, name } = this.role
|
||||||
this.dialogVisible = false
|
this.dialogVisible = false
|
||||||
this.$notify({
|
this.$notify({
|
||||||
title: 'Success',
|
title: 'Success',
|
||||||
|
@ -208,7 +227,6 @@ export default {
|
||||||
<div>Role Key: ${key}</div>
|
<div>Role Key: ${key}</div>
|
||||||
<div>Role Nmae: ${name}</div>
|
<div>Role Nmae: ${name}</div>
|
||||||
<div>Description: ${description}</div>
|
<div>Description: ${description}</div>
|
||||||
<div>Routes: ${routes.join(',')}</div>
|
|
||||||
`,
|
`,
|
||||||
type: 'success'
|
type: 'success'
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in New Issue