From e135e6b6e32328a7591b2498b0953a33eb3fc5dd Mon Sep 17 00:00:00 2001 From: Pan Date: Fri, 15 Mar 2019 17:49:48 +0800 Subject: [PATCH] fix --- src/views/permission/role.vue | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/views/permission/role.vue b/src/views/permission/role.vue index 6872129a..9b4a965d 100644 --- a/src/views/permission/role.vue +++ b/src/views/permission/role.vue @@ -124,6 +124,7 @@ export default { const data = { path: path.resolve(basePath, route.path), title: route.meta && route.meta.title + } // recursive child routes @@ -149,6 +150,7 @@ export default { }, handleAddRole() { this.role = Object.assign({}, defaultRole) + this.$refs.tree.setCheckedNodes([]) this.dialogType = 'new' this.dialogVisible = true }, @@ -180,17 +182,34 @@ export default { }) .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() { const isEdit = this.dialogType === 'edit' - // TODO:refactor - // this.role.routes = this.$refs.tree.getCheckedNodes() + const checkedKeys = this.$refs.tree.getCheckedKeys() + this.role.routes = this.generateTree(deepClone(this.serviceRoutes), '/', checkedKeys) if (isEdit) { await updateRole(this.role.key, this.role) for (let index = 0; index < this.rolesList.length; index++) { 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 } } @@ -199,7 +218,7 @@ export default { this.rolesList.push(this.role) } - const { description, key, name, routes } = this.role + const { description, key, name } = this.role this.dialogVisible = false this.$notify({ title: 'Success', @@ -208,7 +227,6 @@ export default {
Role Key: ${key}
Role Nmae: ${name}
Description: ${description}
-
Routes: ${routes.join(',')}
`, type: 'success' })