From c232663fefd274bb1c170f9f430374ae95fa8e54 Mon Sep 17 00:00:00 2001 From: YaChengMu <1140049363@qq.com> Date: Thu, 8 Apr 2021 09:15:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=8F=9C=E5=8D=95=E6=8E=88?= =?UTF-8?q?=E6=9D=83=E6=94=AF=E6=8C=81=E7=BA=A7=E8=81=94=E9=80=89=E6=8B=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/views/system/role/roleMenuForm.vue | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/frontend/src/views/system/role/roleMenuForm.vue b/frontend/src/views/system/role/roleMenuForm.vue index 364efa7d4..c570c3115 100644 --- a/frontend/src/views/system/role/roleMenuForm.vue +++ b/frontend/src/views/system/role/roleMenuForm.vue @@ -19,7 +19,6 @@ v-model="checkedKeys" multiple checkable - checkStrictly :auto-expand-parent="autoExpandParent" :expanded-keys="expandedKeys" :tree-data="menuTreeData" @@ -56,6 +55,7 @@ menuTreeData: [], expandedKeys: [], checkedKeys: [], + halfCheckedKeys: [], visible: false, confirmLoading: false, formLoading: true, @@ -102,12 +102,14 @@ sysRoleOwnMenu({ id: record.id }).then((res) => { if (res.success) { this.checkedKeys = res.data + this.findAllChildren(this.menuTreeData) } this.formLoading = false }) }, - treeCheck (checkKeys) { + treeCheck (checkKeys, event) { + this.halfCheckedKeys = event.halfCheckedKeys }, onExpand (expandedKeys) { this.expandedKeys = expandedKeys @@ -125,7 +127,7 @@ this.confirmLoading = true validateFields((errors, values) => { if (!errors) { - sysRoleGrantMenu({ id: this.roleEntity.id, grantMenuIdList: this.checkedKeys.checked }).then((res) => { + sysRoleGrantMenu({ id: this.roleEntity.id, grantMenuIdList: this.checkedKeys.concat(this.halfCheckedKeys) }).then((res) => { if (res.success) { this.$message.success('授权成功') this.confirmLoading = false @@ -148,6 +150,19 @@ // 清空已展开的 this.expandedKeys = [] this.visible = false + }, + // 遍历树形然后获取到对父节点进行移除,使用子节点,而且将父节点加入到mainMenuList + findAllChildren(data) { + data.forEach((item, index) => { + if (item.children.length !== 0) { + for (let i = 0; i < this.checkedKeys.length; i++) { + if (item.id === this.checkedKeys[i]) { + this.checkedKeys.splice(i, 1) + } + } + this.findAllChildren(item.children) + } + }) } } } -- Gitee