From 107e9018535f828092ceeb21723ee16899956698 Mon Sep 17 00:00:00 2001 From: zhangdaihao Date: Sun, 20 Oct 2019 22:49:11 +0800 Subject: [PATCH] =?UTF-8?q?JeecgBoot=202.1.1=20=E4=BB=A3=E7=A0=81=E7=94=9F?= =?UTF-8?q?=E6=88=90=E5=99=A8AI=E7=89=88=E6=9C=AC=E5=8F=91=E5=B8=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../views/system/modules/UserRoleModal.vue | 56 +++++++------------ 1 file changed, 20 insertions(+), 36 deletions(-) diff --git a/ant-design-vue-jeecg/src/views/system/modules/UserRoleModal.vue b/ant-design-vue-jeecg/src/views/system/modules/UserRoleModal.vue index 553b8a97..29c4d38d 100644 --- a/ant-design-vue-jeecg/src/views/system/modules/UserRoleModal.vue +++ b/ant-design-vue-jeecg/src/views/system/modules/UserRoleModal.vue @@ -31,10 +31,8 @@
- 全部勾选 取消全选 展开所有 @@ -70,11 +68,10 @@ treeData: [], defaultCheckedKeys:[], checkedKeys:[], - halfCheckedKeys:[], expandedKeysss:[], allTreeKeys:[], autoExpandParent: true, - checkStrictly: false, + checkStrictly: true, title:"角色权限配置", visible: false, loading: false, @@ -88,10 +85,12 @@ } this.$refs.datarule.show(this.selectedKeys[0],this.roleId) }, - onCheck (checkedKeys, { halfCheckedKeys }) { - // 保存选中的和半选中的,后面保存的时候合并提交 - this.checkedKeys = checkedKeys - this.halfCheckedKeys = halfCheckedKeys + onCheck (o) { + if(this.checkStrictly){ + this.checkedKeys = o.checked; + }else{ + this.checkedKeys = o + } }, show(roleId){ this.roleId=roleId @@ -122,18 +121,24 @@ this.checkedKeys = this.allTreeKeys }, cancelCheckALL () { + //this.checkedKeys = this.defaultCheckedKeys this.checkedKeys = [] }, + switchCheckStrictly (v) { + if(v==1){ + this.checkStrictly = false + }else if(v==2){ + this.checkStrictly = true + } + }, handleCancel () { this.close() }, handleSubmit(){ let that = this; - let checkedKeys = [...that.checkedKeys, ...that.halfCheckedKeys] - const permissionIds = checkedKeys.join(",") let params = { roleId:that.roleId, - permissionIds, + permissionIds:that.checkedKeys.join(","), lastpermissionIds:that.defaultCheckedKeys.join(","), }; that.loading = true; @@ -150,15 +155,6 @@ } }) }, - convertTreeListToKeyLeafPairs(treeList, keyLeafPair = []) { - for(const {key, isLeaf, children} of treeList) { - keyLeafPair.push({key, isLeaf}) - if(children && children.length > 0) { - this.convertTreeListToKeyLeafPairs(children, keyLeafPair) - } - } - return keyLeafPair; - }, }, watch: { visible () { @@ -166,23 +162,11 @@ queryTreeListForRole().then((res) => { this.treeData = res.result.treeList this.allTreeKeys = res.result.ids - const keyLeafPairs = this.convertTreeListToKeyLeafPairs(this.treeData) queryRolePermission({roleId:this.roleId}).then((res)=>{ - // 过滤出 leaf node 即可,即选中的 - // Tree组件中checkStrictly默认为false的时候,选中子节点,父节点会自动设置选中或半选中 - // 保存 checkedKeys 以及 halfCheckedKeys 以便于未做任何操作时提交表单数据 - const checkedKeys = [...res.result].filter(key => { - const keyLeafPair = keyLeafPairs.filter(item => item.key === key)[0] - return keyLeafPair && keyLeafPair.isLeaf - }) - const halfCheckedKeys = [...res.result].filter(key => { - const keyLeafPair = keyLeafPairs.filter(item => item.key === key)[0] - return keyLeafPair && !keyLeafPair.isLeaf - }) - this.checkedKeys = [...checkedKeys]; - this.halfCheckedKeys = [...halfCheckedKeys] - this.defaultCheckedKeys = [...halfCheckedKeys, ...checkedKeys]; - this.expandedKeysss = this.allTreeKeys; + this.checkedKeys = [...res.result]; + this.defaultCheckedKeys = [...res.result]; + this.expandedKeysss = this.allTreeKeys; + //console.log(this.defaultCheckedKeys) }) }) } -- GitLab